#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*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int Fork(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");
  } else {
    printf("This is Parent Process!\n");
    wait(NULL);
    printf("Child Complete!\n");
  }
}


x86 assembly (clang, -O0):
<Fork>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1192 <Fork+0x42>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
jne    11ad <Fork+0x5d>
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
jmp    11ce <Fork+0x7e>
lea    0xe71(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <wait@plt>
lea    0xe75(%rip),%rdi
call   1030 <printf@plt>
jmp    11d3 <Fork+0x83>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Fork>:
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
js     118b <Fork+0x3b>
je     117e <Fork+0x2e>
lea    0xea8(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <wait@plt>
lea    0xead(%rip),%rdi
pop    %rax
jmp    1030 <puts@plt>
lea    0xeb0(%rip),%rdi
pop    %rax
jmp    1030 <puts@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
lea    0xe65(%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 = [25 x i8] c"This is Parent Process!\0A\00"
@.str.3 = [17 x i8] c"Child Complete!\0A\00"
define i32 @Fork(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 %19
17: ; preds = %14
%18 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %23
19: ; preds = %14
%20 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @wait(i32* null)
%22 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %19, %17
br label %24
24: ; preds = %23
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [13 x i8] c"Fork Failed!\00"
@str = [24 x i8] c"This is Parent Process!\00"
@str.4 = [16 x i8] c"Child Complete!\00"
@str.5 = [23 x i8] c"This is Child Process!\00"
define i32 @Fork(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 %14, label %11
11: ; preds = %9
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 @wait(i32* null)
br label %14
14: ; preds = %9, %11
%15 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @str.4, i64 0, i64 0), %11 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @str.5, i64 0, i64 0), %9 ]
%16 = tail call i32 @puts(i8* dereferenceable(1) %15)
ret i32 undef
}