#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 int pid_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ getpid();
scalar_t__ getppid();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  pid_t proc_id = fork();
  if (proc_id == -1) {
    fprintf(stderr, "Fork failure\n");
    exit(1);
  } else if (proc_id == 0) {
    fprintf(stdout, "Child : PID=%ld, PPID=%ld\n", (long)getpid(),
            (long)getppid());
    exit(0);
  } else {
    fprintf(stdout, "Parent : PID=%ld, PPID=%ld, FORK_RETURN=%ld\n",
            (long)getpid(), (long)getppid(), (long)proc_id);
    wait(NULL);
    exit(0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11ab <main+0x4b>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
jne    11f2 <main+0x92>
mov    0x2e1c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    %rax,%rcx
lea    0xe2a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
movslq -0x14(%rbp),%r8
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     1197 <main+0x37>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11ce <main+0x6e>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
lea    0xe7a(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe56(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%r14d
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   1050 <getppid@plt>
movslq %ebx,%r8
lea    0xe36(%rip),%rsi
mov    %r14d,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [14 x i8] c"Fork failure\0A\00"
@stdout = global i32 0
@.str.1 = [27 x i8] c"Child : PID=%ld, PPID=%ld\0A\00"
@.str.2 = [45 x i8] c"Parent : PID=%ld, PPID=%ld, FORK_RETURN=%ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
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 eq i32 %8, -1
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([14 x i8], [14 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 %23
17: ; preds = %14
%18 = load i32, i32* @stdout
%19 = call i64 (...) @getpid()
%20 = call i64 (...) @getppid()
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i64 %19, i64 %20)
%22 = call i32 @exit(i32 0)
unreachable
23: ; preds = %14
%24 = load i32, i32* @stdout
%25 = call i64 (...) @getpid()
%26 = call i64 (...) @getppid()
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i64 %25, i64 %26, i64 %28)
%30 = call i32 @wait(i32* null)
%31 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [14 x i8] c"Fork failure\0A\00"
@stdout = global i32 0
@.str.1 = [27 x i8] c"Child : PID=%ld, PPID=%ld\0A\00"
@.str.2 = [45 x i8] c"Parent : PID=%ld, PPID=%ld, FORK_RETURN=%ld\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @fork()
switch i32 %3, label %14 [
i32 -1, label %4
i32 0, label %8
]
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = load i32, i32* @stdout
%10 = tail call i64 (...) @getpid()
%11 = tail call i64 (...) @getppid()
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i64 %10, i64 %11)
%13 = tail call i32 @exit(i32 0)
unreachable
14: ; preds = %2
%15 = load i32, i32* @stdout
%16 = tail call i64 (...) @getpid()
%17 = tail call i64 (...) @getppid()
%18 = sext i32 %3 to i64
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i64 %16, i64 %17, i64 %18)
%20 = tail call i32 @wait(i32* null)
%21 = tail call i32 @exit(i32 0)
unreachable
}