#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_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ child_process(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ parent_process(int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  pid_t pid;
  pid = fork();
  if (pid == -1) {
    fprintf(stderr, "Err.(%s) fork() failed\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (pid == 0)
    child_process(pid);
  else
    parent_process(pid);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%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    11c4 <main+0x64>
mov    0x2e4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rdx
lea    0xe4f(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
jne    11db <main+0x7b>
mov    -0x14(%rbp),%edi
call   1040 <child_process@plt>
jmp    11e3 <main+0x83>
mov    -0x14(%rbp),%edi
call   1030 <parent_process@plt>
mov    0x2dde(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     117a <main+0x1a>
cmp    $0xffffffff,%eax
je     118c <main+0x2c>
mov    %eax,%edi
call   1030 <parent_process@plt>
jmp    1181 <main+0x21>
xor    %edi,%edi
call   1040 <child_process@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret
mov    0x2e4d(%rip),%rax
mov    (%rax),%ebx
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe56(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"Err.(%s) fork() failed\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
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 %17
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* %6
%22 = call i32 @child_process(i32 %21)
br label %26
23: ; preds = %17
%24 = load i32, i32* %6
%25 = call i32 @parent_process(i32 %24)
br label %26
26: ; preds = %23, %20
%27 = load i32, i32* @EXIT_SUCCESS
ret i32 %27
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"Err.(%s) fork() failed\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @fork()
switch i32 %3, label %13 [
i32 -1, label %4
i32 0, label %11
]
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i32, i32* @errno
%7 = tail call i8* @strerror(i32 %6)
%8 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = tail call i32 @child_process(i32 0)
br label %15
13: ; preds = %2
%14 = tail call i32 @parent_process(i32 %3)
br label %15
15: ; preds = %13, %11
%16 = load i32, i32* @EXIT_SUCCESS
ret i32 %16
}