#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 pid_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ printf(char *, int);
int main() {
  int i = 0;
  for (i = 0; i < 10; i++) {
    pid_t child;
    if ((child = fork()) == 0)
      exit(0);
    printf("Child: %d\n", child);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jge    118e <main+0x5e>
mov    $0x0,%al
call   1050 <fork@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jne    1171 <main+0x41>
xor    %edi,%edi
call   1040 <exit@plt>
mov    -0xc(%rbp),%esi
lea    0xe85(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    114d <main+0x1d>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1050 <fork@plt>
test   %eax,%eax
je     1243 <main+0x113>
lea    0xeb9(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %eax,%eax
je     1243 <main+0x113>
lea    0xe9c(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %eax,%eax
je     1243 <main+0x113>
lea    0xe7f(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %eax,%eax
je     1243 <main+0x113>
lea    0xe62(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %eax,%eax
je     1243 <main+0x113>
lea    0xe45(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %eax,%eax
je     1243 <main+0x113>
lea    0xe2c(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %eax,%eax
je     1243 <main+0x113>
lea    0xe13(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %eax,%eax
je     1243 <main+0x113>
lea    0xdfa(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %eax,%eax
je     1243 <main+0x113>
lea    0xde1(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %eax,%eax
je     1243 <main+0x113>
lea    0xdc8(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret
xor    %edi,%edi
call   1040 <exit@plt>

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

LLVM IR (-O2):
@.str = [11 x i8] c"Child: %d\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
%2 = icmp eq i32 %1, 0
br i1 %2, label %3, label %5
3: ; preds = %37, %33, %29, %25, %21, %17, %13, %9, %5, %0
%4 = tail call i32 @exit(i32 0)
unreachable
5: ; preds = %0
%6 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %1)
%7 = tail call i32 (...) @fork()
%8 = icmp eq i32 %7, 0
br i1 %8, label %3, label %9
9: ; preds = %5
%10 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %7)
%11 = tail call i32 (...) @fork()
%12 = icmp eq i32 %11, 0
br i1 %12, label %3, label %13
13: ; preds = %9
%14 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %11)
%15 = tail call i32 (...) @fork()
%16 = icmp eq i32 %15, 0
br i1 %16, label %3, label %17
17: ; preds = %13
%18 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %15)
%19 = tail call i32 (...) @fork()
%20 = icmp eq i32 %19, 0
br i1 %20, label %3, label %21
21: ; preds = %17
%22 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %19)
%23 = tail call i32 (...) @fork()
%24 = icmp eq i32 %23, 0
br i1 %24, label %3, label %25
25: ; preds = %21
%26 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %23)
%27 = tail call i32 (...) @fork()
%28 = icmp eq i32 %27, 0
br i1 %28, label %3, label %29
29: ; preds = %25
%30 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %27)
%31 = tail call i32 (...) @fork()
%32 = icmp eq i32 %31, 0
br i1 %32, label %3, label %33
33: ; preds = %29
%34 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %31)
%35 = tail call i32 (...) @fork()
%36 = icmp eq i32 %35, 0
br i1 %36, label %3, label %37
37: ; preds = %33
%38 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %35)
%39 = tail call i32 (...) @fork()
%40 = icmp eq i32 %39, 0
br i1 %40, label %3, label %41
41: ; preds = %37
%42 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %39)
ret i32 0
}