#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ error(char *);
int fgetc(int /*<<< orphan*/ *);
int send(int, char *, int, int /*<<< orphan*/);
void sendpkt(int fd, FILE *in) {
  char buf[65535];
  int c, sz = 0;
  while ((c = fgetc(in)) != EOF) {
    buf[sz++] = (char)c;
  }
  if (send(fd, buf, sz, 0) != sz)
    error("send() failed");
}


x86 assembly (clang, -O0):
<sendpkt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10020,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x10018(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x10014(%rbp)
mov    0x2e86(%rip),%rcx
cmp    (%rcx),%eax
je     1191 <sendpkt+0x61>
mov    -0x10014(%rbp),%eax
mov    %al,%cl
mov    -0x10018(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x10018(%rbp)
cltq
mov    %cl,-0x10010(%rbp,%rax,1)
jmp    114c <sendpkt+0x1c>
mov    -0x4(%rbp),%edi
lea    -0x10010(%rbp),%rsi
mov    -0x10018(%rbp),%edx
xor    %ecx,%ecx
call   1030 <send@plt>
cmp    -0x10018(%rbp),%eax
je     11c0 <sendpkt+0x90>
lea    0xe45(%rip),%rdi
call   1050 <error@plt>
add    $0x10020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendpkt>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x10008,%rsp
mov    %rsi,%rbp
mov    %edi,%r14d
mov    %rsi,%rdi
call   1040 <fgetc@plt>
mov    0x2e96(%rip),%r15
xor    %ebx,%ebx
cmp    (%r15),%eax
je     1174 <sendpkt+0x44>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
mov    %rbp,%rdi
call   1040 <fgetc@plt>
cmp    (%r15),%eax
jne    1160 <sendpkt+0x30>
mov    %rsp,%rsi
mov    %r14d,%edi
mov    %ebx,%edx
xor    %ecx,%ecx
call   1030 <send@plt>
cmp    %ebx,%eax
je     1193 <sendpkt+0x63>
lea    0xe72(%rip),%rdi
call   1050 <error@plt>
add    $0x10008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
@.str = [14 x i8] c"send() failed\00"
define void @sendpkt(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [65535 x i8]
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
store i32 0, i32* %7
br label %8
8: ; preds = %13, %2
%9 = load i32*, i32** %4
%10 = call i32 @fgetc(i32* %9)
store i32 %10, i32* %6
%11 = load i32, i32* @EOF
%12 = icmp ne i32 %10, %11
br i1 %12, label %13, label %20
13: ; preds = %8
%14 = load i32, i32* %6
%15 = trunc i32 %14 to i8
%16 = load i32, i32* %7
%17 = add nsw i32 %16, 1
store i32 %17, i32* %7
%18 = sext i32 %16 to i64
%19 = getelementptr inbounds [65535 x i8], [65535 x i8]* %5, i64 0, i64 %18
store i8 %15, i8* %19
br label %8
20: ; preds = %8
%21 = load i32, i32* %3
%22 = getelementptr inbounds [65535 x i8], [65535 x i8]* %5, i64 0, i64 0
%23 = load i32, i32* %7
%24 = call i32 @send(i32 %21, i8* %22, i32 %23, i32 0)
%25 = load i32, i32* %7
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %20
%28 = call i32 @error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %27, %20
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [14 x i8] c"send() failed\00"
define void @sendpkt(i32 %0, i32* nocapture %1) {
%3 = alloca [65535 x i8]
%4 = getelementptr inbounds [65535 x i8], [65535 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @fgetc(i32* %1)
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %19, label %8
8: ; preds = %2, %8
%9 = phi i64 [ %12, %8 ], [ 0, %2 ]
%10 = phi i32 [ %14, %8 ], [ %5, %2 ]
%11 = trunc i32 %10 to i8
%12 = add nuw i64 %9, 1
%13 = getelementptr inbounds [65535 x i8], [65535 x i8]* %3, i64 0, i64 %9
store i8 %11, i8* %13
%14 = tail call i32 @fgetc(i32* %1)
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %8
17: ; preds = %8
%18 = trunc i64 %12 to i32
br label %19
19: ; preds = %17, %2
%20 = phi i32 [ 0, %2 ], [ %18, %17 ]
%21 = call i32 @send(i32 %0, i8* %4, i32 %20, i32 0)
%22 = icmp eq i32 %21, %20
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = call i32 @error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %23, %19
ret void
}