#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_WR;
int fread(unsigned char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int send(int, unsigned char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ shutdown(int, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
void *send_entry(void *data) {
  int sock = (int)data;
  unsigned char buffer[(1024)];
  int len;
  while (1) {
    len = fread(buffer, 1, (1024), stdin);
    if (len == 0) {
      shutdown(sock, SHUT_WR);
      return NULL;
    }
    len = send(sock, buffer, len, 0);
    if (len == -1) {
      perror("send");
      return NULL;
    }
  }
}


x86 assembly (clang, -O0):
<send_entry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,-0x14(%rbp)
lea    -0x420(%rbp),%rdi
mov    0x2e7c(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0x0,-0x424(%rbp)
jne    11a6 <send_entry+0x66>
mov    -0x14(%rbp),%edi
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
call   1040 <shutdown@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ee <send_entry+0xae>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x424(%rbp),%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0xffffffff,-0x424(%rbp)
jne    11e9 <send_entry+0xa9>
lea    0xe29(%rip),%rdi
call   1060 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ee <send_entry+0xae>
jmp    1156 <send_entry+0x16>
mov    -0x8(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_entry>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%r14
mov    0x2e8a(%rip),%r15
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    (%r15),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
test   %eax,%eax
je     119b <send_entry+0x5b>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
cmp    $0xffffffff,%eax
jne    1160 <send_entry+0x20>
lea    0xe6c(%rip),%rdi
call   1060 <perror@plt>
jmp    11ac <send_entry+0x6c>
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
call   1040 <shutdown@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@SHUT_WR = global i32 0
@.str = [5 x i8] c"send\00"
define i8* @send_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, %28
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%11 = load i32, i32* @stdin
%12 = call i32 @fread(i8* %10, i32 1, i32 1024, i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %9
%16 = load i32, i32* %4
%17 = load i32, i32* @SHUT_WR
%18 = call i32 @shutdown(i32 %16, i32 %17)
store i8* null, i8** %2
br label %29
19: ; preds = %9
%20 = load i32, i32* %4
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%22 = load i32, i32* %6
%23 = call i32 @send(i32 %20, i8* %21, i32 %22, i32 0)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %19
%27 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %29
28: ; preds = %19
br label %9
29: ; preds = %26, %15
%30 = load i8*, i8** %2
ret i8* %30
}

LLVM IR (-O2):
@stdin = global i32 0
@SHUT_WR = global i32 0
@.str = [5 x i8] c"send\00"
define noalias i8* @send_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 = load i32, i32* @stdin
%8 = call i32 @fread(i8* %5, i32 1, i32 1024, i32 %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = load i32, i32* @SHUT_WR
%12 = call i32 @shutdown(i32 %4, i32 %11)
br label %18
13: ; preds = %6
%14 = call i32 @send(i32 %4, i8* %5, i32 %8, i32 0)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %6
16: ; preds = %13
%17 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %10
ret i8* null
}