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


x86 assembly (clang, -O0):
<forward_data_synch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%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    11ac <forward_data_synch+0x6c>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x414(%rbp),%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0xc(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x414(%rbp),%edx
xor    %ecx,%ecx
call   1050 <send@plt>
jmp    1154 <forward_data_synch+0x14>
mov    -0x8(%rbp),%edi
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
call   1040 <shutdown@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    -0xc(%rbp),%edi
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
call   1040 <shutdown@plt>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
mov    -0x4(%rbp),%edi
mov    0x2e08(%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_synch>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %edx,%r15d
mov    %esi,%r12d
mov    %edi,%r14d
mov    %rsp,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    11a6 <forward_data_synch+0x66>
mov    %eax,%ebx
mov    %rsp,%rbp
mov    %r12d,%edi
mov    %rbp,%rsi
mov    %ebx,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %ebx,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebx
test   %eax,%eax
jg     1170 <forward_data_synch+0x30>
mov    0x2e43(%rip),%rbx
mov    (%rbx),%esi
mov    %r12d,%edi
call   1040 <shutdown@plt>
mov    %r12d,%edi
call   1060 <close@plt>
mov    (%rbx),%esi
mov    %r15d,%edi
call   1040 <shutdown@plt>
mov    %r15d,%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    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SHUT_RDWR = global i32 0
define void @forward_data_synch(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
br label %9
9: ; preds = %14, %3
%10 = load i32, i32* %4
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%12 = call i32 @recv(i32 %10, i8* %11, i32 1024, i32 0)
store i32 %12, i32* %8
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %9
%15 = load i32, i32* %5
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%17 = load i32, i32* %8
%18 = call i32 @send(i32 %15, i8* %16, i32 %17, i32 0)
%19 = load i32, i32* %6
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%21 = load i32, i32* %8
%22 = call i32 @send(i32 %19, i8* %20, i32 %21, i32 0)
br label %9
23: ; preds = %9
%24 = load i32, i32* %5
%25 = load i32, i32* @SHUT_RDWR
%26 = call i32 @shutdown(i32 %24, i32 %25)
%27 = load i32, i32* %5
%28 = call i32 @close(i32 %27)
%29 = load i32, i32* %6
%30 = load i32, i32* @SHUT_RDWR
%31 = call i32 @shutdown(i32 %29, i32 %30)
%32 = load i32, i32* %6
%33 = call i32 @close(i32 %32)
%34 = load i32, i32* %4
%35 = load i32, i32* @SHUT_RDWR
%36 = call i32 @shutdown(i32 %34, i32 %35)
%37 = load i32, i32* %4
%38 = call i32 @close(i32 %37)
ret void
}

LLVM IR (-O2):
@SHUT_RDWR = global i32 0
define void @forward_data_synch(i32 %0, i32 %1, i32 %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = call i32 @recv(i32 %0, i8* %5, i32 1024, i32 0)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %3, %8
%9 = phi i32 [ %12, %8 ], [ %6, %3 ]
%10 = call i32 @send(i32 %1, i8* %5, i32 %9, i32 0)
%11 = call i32 @send(i32 %2, i8* %5, i32 %9, i32 0)
%12 = call i32 @recv(i32 %0, i8* %5, i32 1024, i32 0)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %8, label %14
14: ; preds = %8, %3
%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 %2, i32 %18)
%20 = call i32 @close(i32 %2)
%21 = load i32, i32* @SHUT_RDWR
%22 = call i32 @shutdown(i32 %0, i32 %21)
%23 = call i32 @close(i32 %0)
ret void
}