#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*/ client(int, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int /*<<< orphan*/ server(int, int);
int main(int argc, char *argv[]) {
  int fd1[2], fd2[2];
  int cpid;
  if (pipe(fd1) != 0) {
    perror("pipe");
    exit(0);
  }
  if (pipe(fd2) != 0) {
    perror("pipe");
    exit(0);
  }
  if ((cpid = fork()) == 0) {
    close(fd1[1]);
    close(fd2[0]);
    server(fd1[0], fd2[1]);
    return 0;
  } else if (cpid == -1) {
    perror("fork");
    exit(0);
  } else {
    close(fd1[0]);
    close(fd2[1]);
    client(fd2[0], fd1[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    -0x18(%rbp),%rdi
call   1040 <pipe@plt>
cmp    $0x0,%rax
je     11ac <main+0x3c>
lea    0xe60(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1080 <exit@plt>
lea    -0x20(%rbp),%rdi
call   1040 <pipe@plt>
cmp    $0x0,%rax
je     11d2 <main+0x62>
lea    0xe3a(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jne    120c <main+0x9c>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
mov    -0x20(%rbp),%edi
call   1030 <close@plt>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1050 <server@plt>
movl   $0x0,-0x4(%rbp)
jmp    1250 <main+0xe0>
cmpl   $0xffffffff,-0x24(%rbp)
jne    1229 <main+0xb9>
lea    0xde8(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%edi
call   1030 <close@plt>
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
mov    -0x20(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1070 <client@plt>
jmp    1249 <main+0xd9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0x10(%rsp),%rdi
call   1040 <pipe@plt>
test   %rax,%rax
jne    11e9 <main+0x79>
lea    0x8(%rsp),%rdi
call   1040 <pipe@plt>
test   %rax,%rax
jne    11e9 <main+0x79>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     11c3 <main+0x53>
cmp    $0xffffffff,%eax
je     11f2 <main+0x82>
mov    0x10(%rsp),%edi
call   1030 <close@plt>
mov    0xc(%rsp),%edi
call   1030 <close@plt>
mov    0x8(%rsp),%edi
mov    0x14(%rsp),%esi
call   1070 <client@plt>
jmp    11e2 <main+0x72>
mov    0x14(%rsp),%edi
call   1030 <close@plt>
mov    0x8(%rsp),%edi
call   1030 <close@plt>
mov    0x10(%rsp),%edi
mov    0xc(%rsp),%esi
call   1050 <server@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
lea    0xe10(%rip),%rdi
jmp    11f9 <main+0x89>
lea    0xe0c(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"pipe\00"
@.str.1 = [5 x i8] c"fork\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca [2 x i32]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%10 = call i64 @pipe(i32* %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 0)
unreachable
15: ; preds = %2
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%17 = call i64 @pipe(i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %15
%23 = call i32 (...) @fork()
store i32 %23, i32* %8
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %37
25: ; preds = %22
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%27 = load i32, i32* %26
%28 = call i32 @close(i32 %27)
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%30 = load i32, i32* %29
%31 = call i32 @close(i32 %30)
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%33 = load i32, i32* %32
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%35 = load i32, i32* %34
%36 = call i32 @server(i32 %33, i32 %35)
store i32 0, i32* %3
br label %57
37: ; preds = %22
%38 = load i32, i32* %8
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%42 = call i32 @exit(i32 0)
unreachable
43: ; preds = %37
%44 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%45 = load i32, i32* %44
%46 = call i32 @close(i32 %45)
%47 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%48 = load i32, i32* %47
%49 = call i32 @close(i32 %48)
%50 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%51 = load i32, i32* %50
%52 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%53 = load i32, i32* %52
%54 = call i32 @client(i32 %51, i32 %53)
br label %55
55: ; preds = %43
br label %56
56: ; preds = %55
store i32 0, i32* %3
br label %57
57: ; preds = %56, %25
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@.str = [5 x i8] c"pipe\00"
@.str.1 = [5 x i8] c"fork\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i32]
%4 = alloca [2 x i32]
%5 = bitcast [2 x i32]* %3 to i8*
%6 = bitcast [2 x i32]* %4 to i8*
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%8 = call i64 @pipe(i32* %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
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 0)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%15 = call i64 @pipe(i32* %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %13
%21 = call i32 (...) @fork()
switch i32 %21, label %35 [
i32 0, label %22
i32 -1, label %32
]
22: ; preds = %20
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%24 = load i32, i32* %23
%25 = call i32 @close(i32 %24)
%26 = load i32, i32* %14
%27 = call i32 @close(i32 %26)
%28 = load i32, i32* %7
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%30 = load i32, i32* %29
%31 = call i32 @server(i32 %28, i32 %30)
br label %45
32: ; preds = %20
%33 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 @exit(i32 0)
unreachable
35: ; preds = %20
%36 = load i32, i32* %7
%37 = call i32 @close(i32 %36)
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%39 = load i32, i32* %38
%40 = call i32 @close(i32 %39)
%41 = load i32, i32* %14
%42 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%43 = load i32, i32* %42
%44 = call i32 @client(i32 %41, i32 %43)
br label %45
45: ; preds = %35, %22
ret i32 0
}