#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*/ printf(char *);
int /*<<< orphan*/ tm_load_context(int *, int);
int /*<<< orphan*/ tm_start_timer(int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ tm_terminate_thread(int);
int /*<<< orphan*/ tm_yield(int *, int, int *, int);
void f1() {
  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("hi\n");
      tm_start_timer(0, 100, 0);
    case 31:
      tm_yield((uint8_t *)&_thread_context, sizeof(_thread_context),
               &(_thread_context.pc), -31);
      goto end_function;
    case -31: {
    };
      ;
    }
    tm_terminate_thread(sizeof(_thread_context));
  }
end_function : {};
}


x86 assembly (clang, -O0):
<f1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
mov    $0xc,%esi
call   1070 <tm_load_context@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0xffffffe1,%eax
je     11e9 <f1+0x99>
jmp    1181 <f1+0x31>
mov    -0x14(%rbp),%eax
test   %eax,%eax
je     11a2 <f1+0x52>
jmp    1191 <f1+0x41>
mov    -0x14(%rbp),%eax
sub    $0x1f,%eax
je     11cd <f1+0x7d>
jmp    1206 <f1+0xb6>
movl   $0x0,-0x8(%rbp)
cmpl   $0x14,-0x8(%rbp)
jge    11fc <f1+0xac>
lea    0xe46(%rip),%rdi
call   1040 <printf@plt>
xor    %edx,%edx
mov    $0x64,%esi
mov    %edx,%edi
call   1030 <tm_start_timer@plt>
lea    -0x10(%rbp),%rdi
lea    -0x10(%rbp),%rdx
mov    $0xc,%esi
mov    $0xffffffe1,%ecx
call   1050 <tm_yield@plt>
jmp    120b <f1+0xbb>
jmp    11ee <f1+0x9e>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11a9 <f1+0x59>
mov    $0xc,%edi
call   1060 <tm_terminate_thread@plt>
jmp    120b <f1+0xbb>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f1>:
sub    $0x18,%rsp
movl   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdi
mov    $0xc,%esi
call   1070 <tm_load_context@plt>
mov    0x8(%rsp),%eax
cmp    $0xffffffe1,%eax
je     1187 <f1+0x37>
cmp    $0x1f,%eax
je     11b1 <f1+0x61>
test   %eax,%eax
jne    11d7 <f1+0x87>
movl   $0x0,0x10(%rsp)
jmp    1197 <f1+0x47>
mov    0x10(%rsp),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x10(%rsp)
cmp    $0x12,%eax
jg     11cd <f1+0x7d>
lea    0xe62(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
mov    $0x64,%esi
xor    %edx,%edx
call   1040 <tm_start_timer@plt>
lea    0x8(%rsp),%rdi
mov    $0xc,%esi
mov    %rdi,%rdx
mov    $0xffffffe1,%ecx
call   1050 <tm_yield@plt>
add    $0x18,%rsp
ret
mov    $0xc,%edi
call   1060 <tm_terminate_thread@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.anon = type { i32, i32, i32 }
@.str = [4 x i8] c"hi\0A\00"
define void @f1() {
%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 31, label %16
i32 -31, 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 ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @tm_start_timer(i32 0, i32 100, i32 0)
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 -31)
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 = [3 x i8] c"hi\00"
define void @f1() {
%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 31, label %16
i32 -31, 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 ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
%15 = call i32 @tm_start_timer(i32 0, i32 100, i32 0)
br label %16
16: ; preds = %0, %13
%17 = call i32 @tm_yield(i32* %3, i32 12, i32* %3, i32 -31)
br label %20
18: ; preds = %8
%19 = call i32 @tm_terminate_thread(i32 12)
br label %20
20: ; preds = %0, %18, %16
ret void
}