#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int /*<<< orphan*/ stripTrailingSlash(char *);
size_t strlen(char *);
int /*<<< orphan*/ substringTo(char *, char *, char);
int /*<<< orphan*/ writeBasicResponse(int, int, char *, char *, int);
int /*<<< orphan*/ writeError(int, int);
int /*<<< orphan*/ writeFileResponse(int, char *, struct stat);
void serveGetRequest(int hSocket, const char *webDirectory, char *resource,
                     int verbose) {
  char directory[(1024 * 2) + 2 + 1];
  char dirFile[(1024 * 2) + 2 + 1];
  struct stat filestat;
  DIR *dirp;
  struct dirent *dp;
  stripTrailingSlash(resource);
  strcpy(directory, webDirectory);
  strcat(directory, resource);
  if (stat(directory, &filestat)) {
    if (verbose) {
      printf(" - Unable to stat %s\n", directory);
    }
    writeError(hSocket, 404);
  } else if (S_ISREG(filestat.st_mode)) {
    if (verbose) {
      printf(" - %s is a regular file.\n", directory);
    }
    writeFileResponse(hSocket, directory, filestat);
  } else if (S_ISDIR(filestat.st_mode)) {
    if (verbose) {
      printf(" - %s is a directory.\n", directory);
    }
    dirFile[0] = 0;
    strcat(dirFile, directory);
    strcat(dirFile, "/index.html");
    if (stat(dirFile, &filestat)) {
      if (verbose) {
        printf(" - Generating directory listing.\n");
      }
      char *directoryList = malloc(((1024 * 2) + 2 * 2 + 1) * sizeof(char));
      sprintf(directoryList,
              "<!DOCTYPE html>\n<html lang=\"en\">\n<head><title>Directory "
              "Listing</title></head>\n<body>\n<h1>Index of %s</h1>\n<p><ul>\n",
              resource);
      dirp = opendir(directory);
      while ((dp = readdir(dirp)) != NULL) {
        if (strcmp(dp->d_name, "..") == 0) {
          if (resource[0] != 0) {
            substringTo(dirFile, resource, '/');
            sprintf(&directoryList[strlen(directoryList)],
                    "<li><a href=\"%s\">Parent Directory</a></li>\n", dirFile);
          }
        } else if (strcmp(dp->d_name, ".") != 0) {
          sprintf(&directoryList[strlen(directoryList)],
                  "<li><a href=\"%s/%s/\">%s</a></li>\n", resource, dp->d_name,
                  dp->d_name);
        }
      }
      closedir(dirp);
      strcat(directoryList, "</ul></p></body>\n</html>");
      writeBasicResponse(hSocket, 200, directoryList, "text/html",
                         (int)strlen(directoryList));
      free(directoryList);
    } else {
      if (verbose) {
        printf(" - Found index.html file in directory.\n");
      }
      writeFileResponse(hSocket, dirFile, filestat);
    }
  }
}


x86 assembly (clang, -O0):
<serveGetRequest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1070,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1120 <stripTrailingSlash@plt>
lea    -0x820(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcpy@plt>
lea    -0x820(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1130 <strcat@plt>
lea    -0x820(%rbp),%rdi
lea    -0x1038(%rbp),%rsi
call   10e0 <stat@plt>
cmp    $0x0,%rax
je     12c0 <serveGetRequest+0x90>
cmpl   $0x0,-0x1c(%rbp)
je     12ae <serveGetRequest+0x7e>
lea    -0x820(%rbp),%rsi
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x4(%rbp),%edi
mov    $0x194,%esi
call   10c0 <writeError@plt>
jmp    15a5 <serveGetRequest+0x375>
mov    -0x1038(%rbp),%edi
call   10f0 <S_ISREG@plt>
cmp    $0x0,%rax
je     130e <serveGetRequest+0xde>
cmpl   $0x0,-0x1c(%rbp)
je     12f4 <serveGetRequest+0xc4>
lea    -0x820(%rbp),%rsi
lea    0xd29(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    -0x1038(%rbp),%edx
call   1150 <writeFileResponse@plt>
jmp    15a0 <serveGetRequest+0x370>
mov    -0x1038(%rbp),%edi
call   10a0 <S_ISDIR@plt>
cmp    $0x0,%rax
je     159b <serveGetRequest+0x36b>
cmpl   $0x0,-0x1c(%rbp)
je     1342 <serveGetRequest+0x112>
lea    -0x820(%rbp),%rsi
lea    0xcf5(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
movb   $0x0,-0x1030(%rbp)
lea    -0x1030(%rbp),%rdi
lea    -0x820(%rbp),%rsi
call   1130 <strcat@plt>
lea    -0x1030(%rbp),%rdi
lea    0xcdd(%rip),%rsi
call   1130 <strcat@plt>
lea    -0x1030(%rbp),%rdi
lea    -0x1038(%rbp),%rsi
call   10e0 <stat@plt>
cmp    $0x0,%rax
je     1569 <serveGetRequest+0x339>
cmpl   $0x0,-0x1c(%rbp)
je     13a4 <serveGetRequest+0x174>
lea    0xcb6(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    $0x805,%edi
call   1110 <malloc@plt>
mov    %rax,-0x1050(%rbp)
mov    -0x1050(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xcae(%rip),%rsi
mov    $0x0,%al
call   1140 <sprintf@plt>
lea    -0x820(%rbp),%rdi
call   1060 <opendir@plt>
mov    %rax,-0x1040(%rbp)
mov    -0x1040(%rbp),%rdi
call   1100 <readdir@plt>
mov    %rax,-0x1048(%rbp)
cmp    $0x0,%rax
je     14f5 <serveGetRequest+0x2c5>
mov    -0x1048(%rbp),%rax
mov    (%rax),%rdi
lea    0xcda(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
jne    1481 <serveGetRequest+0x251>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     147c <serveGetRequest+0x24c>
lea    -0x1030(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x2f,%edx
call   1030 <substringTo@plt>
mov    -0x1050(%rbp),%rax
mov    %rax,-0x1058(%rbp)
mov    -0x1050(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x1058(%rbp),%rdi
add    %rax,%rdi
lea    -0x1030(%rbp),%rdx
lea    0xc77(%rip),%rsi
mov    $0x0,%al
call   1140 <sprintf@plt>
jmp    14f0 <serveGetRequest+0x2c0>
mov    -0x1048(%rbp),%rax
mov    (%rax),%rdi
lea    0xc58(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
je     14eb <serveGetRequest+0x2bb>
mov    -0x1050(%rbp),%rax
mov    %rax,-0x1060(%rbp)
mov    -0x1050(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x1060(%rbp),%rdi
add    %rax,%rdi
mov    -0x18(%rbp),%rdx
mov    -0x1048(%rbp),%rax
mov    (%rax),%rcx
mov    -0x1048(%rbp),%rax
mov    (%rax),%r8
lea    0xc34(%rip),%rsi
mov    $0x0,%al
call   1140 <sprintf@plt>
jmp    14f0 <serveGetRequest+0x2c0>
jmp    13e1 <serveGetRequest+0x1b1>
mov    -0x1040(%rbp),%rdi
call   10b0 <closedir@plt>
mov    -0x1050(%rbp),%rdi
lea    0xc2b(%rip),%rsi
call   1130 <strcat@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x106c(%rbp)
mov    -0x1050(%rbp),%rax
mov    %rax,-0x1068(%rbp)
mov    -0x1050(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x106c(%rbp),%edi
mov    -0x1068(%rbp),%rdx
mov    %eax,%r8d
mov    $0xc8,%esi
lea    0xc00(%rip),%rcx
call   1080 <writeBasicResponse@plt>
mov    -0x1050(%rbp),%rdi
call   1040 <free@plt>
jmp    1596 <serveGetRequest+0x366>
cmpl   $0x0,-0x1c(%rbp)
je     1581 <serveGetRequest+0x351>
lea    0xbe3(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x1030(%rbp),%rsi
mov    -0x1038(%rbp),%edx
call   1150 <writeFileResponse@plt>
jmp    159b <serveGetRequest+0x36b>
jmp    15a0 <serveGetRequest+0x370>
jmp    15a5 <serveGetRequest+0x375>
add    $0x1070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serveGetRequest>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1028,%rsp
mov    %ecx,%r15d
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %rdx,%rdi
call   1130 <stripTrailingSlash@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <strcpy@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1140 <strcat@plt>
lea    0x8(%rsp),%rsi
mov    %rbp,%rdi
call   10f0 <stat@plt>
test   %rax,%rax
je     12b9 <serveGetRequest+0x79>
test   %r15d,%r15d
je     12aa <serveGetRequest+0x6a>
lea    0xd62(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %r14d,%edi
mov    $0x194,%esi
call   10d0 <writeError@plt>
jmp    12f0 <serveGetRequest+0xb0>
mov    0x8(%rsp),%edi
call   1100 <S_ISREG@plt>
test   %rax,%rax
je     1302 <serveGetRequest+0xc2>
test   %r15d,%r15d
je     12df <serveGetRequest+0x9f>
lea    0xd43(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    0x8(%rsp),%edx
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
call   1160 <writeFileResponse@plt>
add    $0x1028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rsp),%edi
call   10b0 <S_ISDIR@plt>
test   %rax,%rax
je     12f0 <serveGetRequest+0xb0>
test   %r15d,%r15d
je     1328 <serveGetRequest+0xe8>
lea    0xd14(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
movb   $0x0,0x820(%rsp)
lea    0x820(%rsp),%rbx
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1140 <strcat@plt>
lea    0xcfb(%rip),%rsi
mov    %rbx,%rdi
call   1140 <strcat@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   10f0 <stat@plt>
test   %rax,%rax
je     14d4 <serveGetRequest+0x294>
mov    %r14d,0xc(%rsp)
test   %r15d,%r15d
je     1380 <serveGetRequest+0x140>
lea    0xde7(%rip),%rdi
call   1060 <puts@plt>
mov    $0x805,%edi
call   1120 <malloc@plt>
mov    %rax,%r15
lea    0xcbf(%rip),%rsi
mov    %rax,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1150 <sprintf@plt>
lea    0x10(%rsp),%rdi
call   1070 <opendir@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1110 <readdir@plt>
test   %rax,%rax
je     148d <serveGetRequest+0x24d>
mov    %rax,%r13
lea    0xcfe(%rip),%rbx
lea    0xcf8(%rip),%rbp
jmp    13f4 <serveGetRequest+0x1b4>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1110 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     148d <serveGetRequest+0x24d>
mov    0x0(%r13),%rdi
mov    %rbx,%rsi
call   10e0 <strcmp@plt>
test   %rax,%rax
je     1440 <serveGetRequest+0x200>
mov    0x0(%r13),%rdi
mov    %rbp,%rsi
call   10e0 <strcmp@plt>
test   %rax,%rax
je     13e0 <serveGetRequest+0x1a0>
mov    %r15,%rdi
call   1080 <strlen@plt>
lea    (%rax,%r15,1),%rdi
mov    0x0(%r13),%rcx
lea    0xcc9(%rip),%rsi
mov    %r12,%rdx
mov    %rcx,%r8
xor    %eax,%eax
call   1150 <sprintf@plt>
jmp    13e0 <serveGetRequest+0x1a0>
nopl   0x0(%rax)
cmpb   $0x0,(%r12)
je     13e0 <serveGetRequest+0x1a0>
mov    %rbp,%r13
mov    %rbx,%rbp
lea    0x820(%rsp),%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x2f,%edx
call   1030 <substringTo@plt>
mov    %r15,%rdi
call   1080 <strlen@plt>
lea    (%rax,%r15,1),%rdi
lea    0xc52(%rip),%rsi
mov    %rbx,%rdx
mov    %rbp,%rbx
mov    %r13,%rbp
xor    %eax,%eax
call   1150 <sprintf@plt>
jmp    13e0 <serveGetRequest+0x1a0>
mov    %r14,%rdi
call   10c0 <closedir@plt>
lea    0xc7c(%rip),%rsi
mov    %r15,%rdi
call   1140 <strcat@plt>
mov    %r15,%rdi
call   1080 <strlen@plt>
lea    0xc7e(%rip),%rcx
mov    0xc(%rsp),%edi
mov    $0xc8,%esi
mov    %r15,%rdx
mov    %eax,%r8d
call   1090 <writeBasicResponse@plt>
mov    %r15,%rdi
call   1040 <free@plt>
jmp    12f0 <serveGetRequest+0xb0>
test   %r15d,%r15d
je     14e5 <serveGetRequest+0x2a5>
lea    0xc5b(%rip),%rdi
call   1060 <puts@plt>
mov    0x8(%rsp),%edx
lea    0x820(%rsp),%rsi
jmp    12e8 <serveGetRequest+0xa8>

LLVM IR (-O0):
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@.str = [22 x i8] c" - Unable to stat %s\0A\00"
@.str.1 = [26 x i8] c" - %s is a regular file.\0A\00"
@.str.2 = [23 x i8] c" - %s is a directory.\0A\00"
@.str.3 = [12 x i8] c"/index.html\00"
@.str.4 = [34 x i8] c" - Generating directory listing.\0A\00"
@.str.5 = [116 x i8] c"<!DOCTYPE html>\0A<html lang=\22en\22>\0A<head><title>Directory Listing</title></head>\0A<body>\0A<h1>Index of %s</h1>\0A<p><ul>\0A\00"
@.str.6 = [3 x i8] c"..\00"
@.str.7 = [44 x i8] c"<li><a href=\22%s\22>Parent Directory</a></li>\0A\00"
@.str.8 = [2 x i8] c".\00"
@.str.9 = [34 x i8] c"<li><a href=\22%s/%s/\22>%s</a></li>\0A\00"
@.str.10 = [25 x i8] c"</ul></p></body>\0A</html>\00"
@.str.11 = [10 x i8] c"text/html\00"
@.str.12 = [40 x i8] c" - Found index.html file in directory.\0A\00"
define void @serveGetRequest(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [2051 x i8]
%10 = alloca [2051 x i8]
%11 = alloca %struct.stat
%12 = alloca i32*
%13 = alloca %struct.dirent*
%14 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%15 = load i8*, i8** %7
%16 = call i32 @stripTrailingSlash(i8* %15)
%17 = getelementptr inbounds [2051 x i8], [2051 x i8]* %9, i64 0, i64 0
%18 = load i8*, i8** %6
%19 = call i32 @strcpy(i8* %17, i8* %18)
%20 = getelementptr inbounds [2051 x i8], [2051 x i8]* %9, i64 0, i64 0
%21 = load i8*, i8** %7
%22 = call i32 @strcat(i8* %20, i8* %21)
%23 = getelementptr inbounds [2051 x i8], [2051 x i8]* %9, i64 0, i64 0
%24 = call i64 @stat(i8* %23, %struct.stat* %11)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %4
%27 = load i32, i32* %8
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = getelementptr inbounds [2051 x i8], [2051 x i8]* %9, i64 0, i64 0
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %29, %26
%33 = load i32, i32* %5
%34 = call i32 @writeError(i32 %33, i32 404)
br label %160
35: ; preds = %4
%36 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%37 = load i32, i32* %36
%38 = call i64 @S_ISREG(i32 %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %52
40: ; preds = %35
%41 = load i32, i32* %8
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = getelementptr inbounds [2051 x i8], [2051 x i8]* %9, i64 0, i64 0
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %43, %40
%47 = load i32, i32* %5
%48 = getelementptr inbounds [2051 x i8], [2051 x i8]* %9, i64 0, i64 0
%49 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%50 = load i32, i32* %49
%51 = call i32 @writeFileResponse(i32 %47, i8* %48, i32 %50)
br label %159
52: ; preds = %35
%53 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%54 = load i32, i32* %53
%55 = call i64 @S_ISDIR(i32 %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %158
57: ; preds = %52
%58 = load i32, i32* %8
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %57
%61 = getelementptr inbounds [2051 x i8], [2051 x i8]* %9, i64 0, i64 0
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %61)
br label %63
63: ; preds = %60, %57
%64 = getelementptr inbounds [2051 x i8], [2051 x i8]* %10, i64 0, i64 0
store i8 0, i8* %64
%65 = getelementptr inbounds [2051 x i8], [2051 x i8]* %10, i64 0, i64 0
%66 = getelementptr inbounds [2051 x i8], [2051 x i8]* %9, i64 0, i64 0
%67 = call i32 @strcat(i8* %65, i8* %66)
%68 = getelementptr inbounds [2051 x i8], [2051 x i8]* %10, i64 0, i64 0
%69 = call i32 @strcat(i8* %68, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%70 = getelementptr inbounds [2051 x i8], [2051 x i8]* %10, i64 0, i64 0
%71 = call i64 @stat(i8* %70, %struct.stat* %11)
%72 = icmp ne i64 %71, 0
br i1 %72, label %73, label %146
73: ; preds = %63
%74 = load i32, i32* %8
%75 = icmp ne i32 %74, 0
br i1 %75, label %76, label %78
76: ; preds = %73
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
br label %78
78: ; preds = %76, %73
%79 = call i8* @malloc(i32 2053)
store i8* %79, i8** %14
%80 = load i8*, i8** %14
%81 = load i8*, i8** %7
%82 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %80, i8* getelementptr inbounds ([116 x i8], [116 x i8]* @.str.5, i64 0, i64 0), i8* %81)
%83 = getelementptr inbounds [2051 x i8], [2051 x i8]* %9, i64 0, i64 0
%84 = call i32* @opendir(i8* %83)
store i32* %84, i32** %12
br label %85
85: ; preds = %132, %78
%86 = load i32*, i32** %12
%87 = call %struct.dirent* @readdir(i32* %86)
store %struct.dirent* %87, %struct.dirent** %13
%88 = icmp ne %struct.dirent* %87, null
br i1 %88, label %89, label %133
89: ; preds = %85
%90 = load %struct.dirent*, %struct.dirent** %13
%91 = getelementptr inbounds %struct.dirent, %struct.dirent* %90, i32 0, i32 0
%92 = load i8*, i8** %91
%93 = call i64 @strcmp(i8* %92, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%94 = icmp eq i64 %93, 0
br i1 %94, label %95, label %112
95: ; preds = %89
%96 = load i8*, i8** %7
%97 = getelementptr inbounds i8, i8* %96, i64 0
%98 = load i8, i8* %97
%99 = sext i8 %98 to i32
%100 = icmp ne i32 %99, 0
br i1 %100, label %101, label %111
101: ; preds = %95
%102 = getelementptr inbounds [2051 x i8], [2051 x i8]* %10, i64 0, i64 0
%103 = load i8*, i8** %7
%104 = call i32 @substringTo(i8* %102, i8* %103, i8 signext 47)
%105 = load i8*, i8** %14
%106 = load i8*, i8** %14
%107 = call i64 @strlen(i8* %106)
%108 = getelementptr inbounds i8, i8* %105, i64 %107
%109 = getelementptr inbounds [2051 x i8], [2051 x i8]* %10, i64 0, i64 0
%110 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %108, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.7, i64 0, i64 0), i8* %109)
br label %111
111: ; preds = %101, %95
br label %132
112: ; preds = %89
%113 = load %struct.dirent*, %struct.dirent** %13
%114 = getelementptr inbounds %struct.dirent, %struct.dirent* %113, i32 0, i32 0
%115 = load i8*, i8** %114
%116 = call i64 @strcmp(i8* %115, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%117 = icmp ne i64 %116, 0
br i1 %117, label %118, label %131
118: ; preds = %112
%119 = load i8*, i8** %14
%120 = load i8*, i8** %14
%121 = call i64 @strlen(i8* %120)
%122 = getelementptr inbounds i8, i8* %119, i64 %121
%123 = load i8*, i8** %7
%124 = load %struct.dirent*, %struct.dirent** %13
%125 = getelementptr inbounds %struct.dirent, %struct.dirent* %124, i32 0, i32 0
%126 = load i8*, i8** %125
%127 = load %struct.dirent*, %struct.dirent** %13
%128 = getelementptr inbounds %struct.dirent, %struct.dirent* %127, i32 0, i32 0
%129 = load i8*, i8** %128
%130 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %122, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.9, i64 0, i64 0), i8* %123, i8* %126, i8* %129)
br label %131
131: ; preds = %118, %112
br label %132
132: ; preds = %131, %111
br label %85
133: ; preds = %85
%134 = load i32*, i32** %12
%135 = call i32 @closedir(i32* %134)
%136 = load i8*, i8** %14
%137 = call i32 @strcat(i8* %136, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.10, i64 0, i64 0))
%138 = load i32, i32* %5
%139 = load i8*, i8** %14
%140 = load i8*, i8** %14
%141 = call i64 @strlen(i8* %140)
%142 = trunc i64 %141 to i32
%143 = call i32 @writeBasicResponse(i32 %138, i32 200, i8* %139, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i32 %142)
%144 = load i8*, i8** %14
%145 = call i32 @free(i8* %144)
br label %157
146: ; preds = %63
%147 = load i32, i32* %8
%148 = icmp ne i32 %147, 0
br i1 %148, label %149, label %151
149: ; preds = %146
%150 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.12, i64 0, i64 0))
br label %151
151: ; preds = %149, %146
%152 = load i32, i32* %5
%153 = getelementptr inbounds [2051 x i8], [2051 x i8]* %10, i64 0, i64 0
%154 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%155 = load i32, i32* %154
%156 = call i32 @writeFileResponse(i32 %152, i8* %153, i32 %155)
br label %157
157: ; preds = %151, %133
br label %158
158: ; preds = %157, %52
br label %159
159: ; preds = %158, %46
br label %160
160: ; preds = %159, %32
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@.str = [22 x i8] c" - Unable to stat %s\0A\00"
@.str.1 = [26 x i8] c" - %s is a regular file.\0A\00"
@.str.2 = [23 x i8] c" - %s is a directory.\0A\00"
@.str.3 = [12 x i8] c"/index.html\00"
@.str.5 = [116 x i8] c"<!DOCTYPE html>\0A<html lang=\22en\22>\0A<head><title>Directory Listing</title></head>\0A<body>\0A<h1>Index of %s</h1>\0A<p><ul>\0A\00"
@.str.6 = [3 x i8] c"..\00"
@.str.7 = [44 x i8] c"<li><a href=\22%s\22>Parent Directory</a></li>\0A\00"
@.str.8 = [2 x i8] c".\00"
@.str.9 = [34 x i8] c"<li><a href=\22%s/%s/\22>%s</a></li>\0A\00"
@.str.10 = [25 x i8] c"</ul></p></body>\0A</html>\00"
@.str.11 = [10 x i8] c"text/html\00"
@str = [39 x i8] c" - Found index.html file in directory.\00"
@str.13 = [33 x i8] c" - Generating directory listing.\00"
define void @serveGetRequest(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca [2051 x i8]
%6 = alloca [2051 x i8]
%7 = alloca %struct.stat
%8 = getelementptr inbounds [2051 x i8], [2051 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [2051 x i8], [2051 x i8]* %6, i64 0, i64 0
%10 = bitcast %struct.stat* %7 to i8*
%11 = tail call i32 @stripTrailingSlash(i8* %2)
%12 = call i32 @strcpy(i8* %8, i8* %1)
%13 = call i32 @strcat(i8* %8, i8* %2)
%14 = call i64 @stat(i8* %8, %struct.stat* %7)
%15 = icmp eq i64 %14, 0
br i1 %15, label %22, label %16
16: ; preds = %4
%17 = icmp eq i32 %3, 0
br i1 %17, label %20, label %18
18: ; preds = %16
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %20
20: ; preds = %18, %16
%21 = call i32 @writeError(i32 %0, i32 404)
br label %95
22: ; preds = %4
%23 = getelementptr inbounds %struct.stat, %struct.stat* %7, i64 0, i32 0
%24 = load i32, i32* %23
%25 = call i64 @S_ISREG(i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %34, label %27
27: ; preds = %22
%28 = icmp eq i32 %3, 0
br i1 %28, label %31, label %29
29: ; preds = %27
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %31
31: ; preds = %29, %27
%32 = load i32, i32* %23
%33 = call i32 @writeFileResponse(i32 %0, i8* %8, i32 %32)
br label %95
34: ; preds = %22
%35 = load i32, i32* %23
%36 = call i64 @S_ISDIR(i32 %35)
%37 = icmp eq i64 %36, 0
br i1 %37, label %95, label %38
38: ; preds = %34
%39 = icmp eq i32 %3, 0
br i1 %39, label %42, label %40
40: ; preds = %38
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %8)
br label %42
42: ; preds = %40, %38
store i8 0, i8* %9
%43 = call i32 @strcat(i8* %9, i8* %8)
%44 = call i32 @strcat(i8* %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%45 = call i64 @stat(i8* %9, %struct.stat* %7)
%46 = icmp eq i64 %45, 0
br i1 %46, label %89, label %47
47: ; preds = %42
br i1 %39, label %50, label %48
48: ; preds = %47
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.13, i64 0, i64 0))
br label %50
50: ; preds = %48, %47
%51 = call dereferenceable_or_null(2053) i8* @malloc(i32 2053)
%52 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %51, i8* dereferenceable(1) getelementptr inbounds ([116 x i8], [116 x i8]* @.str.5, i64 0, i64 0), i8* %2)
%53 = call i32* @opendir(i8* %8)
%54 = call %struct.dirent* @readdir(i32* %53)
%55 = icmp eq %struct.dirent* %54, null
br i1 %55, label %82, label %56
56: ; preds = %50, %79
%57 = phi %struct.dirent* [ %80, %79 ], [ %54, %50 ]
%58 = getelementptr inbounds %struct.dirent, %struct.dirent* %57, i64 0, i32 0
%59 = load i8*, i8** %58
%60 = call i64 @strcmp(i8* %59, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %70
62: ; preds = %56
%63 = load i8, i8* %2
%64 = icmp eq i8 %63, 0
br i1 %64, label %79, label %65
65: ; preds = %62
%66 = call i32 @substringTo(i8* %9, i8* %2, i8 signext 47)
%67 = call i64 @strlen(i8* dereferenceable(1) %51)
%68 = getelementptr inbounds i8, i8* %51, i64 %67
%69 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %68, i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.7, i64 0, i64 0), i8* %9)
br label %79
70: ; preds = %56
%71 = load i8*, i8** %58
%72 = call i64 @strcmp(i8* %71, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%73 = icmp eq i64 %72, 0
br i1 %73, label %79, label %74
74: ; preds = %70
%75 = call i64 @strlen(i8* dereferenceable(1) %51)
%76 = getelementptr inbounds i8, i8* %51, i64 %75
%77 = load i8*, i8** %58
%78 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %76, i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.9, i64 0, i64 0), i8* %2, i8* %77, i8* %77)
br label %79
79: ; preds = %70, %74, %62, %65
%80 = call %struct.dirent* @readdir(i32* %53)
%81 = icmp eq %struct.dirent* %80, null
br i1 %81, label %82, label %56
82: ; preds = %79, %50
%83 = call i32 @closedir(i32* %53)
%84 = call i32 @strcat(i8* %51, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.10, i64 0, i64 0))
%85 = call i64 @strlen(i8* dereferenceable(1) %51)
%86 = trunc i64 %85 to i32
%87 = call i32 @writeBasicResponse(i32 %0, i32 200, i8* %51, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i32 %86)
%88 = call i32 @free(i8* %51)
br label %95
89: ; preds = %42
br i1 %39, label %92, label %90
90: ; preds = %89
%91 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
br label %92
92: ; preds = %90, %89
%93 = load i32, i32* %23
%94 = call i32 @writeFileResponse(i32 %0, i8* %9, i32 %93)
br label %95
95: ; preds = %31, %82, %92, %34, %20
ret void
}