#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 */
int WEXITSTATUS(int);
int /*<<< orphan*/ _exit(int);
int fork();
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ wait(int *);
int main(int argc, char **argv) {
  for (int i = 0; i < 10; i++) {
    int pid = fork();
    int status = i + 1;
    if (pid == 0) {
      printf("CHILD %d// PID: %d PPID: %d\n", i + 1, getpid(), getppid());
      _exit(status);
    } else {
      printf("FATHER// PID: %d PPID: %d CHILD_PID: %d\n", getpid(), getppid(),
             pid);
      wait(&status);
      printf("FATHER// CHILD DIED WITH %d", WEXITSTATUS(status));
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    1247 <main+0xd7>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11ec <main+0x7c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1070 <getppid@plt>
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    %eax,%ecx
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1030 <_exit@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1070 <getppid@plt>
mov    -0x28(%rbp),%esi
mov    %eax,%edx
mov    -0x18(%rbp),%ecx
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x1c(%rbp),%rdi
call   1080 <wait@plt>
mov    -0x1c(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1239 <main+0xc9>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118d <main+0x1d>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1,%ebx
lea    0xe96(%rip),%r14
lea    0x4(%rsp),%r15
lea    0xeb3(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1090 <fork@plt>
mov    %eax,%ebp
mov    %ebx,0x4(%rsp)
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%r13d
xor    %eax,%eax
call   1070 <getppid@plt>
test   %ebp,%ebp
je     120c <main+0x9c>
mov    %r14,%rdi
mov    %r13d,%esi
mov    %eax,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
call   1080 <wait@plt>
mov    0x4(%rsp),%edi
call   1060 <WEXITSTATUS@plt>
mov    %r12,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%ebx
cmp    $0xb,%ebx
jne    11a0 <main+0x30>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xded(%rip),%rdi
mov    %ebx,%esi
mov    %r13d,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rsp),%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"CHILD %d// PID: %d PPID: %d\0A\00"
@.str.1 = [41 x i8] c"FATHER// PID: %d PPID: %d CHILD_PID: %d\0A\00"
@.str.2 = [28 x i8] c"FATHER// CHILD DIED WITH %d\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
br label %9
9: ; preds = %36, %2
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 10
br i1 %11, label %12, label %39
12: ; preds = %9
%13 = call i32 (...) @fork()
store i32 %13, i32* %7
%14 = load i32, i32* %6
%15 = add nsw i32 %14, 1
store i32 %15, i32* %8
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %12
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 1
%21 = call i32 (...) @getpid()
%22 = call i32 (...) @getppid()
%23 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %20, i32 %21, i32 %22)
%24 = load i32, i32* %8
%25 = call i32 @_exit(i32 %24)
unreachable
26: ; preds = %12
%27 = call i32 (...) @getpid()
%28 = call i32 (...) @getppid()
%29 = load i32, i32* %7
%30 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 %28, i32 %29)
%31 = call i32 @wait(i32* %8)
%32 = load i32, i32* %8
%33 = call i32 @WEXITSTATUS(i32 %32)
%34 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %26
br label %36
36: ; preds = %35
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %9
39: ; preds = %9
ret i32 1
}

LLVM IR (-O2):
@.str = [29 x i8] c"CHILD %d// PID: %d PPID: %d\0A\00"
@.str.1 = [41 x i8] c"FATHER// PID: %d PPID: %d CHILD_PID: %d\0A\00"
@.str.2 = [28 x i8] c"FATHER// CHILD DIED WITH %d\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
br label %6
5: ; preds = %17
ret i32 1
6: ; preds = %2, %17
%7 = phi i32 [ 0, %2 ], [ %9, %17 ]
%8 = call i32 (...) @fork()
%9 = add nuw nsw i32 %7, 1
store i32 %9, i32* %3
%10 = icmp eq i32 %8, 0
%11 = call i32 (...) @getpid()
%12 = call i32 (...) @getppid()
br i1 %10, label %13, label %17
13: ; preds = %6
%14 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %11, i32 %12)
%15 = load i32, i32* %3
%16 = call i32 @_exit(i32 %15)
unreachable
17: ; preds = %6
%18 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %12, i32 %8)
%19 = call i32 @wait(i32* %3)
%20 = load i32, i32* %3
%21 = call i32 @WEXITSTATUS(i32 %20)
%22 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = icmp eq i32 %9, 10
br i1 %23, label %5, label %6
}