// #target: macos-x64
module test;
import std::io;

fn void test(int x)
{
	$typeof(&$$FUNCTION) ptr = &$$FUNCTION;
	io::printfn("%d", x);
	if (x > 0) ptr(x - 1);
}

fn void main()
{
	test(10);
}

/* #expect: test.ll

define void @test.test(i32 %0) #0 {
entry:
  %ptr = alloca ptr, align 8
  %varargslots = alloca [1 x %any], align 16
  %taddr = alloca i32, align 4
  %retparam = alloca i64, align 8
  store ptr @test.test, ptr %ptr, align 8
  store i32 %0, ptr %taddr, align 4
  %1 = insertvalue %any undef, ptr %taddr, 0
  %2 = insertvalue %any %1, i64 ptrtoint (ptr @"$ct.int" to i64), 1
  store %any %2, ptr %varargslots, align 16
  %3 = call i64 @std.io.printfn(ptr %retparam, ptr @.str, i64 2, ptr %varargslots, i64 1)
  %gt = icmp sgt i32 %0, 0
  br i1 %gt, label %if.then, label %if.exit

if.then:                                          ; preds = %entry
  %4 = load ptr, ptr %ptr, align 8
  %sub = sub i32 %0, 1
  call void %4(i32 %sub)
  br label %if.exit

if.exit:                                          ; preds = %if.then, %entry
  ret void
}