#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*/ cat(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int get_line(int, char *, int);
int /*<<< orphan*/ headers(int, char const *);
int /*<<< orphan*/ not_found(int);
int /*<<< orphan*/ printf(char *, char const *, int);
scalar_t__ strcmp(char *, char *);
void serve_file(int client, const char *filename) {
  FILE *resource = NULL;
  int numchars = 1;
  char buf[1024];
  buf[0] = 'A';
  buf[1] = '\0';
  printf("Serve file %s to %d\n", filename, client);
  while ((numchars > 0) && strcmp("\n", buf)) {
    numchars = get_line(client, buf, sizeof(buf));
  }
  resource = fopen(filename, "r");
  if (resource == NULL) {
    not_found(client);
  } else {
    headers(client, filename);
    cat(client, resource);
  }
  fclose(resource);
}


x86 assembly (clang, -O0):
<serve_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movb   $0x41,-0x420(%rbp)
movb   $0x0,-0x41f(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x4(%rbp),%edx
lea    0xe43(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x421(%rbp)
jle    11f4 <serve_file+0x74>
lea    -0x420(%rbp),%rsi
lea    0xe31(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x421(%rbp)
mov    -0x421(%rbp),%al
test   $0x1,%al
jne    1207 <serve_file+0x87>
jmp    1223 <serve_file+0xa3>
mov    -0x4(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1030 <get_line@plt>
mov    %eax,-0x1c(%rbp)
jmp    11c2 <serve_file+0x42>
mov    -0x10(%rbp),%rdi
lea    0xde7(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    124f <serve_file+0xcf>
mov    -0x4(%rbp),%edi
call   1070 <not_found@plt>
jmp    1267 <serve_file+0xe7>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1080 <headers@plt>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   10a0 <cat@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serve_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
movw   $0x41,(%rsp)
lea    0xe61(%rip),%rdi
mov    %ebp,%edx
call   1050 <printf@plt>
lea    0xe66(%rip),%r15
mov    %rsp,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11d3 <serve_file+0x53>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1030 <get_line@plt>
test   %eax,%eax
jg     11b0 <serve_file+0x30>
lea    0xe3b(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
je     1200 <serve_file+0x80>
mov    %ebp,%edi
mov    %r14,%rsi
call   1080 <headers@plt>
mov    %ebp,%edi
mov    %r15,%rsi
call   10a0 <cat@plt>
jmp    1207 <serve_file+0x87>
mov    %ebp,%edi
call   1070 <not_found@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [21 x i8] c"Serve file %s to %d\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [2 x i8] c"r\00"
define void @serve_file(i32 %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
store i8 65, i8* %4
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 1
store i8 0, i8* %5
%6 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %0)
br label %7
7: ; preds = %2, %10
%8 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = call i32 @get_line(i32 %0, i8* %4, i32 1024)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %7, label %13
13: ; preds = %10, %7
%14 = call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @not_found(i32 %0)
br label %21
18: ; preds = %13
%19 = call i32 @headers(i32 %0, i8* %1)
%20 = call i32 @cat(i32 %0, i32* %14)
br label %21
21: ; preds = %18, %16
%22 = call i32 @fclose(i32* %14)
ret void
}