#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 */

/* Variables and functions */
int /*<<< orphan*/ child_process(int, int);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ parent_process(int, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  int n, i, pid, pipes[2];
  if (pipe(pipes) < 0) {
    printf("We had an error when we tried to create the pipes %d", i);
    perror("pipe");
    exit(0);
  }
  pid = fork();
  if (pid < 0) {
    printf("We had an erorr when we tried to fork");
    exit(1);
  } else if (pid == 0) {
    child_process(pipes[0], pipes[1]);
    exit(0);
  } else {
    parent_process(pipes[0], pipes[1]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x24(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0x0,%rax
jge    11bd <main+0x4d>
mov    -0x18(%rbp),%esi
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe84(%rip),%rdi
call   1070 <perror@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11e9 <main+0x79>
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    1205 <main+0x95>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1050 <child_process@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1030 <parent_process@plt>
jmp    1215 <main+0xa5>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    %rsp,%rdi
call   1060 <pipe@plt>
test   %rax,%rax
js     119b <main+0x2b>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
js     11bc <main+0x4c>
mov    (%rsp),%edi
mov    0x4(%rsp),%esi
je     11d4 <main+0x64>
call   1030 <parent_process@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe5e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe85(%rip),%rdi
call   1070 <perror@plt>
xor    %edi,%edi
call   1080 <exit@plt>
lea    0xe77(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
call   1050 <child_process@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [53 x i8] c"We had an error when we tried to create the pipes %d\00"
@.str.1 = [5 x i8] c"pipe\00"
@.str.2 = [38 x i8] c"We had an erorr when we tried to fork\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [2 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%11 = call i64 @pipe(i32* %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32, i32* %7
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %2
%19 = call i32 (...) @fork()
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %18
%26 = load i32, i32* %8
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %25
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%30 = load i32, i32* %29
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%32 = load i32, i32* %31
%33 = call i32 @child_process(i32 %30, i32 %32)
%34 = call i32 @exit(i32 0)
unreachable
35: ; preds = %25
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%37 = load i32, i32* %36
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%39 = load i32, i32* %38
%40 = call i32 @parent_process(i32 %37, i32 %39)
br label %41
41: ; preds = %35
br label %42
42: ; preds = %41
ret i32 0
}

LLVM IR (-O2):
@.str = [53 x i8] c"We had an error when we tried to create the pipes %d\00"
@.str.1 = [5 x i8] c"pipe\00"
@.str.2 = [38 x i8] c"We had an erorr when we tried to fork\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i32]
%4 = bitcast [2 x i32]* %3 to i8*
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%6 = call i64 @pipe(i32* %5)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 undef)
%10 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @exit(i32 0)
unreachable
12: ; preds = %2
%13 = call i32 (...) @fork()
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %12
%19 = icmp eq i32 %13, 0
%20 = load i32, i32* %5
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%22 = load i32, i32* %21
br i1 %19, label %23, label %26
23: ; preds = %18
%24 = call i32 @child_process(i32 %20, i32 %22)
%25 = call i32 @exit(i32 0)
unreachable
26: ; preds = %18
%27 = call i32 @parent_process(i32 %20, i32 %22)
ret i32 0
}