#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 */
scalar_t__ copy(int, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fileno(int /*<<< orphan*/ *);
scalar_t__ fprintf(int /*<<< orphan*/ *, char *, int, char *);
int get_file_size(int);
char *get_file_type(char *);
int /*<<< orphan*/ send_status(int /*<<< orphan*/ *, int, char const *);
void send_response_file(FILE *client, int fd, char *path, int code,
                        const char *reason_phrase) {
  send_status(client, code, reason_phrase);
  if (fprintf(
          client,
          "Connection: close\r\nContent-Length: %d\r\nContent-Type: %s\r\n\r\n",
          get_file_size(fd), get_file_type(path)) < 0)
    exit(-1);
  fflush(client);
  if (copy(fd, fileno(client)) < 0)
    exit(-1);
}


x86 assembly (clang, -O0):
<send_response_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x28(%rbp),%rdx
call   1030 <send_status@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0xc(%rbp),%edi
call   1090 <get_file_size@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <get_file_type@plt>
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    %rax,%rcx
lea    0xe29(%rip),%rsi
call   1050 <fprintf@plt>
cmp    $0x0,%rax
jge    11f0 <send_response_file+0x70>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1080 <fflush@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <fileno@plt>
mov    -0x3c(%rbp),%edi
mov    %eax,%esi
call   1040 <copy@plt>
cmp    $0x0,%rax
jge    1226 <send_response_file+0xa6>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_response_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %esi,%r14d
mov    %rdi,%rbx
mov    %ecx,%esi
mov    %r8,%rdx
call   1030 <send_status@plt>
mov    %r14d,%edi
call   1090 <get_file_size@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1060 <get_file_type@plt>
lea    0xe4d(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
mov    %rax,%rcx
call   1050 <fprintf@plt>
test   %rax,%rax
js     11ef <send_response_file+0x6f>
mov    %rbx,%rdi
call   1080 <fflush@plt>
mov    %rbx,%rdi
call   1070 <fileno@plt>
mov    %r14d,%edi
mov    %eax,%esi
call   1040 <copy@plt>
test   %rax,%rax
js     11ef <send_response_file+0x6f>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [60 x i8] c"Connection: close\0D\0AContent-Length: %d\0D\0AContent-Type: %s\0D\0A\0D\0A\00"
define void @send_response_file(i32* %0, i32 %1, i8* %2, i32 %3, i8* %4) {
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
store i32* %0, i32** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i8* %4, i8** %10
%11 = load i32*, i32** %6
%12 = load i32, i32* %9
%13 = load i8*, i8** %10
%14 = call i32 @send_status(i32* %11, i32 %12, i8* %13)
%15 = load i32*, i32** %6
%16 = load i32, i32* %7
%17 = call i32 @get_file_size(i32 %16)
%18 = load i8*, i8** %8
%19 = call i8* @get_file_type(i8* %18)
%20 = call i64 @fprintf(i32* %15, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 %17, i8* %19)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %5
%23 = call i32 @exit(i32 -1)
unreachable
24: ; preds = %5
%25 = load i32*, i32** %6
%26 = call i32 @fflush(i32* %25)
%27 = load i32, i32* %7
%28 = load i32*, i32** %6
%29 = call i32 @fileno(i32* %28)
%30 = call i64 @copy(i32 %27, i32 %29)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %24
%33 = call i32 @exit(i32 -1)
unreachable
34: ; preds = %24
ret void
}

LLVM IR (-O2):
@.str = [60 x i8] c"Connection: close\0D\0AContent-Length: %d\0D\0AContent-Type: %s\0D\0A\0D\0A\00"
define void @send_response_file(i32* %0, i32 %1, i8* %2, i32 %3, i8* %4) {
%6 = tail call i32 @send_status(i32* %0, i32 %3, i8* %4)
%7 = tail call i32 @get_file_size(i32 %1)
%8 = tail call i8* @get_file_type(i8* %2)
%9 = tail call i64 @fprintf(i32* %0, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 %7, i8* %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = tail call i32 @exit(i32 -1)
unreachable
13: ; preds = %5
%14 = tail call i32 @fflush(i32* %0)
%15 = tail call i32 @fileno(i32* %0)
%16 = tail call i64 @copy(i32 %1, i32 %15)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = tail call i32 @exit(i32 -1)
unreachable
20: ; preds = %13
ret void
}