#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ http_end_headers(int);
int /*<<< orphan*/ http_send_header(int, char *, char *);
int /*<<< orphan*/ http_send_string(int, char *);
int /*<<< orphan*/ http_start_response(int, int);
void send_file_content(FILE *file, char *type, int fd) {
  http_start_response(fd, 200);
  http_send_header(fd, "Content-type", type);
  http_end_headers(fd);
  char c[100];
  while (fgets(c, 100, file) != NULL) {
    http_send_string(fd, c);
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<send_file_content>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    $0xc8,%esi
call   1070 <http_start_response@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rdx
lea    0xe6f(%rip),%rsi
call   1060 <http_send_header@plt>
mov    -0x14(%rbp),%edi
call   1040 <http_end_headers@plt>
lea    -0x80(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x64,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11cb <send_file_content+0x6b>
mov    -0x14(%rbp),%edi
lea    -0x80(%rbp),%rsi
call   1080 <http_send_string@plt>
jmp    119e <send_file_content+0x3e>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_file_content>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %edx,%edi
mov    $0xc8,%esi
call   1070 <http_start_response@plt>
lea    0xe7d(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
call   1060 <http_send_header@plt>
mov    %ebp,%edi
call   1040 <http_end_headers@plt>
mov    %rsp,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11cf <send_file_content+0x6f>
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
call   1080 <http_send_string@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11b0 <send_file_content+0x50>
mov    %r14,%rdi
call   1030 <fclose@plt>
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Content-type\00"
define void @send_file_content(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [100 x i8]
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i32, i32* %6
%9 = call i32 @http_start_response(i32 %8, i32 200)
%10 = load i32, i32* %6
%11 = load i8*, i8** %5
%12 = call i32 @http_send_header(i32 %10, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i32, i32* %6
%14 = call i32 @http_end_headers(i32 %13)
br label %15
15: ; preds = %20, %3
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%17 = load i32*, i32** %4
%18 = call i32* @fgets(i8* %16, i32 100, i32* %17)
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load i32, i32* %6
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%23 = call i32 @http_send_string(i32 %21, i8* %22)
br label %15
24: ; preds = %15
%25 = load i32*, i32** %4
%26 = call i32 @fclose(i32* %25)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"Content-type\00"
define void @send_file_content(i32* nocapture %0, i8* %1, i32 %2) {
%4 = alloca [100 x i8]
%5 = tail call i32 @http_start_response(i32 %2, i32 200)
%6 = tail call i32 @http_send_header(i32 %2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %1)
%7 = tail call i32 @http_end_headers(i32 %2)
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%9 = call i32* @fgets(i8* %8, i32 100, i32* %0)
%10 = icmp eq i32* %9, null
br i1 %10, label %15, label %11
11: ; preds = %3, %11
%12 = call i32 @http_send_string(i32 %2, i8* %8)
%13 = call i32* @fgets(i8* %8, i32 100, i32* %0)
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %11
15: ; preds = %11, %3
%16 = call i32 @fclose(i32* %0)
ret void
}