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

/* Variables and functions */
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ not_found(int, char *);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
void send_file(int sockfd, char *filename) {
  FILE *fp = NULL;
  char buf[2014];
  fp = fopen(filename, "r");
  if (fp == NULL) {
    not_found(sockfd, filename);
  } else {
    fgets(buf, sizeof(buf), fp);
    while (!feof(fp)) {
      send(sockfd, buf, strlen(buf), 0);
      fgets(buf, sizeof(buf), fp);
    }
  }
}


x86 assembly (clang, -O0):
<send_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x810,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11aa <send_file+0x4a>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <not_found@plt>
jmp    1235 <send_file+0xd5>
lea    -0x800(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x7de,%esi
call   1050 <fgets@plt>
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11dd <send_file+0x7d>
jmp    1230 <send_file+0xd0>
mov    -0x4(%rbp),%eax
mov    %eax,-0x80c(%rbp)
lea    -0x800(%rbp),%rax
mov    %rax,-0x808(%rbp)
lea    -0x800(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x80c(%rbp),%edi
mov    -0x808(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
lea    -0x800(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x7de,%esi
call   1050 <fgets@plt>
jmp    11bf <send_file+0x5f>
jmp    1235 <send_file+0xd5>
add    $0x810,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_file>:
push   %rbp
push   %r14
push   %rbx
sub    $0x7e0,%rsp
mov    %rsi,%rbp
mov    %edi,%r14d
lea    0xe88(%rip),%rsi
mov    %rbp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11ef <send_file+0x8f>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x7de,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11e3 <send_file+0x83>
mov    %rsp,%rbp
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %rbp,%rdi
mov    $0x7de,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     11b0 <send_file+0x50>
add    $0x7e0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %r14d,%edi
mov    %rbp,%rsi
add    $0x7e0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <not_found@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define void @send_file(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [2014 x i8]
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32* null, i32** %5
%7 = load i8*, i8** %4
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %5
%9 = load i32*, i32** %5
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* %3
%13 = load i8*, i8** %4
%14 = call i32 @not_found(i32 %12, i8* %13)
br label %34
15: ; preds = %2
%16 = getelementptr inbounds [2014 x i8], [2014 x i8]* %6, i64 0, i64 0
%17 = load i32*, i32** %5
%18 = call i32 @fgets(i8* %16, i32 2014, i32* %17)
br label %19
19: ; preds = %24, %15
%20 = load i32*, i32** %5
%21 = call i32 @feof(i32* %20)
%22 = icmp ne i32 %21, 0
%23 = xor i1 %22, true
br i1 %23, label %24, label %33
24: ; preds = %19
%25 = load i32, i32* %3
%26 = getelementptr inbounds [2014 x i8], [2014 x i8]* %6, i64 0, i64 0
%27 = getelementptr inbounds [2014 x i8], [2014 x i8]* %6, i64 0, i64 0
%28 = call i32 @strlen(i8* %27)
%29 = call i32 @send(i32 %25, i8* %26, i32 %28, i32 0)
%30 = getelementptr inbounds [2014 x i8], [2014 x i8]* %6, i64 0, i64 0
%31 = load i32*, i32** %5
%32 = call i32 @fgets(i8* %30, i32 2014, i32* %31)
br label %19
33: ; preds = %19
br label %34
34: ; preds = %33, %11
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define void @send_file(i32 %0, i8* %1) {
%3 = alloca [2014 x i8]
%4 = getelementptr inbounds [2014 x i8], [2014 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @not_found(i32 %0, i8* %1)
br label %19
9: ; preds = %2
%10 = call i32 @fgets(i8* %4, i32 2014, i32* %5)
%11 = call i32 @feof(i32* %5)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %9, %13
%14 = call i32 @strlen(i8* %4)
%15 = call i32 @send(i32 %0, i8* %4, i32 %14, i32 0)
%16 = call i32 @fgets(i8* %4, i32 2014, i32* %5)
%17 = call i32 @feof(i32* %5)
%18 = icmp eq i32 %17, 0
br i1 %18, label %13, label %19
19: ; preds = %13, %9, %7
ret void
}