int task1() {
  static int state = 0;
  switch (state) {
  case 0:;
    while (1) {
      printf("%s:%d\n", __func__, 15);
      do {
        state = 16;
        return 0;
      case 16:;
      } while (0);
      printf("%s:%d\n", __func__, 17);
      do {
        state = 18;
        return 1;
      case 18:;
      } while (0);
      printf("%s:%d\n", __func__, 19);
      do {
        state = 20;
        return 2;
      case 20:;
      } while (0);
      printf("%s:%d\n", __func__, 21);
      do {
        state = 22;
        return 3;
      case 22:;
      } while (0);
    }
    state = 0;
  };
}


x86 assembly (clang, -O0):
<task1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2f0e(%rip),%eax
mov    %rax,-0x10(%rbp)
sub    $0x16,%rax
ja     121e <task1+0x10e>
mov    -0x10(%rbp),%rax
lea    0xec9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    1145 <task1+0x35>
lea    0xf10(%rip),%rdi
lea    0xf10(%rip),%rsi
mov    $0xf,%edx
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x10,0x2ec3(%rip)
movl   $0x0,-0x4(%rbp)
jmp    121e <task1+0x10e>
jmp    117a <task1+0x6a>
lea    0xedb(%rip),%rdi
lea    0xedb(%rip),%rsi
mov    $0x11,%edx
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x12,0x2e8e(%rip)
movl   $0x1,-0x4(%rbp)
jmp    121e <task1+0x10e>
jmp    11af <task1+0x9f>
lea    0xea6(%rip),%rdi
lea    0xea6(%rip),%rsi
mov    $0x13,%edx
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x14,0x2e59(%rip)
movl   $0x2,-0x4(%rbp)
jmp    121e <task1+0x10e>
jmp    11e4 <task1+0xd4>
lea    0xe71(%rip),%rdi
lea    0xe71(%rip),%rsi
mov    $0x15,%edx
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x16,0x2e24(%rip)
movl   $0x3,-0x4(%rbp)
jmp    121e <task1+0x10e>
jmp    1219 <task1+0x109>
jmp    1145 <task1+0x35>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<task1>:
push   %rbp
push   %rbx
push   %rax
mov    0x2f13(%rip),%eax
ror    %eax
cmp    $0xb,%eax
ja     1165 <task1+0x55>
mov    $0xf01,%ecx
bt     %eax,%ecx
jae    1165 <task1+0x55>
cltq
lea    0xedd(%rip),%rcx
mov    (%rcx,%rax,4),%edx
lea    0xf03(%rip),%rcx
mov    (%rcx,%rax,4),%ebp
lea    0xf29(%rip),%rcx
mov    (%rcx,%rax,4),%ebx
lea    0xeaf(%rip),%rdi
lea    0xeaf(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebp,0x2ec7(%rip)
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@task1.state = internal global i32 0
@.str = [7 x i8] c"%s:%d\0A\00"
@__func__.task1 = [6 x i8] c"task1\00"
define i32 @task1() {
%1 = alloca i32
%2 = load i32, i32* @task1.state
switch i32 %2, label %21 [
i32 0, label %3
i32 16, label %7
i32 18, label %11
i32 20, label %15
i32 22, label %19
]
3: ; preds = %0
br label %4
4: ; preds = %3, %20
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @__func__.task1, i64 0, i64 0), i32 15)
br label %6
6: ; preds = %4
store i32 16, i32* @task1.state
store i32 0, i32* %1
br label %21
7: ; preds = %0
br label %8
8: ; preds = %7
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @__func__.task1, i64 0, i64 0), i32 17)
br label %10
10: ; preds = %8
store i32 18, i32* @task1.state
store i32 1, i32* %1
br label %21
11: ; preds = %0
br label %12
12: ; preds = %11
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @__func__.task1, i64 0, i64 0), i32 19)
br label %14
14: ; preds = %12
store i32 20, i32* @task1.state
store i32 2, i32* %1
br label %21
15: ; preds = %0
br label %16
16: ; preds = %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @__func__.task1, i64 0, i64 0), i32 21)
br label %18
18: ; preds = %16
store i32 22, i32* @task1.state
store i32 3, i32* %1
br label %21
19: ; preds = %0
br label %20
20: ; preds = %19
br label %4
21: ; preds = %6, %10, %14, %18, %0
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@task1.state = internal unnamed_addr global i32 0
@.str = [7 x i8] c"%s:%d\0A\00"
@__func__.task1 = [6 x i8] c"task1\00"
@switch.table.task1 = [12 x i32] [i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 17, i32 19, i32 21, i32 15]
@switch.table.task1.1 = [12 x i32] [i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 18, i32 20, i32 22, i32 16]
@switch.table.task1.2 = [12 x i32] [i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 1, i32 2, i32 3, i32 0]
define i32 @task1() {
%1 = load i32, i32* @task1.state
%2 = tail call i32 @llvm.fshl.i32(i32 %1, i32 %1, i32 31)
%3 = icmp ult i32 %2, 12
br i1 %3, label %4, label %20
4: ; preds = %0
%5 = trunc i32 %2 to i16
%6 = lshr i16 3841, %5
%7 = and i16 %6, 1
%8 = icmp eq i16 %7, 0
br i1 %8, label %20, label %9
9: ; preds = %4
%10 = sext i32 %2 to i64
%11 = getelementptr inbounds [12 x i32], [12 x i32]* @switch.table.task1, i64 0, i64 %10
%12 = load i32, i32* %11
%13 = sext i32 %2 to i64
%14 = getelementptr inbounds [12 x i32], [12 x i32]* @switch.table.task1.1, i64 0, i64 %13
%15 = load i32, i32* %14
%16 = sext i32 %2 to i64
%17 = getelementptr inbounds [12 x i32], [12 x i32]* @switch.table.task1.2, i64 0, i64 %16
%18 = load i32, i32* %17
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @__func__.task1, i64 0, i64 0), i32 %12)
store i32 %15, i32* @task1.state
br label %20
20: ; preds = %4, %0, %9
%21 = phi i32 [ undef, %0 ], [ %18, %9 ], [ undef, %4 ]
ret i32 %21
}