#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*/ SHUT_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int read(int, char *, int);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ shutdown(int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void read_pipe_dest(int client_sock, int pipe) {
  fprintf(stderr, "READ PIPE DEST \n");
  char buffer[1024];
  int n;
  while ((n = read(pipe, buffer, 1024)) > 0) {
    send(client_sock, buffer, n, 0);
  }
  shutdown(client_sock, SHUT_RDWR);
  close(client_sock);
}


x86 assembly (clang, -O0):
<read_pipe_dest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
lea    0xe8f(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
mov    %eax,-0x414(%rbp)
cmp    $0x0,%eax
jle    11b5 <read_pipe_dest+0x65>
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x414(%rbp),%edx
xor    %ecx,%ecx
call   1040 <send@plt>
jmp    1176 <read_pipe_dest+0x26>
mov    -0x4(%rbp),%edi
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
call   1030 <shutdown@plt>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_pipe_dest>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %esi,%ebp
mov    %edi,%r14d
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
lea    0xe90(%rip),%rsi
call   1070 <fprintf@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x400,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    11b2 <read_pipe_dest+0x62>
mov    %rsp,%rbx
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1060 <read@plt>
test   %eax,%eax
jg     1190 <read_pipe_dest+0x40>
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
call   1030 <shutdown@plt>
mov    %r14d,%edi
call   1050 <close@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [17 x i8] c"READ PIPE DEST \0A\00"
@SHUT_RDWR = global i32 0
define void @read_pipe_dest(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %14, %2
%10 = load i32, i32* %4
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%12 = call i32 @read(i32 %10, i8* %11, i32 1024)
store i32 %12, i32* %6
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %9
%15 = load i32, i32* %3
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%17 = load i32, i32* %6
%18 = call i32 @send(i32 %15, i8* %16, i32 %17, i32 0)
br label %9
19: ; preds = %9
%20 = load i32, i32* %3
%21 = load i32, i32* @SHUT_RDWR
%22 = call i32 @shutdown(i32 %20, i32 %21)
%23 = load i32, i32* %3
%24 = call i32 @close(i32 %23)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [17 x i8] c"READ PIPE DEST \0A\00"
@SHUT_RDWR = global i32 0
define void @read_pipe_dest(i32 %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = call i32 @read(i32 %1, i8* %6, i32 1024)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %2, %9
%10 = phi i32 [ %12, %9 ], [ %7, %2 ]
%11 = call i32 @send(i32 %0, i8* %6, i32 %10, i32 0)
%12 = call i32 @read(i32 %1, i8* %6, i32 1024)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %9, label %14
14: ; preds = %9, %2
%15 = load i32, i32* @SHUT_RDWR
%16 = call i32 @shutdown(i32 %0, i32 %15)
%17 = call i32 @close(i32 %0)
ret void
}