#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*/ close(int);
int /*<<< orphan*/ errx(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, int, int /*<<< orphan*/);
void pushdata(int recvsock, int writesock) {
  char buf[2048];
  int nbytes, sbytes;
  if ((nbytes = recv(recvsock, buf, 2048, 0)) <= 0) {
    if (nbytes == 0) {
      close(writesock);
      errx("Server hung up.\n");
    } else {
      perror("recv");
      exit(1);
    }
  }
  if (send(writesock, buf, nbytes, 0) == -1) {
    perror("send");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<pushdata>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x810(%rbp),%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x814(%rbp)
cmp    $0x0,%eax
jg     11d7 <pushdata+0x77>
cmpl   $0x0,-0x814(%rbp)
jne    11bc <pushdata+0x5c>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
lea    0xe4e(%rip),%rdi
call   1040 <errx@plt>
jmp    11d2 <pushdata+0x72>
lea    0xe4e(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11d7 <pushdata+0x77>
mov    -0x8(%rbp),%edi
lea    -0x810(%rbp),%rsi
mov    -0x814(%rbp),%edx
xor    %ecx,%ecx
call   1050 <send@plt>
cmp    $0xffffffff,%eax
jne    120d <pushdata+0xad>
lea    0xe18(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pushdata>:
push   %rbp
push   %rbx
sub    $0x808,%rsp
mov    %esi,%ebx
mov    %rsp,%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebp
test   %eax,%eax
jg     1195 <pushdata+0x35>
jne    11bb <pushdata+0x5b>
mov    %ebx,%edi
call   1060 <close@plt>
lea    0xe70(%rip),%rdi
call   1040 <errx@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    %ebp,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
cmp    $0xffffffff,%eax
je     11b2 <pushdata+0x52>
add    $0x808,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe5d(%rip),%rdi
jmp    11c2 <pushdata+0x62>
lea    0xe4f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"Server hung up.\0A\00"
@.str.1 = [5 x i8] c"recv\00"
@.str.2 = [5 x i8] c"send\00"
define void @pushdata(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [2048 x i8]
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %3
%9 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%10 = call i32 @recv(i32 %8, i8* %9, i32 2048, i32 0)
store i32 %10, i32* %6
%11 = icmp sle i32 %10, 0
br i1 %11, label %12, label %23
12: ; preds = %2
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i32, i32* %4
%17 = call i32 @close(i32 %16)
%18 = call i32 @errx(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %22
19: ; preds = %12
%20 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %15
br label %23
23: ; preds = %22, %2
%24 = load i32, i32* %4
%25 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%26 = load i32, i32* %6
%27 = call i32 @send(i32 %24, i8* %25, i32 %26, i32 0)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %23
%30 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %23
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"Server hung up.\0A\00"
@.str.1 = [5 x i8] c"recv\00"
@.str.2 = [5 x i8] c"send\00"
define void @pushdata(i32 %0, i32 %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%5 = call i32 @recv(i32 %0, i8* %4, i32 2048, i32 0)
%6 = icmp slt i32 %5, 1
br i1 %6, label %7, label %15
7: ; preds = %2
%8 = icmp eq i32 %5, 0
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = call i32 @close(i32 %1)
%11 = call i32 @errx(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %15
12: ; preds = %7
%13 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %9, %2
%16 = call i32 @send(i32 %1, i8* %4, i32 %5, i32 0)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %15
ret void
}