#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) {
    if (fork() == 0) {
      if (fork() == 0) {
        printf("in child 3 pid=%d,ppid=%d \n", getpid(), getppid());
        while (1)
          ;
      } else {
        printf("in child 2 pid=%d,ppid=%d \n", getpid(), getppid());
        while (1)
          ;
      }
    } else {
      printf("in child 1 pid=%d,ppid=%d \n", getpid(), getppid());
      while (1)
        ;
    }
  } else {
    printf("in 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    11f7 <main+0xb7>
mov    $0x0,%al
call   1060 <fork@plt>
cmp    $0x0,%rax
jne    11d0 <main+0x90>
mov    $0x0,%al
call   1060 <fork@plt>
cmp    $0x0,%rax
jne    11a9 <main+0x69>
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    0xe61(%rip),%rdi
call   1040 <printf@plt>
jmp    11a4 <main+0x64>
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    0xe56(%rip),%rdi
call   1040 <printf@plt>
jmp    11cb <main+0x8b>
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    0xe4b(%rip),%rdi
call   1040 <printf@plt>
jmp    11f2 <main+0xb2>
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    0xe40(%rip),%rdi
call   1040 <printf@plt>
jmp    1219 <main+0xd9>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     1172 <main+0x32>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xeee(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <printf@plt>
nop
jmp    1170 <main+0x30>
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     11a2 <main+0x62>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xea3(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <printf@plt>
xchg   %ax,%ax
jmp    11a0 <main+0x60>
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     11e2 <main+0xa2>
lea    0xe54(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1040 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
jmp    11e0 <main+0xa0>
lea    0xe17(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1040 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
jmp    1200 <main+0xc0>

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

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