#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 recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ shutdown(int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void forward_data(int source_sock, int destination_sock) {
  fprintf(stderr, "FORWARD DATA \n");
  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    0x2e70(%rip),%rax
mov    (%rax),%edi
lea    0xe8f(%rip),%rsi
call   1070 <fprintf@plt>
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    11b7 <forward_data+0x67>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x414(%rbp),%edx
xor    %ecx,%ecx
call   1050 <send@plt>
jmp    1176 <forward_data+0x26>
mov    -0x8(%rbp),%edi
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
call   1040 <shutdown@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    -0x4(%rbp),%edi
mov    0x2e16(%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    0x2e71(%rip),%rax
mov    (%rax),%edi
lea    0xe90(%rip),%rsi
call   1070 <fprintf@plt>
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    11b4 <forward_data+0x64>
mov    %rsp,%rbx
xchg   %ax,%ax
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     1190 <forward_data+0x40>
mov    0x2e35(%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):
@stderr = global i32 0
@.str = [15 x i8] c"FORWARD DATA \0A\00"
@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
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %14, %2
%10 = load i32, i32* %3
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%12 = call i32 @recv(i32 %10, i8* %11, i32 1024, i32 0)
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* %4
%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* %4
%21 = load i32, i32* @SHUT_RDWR
%22 = call i32 @shutdown(i32 %20, i32 %21)
%23 = load i32, i32* %4
%24 = call i32 @close(i32 %23)
%25 = load i32, i32* %3
%26 = load i32, i32* @SHUT_RDWR
%27 = call i32 @shutdown(i32 %25, i32 %26)
%28 = load i32, i32* %3
%29 = call i32 @close(i32 %28)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"FORWARD DATA \0A\00"
@SHUT_RDWR = global i32 0
define void @forward_data(i32 %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = call i32 @recv(i32 %0, i8* %6, i32 1024, i32 0)
%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 %1, i8* %6, i32 %10, i32 0)
%12 = call i32 @recv(i32 %0, i8* %6, i32 1024, i32 0)
%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 %1, i32 %15)
%17 = call i32 @close(i32 %1)
%18 = load i32, i32* @SHUT_RDWR
%19 = call i32 @shutdown(i32 %0, i32 %18)
%20 = call i32 @close(i32 %0)
ret void
}