#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*/ pause();
int sys_fork();
int /*<<< orphan*/ sys_puts(char *);
int /*<<< orphan*/ sys_yield();
int main(void) {
  int pid;
  for (int i = 0; i < 2; i++) {
    if ((pid = sys_fork()) < 0) {
      sys_puts("can't fork\n");
      return -1;
    }
    if (pid == 0)
      break;
  }
  for (int i = 0; i < 10; i++) {
    sys_puts("before yield\n");
    sys_yield();
    sys_puts("after yield\n");
    pause();
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x2,-0xc(%rbp)
jge    11ad <main+0x6d>
mov    $0x0,%al
call   1030 <sys_fork@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    118b <main+0x4b>
lea    0xe86(%rip),%rdi
call   1060 <sys_puts@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f9 <main+0xb9>
cmpl   $0x0,-0x8(%rbp)
jne    119a <main+0x5a>
jmp    11ad <main+0x6d>
jmp    119f <main+0x5f>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1156 <main+0x16>
movl   $0x0,-0x10(%rbp)
cmpl   $0xa,-0x10(%rbp)
jge    11f2 <main+0xb2>
lea    0xe47(%rip),%rdi
call   1060 <sys_puts@plt>
mov    $0x0,%al
call   1040 <sys_yield@plt>
lea    0xe42(%rip),%rdi
call   1060 <sys_puts@plt>
mov    $0x0,%al
call   1050 <pause@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11b4 <main+0x74>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1030 <sys_fork@plt>
test   %eax,%eax
js     12a3 <main+0x163>
je     1164 <main+0x24>
xor    %eax,%eax
call   1030 <sys_fork@plt>
test   %eax,%eax
js     12a3 <main+0x163>
lea    0xea1(%rip),%rbx
mov    %rbx,%rdi
call   1060 <sys_puts@plt>
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <sys_yield@plt>
lea    0xe96(%rip),%rbp
mov    %rbp,%rdi
call   1060 <sys_puts@plt>
xor    %eax,%eax
call   1050 <pause@plt>
mov    %rbx,%rdi
call   1060 <sys_puts@plt>
xor    %eax,%eax
call   1040 <sys_yield@plt>
mov    %rbp,%rdi
call   1060 <sys_puts@plt>
xor    %eax,%eax
call   1050 <pause@plt>
mov    %rbx,%rdi
call   1060 <sys_puts@plt>
xor    %eax,%eax
call   1040 <sys_yield@plt>
mov    %rbp,%rdi
call   1060 <sys_puts@plt>
xor    %eax,%eax
call   1050 <pause@plt>
mov    %rbx,%rdi
call   1060 <sys_puts@plt>
xor    %eax,%eax
call   1040 <sys_yield@plt>
mov    %rbp,%rdi
call   1060 <sys_puts@plt>
xor    %eax,%eax
call   1050 <pause@plt>
mov    %rbx,%rdi
call   1060 <sys_puts@plt>
xor    %eax,%eax
call   1040 <sys_yield@plt>
mov    %rbp,%rdi
call   1060 <sys_puts@plt>
xor    %eax,%eax
call   1050 <pause@plt>
mov    %rbx,%rdi
call   1060 <sys_puts@plt>
xor    %eax,%eax
call   1040 <sys_yield@plt>
mov    %rbp,%rdi
call   1060 <sys_puts@plt>
xor    %eax,%eax
call   1050 <pause@plt>
mov    %rbx,%rdi
call   1060 <sys_puts@plt>
xor    %eax,%eax
call   1040 <sys_yield@plt>
mov    %rbp,%rdi
call   1060 <sys_puts@plt>
xor    %eax,%eax
call   1050 <pause@plt>
mov    %rbx,%rdi
call   1060 <sys_puts@plt>
xor    %eax,%eax
call   1040 <sys_yield@plt>
mov    %rbp,%rdi
call   1060 <sys_puts@plt>
xor    %eax,%eax
call   1050 <pause@plt>
mov    %rbx,%rdi
call   1060 <sys_puts@plt>
xor    %eax,%eax
call   1040 <sys_yield@plt>
mov    %rbp,%rdi
call   1060 <sys_puts@plt>
xor    %eax,%eax
call   1050 <pause@plt>
mov    %rbx,%rdi
call   1060 <sys_puts@plt>
xor    %eax,%eax
call   1040 <sys_yield@plt>
mov    %rbp,%rdi
call   1060 <sys_puts@plt>
xor    %eax,%eax
call   1050 <pause@plt>
jmp    12b5 <main+0x175>
lea    0xd56(%rip),%rdi
call   1060 <sys_puts@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"can't fork\0A\00"
@.str.1 = [14 x i8] c"before yield\0A\00"
@.str.2 = [13 x i8] c"after yield\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
br label %5
5: ; preds = %18, %0
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 2
br i1 %7, label %8, label %21
8: ; preds = %5
%9 = call i32 (...) @sys_fork()
store i32 %9, i32* %2
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @sys_puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %34
13: ; preds = %8
%14 = load i32, i32* %2
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %13
br label %21
17: ; preds = %13
br label %18
18: ; preds = %17
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %5
21: ; preds = %16, %5
store i32 0, i32* %4
br label %22
22: ; preds = %30, %21
%23 = load i32, i32* %4
%24 = icmp slt i32 %23, 10
br i1 %24, label %25, label %33
25: ; preds = %22
%26 = call i32 @sys_puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 (...) @sys_yield()
%28 = call i32 @sys_puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 (...) @pause()
br label %30
30: ; preds = %25
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
br label %22
33: ; preds = %22
store i32 0, i32* %1
br label %34
34: ; preds = %33, %11
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@.str = [12 x i8] c"can't fork\0A\00"
@.str.1 = [14 x i8] c"before yield\0A\00"
@.str.2 = [13 x i8] c"after yield\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @sys_fork()
%2 = icmp slt i32 %1, 0
br i1 %2, label %6, label %8
3: ; preds = %8
%4 = tail call i32 (...) @sys_fork()
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %3, %0
%7 = tail call i32 @sys_puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %51
8: ; preds = %0
%9 = icmp eq i32 %1, 0
br i1 %9, label %10, label %3
10: ; preds = %3, %8
%11 = tail call i32 @sys_puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 (...) @sys_yield()
%13 = tail call i32 @sys_puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%14 = tail call i32 (...) @pause()
%15 = tail call i32 @sys_puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 (...) @sys_yield()
%17 = tail call i32 @sys_puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%18 = tail call i32 (...) @pause()
%19 = tail call i32 @sys_puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 (...) @sys_yield()
%21 = tail call i32 @sys_puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%22 = tail call i32 (...) @pause()
%23 = tail call i32 @sys_puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%24 = tail call i32 (...) @sys_yield()
%25 = tail call i32 @sys_puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%26 = tail call i32 (...) @pause()
%27 = tail call i32 @sys_puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%28 = tail call i32 (...) @sys_yield()
%29 = tail call i32 @sys_puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%30 = tail call i32 (...) @pause()
%31 = tail call i32 @sys_puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%32 = tail call i32 (...) @sys_yield()
%33 = tail call i32 @sys_puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%34 = tail call i32 (...) @pause()
%35 = tail call i32 @sys_puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%36 = tail call i32 (...) @sys_yield()
%37 = tail call i32 @sys_puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%38 = tail call i32 (...) @pause()
%39 = tail call i32 @sys_puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%40 = tail call i32 (...) @sys_yield()
%41 = tail call i32 @sys_puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%42 = tail call i32 (...) @pause()
%43 = tail call i32 @sys_puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%44 = tail call i32 (...) @sys_yield()
%45 = tail call i32 @sys_puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%46 = tail call i32 (...) @pause()
%47 = tail call i32 @sys_puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%48 = tail call i32 (...) @sys_yield()
%49 = tail call i32 @sys_puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%50 = tail call i32 (...) @pause()
br label %51
51: ; preds = %10, %6
%52 = phi i32 [ -1, %6 ], [ 0, %10 ]
ret i32 %52
}