#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_1, newpid_2;
  printf("Before: my pid is %d\n", getpid());
  if ((newpid_1 = fork()) == -1)
    perror("fork");
  else if (newpid_1 == 0)
    child_code(2);
  else {
    if ((newpid_2 = fork()) == -1)
      perror("fork");
    else if (newpid_2 == 0)
      child_code(2);
    parent_code(newpid_1);
    parent_code(newpid_2);
  }
  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    1213 <main+0xb3>
cmpl   $0x0,-0x8(%rbp)
jne    11c1 <main+0x61>
mov    $0x2,%edi
call   1070 <child_code@plt>
jmp    120e <main+0xae>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    11e5 <main+0x85>
lea    0xe3b(%rip),%rdi
call   1050 <perror@plt>
jmp    11fe <main+0x9e>
cmpl   $0x0,-0xc(%rbp)
jne    11f9 <main+0x99>
mov    $0x2,%edi
call   1070 <child_code@plt>
jmp    11fe <main+0x9e>
mov    -0x8(%rbp),%edi
call   1060 <parent_code@plt>
mov    -0xc(%rbp),%edi
call   1060 <parent_code@plt>
jmp    1213 <main+0xb3>
mov    0x2dc6(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe8f(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     11aa <main+0x4a>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     11de <main+0x7e>
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,%ebp
test   %eax,%eax
je     11b6 <main+0x56>
cmp    $0xffffffff,%ebp
jne    11c0 <main+0x60>
lea    0xe73(%rip),%rdi
call   1050 <perror@plt>
jmp    11c0 <main+0x60>
mov    $0x2,%edi
call   1070 <child_code@plt>
jmp    11ce <main+0x6e>
mov    $0x2,%edi
call   1070 <child_code@plt>
mov    %ebx,%edi
call   1060 <parent_code@plt>
mov    %ebp,%edi
call   1060 <parent_code@plt>
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe31(%rip),%rdi
call   1050 <perror@plt>
jmp    11ce <main+0x6e>

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
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (...) @getpid()
%5 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = call i32 (...) @fork()
store i32 %6, i32* %2
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %32
10: ; preds = %0
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @child_code(i32 2)
br label %31
15: ; preds = %10
%16 = call i32 (...) @fork()
store i32 %16, i32* %3
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %26
20: ; preds = %15
%21 = load i32, i32* %3
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 @child_code(i32 2)
br label %25
25: ; preds = %23, %20
br label %26
26: ; preds = %25, %18
%27 = load i32, i32* %2
%28 = call i32 @parent_code(i32 %27)
%29 = load i32, i32* %3
%30 = call i32 @parent_code(i32 %29)
br label %31
31: ; preds = %26, %13
br label %32
32: ; preds = %31, %8
%33 = load i32, i32* @EXIT_SUCCESS
ret i32 %33
}

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 %17
6: ; preds = %0
%7 = tail call i32 @child_code(i32 2)
br label %17
8: ; preds = %0
%9 = tail call i32 (...) @fork()
switch i32 %9, label %14 [
i32 -1, label %10
i32 0, label %12
]
10: ; preds = %8
%11 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %14
12: ; preds = %8
%13 = tail call i32 @child_code(i32 2)
br label %14
14: ; preds = %8, %12, %10
%15 = tail call i32 @parent_code(i32 %3)
%16 = tail call i32 @parent_code(i32 %9)
br label %17
17: ; preds = %6, %14, %4
%18 = load i32, i32* @EXIT_SUCCESS
ret i32 %18
}