#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 */

/* Variables and functions */
int get_request_path(char *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ report_errno(char *);
int send_packets(int, char *, char *);
int /*<<< orphan*/ send_server_error(int);
int send_200_request(int connfd, char request[65536]) {
  char *filepath = (char *)malloc(sizeof(char) * 1024);
  int path_length = get_request_path(request, filepath);
  if (path_length == -1) {
    report_errno("error getting filepath.");
    send_server_error(connfd);
    return -1;
  } else {
    if (path_length == 0)
      filepath = "index.html";
    char *file_contents = (char *)malloc(65536);
    memset(file_contents, ' ', 65536);
    printf("Got message.");
    if (send_packets(connfd, file_contents, filepath) == -1) {
      char *message = "had trouble sending packets. ";
      report_errno(message);
      return -1;
    };
  }
  return 0;
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <get_request_path@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11c7 <send_200_request+0x57>
lea    0xe52(%rip),%rdi
call   1080 <report_errno@plt>
mov    -0x8(%rbp),%edi
call   1090 <send_server_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124e <send_200_request+0xde>
cmpl   $0x0,-0x1c(%rbp)
jne    11dc <send_200_request+0x6c>
lea    0xe40(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    $0x10000,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x20,%esi
mov    $0x10000,%edx
call   1040 <memset@plt>
lea    0xe1f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <send_packets@plt>
cmp    $0xffffffff,%eax
jne    1242 <send_200_request+0xd2>
lea    0xe07(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1080 <report_errno@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124e <send_200_request+0xde>
jmp    1247 <send_200_request+0xd7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbp
mov    %edi,%r14d
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %rax,%rsi
call   1060 <get_request_path@plt>
test   %eax,%eax
je     11b6 <send_200_request+0x46>
cmp    $0xffffffff,%eax
jne    11bd <send_200_request+0x4d>
lea    0xe5e(%rip),%rdi
call   1080 <report_errno@plt>
mov    %r14d,%edi
call   1090 <send_server_error@plt>
mov    $0xffffffff,%eax
jmp    1213 <send_200_request+0xa3>
lea    0xe5b(%rip),%rbx
mov    $0x10000,%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    $0x20,%esi
mov    $0x10000,%edx
call   1040 <memset@plt>
lea    0xe40(%rip),%rdi
call   1030 <printf@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1050 <send_packets@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1209 <send_200_request+0x99>
lea    0xe2c(%rip),%rdi
call   1080 <report_errno@plt>
xor    %eax,%eax
cmp    $0xffffffff,%ebx
sete   %al
neg    %eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"error getting filepath.\00"
@.str.1 = [11 x i8] c"index.html\00"
@.str.2 = [13 x i8] c"Got message.\00"
@.str.3 = [30 x i8] c"had trouble sending packets. \00"
define i32 @send_200_request(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
%10 = call i64 @malloc(i32 1024)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %6
%12 = load i8*, i8** %5
%13 = load i8*, i8** %6
%14 = call i32 @get_request_path(i8* %12, i8* %13)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = call i32 @report_errno(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* %4
%20 = call i32 @send_server_error(i32 %19)
store i32 -1, i32* %3
br label %41
21: ; preds = %2
%22 = load i32, i32* %7
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %21
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8** %6
br label %25
25: ; preds = %24, %21
%26 = call i64 @malloc(i32 65536)
%27 = inttoptr i64 %26 to i8*
store i8* %27, i8** %8
%28 = load i8*, i8** %8
%29 = call i32 @memset(i8* %28, i8 signext 32, i32 65536)
%30 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32, i32* %4
%32 = load i8*, i8** %8
%33 = load i8*, i8** %6
%34 = call i32 @send_packets(i32 %31, i8* %32, i8* %33)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %39
36: ; preds = %25
store i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8** %9
%37 = load i8*, i8** %9
%38 = call i32 @report_errno(i8* %37)
store i32 -1, i32* %3
br label %41
39: ; preds = %25
br label %40
40: ; preds = %39
store i32 0, i32* %3
br label %41
41: ; preds = %40, %36, %17
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@.str = [24 x i8] c"error getting filepath.\00"
@.str.1 = [11 x i8] c"index.html\00"
@.str.2 = [13 x i8] c"Got message.\00"
@.str.3 = [30 x i8] c"had trouble sending packets. \00"
define i32 @send_200_request(i32 %0, i8* %1) {
%3 = tail call i64 @malloc(i32 1024)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @get_request_path(i8* %1, i8* %4)
switch i32 %5, label %10 [
i32 -1, label %6
i32 0, label %9
]
6: ; preds = %2
%7 = tail call i32 @report_errno(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @send_server_error(i32 %0)
br label %22
9: ; preds = %2
br label %10
10: ; preds = %2, %9
%11 = phi i8* [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), %9 ], [ %4, %2 ]
%12 = tail call i64 @malloc(i32 65536)
%13 = inttoptr i64 %12 to i8*
%14 = tail call i32 @memset(i8* %13, i8 signext 32, i32 65536)
%15 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%16 = tail call i32 @send_packets(i32 %0, i8* %13, i8* %11)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %10
%19 = tail call i32 @report_errno(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %10, %18
%21 = sext i1 %17 to i32
br label %22
22: ; preds = %20, %6
%23 = phi i32 [ -1, %6 ], [ %21, %20 ]
ret i32 %23
}