#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 /*<<< orphan*/ execlp(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int Exec(int argc, char *argv[]) {
  int pid;
  pid = fork();
  if (pid < 0) {
    fprintf(stderr, "Fork Failed!");
    exit(-1);
  } else if (pid == 0) {
    printf("This is Child Process!\n");
    execlp("/hello", "hello", NULL);
  } else {
    printf("This is Parent Process!\n");
    wait(NULL);
    printf("Child Complete!\n");
  }
}


x86 assembly (clang, -O0):
<Exec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11a2 <Exec+0x42>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
jne    11d4 <Exec+0x74>
lea    0xe5a(%rip),%rdi
call   1030 <printf@plt>
lea    0xe66(%rip),%rdi
lea    0xe60(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <execlp@plt>
jmp    11f5 <Exec+0x95>
lea    0xe51(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <wait@plt>
lea    0xe55(%rip),%rdi
call   1030 <printf@plt>
jmp    11fa <Exec+0x9a>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Exec>:
push   %rax
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
js     11b2 <Exec+0x52>
je     118f <Exec+0x2f>
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <wait@plt>
lea    0xea4(%rip),%rdi
call   1030 <puts@plt>
pop    %rcx
ret
lea    0xea6(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6b(%rip),%rdi
lea    0xe65(%rip),%rsi
xor    %edx,%edx
call   1060 <execlp@plt>
pop    %rcx
ret
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
lea    0xe3e(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [13 x i8] c"Fork Failed!\00"
@.str.1 = [24 x i8] c"This is Child Process!\0A\00"
@.str.2 = [7 x i8] c"/hello\00"
@.str.3 = [6 x i8] c"hello\00"
@.str.4 = [25 x i8] c"This is Parent Process!\0A\00"
@.str.5 = [17 x i8] c"Child Complete!\0A\00"
define i32 @Exec(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 (...) @fork()
store i32 %7, i32* %6
%8 = load i32, i32* %6
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %2
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @execlp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* null)
br label %24
20: ; preds = %14
%21 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%22 = call i32 @wait(i32* null)
%23 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %24
24: ; preds = %20, %17
br label %25
25: ; preds = %24
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [13 x i8] c"Fork Failed!\00"
@.str.2 = [7 x i8] c"/hello\00"
@.str.3 = [6 x i8] c"hello\00"
@str = [24 x i8] c"This is Parent Process!\00"
@str.6 = [16 x i8] c"Child Complete!\00"
@str.7 = [23 x i8] c"This is Child Process!\00"
define i32 @Exec(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @fork()
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %2
%10 = icmp eq i32 %3, 0
br i1 %10, label %11, label %14
11: ; preds = %9
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.7, i64 0, i64 0))
%13 = tail call i32 @execlp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* null)
br label %18
14: ; preds = %9
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%16 = tail call i32 @wait(i32* null)
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.6, i64 0, i64 0))
br label %18
18: ; preds = %11, %14
ret i32 undef
}