// #target: macos-x64
module test;

fn void test2() {}
fn void testA() {}
fn void testB() {}
fn void test3() {}

fn int main(int argc, char** argv)
{
	int a = 0;
    while (a)
    {
	    defer test2();
	    defer
	    {
	       testA();
	       testB();
	    }
        if (argc == 1) break;
        test3();
    }
    return 0;
}

/* #expect: test.ll

define i32 @main(i32 %0, ptr %1) #0 {
entry:
  %a = alloca i32, align 4
  store i32 0, ptr %a, align 4
  br label %loop.cond

loop.cond:                                        ; preds = %if.exit, %entry
  %2 = load i32, ptr %a, align 4
  %i2b = icmp ne i32 %2, 0
  br i1 %i2b, label %loop.body, label %loop.exit

loop.body:                                        ; preds = %loop.cond
  %eq = icmp eq i32 %0, 1
  br i1 %eq, label %if.then, label %if.exit

if.then:                                          ; preds = %loop.body
  call void @test.testA()
  call void @test.testB()
  call void @test.test2()
  br label %loop.exit

if.exit:                                          ; preds = %loop.body
  call void @test.test3()
  call void @test.testA()
  call void @test.testB()
  call void @test.test2()
  br label %loop.cond

loop.exit:                                        ; preds = %if.then, %loop.cond
  ret i32 0
}
