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

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ handle_fatal_error_and_exit(char *);
int /*<<< orphan*/ manage_child();
int /*<<< orphan*/ manage_parent(scalar_t__);
int main(void) {
  pid_t pid;
  pid = fork();
  if (pid < 0) {
    handle_fatal_error_and_exit("Error using fork().\n");
  }
  if (pid > 0) {
    manage_parent(pid);
  } else {
    manage_child();
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    1181 <main+0x31>
lea    0xe84(%rip),%rdi
call   1030 <handle_fatal_error_and_exit@plt>
cmpq   $0x0,-0x10(%rbp)
jle    119a <main+0x4a>
mov    -0x10(%rbp),%rdi
call   1040 <manage_parent@plt>
jmp    11a1 <main+0x51>
mov    $0x0,%al
call   1050 <manage_child@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
jns    116b <main+0x1b>
lea    0xe9c(%rip),%rdi
call   1030 <handle_fatal_error_and_exit@plt>
jmp    116d <main+0x1d>
jne    1176 <main+0x26>
xor    %eax,%eax
call   1050 <manage_child@plt>
jmp    117e <main+0x2e>
mov    %rax,%rdi
call   1040 <manage_parent@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"Error using fork().\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
store i32 0, i32* %1
%3 = call i64 (...) @fork()
store i64 %3, i64* %2
%4 = load i64, i64* %2
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @handle_fatal_error_and_exit(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = load i64, i64* %2
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i64, i64* %2
%13 = call i32 @manage_parent(i64 %12)
br label %16
14: ; preds = %8
%15 = call i32 (...) @manage_child()
br label %16
16: ; preds = %14, %11
%17 = load i32, i32* @EXIT_SUCCESS
%18 = call i32 @exit(i32 %17)
unreachable
}

LLVM IR (-O2):
@.str = [21 x i8] c"Error using fork().\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp slt i64 %1, 0
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @handle_fatal_error_and_exit(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %9
5: ; preds = %0
%6 = icmp eq i64 %1, 0
br i1 %6, label %9, label %7
7: ; preds = %5
%8 = tail call i32 @manage_parent(i64 %1)
br label %11
9: ; preds = %3, %5
%10 = tail call i32 (...) @manage_child()
br label %11
11: ; preds = %9, %7
%12 = load i32, i32* @EXIT_SUCCESS
%13 = tail call i32 @exit(i32 %12)
unreachable
}