#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 int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ client(int, int);
int close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ perror(char *);
int pipe(int *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ server(int, int);
char *strerror(int /*<<< orphan*/);
int waitpid(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int pipe1[2];
  int pipe2[2];
  pid_t childfd;
  if (-1 == pipe(pipe1) || -1 == pipe(pipe2)) {
    printf("create pipe error: %s", strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (0 == (childfd = fork())) {
    if (-1 == close(pipe1[1]) || -1 == close(pipe2[0])) {
      printf("close pipe error: %s", strerror(errno));
      exit(EXIT_FAILURE);
    }
    server(pipe1[0], pipe2[1]);
    exit(EXIT_SUCCESS);
  }
  if (-1 == close(pipe1[0]) || -1 == close(pipe2[1])) {
    printf("close pipe error: %s", strerror(errno));
    exit(EXIT_FAILURE);
  }
  client(pipe2[0], pipe1[1]);
  if (-1 == waitpid(childfd, NULL, 0)) {
    perror("waitpid error");
    exit(EXIT_FAILURE);
  }
  exit(EXIT_SUCCESS);
}


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   1050 <pipe@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     11e6 <main+0x46>
lea    -0x20(%rbp),%rdi
call   1050 <pipe@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1211 <main+0x71>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %rax,%rsi
lea    0xe02(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x24(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
jne    1299 <main+0xf9>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     1255 <main+0xb5>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1280 <main+0xe0>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %rax,%rsi
lea    0xda9(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1060 <server@plt>
mov    0x2d3e(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     12c7 <main+0x127>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    12f2 <main+0x152>
mov    0x2d12(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %rax,%rsi
lea    0xd37(%rip),%rdi
call   1030 <printf@plt>
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1090 <client@plt>
mov    -0x24(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <waitpid@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1334 <main+0x194>
lea    0xd0a(%rip),%rdi
call   1080 <perror@plt>
mov    0x2cab(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2c95(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
cmp    $0xffffffff,%eax
je     11c1 <main+0x21>
mov    %rsp,%rdi
call   1050 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11d8 <main+0x38>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xe2a(%rip),%rdi
jmp    1240 <main+0xa0>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %eax,%eax
jne    120d <main+0x6d>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
je     122b <main+0x8b>
mov    (%rsp),%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
je     122b <main+0x8b>
mov    0x8(%rsp),%edi
mov    0x4(%rsp),%esi
call   1060 <server@plt>
jmp    1280 <main+0xe0>
mov    %eax,%ebx
mov    0x8(%rsp),%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
je     122b <main+0x8b>
mov    0x4(%rsp),%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
jne    1256 <main+0xb6>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xdd6(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    (%rsp),%edi
mov    0xc(%rsp),%esi
call   1090 <client@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    1280 <main+0xe0>
lea    0xdb2(%rip),%rdi
call   1080 <perror@plt>
jmp    1248 <main+0xa8>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"create pipe error: %s\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [21 x i8] c"close pipe error: %s\00"
@EXIT_SUCCESS = global i32 0
@.str.2 = [14 x i8] c"waitpid error\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 i32 @pipe(i32* %9)
%11 = icmp eq i32 -1, %10
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%14 = call i32 @pipe(i32* %13)
%15 = icmp eq i32 -1, %14
br i1 %15, label %16, label %22
16: ; preds = %12, %2
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %12
%23 = call i32 (...) @fork()
store i32 %23, i32* %8
%24 = icmp eq i32 0, %23
br i1 %24, label %25, label %49
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 = icmp eq i32 -1, %28
br i1 %29, label %35, label %30
30: ; preds = %25
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%32 = load i32, i32* %31
%33 = call i32 @close(i32 %32)
%34 = icmp eq i32 -1, %33
br i1 %34, label %35, label %41
35: ; preds = %30, %25
%36 = load i32, i32* @errno
%37 = call i8* @strerror(i32 %36)
%38 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %37)
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %30
%42 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%43 = load i32, i32* %42
%44 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%45 = load i32, i32* %44
%46 = call i32 @server(i32 %43, i32 %45)
%47 = load i32, i32* @EXIT_SUCCESS
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %22
%50 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%51 = load i32, i32* %50
%52 = call i32 @close(i32 %51)
%53 = icmp eq i32 -1, %52
br i1 %53, label %59, label %54
54: ; preds = %49
%55 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%56 = load i32, i32* %55
%57 = call i32 @close(i32 %56)
%58 = icmp eq i32 -1, %57
br i1 %58, label %59, label %65
59: ; preds = %54, %49
%60 = load i32, i32* @errno
%61 = call i8* @strerror(i32 %60)
%62 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %61)
%63 = load i32, i32* @EXIT_FAILURE
%64 = call i32 @exit(i32 %63)
unreachable
65: ; preds = %54
%66 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%67 = load i32, i32* %66
%68 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%69 = load i32, i32* %68
%70 = call i32 @client(i32 %67, i32 %69)
%71 = load i32, i32* %8
%72 = call i32 @waitpid(i32 %71, i32* null, i32 0)
%73 = icmp eq i32 -1, %72
br i1 %73, label %74, label %78
74: ; preds = %65
%75 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%76 = load i32, i32* @EXIT_FAILURE
%77 = call i32 @exit(i32 %76)
unreachable
78: ; preds = %65
%79 = load i32, i32* @EXIT_SUCCESS
%80 = call i32 @exit(i32 %79)
unreachable
}

LLVM IR (-O2):
@.str = [22 x i8] c"create pipe error: %s\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [21 x i8] c"close pipe error: %s\00"
@EXIT_SUCCESS = global i32 0
@.str.2 = [14 x i8] c"waitpid error\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 i32 @pipe(i32* %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%12 = call i32 @pipe(i32* %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %20
14: ; preds = %10, %2
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %10
%21 = call i32 (...) @fork()
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %45
23: ; preds = %20
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%25 = load i32, i32* %24
%26 = call i32 @close(i32 %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %32, label %28
28: ; preds = %23
%29 = load i32, i32* %11
%30 = call i32 @close(i32 %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %38
32: ; preds = %28, %23
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %34)
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %28
%39 = load i32, i32* %7
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%41 = load i32, i32* %40
%42 = call i32 @server(i32 %39, i32 %41)
%43 = load i32, i32* @EXIT_SUCCESS
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %20
%46 = load i32, i32* %7
%47 = call i32 @close(i32 %46)
%48 = icmp eq i32 %47, -1
br i1 %48, label %54, label %49
49: ; preds = %45
%50 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%51 = load i32, i32* %50
%52 = call i32 @close(i32 %51)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %60
54: ; preds = %49, %45
%55 = load i32, i32* @errno
%56 = call i8* @strerror(i32 %55)
%57 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %56)
%58 = load i32, i32* @EXIT_FAILURE
%59 = call i32 @exit(i32 %58)
unreachable
60: ; preds = %49
%61 = load i32, i32* %11
%62 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%63 = load i32, i32* %62
%64 = call i32 @client(i32 %61, i32 %63)
%65 = call i32 @waitpid(i32 %21, i32* null, i32 0)
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %71
67: ; preds = %60
%68 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%69 = load i32, i32* @EXIT_FAILURE
%70 = call i32 @exit(i32 %69)
unreachable
71: ; preds = %60
%72 = load i32, i32* @EXIT_SUCCESS
%73 = call i32 @exit(i32 %72)
unreachable
}