#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 fork();
int getpid();
int /*<<< orphan*/ printf(char *, int, ...);
int main() {
  int pid;
  int var;
  var = 53;
  pid = fork();
  if (pid == 0) {
    printf("Child ID\t%d\n", getpid());
    var = -100;
  } else {
    printf("Parent ID\t%d\n", getpid());
    var = 100;
  }
  printf("var = %d\t'var' address = %p\tprocessID = %d\n", var, &var, getpid());
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x35,-0xc(%rbp)
mov    $0x0,%al
call   1050 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    117d <main+0x4d>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffff9c,-0xc(%rbp)
jmp    119b <main+0x6b>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x64,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x10(%rbp),%esi
mov    %eax,%ecx
lea    0xe67(%rip),%rdi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1050 <fork@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
test   %ebx,%ebx
lea    0xeb2(%rip),%rcx
lea    0xeb8(%rip),%rdi
cmove  %rcx,%rdi
mov    $0xffffff9c,%ecx
mov    $0x64,%ebx
cmove  %ecx,%ebx
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,0xc(%rsp)
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe9a(%rip),%rdi
lea    0xc(%rsp),%rdx
mov    %ebx,%esi
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Child ID\09%d\0A\00"
@.str.1 = [14 x i8] c"Parent ID\09%d\0A\00"
@.str.2 = [44 x i8] c"var = %d\09'var' address = %p\09processID = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
store i32 53, i32* %3
%4 = call i32 (...) @fork()
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 (...) @getpid()
%9 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 -100, i32* %3
br label %13
10: ; preds = %0
%11 = call i32 (...) @getpid()
%12 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %11)
store i32 100, i32* %3
br label %13
13: ; preds = %10, %7
%14 = load i32, i32* %3
%15 = call i32 (...) @getpid()
%16 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %14, i32* %3, i32 %15)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"Child ID\09%d\0A\00"
@.str.1 = [14 x i8] c"Parent ID\09%d\0A\00"
@.str.2 = [44 x i8] c"var = %d\09'var' address = %p\09processID = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (...) @fork()
%4 = icmp eq i32 %3, 0
%5 = tail call i32 (...) @getpid()
%6 = select i1 %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0)
%7 = select i1 %4, i32 -100, i32 100
%8 = tail call i32 (i8*, i32, ...) @printf(i8* %6, i32 %5)
store i32 %7, i32* %1
%9 = tail call i32 (...) @getpid()
%10 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %7, i32* %1, i32 %9)
ret i32 0
}