#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 recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ shutdown(int, int /*<<< orphan*/);
void forward_data(int source_sock, int destination_sock) {
  char buffer[1024];
  int n;
  while ((n = recv(source_sock, buffer, 1024, 0)) > 0) {
    send(destination_sock, buffer, n, 0);
  }
  shutdown(destination_sock, SHUT_RDWR);
  close(destination_sock);
  shutdown(source_sock, SHUT_RDWR);
  close(source_sock);
}


x86 assembly (clang, -O0):
<forward_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x414(%rbp)
cmp    $0x0,%eax
jle    1192 <forward_data+0x52>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x414(%rbp),%edx
xor    %ecx,%ecx
call   1050 <send@plt>
jmp    1151 <forward_data+0x11>
mov    -0x8(%rbp),%edi
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
call   1040 <shutdown@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    -0x4(%rbp),%edi
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
call   1040 <shutdown@plt>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<forward_data>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %esi,%ebp
mov    %edi,%r14d
mov    %rsp,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    1194 <forward_data+0x54>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jg     1170 <forward_data+0x30>
mov    0x2e55(%rip),%rbx
mov    (%rbx),%esi
mov    %ebp,%edi
call   1040 <shutdown@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    (%rbx),%esi
mov    %r14d,%edi
call   1040 <shutdown@plt>
mov    %r14d,%edi
call   1060 <close@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@SHUT_RDWR = global i32 0
define void @forward_data(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
br label %7
7: ; preds = %12, %2
%8 = load i32, i32* %3
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%10 = call i32 @recv(i32 %8, i8* %9, i32 1024, i32 0)
store i32 %10, i32* %6
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %7
%13 = load i32, i32* %4
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%15 = load i32, i32* %6
%16 = call i32 @send(i32 %13, i8* %14, i32 %15, i32 0)
br label %7
17: ; preds = %7
%18 = load i32, i32* %4
%19 = load i32, i32* @SHUT_RDWR
%20 = call i32 @shutdown(i32 %18, i32 %19)
%21 = load i32, i32* %4
%22 = call i32 @close(i32 %21)
%23 = load i32, i32* %3
%24 = load i32, i32* @SHUT_RDWR
%25 = call i32 @shutdown(i32 %23, i32 %24)
%26 = load i32, i32* %3
%27 = call i32 @close(i32 %26)
ret void
}

LLVM IR (-O2):
@SHUT_RDWR = global i32 0
define void @forward_data(i32 %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32 @recv(i32 %0, i8* %4, i32 1024, i32 0)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %2, %7
%8 = phi i32 [ %10, %7 ], [ %5, %2 ]
%9 = call i32 @send(i32 %1, i8* %4, i32 %8, i32 0)
%10 = call i32 @recv(i32 %0, i8* %4, i32 1024, i32 0)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %7, label %12
12: ; preds = %7, %2
%13 = load i32, i32* @SHUT_RDWR
%14 = call i32 @shutdown(i32 %1, i32 %13)
%15 = call i32 @close(i32 %1)
%16 = load i32, i32* @SHUT_RDWR
%17 = call i32 @shutdown(i32 %0, i32 %16)
%18 = call i32 @close(i32 %0)
ret void
}