#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*/ printf(char *);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ shutdown(int, int /*<<< orphan*/);
void receive_data_synch(int source_sock, int destination_sock,
                        int duplicate_destination_sock) {
  char buffer[1024];
  int n;
  char dup_buffer[1024];
  int dup_n;
  while ((n = recv(source_sock, buffer, 1024, 0)) > 0) {
    send(destination_sock, buffer, n, 0);
    if (recv(duplicate_destination_sock, dup_buffer, n, 0) != n) {
      printf("Error in receiving data from duplicate");
    }
  }
  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):
<receive_data_synch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%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    11d4 <receive_data_synch+0x84>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x414(%rbp),%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0xc(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    -0x414(%rbp),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    -0x414(%rbp),%eax
je     11cf <receive_data_synch+0x7f>
lea    0xe36(%rip),%rdi
call   1060 <printf@plt>
jmp    1164 <receive_data_synch+0x14>
mov    -0x8(%rbp),%edi
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
call   1040 <shutdown@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
mov    -0xc(%rbp),%edi
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
call   1040 <shutdown@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
mov    -0x4(%rbp),%edi
mov    0x2de0(%rip),%rax
mov    (%rax),%esi
call   1040 <shutdown@plt>
mov    -0x4(%rbp),%edi
call   1070 <close@plt>
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<receive_data_synch>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %edx,%r15d
mov    %esi,%ebx
mov    %edi,%r14d
mov    %rsp,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    11db <receive_data_synch+0x8b>
mov    %eax,%r13d
mov    %rsp,%rbp
lea    0x400(%rsp),%r12
jmp    11a9 <receive_data_synch+0x59>
nopl   0x0(%rax)
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%r13d
test   %eax,%eax
jle    11db <receive_data_synch+0x8b>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r13d,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %r15d,%edi
mov    %r12,%rsi
mov    %r13d,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    %r13d,%eax
je     1190 <receive_data_synch+0x40>
lea    0xe2c(%rip),%rdi
call   1060 <printf@plt>
jmp    1190 <receive_data_synch+0x40>
mov    0x2e0e(%rip),%rbp
mov    0x0(%rbp),%esi
mov    %ebx,%edi
call   1040 <shutdown@plt>
mov    %ebx,%edi
call   1070 <close@plt>
mov    0x0(%rbp),%esi
mov    %r15d,%edi
call   1040 <shutdown@plt>
mov    %r15d,%edi
call   1070 <close@plt>
mov    0x0(%rbp),%esi
mov    %r14d,%edi
call   1040 <shutdown@plt>
mov    %r14d,%edi
call   1070 <close@plt>
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Error in receiving data from duplicate\00"
@SHUT_RDWR = global i32 0
define void @receive_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
%9 = alloca [1024 x i8]
%10 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
br label %11
11: ; preds = %29, %3
%12 = load i32, i32* %4
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%14 = call i32 @recv(i32 %12, i8* %13, i32 1024, i32 0)
store i32 %14, i32* %8
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %30
16: ; preds = %11
%17 = load i32, i32* %5
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%19 = load i32, i32* %8
%20 = call i32 @send(i32 %17, i8* %18, i32 %19, i32 0)
%21 = load i32, i32* %6
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%23 = load i32, i32* %8
%24 = call i32 @recv(i32 %21, i8* %22, i32 %23, i32 0)
%25 = load i32, i32* %8
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %16
%28 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %27, %16
br label %11
30: ; preds = %11
%31 = load i32, i32* %5
%32 = load i32, i32* @SHUT_RDWR
%33 = call i32 @shutdown(i32 %31, i32 %32)
%34 = load i32, i32* %5
%35 = call i32 @close(i32 %34)
%36 = load i32, i32* %6
%37 = load i32, i32* @SHUT_RDWR
%38 = call i32 @shutdown(i32 %36, i32 %37)
%39 = load i32, i32* %6
%40 = call i32 @close(i32 %39)
%41 = load i32, i32* %4
%42 = load i32, i32* @SHUT_RDWR
%43 = call i32 @shutdown(i32 %41, i32 %42)
%44 = load i32, i32* %4
%45 = call i32 @close(i32 %44)
ret void
}

LLVM IR (-O2):
@.str = [39 x i8] c"Error in receiving data from duplicate\00"
@SHUT_RDWR = global i32 0
define void @receive_data_synch(i32 %0, i32 %1, i32 %2) {
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%8 = call i32 @recv(i32 %0, i8* %6, i32 1024, i32 0)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %20
10: ; preds = %3, %17
%11 = phi i32 [ %18, %17 ], [ %8, %3 ]
%12 = call i32 @send(i32 %1, i8* %6, i32 %11, i32 0)
%13 = call i32 @recv(i32 %2, i8* %7, i32 %11, i32 0)
%14 = icmp eq i32 %13, %11
br i1 %14, label %17, label %15
15: ; preds = %10
%16 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %10
%18 = call i32 @recv(i32 %0, i8* %6, i32 1024, i32 0)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %10, label %20
20: ; preds = %17, %3
%21 = load i32, i32* @SHUT_RDWR
%22 = call i32 @shutdown(i32 %1, i32 %21)
%23 = call i32 @close(i32 %1)
%24 = load i32, i32* @SHUT_RDWR
%25 = call i32 @shutdown(i32 %2, i32 %24)
%26 = call i32 @close(i32 %2)
%27 = load i32, i32* @SHUT_RDWR
%28 = call i32 @shutdown(i32 %0, i32 %27)
%29 = call i32 @close(i32 %0)
ret void
}