// #target: macos-x64
module test;

extern fn int printf(char*, ...);
extern fn int foo();

fn int main()
{
  while (foo())
  {
     switch (foo())
     {
        case 0:
        case 1:
        case 2:
        case 3:
            printf("3");
            nextcase;
        case 4:
            printf("4");
            nextcase;
        case 5:
        case 6:
        default:
            break;
     }
   }
   return 0;
}

/* #expect: test.ll

source_filename = "test"
target datalayout = "e-m:o-p270:32:32-p271:32
target triple = "x86_64-apple

@.str = private unnamed_addr constant [2 x i8] c"3\00", align 1
@.str.1 = private unnamed_addr constant [2 x i8] c"4\00", align 1


declare i32 @printf(ptr, ...) #0


declare i32 @foo() #0


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

loop.cond:                                        ; preds = %switch.exit, %entry
  %0 = call i32 @foo()
  %i2b = icmp ne i32 %0, 0
  br i1 %i2b, label %loop.body, label %loop.exit

loop.body:                                        ; preds = %loop.cond
  %1 = call i32 @foo()
  store i32 %1, ptr %switch, align 4
  br label %switch.entry

switch.entry:                                     ; preds = %loop.body
  %2 = load i32, ptr %switch, align 4
  switch i32 %2, label %switch.default [
    i32 0, label %switch.case
    i32 1, label %switch.case
    i32 2, label %switch.case
    i32 3, label %switch.case
    i32 4, label %switch.case1
    i32 5, label %switch.default
    i32 6, label %switch.default
  ]

switch.case:                                      ; preds = %switch.entry, %switch.entry, %switch.entry, %switch.entry
  %3 = call i32 (ptr, ...) @printf(ptr @.str)
  br label %switch.case1

switch.case1:                                     ; preds = %switch.entry, %switch.case
  %4 = call i32 (ptr, ...) @printf(ptr @.str.1)
  br label %switch.default

switch.default:                                   ; preds = %switch.entry, %switch.entry, %switch.case1, %switch.entry
  br label %switch.exit

switch.exit:                                      ; preds = %switch.default
  br label %loop.cond

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