#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int get_line(int, char *, int);
int /*<<< orphan*/ not_found(int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ transmit_file(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ transmit_headers(int, char const *, int);
void serve_file(int s, const char *path) {
  FILE *file = NULL;
  int filesize;
  int numchars = 1;
  char buf[9000];
  buf[0] = 'A';
  buf[1] = '\0';
  while ((numchars > 0) && strcmp("\n", buf))
    numchars = get_line(s, buf, sizeof(buf));
  file = fopen(path, "r");
  if (file == NULL)
    not_found(s);
  else {
    fseek(file, 0, SEEK_END);
    filesize = ftell(file);
    fseek(file, 0, SEEK_SET);
    transmit_headers(s, path, filesize);
    transmit_file(s, file);
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<serve_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2360,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x1,-0x20(%rbp)
movb   $0x41,-0x2350(%rbp)
movb   $0x0,-0x234f(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x20(%rbp)
mov    %al,-0x2351(%rbp)
jle    11f1 <serve_file+0x61>
lea    -0x2350(%rbp),%rsi
lea    0xe21(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x2351(%rbp)
mov    -0x2351(%rbp),%al
test   $0x1,%al
jne    1204 <serve_file+0x74>
jmp    1220 <serve_file+0x90>
mov    -0x4(%rbp),%edi
lea    -0x2350(%rbp),%rsi
mov    $0x2328,%edx
call   1030 <get_line@plt>
mov    %eax,-0x20(%rbp)
jmp    11bf <serve_file+0x2f>
mov    -0x10(%rbp),%rdi
lea    0xdd7(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    124c <serve_file+0xbc>
mov    -0x4(%rbp),%edi
call   1070 <not_found@plt>
jmp    129b <serve_file+0x10b>
mov    -0x18(%rbp),%rdi
mov    0x2d91(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d61(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   10a0 <transmit_headers@plt>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1090 <transmit_file@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x2360,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serve_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x2328,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
movw   $0x41,(%rsp)
lea    0xe51(%rip),%r15
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11e3 <serve_file+0x53>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x2328,%edx
call   1030 <get_line@plt>
test   %eax,%eax
jg     11c0 <serve_file+0x30>
lea    0xe18(%rip),%rsi
mov    %r14,%rdi
call   10b0 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
je     1242 <serve_file+0xb2>
mov    0x2de7(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r15,%rdi
call   1060 <ftell@plt>
mov    %eax,%ebx
mov    0x2dba(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   10a0 <transmit_headers@plt>
mov    %ebp,%edi
mov    %r15,%rsi
call   1090 <transmit_file@plt>
jmp    1249 <serve_file+0xb9>
mov    %ebp,%edi
call   1070 <not_found@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
add    $0x2328,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define void @serve_file(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [9000 x i8]
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32* null, i32** %5
store i32 1, i32* %7
%9 = getelementptr inbounds [9000 x i8], [9000 x i8]* %8, i64 0, i64 0
store i8 65, i8* %9
%10 = getelementptr inbounds [9000 x i8], [9000 x i8]* %8, i64 0, i64 1
store i8 0, i8* %10
br label %11
11: ; preds = %20, %2
%12 = load i32, i32* %7
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = getelementptr inbounds [9000 x i8], [9000 x i8]* %8, i64 0, i64 0
%16 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = icmp ne i64 %16, 0
br label %18
18: ; preds = %14, %11
%19 = phi i1 [ false, %11 ], [ %17, %14 ]
br i1 %19, label %20, label %24
20: ; preds = %18
%21 = load i32, i32* %3
%22 = getelementptr inbounds [9000 x i8], [9000 x i8]* %8, i64 0, i64 0
%23 = call i32 @get_line(i32 %21, i8* %22, i32 9000)
store i32 %23, i32* %7
br label %11
24: ; preds = %18
%25 = load i8*, i8** %4
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %26, i32** %5
%27 = load i32*, i32** %5
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load i32, i32* %3
%31 = call i32 @not_found(i32 %30)
br label %48
32: ; preds = %24
%33 = load i32*, i32** %5
%34 = load i32, i32* @SEEK_END
%35 = call i32 @fseek(i32* %33, i32 0, i32 %34)
%36 = load i32*, i32** %5
%37 = call i32 @ftell(i32* %36)
store i32 %37, i32* %6
%38 = load i32*, i32** %5
%39 = load i32, i32* @SEEK_SET
%40 = call i32 @fseek(i32* %38, i32 0, i32 %39)
%41 = load i32, i32* %3
%42 = load i8*, i8** %4
%43 = load i32, i32* %6
%44 = call i32 @transmit_headers(i32 %41, i8* %42, i32 %43)
%45 = load i32, i32* %3
%46 = load i32*, i32** %5
%47 = call i32 @transmit_file(i32 %45, i32* %46)
br label %48
48: ; preds = %32, %29
%49 = load i32*, i32** %5
%50 = call i32 @fclose(i32* %49)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define void @serve_file(i32 %0, i8* %1) {
%3 = alloca [9000 x i8]
%4 = getelementptr inbounds [9000 x i8], [9000 x i8]* %3, i64 0, i64 0
store i8 65, i8* %4
%5 = getelementptr inbounds [9000 x i8], [9000 x i8]* %3, i64 0, i64 1
store i8 0, i8* %5
br label %6
6: ; preds = %2, %9
%7 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = call i32 @get_line(i32 %0, i8* %4, i32 9000)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %6, label %12
12: ; preds = %9, %6
%13 = call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @not_found(i32 %0)
br label %25
17: ; preds = %12
%18 = load i32, i32* @SEEK_END
%19 = call i32 @fseek(i32* %13, i32 0, i32 %18)
%20 = call i32 @ftell(i32* %13)
%21 = load i32, i32* @SEEK_SET
%22 = call i32 @fseek(i32* %13, i32 0, i32 %21)
%23 = call i32 @transmit_headers(i32 %0, i8* %1, i32 %20)
%24 = call i32 @transmit_file(i32 %0, i32* %13)
br label %25
25: ; preds = %17, %15
%26 = call i32 @fclose(i32* %13)
ret void
}