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

/* Variables and functions */
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, scalar_t__);
int /*<<< orphan*/ sleep(int);
int main() {
  int i;
  pid_t pid;
  for (i = 1; i <= 10; i++) {
    pid = fork();
    if (pid == 0) {
      return (i);
    } else {
      printf("Created child with ID: %d\n", pid);
    }
  }
  sleep(99999);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jg     1194 <main+0x64>
mov    $0x0,%al
call   1050 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1171 <main+0x41>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a5 <main+0x75>
mov    -0x10(%rbp),%rsi
lea    0xe84(%rip),%rdi
call   1030 <printf@plt>
jmp    1186 <main+0x56>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1146 <main+0x16>
mov    $0x1869f,%edi
call   1040 <sleep@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     126d <main+0x13d>
lea    0xeb8(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1274 <main+0x144>
lea    0xe99(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     127b <main+0x14b>
lea    0xe7a(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1282 <main+0x152>
lea    0xe5b(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1289 <main+0x159>
lea    0xe3c(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1290 <main+0x160>
lea    0xe1d(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     1297 <main+0x167>
lea    0xdfe(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     129e <main+0x16e>
lea    0xddf(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     12a5 <main+0x175>
lea    0xdc4(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     12ac <main+0x17c>
lea    0xda7(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    $0x1869f,%edi
call   1040 <sleep@plt>
jmp    12b1 <main+0x181>
mov    $0x1,%ebx
jmp    12b1 <main+0x181>
mov    $0x2,%ebx
jmp    12b1 <main+0x181>
mov    $0x3,%ebx
jmp    12b1 <main+0x181>
mov    $0x4,%ebx
jmp    12b1 <main+0x181>
mov    $0x5,%ebx
jmp    12b1 <main+0x181>
mov    $0x6,%ebx
jmp    12b1 <main+0x181>
mov    $0x7,%ebx
jmp    12b1 <main+0x181>
mov    $0x8,%ebx
jmp    12b1 <main+0x181>
mov    $0x9,%ebx
jmp    12b1 <main+0x181>
mov    $0xa,%ebx
mov    %ebx,%eax
pop    %rbx
ret

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

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