#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(char *);
int /*<<< orphan*/ manage_child(int *);
int /*<<< orphan*/ manage_parent(int *);
int pipe(int *);
int main(void) {
  pid_t pid;
  int anonymous_pipe[2];
  if (pipe(anonymous_pipe) == -1) {
    handle_fatal_error("Error creating pipe.\n");
  }
  pid = fork();
  if (pid < 0) {
    handle_fatal_error("Error using fork().\n");
  }
  if (pid > 0) {
    manage_parent(anonymous_pipe);
  } else {
    manage_child(anonymous_pipe);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x18(%rbp),%rdi
call   1040 <pipe@plt>
cmp    $0xffffffff,%eax
jne    118d <main+0x2d>
lea    0xe78(%rip),%rdi
call   1030 <handle_fatal_error@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    11af <main+0x4f>
lea    0xe6c(%rip),%rdi
call   1030 <handle_fatal_error@plt>
cmpq   $0x0,-0x10(%rbp)
jle    11c8 <main+0x68>
lea    -0x18(%rbp),%rdi
call   1050 <manage_parent@plt>
jmp    11d1 <main+0x71>
lea    -0x18(%rbp),%rdi
call   1060 <manage_child@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    %rsp,%rdi
call   1040 <pipe@plt>
cmp    $0xffffffff,%eax
jne    117a <main+0x1a>
lea    0xe8b(%rip),%rdi
call   1030 <handle_fatal_error@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
jns    1194 <main+0x34>
lea    0xe89(%rip),%rdi
call   1030 <handle_fatal_error@plt>
jmp    1196 <main+0x36>
jne    11a0 <main+0x40>
mov    %rsp,%rdi
call   1060 <manage_child@plt>
jmp    11a8 <main+0x48>
mov    %rsp,%rdi
call   1050 <manage_parent@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"Error creating pipe.\0A\00"
@.str.1 = [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 [2 x i32]
store i32 0, i32* %1
%4 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%5 = call i32 @pipe(i32* %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @handle_fatal_error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = call i64 (...) @fork()
store i64 %10, i64* %2
%11 = load i64, i64* %2
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @handle_fatal_error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %9
%16 = load i64, i64* %2
%17 = icmp sgt i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%20 = call i32 @manage_parent(i32* %19)
br label %24
21: ; preds = %15
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%23 = call i32 @manage_child(i32* %22)
br label %24
24: ; preds = %21, %18
%25 = load i32, i32* @EXIT_SUCCESS
%26 = call i32 @exit(i32 %25)
unreachable
}

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