#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 EXIT_SUCCESS;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  pid_t pids[9];
  int i;
  int n = 9;
  for (i = 0; i < n; i++) {
    pids[i] = fork();
    if (pids[i] < 0) {
      perror("fork");
      abort();
    } else if (pids[i] == 0) {
      printf("I am a child: %d with PID: %d\n", i, getpid());
      printf("Child will exit now...\n");
      exit(0);
    }
  }
  wait(NULL);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x9,-0x68(%rbp)
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x68(%rbp),%eax
jge    1233 <main+0xc3>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,%rcx
movslq -0x64(%rbp),%rax
mov    %rcx,-0x60(%rbp,%rax,8)
movslq -0x64(%rbp),%rax
cmpq   $0x0,-0x60(%rbp,%rax,8)
jge    11d6 <main+0x66>
lea    0xe36(%rip),%rdi
call   1060 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
movslq -0x64(%rbp),%rax
cmpq   $0x0,-0x60(%rbp,%rax,8)
jne    121b <main+0xab>
mov    -0x64(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x6c(%rbp),%esi
mov    %eax,%edx
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
jmp    1220 <main+0xb0>
jmp    1225 <main+0xb5>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1194 <main+0x24>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <wait@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
js     1223 <main+0xa3>
je     126c <main+0xec>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
js     1223 <main+0xa3>
je     1236 <main+0xb6>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
js     1223 <main+0xa3>
je     123d <main+0xbd>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
js     1223 <main+0xa3>
je     1244 <main+0xc4>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
js     1223 <main+0xa3>
je     124b <main+0xcb>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
js     1223 <main+0xa3>
je     1252 <main+0xd2>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
js     1223 <main+0xa3>
je     1259 <main+0xd9>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
js     1223 <main+0xa3>
je     1260 <main+0xe0>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
js     1223 <main+0xa3>
je     1267 <main+0xe7>
xor    %edi,%edi
call   1090 <wait@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret
lea    0xdd6(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>
mov    $0x1,%ebx
jmp    126c <main+0xec>
mov    $0x2,%ebx
jmp    126c <main+0xec>
mov    $0x3,%ebx
jmp    126c <main+0xec>
mov    $0x4,%ebx
jmp    126c <main+0xec>
mov    $0x5,%ebx
jmp    126c <main+0xec>
mov    $0x6,%ebx
jmp    126c <main+0xec>
mov    $0x7,%ebx
jmp    126c <main+0xec>
mov    $0x8,%ebx
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xd8b(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd98(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
@.str.1 = [31 x i8] c"I am a child: %d with PID: %d\0A\00"
@.str.2 = [24 x i8] c"Child will exit now...\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [9 x i64]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 9, i32* %8
store i32 0, i32* %7
br label %9
9: ; preds = %40, %2
%10 = load i32, i32* %7
%11 = load i32, i32* %8
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %43
13: ; preds = %9
%14 = call i64 (...) @fork()
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [9 x i64], [9 x i64]* %6, i64 0, i64 %16
store i64 %14, i64* %17
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [9 x i64], [9 x i64]* %6, i64 0, i64 %19
%21 = load i64, i64* %20
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %13
%24 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%25 = call i32 (...) @abort()
unreachable
26: ; preds = %13
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [9 x i64], [9 x i64]* %6, i64 0, i64 %28
%30 = load i64, i64* %29
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %26
%33 = load i32, i32* %7
%34 = call i32 (...) @getpid()
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %33, i32 %34)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%37 = call i32 @exit(i32 0)
unreachable
38: ; preds = %26
br label %39
39: ; preds = %38
br label %40
40: ; preds = %39
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %9
43: ; preds = %9
%44 = call i32 @wait(i32* null)
%45 = load i32, i32* @EXIT_SUCCESS
ret i32 %45
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
@.str.1 = [31 x i8] c"I am a child: %d with PID: %d\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [23 x i8] c"Child will exit now...\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 (...) @fork()
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %51, %46, %41, %36, %31, %26, %21, %16, %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 (...) @abort()
unreachable
8: ; preds = %2
%9 = icmp eq i64 %3, 0
br i1 %9, label %10, label %16
10: ; preds = %54, %49, %44, %39, %34, %29, %24, %19, %8
%11 = phi i32 [ 0, %8 ], [ 1, %19 ], [ 2, %24 ], [ 3, %29 ], [ 4, %34 ], [ 5, %39 ], [ 6, %44 ], [ 7, %49 ], [ 8, %54 ]
%12 = tail call i32 (...) @getpid()
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %12)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %8
%17 = tail call i64 (...) @fork()
%18 = icmp slt i64 %17, 0
br i1 %18, label %5, label %19
19: ; preds = %16
%20 = icmp eq i64 %17, 0
br i1 %20, label %10, label %21
21: ; preds = %19
%22 = tail call i64 (...) @fork()
%23 = icmp slt i64 %22, 0
br i1 %23, label %5, label %24
24: ; preds = %21
%25 = icmp eq i64 %22, 0
br i1 %25, label %10, label %26
26: ; preds = %24
%27 = tail call i64 (...) @fork()
%28 = icmp slt i64 %27, 0
br i1 %28, label %5, label %29
29: ; preds = %26
%30 = icmp eq i64 %27, 0
br i1 %30, label %10, label %31
31: ; preds = %29
%32 = tail call i64 (...) @fork()
%33 = icmp slt i64 %32, 0
br i1 %33, label %5, label %34
34: ; preds = %31
%35 = icmp eq i64 %32, 0
br i1 %35, label %10, label %36
36: ; preds = %34
%37 = tail call i64 (...) @fork()
%38 = icmp slt i64 %37, 0
br i1 %38, label %5, label %39
39: ; preds = %36
%40 = icmp eq i64 %37, 0
br i1 %40, label %10, label %41
41: ; preds = %39
%42 = tail call i64 (...) @fork()
%43 = icmp slt i64 %42, 0
br i1 %43, label %5, label %44
44: ; preds = %41
%45 = icmp eq i64 %42, 0
br i1 %45, label %10, label %46
46: ; preds = %44
%47 = tail call i64 (...) @fork()
%48 = icmp slt i64 %47, 0
br i1 %48, label %5, label %49
49: ; preds = %46
%50 = icmp eq i64 %47, 0
br i1 %50, label %10, label %51
51: ; preds = %49
%52 = tail call i64 (...) @fork()
%53 = icmp slt i64 %52, 0
br i1 %53, label %5, label %54
54: ; preds = %51
%55 = icmp eq i64 %52, 0
br i1 %55, label %10, label %56
56: ; preds = %54
%57 = tail call i32 @wait(i32* null)
%58 = load i32, i32* @EXIT_SUCCESS
ret i32 %58
}