#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int uint8_t;
typedef int int32_t;
typedef int /*<<< orphan*/ _thread_context;

/* Variables and functions */
int /*<<< orphan*/ Wait(double);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ tm_load_context(int *, int);
int /*<<< orphan*/ tm_terminate_thread(int);
int /*<<< orphan*/ tm_yield(int *, int, int *, int);
void f2() {
  struct {
    int32_t pc;
    uint8_t a;
    uint8_t i;
  } _thread_context;
  _thread_context.pc = 0;
  tm_load_context((uint8_t *)&_thread_context, sizeof(_thread_context));
  ;
  switch (_thread_context.pc) {
  case 0: {
  };
    for (_thread_context.i = 0; _thread_context.i < 20; _thread_context.i++) {
      printf("hello\n");
      Wait(0.05);
    case 49:
      tm_yield((uint8_t *)&_thread_context, sizeof(_thread_context),
               &(_thread_context.pc), -49);
      goto end_function;
    case -49: {
    };
    }
    tm_terminate_thread(sizeof(_thread_context));
  }
end_function : {};
}


x86 assembly (clang, -O0):
<f2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
mov    $0xc,%esi
call   1060 <tm_load_context@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0xffffffcf,%eax
je     11e8 <f2+0x98>
jmp    1181 <f2+0x31>
mov    -0x14(%rbp),%eax
test   %eax,%eax
je     11a2 <f2+0x52>
jmp    1191 <f2+0x41>
mov    -0x14(%rbp),%eax
sub    $0x31,%eax
je     11cc <f2+0x7c>
jmp    1205 <f2+0xb5>
movl   $0x0,-0x8(%rbp)
cmpl   $0x14,-0x8(%rbp)
jge    11fb <f2+0xab>
lea    0xe4e(%rip),%rdi
call   1030 <printf@plt>
movsd  0xe39(%rip),%xmm0
call   1070 <Wait@plt>
lea    -0x10(%rbp),%rdi
lea    -0x10(%rbp),%rdx
mov    $0xc,%esi
mov    $0xffffffcf,%ecx
call   1040 <tm_yield@plt>
jmp    120a <f2+0xba>
jmp    11ed <f2+0x9d>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11a9 <f2+0x59>
mov    $0xc,%edi
call   1050 <tm_terminate_thread@plt>
jmp    120a <f2+0xba>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f2>:
sub    $0x18,%rsp
movl   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdi
mov    $0xc,%esi
call   1060 <tm_load_context@plt>
mov    0x8(%rsp),%eax
cmp    $0xffffffcf,%eax
je     1187 <f2+0x37>
cmp    $0x31,%eax
je     11b0 <f2+0x60>
test   %eax,%eax
jne    11d6 <f2+0x86>
movl   $0x0,0x10(%rsp)
jmp    1197 <f2+0x47>
mov    0x10(%rsp),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x10(%rsp)
cmp    $0x12,%eax
jg     11cc <f2+0x7c>
lea    0xe6a(%rip),%rdi
call   1030 <puts@plt>
movsd  0xe55(%rip),%xmm0
call   1070 <Wait@plt>
lea    0x8(%rsp),%rdi
mov    $0xc,%esi
mov    %rdi,%rdx
mov    $0xffffffcf,%ecx
call   1040 <tm_yield@plt>
add    $0x18,%rsp
ret
mov    $0xc,%edi
call   1050 <tm_terminate_thread@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.anon = type { i32, i32, i32 }
@.str = [7 x i8] c"hello\0A\00"
define void @f2() {
%1 = alloca %struct.anon
%2 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 0
store i32 0, i32* %2
%3 = bitcast %struct.anon* %1 to i32*
%4 = call i32 @tm_load_context(i32* %3, i32 12)
%5 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 0
%6 = load i32, i32* %5
switch i32 %6, label %27 [
i32 0, label %7
i32 49, label %16
i32 -49, label %20
]
7: ; preds = %0
%8 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 2
store i32 0, i32* %8
br label %9
9: ; preds = %21, %7
%10 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 2
%11 = load i32, i32* %10
%12 = icmp slt i32 %11, 20
br i1 %12, label %13, label %25
13: ; preds = %9
%14 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @Wait(double 5.000000e-02)
br label %16
16: ; preds = %0, %13
%17 = bitcast %struct.anon* %1 to i32*
%18 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 0
%19 = call i32 @tm_yield(i32* %17, i32 12, i32* %18, i32 -49)
br label %28
20: ; preds = %0
br label %21
21: ; preds = %20
%22 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 2
%23 = load i32, i32* %22
%24 = add nsw i32 %23, 1
store i32 %24, i32* %22
br label %9
25: ; preds = %9
%26 = call i32 @tm_terminate_thread(i32 12)
br label %27
27: ; preds = %25, %0
br label %28
28: ; preds = %27, %16
ret void
}

LLVM IR (-O2):
%struct.anon = type { i32, i32, i32 }
@str = [6 x i8] c"hello\00"
define void @f2() {
%1 = alloca %struct.anon
%2 = bitcast %struct.anon* %1 to i8*
%3 = getelementptr inbounds %struct.anon, %struct.anon* %1, i64 0, i32 0
store i32 0, i32* %3
%4 = call i32 @tm_load_context(i32* %3, i32 12)
%5 = load i32, i32* %3
switch i32 %5, label %20 [
i32 0, label %6
i32 49, label %16
i32 -49, label %8
]
6: ; preds = %0
%7 = getelementptr inbounds %struct.anon, %struct.anon* %1, i64 0, i32 2
store i32 0, i32* %7
br label %13
8: ; preds = %0
%9 = getelementptr inbounds %struct.anon, %struct.anon* %1, i64 0, i32 2
%10 = load i32, i32* %9
%11 = add nsw i32 %10, 1
store i32 %11, i32* %9
%12 = icmp slt i32 %10, 19
br i1 %12, label %13, label %18
13: ; preds = %6, %8
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%15 = call i32 @Wait(double 5.000000e-02)
br label %16
16: ; preds = %0, %13
%17 = call i32 @tm_yield(i32* %3, i32 12, i32* %3, i32 -49)
br label %20
18: ; preds = %8
%19 = call i32 @tm_terminate_thread(i32 12)
br label %20
20: ; preds = %0, %18, %16
ret void
}