#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 */
typedef scalar_t__ pid_t;

/* Variables and functions */
scalar_t__ fork();
int getpid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main() {
  pid_t pid;
  pid = fork();
  if (pid < 0) {
    printf("\nError !! Process not created successfully.\n");
  } else if (pid == 0) {
    printf("\nHI PAPA and my PID is : %d\n\n", getpid());
  } else if (pid > 0) {
    wait(NULL);
    printf("\nI am your PAPA !! and my PID is : %d\n\n", getpid());
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    1178 <main+0x38>
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11d4 <main+0x94>
cmpq   $0x0,-0x10(%rbp)
jne    119f <main+0x5f>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11cf <main+0x8f>
cmpq   $0x0,-0x10(%rbp)
jle    11ca <main+0x8a>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <wait@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11cf <main+0x8f>
jmp    11d4 <main+0x94>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
js     1176 <main+0x26>
je     1184 <main+0x34>
xor    %edi,%edi
call   1060 <wait@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xeaa(%rip),%rdi
jmp    1192 <main+0x42>
lea    0xec9(%rip),%rdi
call   1030 <puts@plt>
jmp    119b <main+0x4b>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe6e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [45 x i8] c"\0AError !! Process not created successfully.\0A\00"
@.str.1 = [30 x i8] c"\0AHI PAPA and my PID is : %d\0A\0A\00"
@.str.2 = [40 x i8] c"\0AI am your PAPA !! and my PID is : %d\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
store i32 0, i32* %1
%3 = call i64 (...) @fork()
store i64 %3, i64* %2
%4 = load i64, i64* %2
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %23
8: ; preds = %0
%9 = load i64, i64* %2
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = call i32 (...) @getpid()
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %12)
br label %22
14: ; preds = %8
%15 = load i64, i64* %2
%16 = icmp sgt i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = call i32 @wait(i32* null)
%19 = call i32 (...) @getpid()
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %17, %14
br label %22
22: ; preds = %21, %11
br label %23
23: ; preds = %22, %6
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [30 x i8] c"\0AHI PAPA and my PID is : %d\0A\0A\00"
@.str.2 = [40 x i8] c"\0AI am your PAPA !! and my PID is : %d\0A\0A\00"
@str = [44 x i8] c"\0AError !! Process not created successfully.\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp slt i64 %1, 0
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
br label %14
5: ; preds = %0
%6 = icmp eq i64 %1, 0
br i1 %6, label %7, label %10
7: ; preds = %5
%8 = tail call i32 (...) @getpid()
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %8)
br label %14
10: ; preds = %5
%11 = tail call i32 @wait(i32* null)
%12 = tail call i32 (...) @getpid()
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %7, %10, %3
ret i32 0
}