#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ not_found_404(int);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send_header(int, char *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
void send_data(int send_to, char *content_type, char *filepath) {
  if (strcmp(filepath, "./") == 0) {
    strcat(filepath, "index.html");
  }
  FILE *file;
  file = fopen(filepath, "r");
  if (file != NULL) {
    send_header(send_to, content_type);
    send(send_to, "\r\n", 2, 0);
    char buf[1024];
    fgets(buf, sizeof(buf), file);
    while (!feof(file)) {
      send(send_to, buf, strlen(buf), 0);
      fgets(buf, sizeof(buf), file);
    }
  } else {
    send_header(send_to, content_type);
    send(send_to, "\r\n", 2, 0);
    not_found_404(send_to);
  }
  if (file != NULL)
    fclose(file);
}


x86 assembly (clang, -O0):
<send_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    11e0 <send_data+0x40>
mov    -0x18(%rbp),%rdi
lea    0xe28(%rip),%rsi
call   10c0 <strcat@plt>
mov    -0x18(%rbp),%rdi
lea    0xe23(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12ac <send_data+0x10c>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1080 <send_header@plt>
mov    -0x4(%rbp),%edi
lea    0xdfb(%rip),%rsi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
lea    -0x420(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
mov    -0x20(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1254 <send_data+0xb4>
jmp    12a7 <send_data+0x107>
mov    -0x4(%rbp),%eax
mov    %eax,-0x42c(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x428(%rbp)
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x42c(%rbp),%edi
mov    -0x428(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
lea    -0x420(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
jmp    1236 <send_data+0x96>
jmp    12d6 <send_data+0x136>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1080 <send_header@plt>
mov    -0x4(%rbp),%edi
lea    0xd4e(%rip),%rsi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0x4(%rbp),%edi
call   10a0 <not_found_404@plt>
cmpq   $0x0,-0x20(%rbp)
je     12ea <send_data+0x14a>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_data>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %edi,%r14d
lea    0xe45(%rip),%rsi
mov    %rdx,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    11d7 <send_data+0x37>
lea    0xe34(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <strcat@plt>
lea    0xe30(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <fopen@plt>
mov    %rax,%rbx
mov    %r14d,%edi
mov    %rbp,%rsi
call   1080 <send_header@plt>
lea    0xe15(%rip),%rsi
mov    %r14d,%edi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
test   %rbx,%rbx
je     1277 <send_data+0xd7>
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    1263 <send_data+0xc3>
mov    %rsp,%rbp
xchg   %ax,%ax
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
je     1230 <send_data+0x90>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %r14d,%edi
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    10a0 <not_found_404@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"./\00"
@.str.1 = [11 x i8] c"index.html\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"\0D\0A\00"
define void @send_data(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca [1024 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %6
%10 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %3
%13 = load i8*, i8** %6
%14 = call i32 @strcat(i8* %13, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %12, %3
%16 = load i8*, i8** %6
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %17, i32** %7
%18 = load i32*, i32** %7
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %44
20: ; preds = %15
%21 = load i32, i32* %4
%22 = load i8*, i8** %5
%23 = call i32 @send_header(i32 %21, i8* %22)
%24 = load i32, i32* %4
%25 = call i32 @send(i32 %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2, i32 0)
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%27 = load i32*, i32** %7
%28 = call i32 @fgets(i8* %26, i32 1024, i32* %27)
br label %29
29: ; preds = %34, %20
%30 = load i32*, i32** %7
%31 = call i32 @feof(i32* %30)
%32 = icmp ne i32 %31, 0
%33 = xor i1 %32, true
br i1 %33, label %34, label %43
34: ; preds = %29
%35 = load i32, i32* %4
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%38 = call i32 @strlen(i8* %37)
%39 = call i32 @send(i32 %35, i8* %36, i32 %38, i32 0)
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%41 = load i32*, i32** %7
%42 = call i32 @fgets(i8* %40, i32 1024, i32* %41)
br label %29
43: ; preds = %29
br label %52
44: ; preds = %15
%45 = load i32, i32* %4
%46 = load i8*, i8** %5
%47 = call i32 @send_header(i32 %45, i8* %46)
%48 = load i32, i32* %4
%49 = call i32 @send(i32 %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2, i32 0)
%50 = load i32, i32* %4
%51 = call i32 @not_found_404(i32 %50)
br label %52
52: ; preds = %44, %43
%53 = load i32*, i32** %7
%54 = icmp ne i32* %53, null
br i1 %54, label %55, label %58
55: ; preds = %52
%56 = load i32*, i32** %7
%57 = call i32 @fclose(i32* %56)
br label %58
58: ; preds = %55, %52
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"./\00"
@.str.1 = [11 x i8] c"index.html\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"\0D\0A\00"
define void @send_data(i32 %0, i8* %1, i8* %2) {
%4 = alloca [1024 x i8]
%5 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @strcat(i8* %2, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %7, %3
%10 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i32* %10, null
%12 = tail call i32 @send_header(i32 %0, i8* %1)
%13 = tail call i32 @send(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2, i32 0)
br i1 %11, label %25, label %14
14: ; preds = %9
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%16 = call i32 @fgets(i8* %15, i32 1024, i32* %10)
%17 = call i32 @feof(i32* %10)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %14, %19
%20 = call i32 @strlen(i8* %15)
%21 = call i32 @send(i32 %0, i8* %15, i32 %20, i32 0)
%22 = call i32 @fgets(i8* %15, i32 1024, i32* %10)
%23 = call i32 @feof(i32* %10)
%24 = icmp eq i32 %23, 0
br i1 %24, label %19, label %27
25: ; preds = %9
%26 = tail call i32 @not_found_404(i32 %0)
br label %29
27: ; preds = %19, %14
%28 = call i32 @fclose(i32* %10)
br label %29
29: ; preds = %25, %27
ret void
}