#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() {
  int a = 4, b = 5;
  pid_t pid;
  pid = fork();
  if (pid < 0) {
    printf("\nError !! Process not created successfully.\n");
  } else if (pid == 0) {
    int a = 30, b = 10;
    printf("\nHI PAPA !! and my PID is : %d\n", getpid());
    printf("sum is : %d", a + b);
  } else if (pid > 0) {
    wait(NULL);
    printf("\nI am your PAPA !! and my PID is : %d\n\n", getpid());
    printf("Diff is : %d\n\n", a - b);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x4,-0x8(%rbp)
movl   $0x5,-0xc(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1186 <main+0x46>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1218 <main+0xd8>
cmpq   $0x0,-0x18(%rbp)
jne    11cf <main+0x8f>
movl   $0x1e,-0x1c(%rbp)
movl   $0xa,-0x20(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%esi
add    -0x20(%rbp),%esi
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1213 <main+0xd3>
cmpq   $0x0,-0x18(%rbp)
jle    120e <main+0xce>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <wait@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%esi
sub    -0xc(%rbp),%esi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1213 <main+0xd3>
jmp    1218 <main+0xd8>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
js     118b <main+0x3b>
je     1199 <main+0x49>
xor    %edi,%edi
call   1060 <wait@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xeb8(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xed0(%rip),%rdi
mov    $0xffffffff,%esi
jmp    11bc <main+0x6c>
lea    0xed1(%rip),%rdi
call   1030 <puts@plt>
jmp    11c3 <main+0x73>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe59(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe69(%rip),%rdi
mov    $0x28,%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 = [32 x i8] c"\0AHI PAPA !! and my PID is : %d\0A\00"
@.str.2 = [12 x i8] c"sum is : %d\00"
@.str.3 = [40 x i8] c"\0AI am your PAPA !! and my PID is : %d\0A\0A\00"
@.str.4 = [15 x i8] c"Diff is : %d\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 4, i32* %2
store i32 5, i32* %3
%7 = call i64 (...) @fork()
store i64 %7, i64* %4
%8 = load i64, i64* %4
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %35
12: ; preds = %0
%13 = load i64, i64* %4
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %12
store i32 30, i32* %5
store i32 10, i32* %6
%16 = call i32 (...) @getpid()
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %5
%19 = load i32, i32* %6
%20 = add nsw i32 %18, %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %20)
br label %34
22: ; preds = %12
%23 = load i64, i64* %4
%24 = icmp sgt i64 %23, 0
br i1 %24, label %25, label %33
25: ; preds = %22
%26 = call i32 @wait(i32* null)
%27 = call i32 (...) @getpid()
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %2
%30 = load i32, i32* %3
%31 = sub nsw i32 %29, %30
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %25, %22
br label %34
34: ; preds = %33, %15
br label %35
35: ; preds = %34, %10
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [32 x i8] c"\0AHI PAPA !! and my PID is : %d\0A\00"
@.str.2 = [12 x i8] c"sum is : %d\00"
@.str.3 = [40 x i8] c"\0AI am your PAPA !! and my PID is : %d\0A\0A\00"
@.str.4 = [15 x i8] c"Diff 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 %16
5: ; preds = %0
%6 = icmp eq i64 %1, 0
br i1 %6, label %7, label %11
7: ; preds = %5
%8 = tail call i32 (...) @getpid()
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 40)
br label %16
11: ; preds = %5
%12 = tail call i32 @wait(i32* null)
%13 = tail call i32 (...) @getpid()
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 -1)
br label %16
16: ; preds = %7, %11, %3
ret i32 0
}