// #target: macos-x64
module test;
fn void test1() {}
fn void test2() {}
fn void test3() {}
fn void test4() {}
fn void test5() {}
fn void test6() {}
fn void test7() {}
fn void test8() {}
fn void test9() {}

fn int main(int argc, char **argv)
{
    defer test1();
    int a = 0;
    while (a)
    {
	    defer test2();
        if (argc == 1) return a + argc;
        defer test3();
        test4();
    }
    defer test5();
    while (a)
    {
        defer test6();
        if (argc == 1) return a + 2;
        defer test7();
		test8();
		return 2 + 2;
    }
    return 0 + argc;
}

/* #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
  %3 = load i32, ptr %a, align 4
  %add = add i32 %3, %0
  call void @test.test2()
  call void @test.test1()
  ret i32 %add

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

loop.exit:                                        ; preds = %loop.cond
  br label %loop.cond1

loop.cond1:                                       ; preds = %loop.exit
  %4 = load i32, ptr %a, align 4
  %i2b2 = icmp ne i32 %4, 0
  br i1 %i2b2, label %loop.body3, label %loop.exit8

loop.body3:                                       ; preds = %loop.cond1
  %eq4 = icmp eq i32 %0, 1
  br i1 %eq4, label %if.then5, label %if.exit7

if.then5:                                         ; preds = %loop.body3
  %5 = load i32, ptr %a, align 4
  %add6 = add i32 %5, 2
  call void @test.test6()
  call void @test.test5()
  call void @test.test1()
  ret i32 %add6

if.exit7:                                         ; preds = %loop.body3
  call void @test.test8()
  call void @test.test7()
  call void @test.test6()
  call void @test.test5()
  call void @test.test1()
  ret i32 4

loop.exit8:                                       ; preds = %loop.cond1
  %add9 = add i32 0, %0
  call void @test.test5()
  call void @test.test1()
  ret i32 %add9
}