#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*/ client(char *, int, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fork();
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ server(int, int);
int /*<<< orphan*/ waitpid(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf("usage: %s <pathname>\n", argv[0]);
    return 1;
  }
  int pipe1[2];
  int pipe2[2];
  pid_t child_pid;
  if (pipe(pipe1) != 0) {
    printf("create pipe1 error\n");
    exit(1);
  }
  if (pipe(pipe1) != 0) {
    printf("create pipe1 error\n");
    exit(1);
  }
  if ((child_pid = fork()) == 0) {
    close(pipe1[1]);
    close(pipe2[0]);
    server(pipe1[0], pipe2[1]);
    exit(0);
  }
  close(pipe1[0]);
  close(pipe2[1]);
  client(argv[1], pipe2[0], pipe1[1]);
  waitpid(child_pid, NULL, 0);
  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)
cmpl   $0x2,-0x8(%rbp)
jge    11c1 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1284 <main+0x104>
lea    -0x18(%rbp),%rdi
call   1050 <pipe@plt>
cmp    $0x0,%rax
je     11ec <main+0x6c>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x18(%rbp),%rdi
call   1050 <pipe@plt>
cmp    $0x0,%rax
je     1217 <main+0x97>
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jne    124c <main+0xcc>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1060 <server@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x20(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1080 <client@plt>
mov    -0x24(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <waitpid@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
cmp    $0x1,%edi
jg     11b8 <main+0x28>
mov    (%r14),%rsi
lea    0xe56(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebx
jmp    120b <main+0x7b>
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
test   %rax,%rax
jne    1216 <main+0x86>
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
test   %rax,%rax
jne    1216 <main+0x86>
xor    %ebx,%ebx
xor    %eax,%eax
call   10b0 <fork@plt>
test   %eax,%eax
je     122c <main+0x9c>
mov    %eax,%ebp
mov    0x8(%rsp),%edi
call   1050 <close@plt>
call   1050 <close@plt>
mov    0x8(%r14),%rdi
mov    0xc(%rsp),%edx
call   1090 <client@plt>
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <waitpid@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdf9(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
call   1050 <close@plt>
mov    0x8(%rsp),%edi
call   1070 <server@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

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

LLVM IR (-O2):
@.str = [22 x i8] c"usage: %s <pathname>\0A\00"
@str.2 = [19 x i8] c"create pipe1 error\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i32]
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %43
8: ; preds = %2
%9 = bitcast [2 x i32]* %3 to i8*
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%11 = call i64 @pipe(i32* %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.2, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %8
%17 = call i64 @pipe(i32* %10)
%18 = icmp eq i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.2, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %16
%23 = call i32 (...) @fork()
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %33
25: ; preds = %22
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%27 = load i32, i32* %26
%28 = call i32 @close(i32 %27)
%29 = call i32 @close(i32 undef)
%30 = load i32, i32* %10
%31 = call i32 @server(i32 %30, i32 undef)
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %22
%34 = load i32, i32* %10
%35 = call i32 @close(i32 %34)
%36 = call i32 @close(i32 undef)
%37 = getelementptr inbounds i8*, i8** %1, i64 1
%38 = load i8*, i8** %37
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%40 = load i32, i32* %39
%41 = call i32 @client(i8* %38, i32 undef, i32 %40)
%42 = call i32 @waitpid(i32 %23, i32* null, i32 0)
br label %43
43: ; preds = %33, %5
%44 = phi i32 [ 1, %5 ], [ 0, %33 ]
ret i32 %44
}