#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 */
int WEXITSTATUS(int);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, scalar_t__, ...);
int /*<<< orphan*/ sleep(int);
scalar_t__ wait(int *);
int main() {
  int i, j;
  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);
    }
  }
  for (i = 0; i < 10; i++) {
    pid = wait(&j);
    printf("%d returned %d\n", pid, WEXITSTATUS(j));
  }
  sleep(99999);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jg     11b6 <main+0x66>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1191 <main+0x41>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1217 <main+0xc7>
mov    -0x18(%rbp),%rsi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a8 <main+0x58>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1166 <main+0x16>
movl   $0x0,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jge    1206 <main+0xb6>
lea    -0xc(%rbp),%rdi
call   1060 <wait@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11bd <main+0x6d>
mov    $0x1869f,%edi
call   1050 <sleep@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     141a <main+0x2ca>
lea    0xe91(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     1421 <main+0x2d1>
lea    0xe70(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     1428 <main+0x2d8>
lea    0xe4f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     142f <main+0x2df>
lea    0xe2e(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     1436 <main+0x2e6>
lea    0xe0d(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     143d <main+0x2ed>
lea    0xdec(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     1444 <main+0x2f4>
lea    0xdcb(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     144b <main+0x2fb>
lea    0xdaa(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     1452 <main+0x302>
lea    0xd89(%rip),%rdi
xor    %ebx,%ebx
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     1459 <main+0x309>
lea    0xd66(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1060 <wait@plt>
mov    %rax,%r12
mov    0x4(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
lea    0xd57(%rip),%r15
mov    %r15,%rdi
mov    %r12,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
call   1060 <wait@plt>
mov    %rax,%r12
mov    0x4(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
call   1060 <wait@plt>
mov    %rax,%r12
mov    0x4(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
call   1060 <wait@plt>
mov    %rax,%r12
mov    0x4(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
call   1060 <wait@plt>
mov    %rax,%r12
mov    0x4(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
call   1060 <wait@plt>
mov    %rax,%r12
mov    0x4(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
call   1060 <wait@plt>
mov    %rax,%r12
mov    0x4(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
call   1060 <wait@plt>
mov    %rax,%r12
mov    0x4(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
call   1060 <wait@plt>
mov    %rax,%r12
mov    0x4(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
call   1060 <wait@plt>
mov    %rax,%r14
mov    0x4(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1869f,%edi
call   1050 <sleep@plt>
jmp    145e <main+0x30e>
mov    $0x1,%ebx
jmp    145e <main+0x30e>
mov    $0x2,%ebx
jmp    145e <main+0x30e>
mov    $0x3,%ebx
jmp    145e <main+0x30e>
mov    $0x4,%ebx
jmp    145e <main+0x30e>
mov    $0x5,%ebx
jmp    145e <main+0x30e>
mov    $0x6,%ebx
jmp    145e <main+0x30e>
mov    $0x7,%ebx
jmp    145e <main+0x30e>
mov    $0x8,%ebx
jmp    145e <main+0x30e>
mov    $0x9,%ebx
jmp    145e <main+0x30e>
mov    $0xa,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [27 x i8] c"Created child with ID: %d\0A\00"
@.str.1 = [16 x i8] c"%d returned %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %84, label %5
5: ; preds = %0
%6 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %3)
%7 = tail call i64 (...) @fork()
%8 = icmp eq i64 %7, 0
br i1 %8, label %84, label %9
9: ; preds = %5
%10 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %7)
%11 = tail call i64 (...) @fork()
%12 = icmp eq i64 %11, 0
br i1 %12, label %84, label %13
13: ; preds = %9
%14 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %11)
%15 = tail call i64 (...) @fork()
%16 = icmp eq i64 %15, 0
br i1 %16, label %84, label %17
17: ; preds = %13
%18 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %15)
%19 = tail call i64 (...) @fork()
%20 = icmp eq i64 %19, 0
br i1 %20, label %84, label %21
21: ; preds = %17
%22 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %19)
%23 = tail call i64 (...) @fork()
%24 = icmp eq i64 %23, 0
br i1 %24, label %84, label %25
25: ; preds = %21
%26 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %23)
%27 = tail call i64 (...) @fork()
%28 = icmp eq i64 %27, 0
br i1 %28, label %84, label %29
29: ; preds = %25
%30 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %27)
%31 = tail call i64 (...) @fork()
%32 = icmp eq i64 %31, 0
br i1 %32, label %84, label %33
33: ; preds = %29
%34 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %31)
%35 = tail call i64 (...) @fork()
%36 = icmp eq i64 %35, 0
br i1 %36, label %84, label %37
37: ; preds = %33
%38 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %35)
%39 = tail call i64 (...) @fork()
%40 = icmp eq i64 %39, 0
br i1 %40, label %84, label %41
41: ; preds = %37
%42 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %39)
%43 = call i64 @wait(i32* %1)
%44 = load i32, i32* %1
%45 = call i32 @WEXITSTATUS(i32 %44)
%46 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %43, i32 %45)
%47 = call i64 @wait(i32* %1)
%48 = load i32, i32* %1
%49 = call i32 @WEXITSTATUS(i32 %48)
%50 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %47, i32 %49)
%51 = call i64 @wait(i32* %1)
%52 = load i32, i32* %1
%53 = call i32 @WEXITSTATUS(i32 %52)
%54 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %51, i32 %53)
%55 = call i64 @wait(i32* %1)
%56 = load i32, i32* %1
%57 = call i32 @WEXITSTATUS(i32 %56)
%58 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %55, i32 %57)
%59 = call i64 @wait(i32* %1)
%60 = load i32, i32* %1
%61 = call i32 @WEXITSTATUS(i32 %60)
%62 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %59, i32 %61)
%63 = call i64 @wait(i32* %1)
%64 = load i32, i32* %1
%65 = call i32 @WEXITSTATUS(i32 %64)
%66 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %63, i32 %65)
%67 = call i64 @wait(i32* %1)
%68 = load i32, i32* %1
%69 = call i32 @WEXITSTATUS(i32 %68)
%70 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %67, i32 %69)
%71 = call i64 @wait(i32* %1)
%72 = load i32, i32* %1
%73 = call i32 @WEXITSTATUS(i32 %72)
%74 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %71, i32 %73)
%75 = call i64 @wait(i32* %1)
%76 = load i32, i32* %1
%77 = call i32 @WEXITSTATUS(i32 %76)
%78 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %75, i32 %77)
%79 = call i64 @wait(i32* %1)
%80 = load i32, i32* %1
%81 = call i32 @WEXITSTATUS(i32 %80)
%82 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %79, i32 %81)
%83 = call i32 @sleep(i32 99999)
br label %84
84: ; preds = %0, %5, %9, %13, %17, %21, %25, %29, %33, %37, %41
%85 = phi i32 [ 0, %41 ], [ 1, %0 ], [ 2, %5 ], [ 3, %9 ], [ 4, %13 ], [ 5, %17 ], [ 6, %21 ], [ 7, %25 ], [ 8, %29 ], [ 9, %33 ], [ 10, %37 ]
ret i32 %85
}