#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
void send_file(FILE *client, char *filename) {
  FILE *fp;
  int *buf;
  fp = fopen(filename, "r");
  while (!feof(fp)) {
    fread(buf, 1, 1, fp);
    fwrite(buf, 1, 1, client);
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<send_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1192 <send_file+0x42>
jmp    11bf <send_file+0x6f>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1070 <fwrite@plt>
jmp    1174 <send_file+0x24>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_file>:
push   %rbx
mov    %rsi,%rdi
lea    0xeb5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <feof@plt>
test   %eax,%eax
je     1168 <send_file+0x28>
mov    %rbx,%rdi
pop    %rbx
jmp    1040 <fclose@plt>
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@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 i32*
store i32* %0, i32** %3
store i8* %1, i8** %4
%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
br label %9
9: ; preds = %14, %2
%10 = load i32*, i32** %5
%11 = call i32 @feof(i32* %10)
%12 = icmp ne i32 %11, 0
%13 = xor i1 %12, true
br i1 %13, label %14, label %21
14: ; preds = %9
%15 = load i32*, i32** %6
%16 = load i32*, i32** %5
%17 = call i32 @fread(i32* %15, i32 1, i32 1, i32* %16)
%18 = load i32*, i32** %6
%19 = load i32*, i32** %3
%20 = call i32 @fwrite(i32* %18, i32 1, i32 1, i32* %19)
br label %9
21: ; preds = %9
%22 = load i32*, i32** %5
%23 = call i32 @fclose(i32* %22)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define void @send_file(i32* nocapture readnone %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @feof(i32* %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @fread(i32* undef, i32 1, i32 1, i32* %3)
unreachable
8: ; preds = %2
%9 = tail call i32 @fclose(i32* %3)
ret void
}