#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 */
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, int);
int sched_getcpu();
int main() {
  for (int i = 0; i < 20; i++) {
    if (fork() == 0) {
      printf("%d\n", sched_getcpu());
      return 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x14,-0x8(%rbp)
jge    1195 <main+0x65>
mov    $0x0,%al
call   1050 <fork@plt>
cmp    $0x0,%rax
jne    1182 <main+0x52>
mov    $0x0,%al
call   1040 <sched_getcpu@plt>
mov    %eax,%esi
lea    0xe8f(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    119c <main+0x6c>
jmp    1187 <main+0x57>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1146 <main+0x16>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1245 <main+0x115>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1245 <main+0x115>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1245 <main+0x115>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1245 <main+0x115>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1245 <main+0x115>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1245 <main+0x115>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1245 <main+0x115>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1245 <main+0x115>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1245 <main+0x115>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1245 <main+0x115>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1245 <main+0x115>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1245 <main+0x115>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1245 <main+0x115>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1245 <main+0x115>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1245 <main+0x115>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1245 <main+0x115>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1245 <main+0x115>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1245 <main+0x115>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1245 <main+0x115>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
jne    125a <main+0x12a>
xor    %eax,%eax
call   1040 <sched_getcpu@plt>
lea    0xdad(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
br label %3
3: ; preds = %13, %0
%4 = load i32, i32* %2
%5 = icmp slt i32 %4, 20
br i1 %5, label %6, label %16
6: ; preds = %3
%7 = call i64 (...) @fork()
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = call i32 (...) @sched_getcpu()
%11 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 0, i32* %1
br label %17
12: ; preds = %6
br label %13
13: ; preds = %12
%14 = load i32, i32* %2
%15 = add nsw i32 %14, 1
store i32 %15, i32* %2
br label %3
16: ; preds = %3
store i32 0, i32* %1
br label %17
17: ; preds = %16, %9
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp eq i64 %1, 0
br i1 %2, label %60, label %3
3: ; preds = %0
%4 = tail call i64 (...) @fork()
%5 = icmp eq i64 %4, 0
br i1 %5, label %60, label %6
6: ; preds = %3
%7 = tail call i64 (...) @fork()
%8 = icmp eq i64 %7, 0
br i1 %8, label %60, label %9
9: ; preds = %6
%10 = tail call i64 (...) @fork()
%11 = icmp eq i64 %10, 0
br i1 %11, label %60, label %12
12: ; preds = %9
%13 = tail call i64 (...) @fork()
%14 = icmp eq i64 %13, 0
br i1 %14, label %60, label %15
15: ; preds = %12
%16 = tail call i64 (...) @fork()
%17 = icmp eq i64 %16, 0
br i1 %17, label %60, label %18
18: ; preds = %15
%19 = tail call i64 (...) @fork()
%20 = icmp eq i64 %19, 0
br i1 %20, label %60, label %21
21: ; preds = %18
%22 = tail call i64 (...) @fork()
%23 = icmp eq i64 %22, 0
br i1 %23, label %60, label %24
24: ; preds = %21
%25 = tail call i64 (...) @fork()
%26 = icmp eq i64 %25, 0
br i1 %26, label %60, label %27
27: ; preds = %24
%28 = tail call i64 (...) @fork()
%29 = icmp eq i64 %28, 0
br i1 %29, label %60, label %30
30: ; preds = %27
%31 = tail call i64 (...) @fork()
%32 = icmp eq i64 %31, 0
br i1 %32, label %60, label %33
33: ; preds = %30
%34 = tail call i64 (...) @fork()
%35 = icmp eq i64 %34, 0
br i1 %35, label %60, label %36
36: ; preds = %33
%37 = tail call i64 (...) @fork()
%38 = icmp eq i64 %37, 0
br i1 %38, label %60, label %39
39: ; preds = %36
%40 = tail call i64 (...) @fork()
%41 = icmp eq i64 %40, 0
br i1 %41, label %60, label %42
42: ; preds = %39
%43 = tail call i64 (...) @fork()
%44 = icmp eq i64 %43, 0
br i1 %44, label %60, label %45
45: ; preds = %42
%46 = tail call i64 (...) @fork()
%47 = icmp eq i64 %46, 0
br i1 %47, label %60, label %48
48: ; preds = %45
%49 = tail call i64 (...) @fork()
%50 = icmp eq i64 %49, 0
br i1 %50, label %60, label %51
51: ; preds = %48
%52 = tail call i64 (...) @fork()
%53 = icmp eq i64 %52, 0
br i1 %53, label %60, label %54
54: ; preds = %51
%55 = tail call i64 (...) @fork()
%56 = icmp eq i64 %55, 0
br i1 %56, label %60, label %57
57: ; preds = %54
%58 = tail call i64 (...) @fork()
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %57, %54, %51, %48, %45, %42, %39, %36, %33, %30, %27, %24, %21, %18, %15, %12, %9, %6, %3, %0
%61 = tail call i32 (...) @sched_getcpu()
%62 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %61)
br label %63
63: ; preds = %57, %60
ret i32 0
}