#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*/ fflush(int /*<<< orphan*/);
int fwrite(unsigned char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int recv(int, unsigned char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
void *recv_entry(void *data) {
  int sock = (int)data;
  unsigned char buffer[(1024)];
  int len;
  while (1) {
    len = recv(sock, buffer, (1024), 0);
    if (len <= 0) {
      fflush(stdout);
      if (len == -1) {
        perror("recv");
      }
      return NULL;
    }
    len = fwrite(buffer, len, 1, stdout);
    if (len == -1) {
      perror("fwrite");
      return NULL;
    }
  }
}


x86 assembly (clang, -O0):
<recv_entry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0x0,-0x424(%rbp)
jg     11b3 <recv_entry+0x73>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
cmpl   $0xffffffff,-0x424(%rbp)
jne    11a6 <recv_entry+0x66>
lea    0xe5f(%rip),%rdi
call   1050 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    1204 <recv_entry+0xc4>
lea    -0x420(%rbp),%rdi
mov    -0x424(%rbp),%esi
mov    0x2e19(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0xffffffff,-0x424(%rbp)
jne    11ff <recv_entry+0xbf>
lea    0xe18(%rip),%rdi
call   1050 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    1204 <recv_entry+0xc4>
jmp    1156 <recv_entry+0x16>
mov    -0x8(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recv_entry>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%r15
mov    %rsp,%rbx
mov    0x2e84(%rip),%r12
lea    0xea2(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebp
mov    (%r12),%ecx
test   %eax,%eax
jle    11a2 <recv_entry+0x62>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
call   1060 <fwrite@plt>
cmp    $0xffffffff,%eax
jne    1170 <recv_entry+0x30>
jmp    11c7 <recv_entry+0x87>
mov    %ecx,%edi
call   1040 <fflush@plt>
cmp    $0xffffffff,%ebp
je     11c0 <recv_entry+0x80>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe39(%rip),%r14
mov    %r14,%rdi
call   1050 <perror@plt>
jmp    11ae <recv_entry+0x6e>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [5 x i8] c"recv\00"
@.str.1 = [7 x i8] c"fwrite\00"
define i8* @recv_entry(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = ptrtoint i8* %7 to i32
store i32 %8, i32* %4
br label %9
9: ; preds = %1, %32
%10 = load i32, i32* %4
%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 = load i32, i32* %6
%14 = icmp sle i32 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %9
%16 = load i32, i32* @stdout
%17 = call i32 @fflush(i32 %16)
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %15
store i8* null, i8** %2
br label %33
23: ; preds = %9
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%25 = load i32, i32* %6
%26 = load i32, i32* @stdout
%27 = call i32 @fwrite(i8* %24, i32 %25, i32 1, i32 %26)
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %23
%31 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %2
br label %33
32: ; preds = %23
br label %9
33: ; preds = %30, %22
%34 = load i8*, i8** %2
ret i8* %34
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [5 x i8] c"recv\00"
@.str.1 = [7 x i8] c"fwrite\00"
define noalias i8* @recv_entry(i8* %0) {
%2 = alloca [1024 x i8]
%3 = ptrtoint i8* %0 to i64
%4 = trunc i64 %3 to i32
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
br label %6
6: ; preds = %13, %1
%7 = call i32 @recv(i32 %4, i8* %5, i32 1024, i32 0)
%8 = icmp slt i32 %7, 1
%9 = load i32, i32* @stdout
br i1 %8, label %10, label %13
10: ; preds = %6
%11 = call i32 @fflush(i32 %9)
%12 = icmp eq i32 %7, -1
br i1 %12, label %16, label %19
13: ; preds = %6
%14 = call i32 @fwrite(i8* %5, i32 %7, i32 1, i32 %9)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %6
16: ; preds = %13, %10
%17 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %10 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %13 ]
%18 = call i32 @perror(i8* %17)
br label %19
19: ; preds = %16, %10
ret i8* null
}