#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 void FILE;

/* Variables and functions */
int /*<<< orphan*/ cat(int, void *);
int /*<<< orphan*/ fclose(void *);
void *fopen(char const *, char *);
int get_line(int, char *, int);
int /*<<< orphan*/ headers(int, char const *);
int /*<<< orphan*/ not_found(int);
scalar_t__ strcmp(char *, char *);
void serve_file(int client, const char *filename) {
  FILE *resource = ((void *)0);
  int numchars = 1;
  char buf[1024];
  buf[0] = 'A';
  buf[1] = '\0';
  while ((numchars > 0) && strcmp("\n", buf))
    numchars = get_line(client, buf, sizeof(buf));
  resource = fopen(filename, "r");
  if (resource == ((void *)0))
    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)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x421(%rbp)
jle    11d1 <serve_file+0x61>
lea    -0x420(%rbp),%rsi
lea    0xe41(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x421(%rbp)
mov    -0x421(%rbp),%al
test   $0x1,%al
jne    11e4 <serve_file+0x74>
jmp    1200 <serve_file+0x90>
mov    -0x4(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1030 <get_line@plt>
mov    %eax,-0x1c(%rbp)
jmp    119f <serve_file+0x2f>
mov    -0x10(%rbp),%rdi
lea    0xdf7(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    122c <serve_file+0xbc>
mov    -0x4(%rbp),%edi
call   1060 <not_found@plt>
jmp    1244 <serve_file+0xd4>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <headers@plt>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1090 <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    0xe71(%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     11c3 <serve_file+0x53>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1030 <get_line@plt>
test   %eax,%eax
jg     11a0 <serve_file+0x30>
lea    0xe38(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
je     11f0 <serve_file+0x80>
mov    %ebp,%edi
mov    %r14,%rsi
call   1070 <headers@plt>
mov    %ebp,%edi
mov    %r15,%rsi
call   1090 <cat@plt>
jmp    11f7 <serve_file+0x87>
mov    %ebp,%edi
call   1060 <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 = [2 x i8] c"\0A\00"
@.str.1 = [2 x i8] c"r\00"
define void @serve_file(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [1024 x i8]
store i32 %0, i32* %3
store i8* %1, i8** %4
store i8* null, i8** %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
br label %10
10: ; preds = %19, %2
%11 = load i32, i32* %6
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%15 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = icmp ne i64 %15, 0
br label %17
17: ; preds = %13, %10
%18 = phi i1 [ false, %10 ], [ %16, %13 ]
br i1 %18, label %19, label %23
19: ; preds = %17
%20 = load i32, i32* %3
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%22 = call i32 @get_line(i32 %20, i8* %21, i32 1024)
store i32 %22, i32* %6
br label %10
23: ; preds = %17
%24 = load i8*, i8** %4
%25 = call i8* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %25, i8** %5
%26 = load i8*, i8** %5
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = load i32, i32* %3
%30 = call i32 @not_found(i32 %29)
br label %38
31: ; preds = %23
%32 = load i32, i32* %3
%33 = load i8*, i8** %4
%34 = call i32 @headers(i32 %32, i8* %33)
%35 = load i32, i32* %3
%36 = load i8*, i8** %5
%37 = call i32 @cat(i32 %35, i8* %36)
br label %38
38: ; preds = %31, %28
%39 = load i8*, i8** %5
%40 = call i32 @fclose(i8* %39)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [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
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 1024)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %6, label %12
12: ; preds = %9, %6
%13 = call i8* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @not_found(i32 %0)
br label %20
17: ; preds = %12
%18 = call i32 @headers(i32 %0, i8* %1)
%19 = call i32 @cat(i32 %0, i8* %13)
br label %20
20: ; preds = %17, %15
%21 = call i32 @fclose(i8* %13)
ret void
}