#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;
void *create_shared_memory();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ handle_fatal_error(char *);
int /*<<< orphan*/ manage_child(void *);
int /*<<< orphan*/ manage_parent(void *);
int main(void) {
  pid_t pid;
  void *shared_memory;
  shared_memory = create_shared_memory();
  pid = fork();
  if (pid < 0) {
    handle_fatal_error("Error using fork().\n");
  }
  if (pid > 0) {
    manage_parent(shared_memory);
  } else {
    manage_child(shared_memory);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <create_shared_memory@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    119c <main+0x3c>
lea    0xe69(%rip),%rdi
call   1030 <handle_fatal_error@plt>
cmpq   $0x0,-0x10(%rbp)
jle    11b5 <main+0x55>
mov    -0x18(%rbp),%rdi
call   1040 <manage_parent@plt>
jmp    11be <main+0x5e>
mov    -0x18(%rbp),%rdi
call   1050 <manage_child@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1070 <create_shared_memory@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
jns    1185 <main+0x25>
lea    0xe82(%rip),%rdi
call   1030 <handle_fatal_error@plt>
jmp    1187 <main+0x27>
jne    1191 <main+0x31>
mov    %rbx,%rdi
call   1050 <manage_child@plt>
jmp    1199 <main+0x39>
mov    %rbx,%rdi
call   1040 <manage_parent@plt>
mov    0x2e40(%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
%3 = alloca i8*
store i32 0, i32* %1
%4 = call i8* (...) @create_shared_memory()
store i8* %4, i8** %3
%5 = call i64 (...) @fork()
store i64 %5, i64* %2
%6 = load i64, i64* %2
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @handle_fatal_error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = load i64, i64* %2
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i8*, i8** %3
%15 = call i32 @manage_parent(i8* %14)
br label %19
16: ; preds = %10
%17 = load i8*, i8** %3
%18 = call i32 @manage_child(i8* %17)
br label %19
19: ; preds = %16, %13
%20 = load i32, i32* @EXIT_SUCCESS
%21 = call i32 @exit(i32 %20)
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 i8* (...) @create_shared_memory()
%2 = tail call i64 (...) @fork()
%3 = icmp slt i64 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @handle_fatal_error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %10
6: ; preds = %0
%7 = icmp eq i64 %2, 0
br i1 %7, label %10, label %8
8: ; preds = %6
%9 = tail call i32 @manage_parent(i8* %1)
br label %12
10: ; preds = %4, %6
%11 = tail call i32 @manage_child(i8* %1)
br label %12
12: ; preds = %10, %8
%13 = load i32, i32* @EXIT_SUCCESS
%14 = tail call i32 @exit(i32 %13)
unreachable
}