#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() {
  int i;
  for (i = 0; i < 3; i++) {
    if (fork() == 0) {
      printf("Created child with pid= %d and its parent is = %d\n", getpid(),
             getppid());
      break;
    } else {
      if (i == 0)
        printf("In parent pid is = %d, its parent is = %d\n", getpid(),
               getppid());
    }
  }
  while (1)
    ;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11dc <main+0x9c>
mov    $0x0,%al
call   1060 <fork@plt>
cmp    $0x0,%rax
jne    1198 <main+0x58>
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    0xe72(%rip),%rdi
call   1040 <printf@plt>
jmp    11dc <main+0x9c>
cmpl   $0x0,-0x8(%rbp)
jne    11c4 <main+0x84>
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    0xe74(%rip),%rdi
call   1040 <printf@plt>
jmp    11c9 <main+0x89>
jmp    11ce <main+0x8e>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1156 <main+0x16>
jmp    11e1 <main+0xa1>
jmp    11e1 <main+0xa1>

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     1185 <main+0x45>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xecf(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     1185 <main+0x45>
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
jne    11b0 <main+0x70>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe64(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
nop
jmp    11b0 <main+0x70>

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

LLVM IR (-O2):
@.str = [51 x i8] c"Created child with pid= %d and its parent is = %d\0A\00"
@.str.1 = [43 x i8] c"In parent pid is = %d, its parent is = %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 = %13, %7, %0
%4 = tail call i32 (...) @getpid()
%5 = tail call i32 (...) @getppid()
%6 = tail call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %5)
br label %16
7: ; preds = %0
%8 = tail call i32 (...) @getpid()
%9 = tail call i32 (...) @getppid()
%10 = tail call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %8, i32 %9)
%11 = tail call i64 (...) @fork()
%12 = icmp eq i64 %11, 0
br i1 %12, label %3, label %13
13: ; preds = %7
%14 = tail call i64 (...) @fork()
%15 = icmp eq i64 %14, 0
br i1 %15, label %3, label %16
16: ; preds = %13, %3
br label %17
17: ; preds = %16, %17
br label %17
}