#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 */
scalar_t__ fork();
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, int, int);
main() {
  if (fork() == 0) {
    printf("child 1 pid=%d ppid=%d\n", getpid(), getppid());
  } else {
    if (fork() == 0) {
      printf("child 2 pid=%d ppid=%d\n", getpid(), getppid());
    } else {
      if (fork() == 0) {
        printf("child 3 pid=%d ppid=%d\n", getpid(), getppid());
      } else {
        printf("parent pid=%d ppid=%d\n", getpid(), getppid());
        while (1)
          ;
      }
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
cmp    $0x0,%rax
jne    1187 <main+0x47>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x8(%rbp),%esi
mov    %eax,%edx
lea    0xe83(%rip),%rdi
call   1040 <printf@plt>
jmp    1228 <main+0xe8>
mov    $0x0,%al
call   1060 <fork@plt>
cmp    $0x0,%rax
jne    11bf <main+0x7f>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0xc(%rbp),%esi
mov    %eax,%edx
lea    0xe63(%rip),%rdi
call   1040 <printf@plt>
jmp    1223 <main+0xe3>
mov    $0x0,%al
call   1060 <fork@plt>
cmp    $0x0,%rax
jne    11f7 <main+0xb7>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x10(%rbp),%esi
mov    %eax,%edx
lea    0xe43(%rip),%rdi
call   1040 <printf@plt>
jmp    121e <main+0xde>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x14(%rbp),%esi
mov    %eax,%edx
lea    0xe34(%rip),%rdi
call   1040 <printf@plt>
jmp    1219 <main+0xd9>
jmp    1223 <main+0xe3>
jmp    1228 <main+0xe8>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     1192 <main+0x52>
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     11ab <main+0x6b>
xor    %eax,%eax
call   1060 <fork@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <getppid@plt>
test   %rbx,%rbx
je     11c6 <main+0x86>
lea    0xec7(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1040 <printf@plt>
nopw   0x0(%rax,%rax,1)
jmp    1190 <main+0x50>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe57(%rip),%rdi
jmp    11c2 <main+0x82>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe56(%rip),%rdi
mov    %ebx,%esi
jmp    11cf <main+0x8f>
lea    0xe63(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"child 1 pid=%d ppid=%d\0A\00"
@.str.1 = [24 x i8] c"child 2 pid=%d ppid=%d\0A\00"
@.str.2 = [24 x i8] c"child 3 pid=%d ppid=%d\0A\00"
@.str.3 = [23 x i8] c"parent pid=%d ppid=%d\0A\00"
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i64 (...) @fork()
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = call i32 (...) @getpid()
%6 = call i32 (...) @getppid()
%7 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6)
br label %29
8: ; preds = %0
%9 = call i64 (...) @fork()
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = call i32 (...) @getpid()
%13 = call i32 (...) @getppid()
%14 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 %13)
br label %28
15: ; preds = %8
%16 = call i64 (...) @fork()
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = call i32 (...) @getpid()
%20 = call i32 (...) @getppid()
%21 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %19, i32 %20)
br label %27
22: ; preds = %15
%23 = call i32 (...) @getpid()
%24 = call i32 (...) @getppid()
%25 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %23, i32 %24)
br label %26
26: ; preds = %22, %26
br label %26
27: ; preds = %18
br label %28
28: ; preds = %27, %11
br label %29
29: ; preds = %28, %4
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@.str = [24 x i8] c"child 1 pid=%d ppid=%d\0A\00"
@.str.1 = [24 x i8] c"child 2 pid=%d ppid=%d\0A\00"
@.str.2 = [24 x i8] c"child 3 pid=%d ppid=%d\0A\00"
@.str.3 = [23 x i8] c"parent pid=%d ppid=%d\0A\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %7
3: ; preds = %0
%4 = tail call i32 (...) @getpid()
%5 = tail call i32 (...) @getppid()
%6 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %5)
br label %24
7: ; preds = %0
%8 = tail call i64 (...) @fork()
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = tail call i32 (...) @getpid()
%12 = tail call i32 (...) @getppid()
%13 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %12)
br label %24
14: ; preds = %7
%15 = tail call i64 (...) @fork()
%16 = icmp eq i64 %15, 0
%17 = tail call i32 (...) @getpid()
%18 = tail call i32 (...) @getppid()
br i1 %16, label %19, label %21
19: ; preds = %14
%20 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 %18)
br label %24
21: ; preds = %14
%22 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %17, i32 %18)
br label %23
23: ; preds = %21, %23
br label %23
24: ; preds = %10, %19, %3
ret i32 0
}