#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(int);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ parent(int);
int /*<<< orphan*/ perror(char *);
int pipe(int *);
int main(int argc, char **argv) {
  int fds[2];
  if (pipe(fds) == -1) {
    perror("pipe");
    exit(1);
  }
  if (fork() == 0) {
    child(fds[0]);
  } else {
    parent(fds[1]);
  }
  return 0;
}


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)
lea    -0x18(%rbp),%rdi
call   1050 <pipe@plt>
cmp    $0xffffffff,%eax
jne    119e <main+0x3e>
lea    0xe71(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    $0x0,%al
call   1080 <fork@plt>
cmp    $0x0,%rax
jne    11bc <main+0x5c>
mov    -0x18(%rbp),%edi
call   1030 <child@plt>
jmp    11c4 <main+0x64>
mov    -0x14(%rbp),%edi
call   1040 <parent@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    %rsp,%rdi
call   1050 <pipe@plt>
cmp    $0xffffffff,%eax
je     1191 <main+0x31>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     1185 <main+0x25>
mov    0x4(%rsp),%edi
call   1040 <parent@plt>
jmp    118d <main+0x2d>
mov    (%rsp),%edi
call   1030 <child@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe68(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"pipe\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%8 = call i32 @pipe(i32* %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = call i64 (...) @fork()
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%18 = load i32, i32* %17
%19 = call i32 @child(i32 %18)
br label %24
20: ; preds = %13
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%22 = load i32, i32* %21
%23 = call i32 @parent(i32 %22)
br label %24
24: ; preds = %20, %16
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"pipe\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 i32 @pipe(i32* %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = call i64 (...) @fork()
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* %5
%16 = call i32 @child(i32 %15)
br label %21
17: ; preds = %11
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%19 = load i32, i32* %18
%20 = call i32 @parent(i32 %19)
br label %21
21: ; preds = %17, %14
ret i32 0
}