#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 */

/* Variables and functions */
int /*<<< orphan*/ init();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ process1(int, int);
int /*<<< orphan*/ process2(int, int);
int /*<<< orphan*/ process3(int, int);
int scheduler();
int main() {
  int k, s1, s2;
  printf("C.O.S example one\n");
  init();
  s1 = 0;
  s2 = 0;
  printf("s1=%d,s2=%d\n", s1, s2);
loop:
  k = scheduler();
  if (k != -1)
    switch (k) {
    case 1:
      process1(s1, s2);
      goto loop;
    case 2:
      process2(s1, s2);
      goto loop;
    case 3:
      process3(s1, s2);
      goto loop;
    default:
      printf("process identifer error\n");
    }
  printf("s1=%d,s2=%d", s1, s2);
  printf("completed\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <init@plt>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <scheduler@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
je     1233 <main+0xd3>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x1,%eax
je     11f0 <main+0x90>
jmp    11ce <main+0x6e>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
je     1200 <main+0xa0>
jmp    11df <main+0x7f>
mov    -0x14(%rbp),%eax
sub    $0x3,%eax
je     1210 <main+0xb0>
jmp    1220 <main+0xc0>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1060 <process1@plt>
jmp    11a6 <main+0x46>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <process2@plt>
jmp    11a6 <main+0x46>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1070 <process3@plt>
jmp    11a6 <main+0x46>
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1233 <main+0xd3>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xeb5(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1060 <init@plt>
lea    0xe89(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe63(%rip),%rbx
jmp    11a9 <main+0x39>
nop
xor    %edi,%edi
xor    %esi,%esi
call   1080 <process3@plt>
xor    %eax,%eax
call   1090 <scheduler@plt>
add    $0x1,%eax
cmp    $0x4,%eax
ja     11db <main+0x6b>
movslq (%rbx,%rax,4),%rax
add    %rbx,%rax
jmp    *%rax
xor    %edi,%edi
xor    %esi,%esi
call   1070 <process1@plt>
jmp    11a9 <main+0x39>
nopl   0x0(%rax)
xor    %edi,%edi
xor    %esi,%esi
call   1030 <process2@plt>
jmp    11a9 <main+0x39>
lea    0xe67(%rip),%rdi
call   1040 <puts@plt>
lea    0xe33(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe3f(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"C.O.S example one\0A\00"
@.str.1 = [13 x i8] c"s1=%d,s2=%d\0A\00"
@.str.2 = [25 x i8] c"process identifer error\0A\00"
@.str.3 = [12 x i8] c"s1=%d,s2=%d\00"
@.str.4 = [11 x i8] c"completed\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (...) @init()
store i32 0, i32* %3
store i32 0, i32* %4
%7 = load i32, i32* %3
%8 = load i32, i32* %4
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 %8)
br label %10
10: ; preds = %24, %20, %16, %0
%11 = call i32 (...) @scheduler()
store i32 %11, i32* %2
%12 = load i32, i32* %2
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %31
14: ; preds = %10
%15 = load i32, i32* %2
switch i32 %15, label %28 [
i32 1, label %16
i32 2, label %20
i32 3, label %24
]
16: ; preds = %14
%17 = load i32, i32* %3
%18 = load i32, i32* %4
%19 = call i32 @process1(i32 %17, i32 %18)
br label %10
20: ; preds = %14
%21 = load i32, i32* %3
%22 = load i32, i32* %4
%23 = call i32 @process2(i32 %21, i32 %22)
br label %10
24: ; preds = %14
%25 = load i32, i32* %3
%26 = load i32, i32* %4
%27 = call i32 @process3(i32 %25, i32 %26)
br label %10
28: ; preds = %14
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %28
br label %31
31: ; preds = %30, %10
%32 = load i32, i32* %3
%33 = load i32, i32* %4
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %32, i32 %33)
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
@.str.1 = [13 x i8] c"s1=%d,s2=%d\0A\00"
@.str.3 = [12 x i8] c"s1=%d,s2=%d\00"
@str = [18 x i8] c"C.O.S example one\00"
@str.5 = [10 x i8] c"completed\00"
@str.6 = [24 x i8] c"process identifer error\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 (...) @init()
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 0)
br label %4
4: ; preds = %8, %0
%5 = tail call i32 (...) @scheduler()
switch i32 %5, label %13 [
i32 -1, label %15
i32 1, label %6
i32 2, label %9
i32 3, label %11
]
6: ; preds = %4
%7 = tail call i32 @process1(i32 0, i32 0)
br label %8
8: ; preds = %6, %9, %11
br label %4
9: ; preds = %4
%10 = tail call i32 @process2(i32 0, i32 0)
br label %8
11: ; preds = %4
%12 = tail call i32 @process3(i32 0, i32 0)
br label %8
13: ; preds = %4
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.6, i64 0, i64 0))
br label %15
15: ; preds = %4, %13
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 0, i32 0)
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.5, i64 0, i64 0))
ret i32 0
}