#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*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main() {
  int var = 5;
  pid_t ret;
  printf("Main Process PID = %d\n", getpid());
  ret = fork();
  if (ret == 0) {
    printf(" >> ret = %d\n", ret);
  } else {
    printf(" ret = %d\n", ret);
  }
  if (ret < 0) {
    fprintf(stderr, "Fork Failed");
    exit(-1);
  } else if (ret == 0) {
    printf(">> Parent PID = %d\n", getppid());
    printf(">> Child PID = %d\n", getpid());
    var = var + 10;
    printf(">>var = %d\n", var);
  } else {
    wait(NULL);
    printf("Child Complete\n");
  }
  printf("var = %d\n", var);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x5,-0x8(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ca <main+0x5a>
mov    -0x10(%rbp),%rsi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11dc <main+0x6c>
mov    -0x10(%rbp),%rsi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
jge    1206 <main+0x96>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
lea    0xe2e(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jne    125e <main+0xee>
mov    $0x0,%al
call   1060 <getppid@plt>
mov    %eax,%esi
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1275 <main+0x105>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <wait@plt>
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    127a <main+0x10a>
mov    -0x8(%rbp),%esi
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe71(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
je     11db <main+0x5b>
mov    %rax,%rbx
lea    0xe6c(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
test   %rbx,%rbx
js     1245 <main+0xc5>
xor    %edi,%edi
call   1090 <wait@plt>
lea    0xe95(%rip),%rdi
call   1030 <puts@plt>
mov    $0x5,%ebx
jmp    1231 <main+0xb1>
lea    0xe35(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <getppid@plt>
lea    0xe38(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe35(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe38(%rip),%rdi
mov    $0xf,%ebx
mov    $0xf,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe22(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
lea    0xdd0(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"Main Process PID = %d\0A\00"
@.str.1 = [14 x i8] c" >> ret = %d\0A\00"
@.str.2 = [11 x i8] c" ret = %d\0A\00"
@stderr = global i32 0
@.str.3 = [12 x i8] c"Fork Failed\00"
@.str.4 = [20 x i8] c">> Parent PID = %d\0A\00"
@.str.5 = [19 x i8] c">> Child PID = %d\0A\00"
@.str.6 = [12 x i8] c">>var = %d\0A\00"
@.str.7 = [16 x i8] c"Child Complete\0A\00"
@.str.8 = [10 x i8] c"var = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
store i32 0, i32* %1
store i32 5, i32* %2
%4 = call i32 (...) @getpid()
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = call i64 (...) @fork()
store i64 %6, i64* %3
%7 = load i64, i64* %3
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = load i64, i64* %3
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 %10)
br label %15
12: ; preds = %0
%13 = load i64, i64* %3
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 %13)
br label %15
15: ; preds = %12, %9
%16 = load i64, i64* %3
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%21 = call i32 @exit(i32 -1)
unreachable
22: ; preds = %15
%23 = load i64, i64* %3
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %34
25: ; preds = %22
%26 = call i32 (...) @getppid()
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%28 = call i32 (...) @getpid()
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %2
%31 = add nsw i32 %30, 10
store i32 %31, i32* %2
%32 = load i32, i32* %2
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %32)
br label %37
34: ; preds = %22
%35 = call i32 @wait(i32* null)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
br label %37
37: ; preds = %34, %25
br label %38
38: ; preds = %37
%39 = load i32, i32* %2
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %1
ret i32 %41
}

LLVM IR (-O2):
@.str = [23 x i8] c"Main Process PID = %d\0A\00"
@.str.1 = [14 x i8] c" >> ret = %d\0A\00"
@.str.2 = [11 x i8] c" ret = %d\0A\00"
@stderr = global i32 0
@.str.3 = [12 x i8] c"Fork Failed\00"
@.str.4 = [20 x i8] c">> Parent PID = %d\0A\00"
@.str.5 = [19 x i8] c">> Child PID = %d\0A\00"
@.str.6 = [12 x i8] c">>var = %d\0A\00"
@.str.8 = [10 x i8] c"var = %d\0A\00"
@str = [15 x i8] c"Child Complete\00"
define i32 @main() {
%1 = tail call i32 (...) @getpid()
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %12, label %5
5: ; preds = %0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 %3)
%7 = icmp slt i64 %3, 0
br i1 %7, label %8, label %19
8: ; preds = %5
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%11 = tail call i32 @exit(i32 -1)
unreachable
12: ; preds = %0
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 0)
%14 = tail call i32 (...) @getppid()
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %14)
%16 = tail call i32 (...) @getpid()
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %16)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 15)
br label %22
19: ; preds = %5
%20 = tail call i32 @wait(i32* null)
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %22
22: ; preds = %12, %19
%23 = phi i32 [ 15, %12 ], [ 5, %19 ]
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 %23)
ret i32 0
}