// #target: macos-x64

module foo;
fn int test()
{
    static int x = 0;
    return 1 + x++;
}

extern fn void printf(char*, ...);

fn void main()
{
    int i = 10;
    do
    {
        printf("%d\n", test());
    } while (false);
    do
    {
        printf("%d, %d\n", i, test());
    };
    do
    {
        if (i < 0) continue;
        printf("A\n", i, test());
    };
    do
    {
        if (i < 0) break;
        printf("B\n", i, test());
    };

}

/* #expect: foo.ll

@test.x = internal unnamed_addr global i32 0, align 4
@.str = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
@.str.1 = private unnamed_addr constant [8 x i8] c"%d, %d\0A\00", align 1

define void @foo.main() #0 {
entry:
  %i = alloca i32, align 4
  store i32 10, ptr %i, align 4
  %0 = call i32 @foo.test()
  call void (ptr, ...) @printf(ptr @.str, i32 %0)
  %1 = call i32 @foo.test()
  %2 = load i32, ptr %i, align 4
  call void (ptr, ...) @printf(ptr @.str.1, i32 %2, i32 %1)
  %3 = load i32, ptr %i, align 4
  %lt = icmp slt i32 %3, 0
  br i1 %lt, label %if.then, label %if.exit

if.then:                                          ; preds = %entry
  br label %loop.exit

if.exit:                                          ; preds = %entry
  %4 = call i32 @foo.test()
  %5 = load i32, ptr %i, align 4
  call void (ptr, ...) @printf(ptr @.str.2, i32 %5, i32 %4)
  br label %loop.exit

loop.exit:                                        ; preds = %if.exit, %if.then
  %6 = load i32, ptr %i, align 4
  %lt1 = icmp slt i32 %6, 0
  br i1 %lt1, label %if.then2, label %if.exit3

if.then2:                                         ; preds = %loop.exit
  br label %loop.exit4

if.exit3:                                         ; preds = %loop.exit
  %7 = call i32 @foo.test()
  %8 = load i32, ptr %i, align 4
  call void (ptr, ...) @printf(ptr @.str.3, i32 %8, i32 %7)
  br label %loop.exit4

loop.exit4:                                       ; preds = %if.exit3, %if.then2
  ret void
}
