#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 fork();
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int pid;
  printf("Hello World!\n");
  printf("Here I am  before use of forking\n");
  printf("I am the PARENT process and pid is : %d\n", getpid());
  pid = fork();
  if (pid == 0) {
    printf("\n\nHere I am just after forking\n");
    printf("I am the Child process and pid is :%d\n", getpid());
    printf("My parent's pid is: %d\n", getppid());
  } else {
    printf("\n\nHere I am just after forking\n");
    printf("I am the Parent process and pid is: %d\n", getpid());
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11d7 <main+0x97>
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getppid@plt>
mov    %eax,%esi
lea    0xed5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11fc <main+0xbc>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xf38(%rip),%rdi
call   1030 <puts@plt>
lea    0xf39(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe89(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <fork@plt>
lea    0xf30(%rip),%rdi
test   %eax,%eax
je     11a7 <main+0x57>
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xec3(%rip),%rdi
jmp    11d1 <main+0x81>
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe6f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <getppid@plt>
lea    0xe7f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Hello World!\0A\00"
@.str.1 = [34 x i8] c"Here I am before use of forking\0A\00"
@.str.2 = [41 x i8] c"I am the PARENT process and pid is : %d\0A\00"
@.str.3 = [32 x i8] c"\0A\0AHere I am just after forking\0A\00"
@.str.4 = [39 x i8] c"I am the Child process and pid is :%d\0A\00"
@.str.5 = [24 x i8] c"My parent's pid is: %d\0A\00"
@.str.6 = [40 x i8] c"I am the Parent process and pid is: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 (...) @getpid()
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%7 = call i32 (...) @fork()
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 (...) @getpid()
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %12)
%14 = call i32 (...) @getppid()
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %14)
br label %20
16: ; preds = %0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 (...) @getpid()
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %16, %10
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@.str.2 = [41 x i8] c"I am the PARENT process and pid is : %d\0A\00"
@.str.4 = [39 x i8] c"I am the Child process and pid is :%d\0A\00"
@.str.5 = [24 x i8] c"My parent's pid is: %d\0A\00"
@.str.6 = [40 x i8] c"I am the Parent process and pid is: %d\0A\00"
@str = [13 x i8] c"Hello World!\00"
@str.7 = [33 x i8] c"Here I am before use of forking\00"
@str.9 = [31 x i8] c"\0A\0AHere I am just after forking\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.7, i64 0, i64 0))
%3 = tail call i32 (...) @getpid()
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %3)
%5 = tail call i32 (...) @fork()
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.9, i64 0, i64 0))
%9 = tail call i32 (...) @getpid()
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %9)
%11 = tail call i32 (...) @getppid()
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %11)
br label %17
13: ; preds = %0
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.9, i64 0, i64 0))
%15 = tail call i32 (...) @getpid()
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %13, %7
ret i32 0
}