#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 */
int /*<<< orphan*/ execlp(char *, char *, int /*<<< orphan*/ *);
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, let me call test case and my PID is : %d\n\n", getpid());
    execlp("/home/jatin/Documents/os/testcase", "testcase", NULL);
  } 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   1070 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    1188 <main+0x38>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11fb <main+0xab>
cmpq   $0x0,-0x10(%rbp)
jne    11c6 <main+0x76>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb1(%rip),%rdi
lea    0xec3(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <execlp@plt>
jmp    11f6 <main+0xa6>
cmpq   $0x0,-0x10(%rbp)
jle    11f1 <main+0xa1>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <wait@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f6 <main+0xa6>
jmp    11fb <main+0xab>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
js     118f <main+0x2f>
je     119d <main+0x3d>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xed3(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11c9 <main+0x69>
lea    0xee9(%rip),%rdi
call   1030 <puts@plt>
jmp    11c9 <main+0x69>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe55(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe7a(%rip),%rdi
lea    0xe8c(%rip),%rsi
xor    %edx,%edx
call   1060 <execlp@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [45 x i8] c"\0AError !! Process not created successfully.\0A\00"
@.str.1 = [53 x i8] c"\0AHI PAPA, let me call test case and my PID is : %d\0A\0A\00"
@.str.2 = [34 x i8] c"/home/jatin/Documents/os/testcase\00"
@.str.3 = [9 x i8] c"testcase\00"
@.str.4 = [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 %24
8: ; preds = %0
%9 = load i64, i64* %2
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = call i32 (...) @getpid()
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = call i32 @execlp(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32* null)
br label %23
15: ; preds = %8
%16 = load i64, i64* %2
%17 = icmp sgt i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = call i32 @wait(i32* null)
%20 = call i32 (...) @getpid()
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %18, %15
br label %23
23: ; preds = %22, %11
br label %24
24: ; preds = %23, %6
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [53 x i8] c"\0AHI PAPA, let me call test case and my PID is : %d\0A\0A\00"
@.str.2 = [34 x i8] c"/home/jatin/Documents/os/testcase\00"
@.str.3 = [9 x i8] c"testcase\00"
@.str.4 = [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 %15
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 ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = tail call i32 @execlp(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32* null)
br label %15
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.4, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %7, %11, %3
ret i32 0
}