#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 EXIT_SUCCESS;
int /*<<< orphan*/ child_code(int);
int fork();
int getpid();
int /*<<< orphan*/ parent_code(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int main(void) {
  int newpid;
  printf("Before: my pid is %d\n", getpid());
  if ((newpid = fork()) == -1)
    perror("fork");
  else if (newpid == 0)
    child_code(2);
  else
    parent_code(newpid);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe81(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    11a8 <main+0x48>
lea    0xe78(%rip),%rdi
call   1050 <perror@plt>
jmp    11ce <main+0x6e>
cmpl   $0x0,-0x8(%rbp)
jne    11c1 <main+0x61>
mov    $0x2,%edi
call   1070 <child_code@plt>
jmp    11c9 <main+0x69>
mov    -0x8(%rbp),%edi
call   1060 <parent_code@plt>
jmp    11ce <main+0x6e>
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe91(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     118f <main+0x2f>
cmp    $0xffffffff,%eax
je     11a4 <main+0x44>
mov    %eax,%edi
call   1060 <parent_code@plt>
jmp    1199 <main+0x39>
mov    $0x2,%edi
call   1070 <child_code@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret
lea    0xe6b(%rip),%rdi
call   1050 <perror@plt>
jmp    1199 <main+0x39>

LLVM IR (-O0):
@.str = [22 x i8] c"Before: my pid is %d\0A\00"
@.str.1 = [5 x i8] c"fork\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (...) @getpid()
%4 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = call i32 (...) @fork()
store i32 %5, i32* %2
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %18
9: ; preds = %0
%10 = load i32, i32* %2
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 @child_code(i32 2)
br label %17
14: ; preds = %9
%15 = load i32, i32* %2
%16 = call i32 @parent_code(i32 %15)
br label %17
17: ; preds = %14, %12
br label %18
18: ; preds = %17, %7
%19 = load i32, i32* @EXIT_SUCCESS
ret i32 %19
}

LLVM IR (-O2):
@.str = [22 x i8] c"Before: my pid is %d\0A\00"
@.str.1 = [5 x i8] c"fork\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i32 (...) @getpid()
%2 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32 (...) @fork()
switch i32 %3, label %8 [
i32 -1, label %4
i32 0, label %6
]
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %10
6: ; preds = %0
%7 = tail call i32 @child_code(i32 2)
br label %10
8: ; preds = %0
%9 = tail call i32 @parent_code(i32 %3)
br label %10
10: ; preds = %6, %8, %4
%11 = load i32, i32* @EXIT_SUCCESS
ret i32 %11
}