#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 st_size;
  int /*<<< orphan*/ st_mtime;
  int /*<<< orphan*/ st_mode;
};
struct dirent {
  int /*<<< orphan*/ d_name;
};
typedef int /*<<< orphan*/ location;
typedef int /*<<< orphan*/ line;
typedef int /*<<< orphan*/ idx;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ alphasort;
scalar_t__ chdir(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
char *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ file_details(char *, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
char *get_mime_type(char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ putchar(int);
int scandir(char *, struct dirent ***, int /*<<< orphan*/ *,
            int /*<<< orphan*/);
int /*<<< orphan*/ send_error(int, char *, char *, char *);
int /*<<< orphan*/ send_headers(int, char *, char *, char *, int,
                                int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int sscanf(char *, char *, char *, char *, char *);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strcasecmp(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strdecode(char *, char *);
size_t strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *strstr(char *, char *);
int main(int argc, char **argv) {
  char line[10000], method[10000], path[10000], protocol[10000], idx[20000],
      location[20000], command[20000];
  char *file;
  size_t len;
  int ich;
  struct stat sb;
  FILE *fp;
  struct dirent **dl;
  int i, n;
  if (argc != 2)
    send_error(500, "Internal Error", (char *)0,
               "Config error - no dir specified.");
  if (chdir(argv[1]) < 0)
    send_error(500, "Internal Error", (char *)0,
               "Config error - couldn't chdir().");
  if (fgets(line, sizeof(line), stdin) == (char *)0)
    send_error(400, "Bad Request", (char *)0, "No request found.");
  if (sscanf(line, "%[^ ] %[^ ] %[^ ]", method, path, protocol) != 3)
    send_error(400, "Bad Request", (char *)0, "Can't parse request.");
  while (fgets(line, sizeof(line), stdin) != (char *)0) {
    if (strcmp(line, "\n") == 0 || strcmp(line, "\r\n") == 0)
      break;
  }
  if (strcasecmp(method, "get") != 0)
    send_error(501, "Not Implemented", (char *)0,
               "That method is not implemented.");
  if (path[0] != '/')
    send_error(400, "Bad Request", (char *)0, "Bad filename.");
  file = &(path[1]);
  strdecode(file, file);
  if (file[0] == '\0')
    file = "./";
  len = strlen(file);
  if (file[0] == '/' || strcmp(file, "..") == 0 ||
      strncmp(file, "../", 3) == 0 || strstr(file, "/../") != (char *)0 ||
      strcmp(&(file[len - 3]), "/..") == 0)
    send_error(400, "Bad Request", (char *)0, "Illegal filename.");
  for (i = len; i > 0; --i)
    if (file[i] == '?')
      break;
  if (file[i] == '?') {
    len = i;
    file[i] = '\0';
  }
  if (stat(file, &sb) < 0)
    send_error(404, "Not Found", (char *)0, "File not found.");
  if (S_ISDIR(sb.st_mode)) {
    if (file[len - 1] != '/') {
      (void)snprintf(location, sizeof(location), "Location: %s/", path);
      send_error(302, "Found", location, "Directories must end with a slash.");
    }
    (void)snprintf(idx, sizeof(idx), "%sindex.html", file);
    if (stat(idx, &sb) >= 0) {
      file = idx;
      goto do_file;
    }
    send_headers(200, "Ok", (char *)0, "text/html", -1, sb.st_mtime);
    (void)printf("<html><head><title>Index of %s</title></head>\n<body "
                 "bgcolor=\"#99cc99\"><h4>Index of %s</h4>\n<pre>\n",
                 file, file);
    n = scandir(file, &dl, NULL, alphasort);
    if (n < 0)
      perror("scandir");
    else
      for (i = 0; i < n; ++i)
        file_details(file, dl[i]->d_name);
    (void)printf("</pre>\n<hr>\n<address><a "
                 "href=\"%s\">%s</a></address>\n</body></html>\n",
                 "http://www.acme.com/software/micro_httpd/", "micro_httpd");
  } else {
  do_file:
    fp = fopen(file, "r");
    if (fp == (FILE *)0)
      send_error(403, "Forbidden", (char *)0, "File is protected.");
    send_headers(200, "Ok", (char *)0, get_mime_type(file), sb.st_size,
                 sb.st_mtime);
    while ((ich = getc(fp)) != EOF)
      putchar(ich);
  }
  (void)fflush(stdout);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x186f0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     12bf <main+0x3f>
mov    $0x1f4,%edi
lea    0xd51(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
lea    0xd55(%rip),%rcx
call   1120 <send_error@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <chdir@plt>
cmp    $0x0,%rax
jge    12f2 <main+0x72>
mov    $0x1f4,%edi
lea    0xd1e(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
lea    0xd43(%rip),%rcx
call   1120 <send_error@plt>
lea    -0x2720(%rbp),%rdi
mov    0x2ce8(%rip),%rax
mov    (%rax),%edx
mov    $0x2710,%esi
call   10c0 <fgets@plt>
cmp    $0x0,%rax
jne    1332 <main+0xb2>
mov    $0x190,%edi
lea    0xd2f(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
lea    0xd30(%rip),%rcx
call   1120 <send_error@plt>
lea    -0x2720(%rbp),%rdi
lea    -0x4e30(%rbp),%rdx
lea    -0x7540(%rbp),%rcx
lea    -0x9c50(%rbp),%r8
lea    0xd1a(%rip),%rsi
call   1140 <sscanf@plt>
cmp    $0x3,%eax
je     137f <main+0xff>
mov    $0x190,%edi
lea    0xce2(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
lea    0xd07(%rip),%rcx
call   1120 <send_error@plt>
jmp    1384 <main+0x104>
lea    -0x2720(%rbp),%rdi
mov    0x2c56(%rip),%rax
mov    (%rax),%edx
mov    $0x2710,%esi
call   10c0 <fgets@plt>
cmp    $0x0,%rax
je     13ec <main+0x16c>
lea    -0x2720(%rbp),%rdi
lea    0xce1(%rip),%rsi
call   10f0 <strcmp@plt>
cmp    $0x0,%rax
je     13e2 <main+0x162>
lea    -0x2720(%rbp),%rdi
lea    0xcc3(%rip),%rsi
call   10f0 <strcmp@plt>
cmp    $0x0,%rax
jne    13e7 <main+0x167>
jmp    13ec <main+0x16c>
jmp    1384 <main+0x104>
lea    -0x4e30(%rbp),%rdi
lea    0xc9f(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
je     1425 <main+0x1a5>
mov    $0x1f5,%edi
lea    0xc88(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
lea    0xc8d(%rip),%rcx
call   1120 <send_error@plt>
movsbl -0x7540(%rbp),%eax
cmp    $0x2f,%eax
je     1451 <main+0x1d1>
mov    $0x190,%edi
lea    0xc10(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
lea    0xc81(%rip),%rcx
call   1120 <send_error@plt>
lea    -0x7540(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x186b8(%rbp)
mov    -0x186b8(%rbp),%rdi
mov    -0x186b8(%rbp),%rsi
call   1180 <strdecode@plt>
mov    -0x186b8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1497 <main+0x217>
lea    0xc4d(%rip),%rax
mov    %rax,-0x186b8(%rbp)
mov    -0x186b8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x186c0(%rbp)
mov    -0x186b8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1544 <main+0x2c4>
mov    -0x186b8(%rbp),%rdi
lea    0xc16(%rip),%rsi
call   10f0 <strcmp@plt>
cmp    $0x0,%rax
je     1544 <main+0x2c4>
mov    -0x186b8(%rbp),%rdi
lea    0xbf4(%rip),%rsi
mov    $0x3,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
je     1544 <main+0x2c4>
mov    -0x186b8(%rbp),%rdi
lea    0xbd1(%rip),%rsi
call   11a0 <strstr@plt>
cmp    $0x0,%rax
jne    1544 <main+0x2c4>
mov    -0x186b8(%rbp),%rdi
mov    -0x186c0(%rbp),%rax
sub    $0x3,%rax
add    %rax,%rdi
lea    0xbab(%rip),%rsi
call   10f0 <strcmp@plt>
cmp    $0x0,%rax
jne    1560 <main+0x2e0>
mov    $0x190,%edi
lea    0xb01(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
lea    0xb89(%rip),%rcx
call   1120 <send_error@plt>
mov    -0x186c0(%rbp),%rax
mov    %eax,-0x186e4(%rbp)
cmpl   $0x0,-0x186e4(%rbp)
jle    15b3 <main+0x333>
mov    -0x186b8(%rbp),%rax
movslq -0x186e4(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3f,%eax
jne    159a <main+0x31a>
jmp    15b3 <main+0x333>
jmp    159f <main+0x31f>
mov    -0x186e4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x186e4(%rbp)
jmp    156d <main+0x2ed>
mov    -0x186b8(%rbp),%rax
movslq -0x186e4(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3f,%eax
jne    15ee <main+0x36e>
movslq -0x186e4(%rbp),%rax
mov    %rax,-0x186c0(%rbp)
mov    -0x186b8(%rbp),%rax
movslq -0x186e4(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x186b8(%rbp),%rdi
lea    -0x186d0(%rbp),%rsi
call   1100 <stat@plt>
cmp    $0x0,%rax
jge    1627 <main+0x3a7>
mov    $0x194,%edi
lea    0xadf(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
lea    0xade(%rip),%rcx
call   1120 <send_error@plt>
mov    -0x186c8(%rbp),%edi
call   1090 <S_ISDIR@plt>
cmp    $0x0,%rax
je     17e3 <main+0x563>
mov    -0x186b8(%rbp),%rax
mov    -0x186c0(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     1699 <main+0x419>
lea    -0x13890(%rbp),%rdi
lea    -0x7540(%rbp),%rcx
mov    $0x4e20,%esi
lea    0xa9b(%rip),%rdx
call   10a0 <snprintf@plt>
lea    -0x13890(%rbp),%rdx
mov    $0x12e,%edi
lea    0xa6d(%rip),%rsi
lea    0xa8a(%rip),%rcx
call   1120 <send_error@plt>
lea    -0xea70(%rbp),%rdi
mov    -0x186b8(%rbp),%rcx
mov    $0x4e20,%esi
lea    0xa8e(%rip),%rdx
call   10a0 <snprintf@plt>
lea    -0xea70(%rbp),%rdi
lea    -0x186d0(%rbp),%rsi
call   1100 <stat@plt>
cmp    $0x0,%rax
jl     16e8 <main+0x468>
lea    -0xea70(%rbp),%rax
mov    %rax,-0x186b8(%rbp)
jmp    17e8 <main+0x568>
mov    -0x186cc(%rbp),%r9d
mov    $0xc8,%edi
lea    0xa53(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
lea    0xa4b(%rip),%rcx
mov    $0xffffffff,%r8d
call   10d0 <send_headers@plt>
mov    -0x186b8(%rbp),%rsi
mov    -0x186b8(%rbp),%rdx
lea    0xa35(%rip),%rdi
call   1080 <printf@plt>
mov    -0x186b8(%rbp),%rdi
mov    0x288f(%rip),%rax
mov    (%rax),%ecx
lea    -0x186e0(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   10b0 <scandir@plt>
mov    %eax,-0x186e8(%rbp)
cmpl   $0x0,-0x186e8(%rbp)
jge    176f <main+0x4ef>
lea    0xa58(%rip),%rdi
call   1160 <perror@plt>
jmp    17c4 <main+0x544>
movl   $0x0,-0x186e4(%rbp)
mov    -0x186e4(%rbp),%eax
cmp    -0x186e8(%rbp),%eax
jge    17bf <main+0x53f>
mov    -0x186b8(%rbp),%rdi
mov    -0x186e0(%rbp),%rax
movslq -0x186e4(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%esi
call   1110 <file_details@plt>
mov    -0x186e4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x186e4(%rbp)
jmp    1779 <main+0x4f9>
jmp    17c4 <main+0x544>
lea    0x9fa(%rip),%rdi
lea    0xa36(%rip),%rsi
lea    0xa59(%rip),%rdx
call   1080 <printf@plt>
jmp    1894 <main+0x614>
jmp    17e8 <main+0x568>
mov    -0x186b8(%rbp),%rdi
lea    0x9cd(%rip),%rsi
call   1150 <fopen@plt>
mov    %rax,-0x186d8(%rbp)
cmpq   $0x0,-0x186d8(%rbp)
jne    182c <main+0x5ac>
mov    $0x193,%edi
lea    0xa22(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
lea    0xa21(%rip),%rcx
call   1120 <send_error@plt>
mov    -0x186b8(%rbp),%rdi
call   10e0 <get_mime_type@plt>
mov    %rax,%rcx
mov    -0x186d0(%rbp),%r8d
mov    -0x186cc(%rbp),%r9d
mov    $0xc8,%edi
lea    0x8f9(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   10d0 <send_headers@plt>
mov    -0x186d8(%rbp),%rdi
call   1190 <getc@plt>
mov    %eax,-0x186c4(%rbp)
mov    0x2769(%rip),%rcx
cmp    (%rcx),%eax
je     188f <main+0x60f>
mov    -0x186c4(%rbp),%edi
call   1030 <putchar@plt>
jmp    185e <main+0x5de>
jmp    1894 <main+0x614>
mov    0x2735(%rip),%rax
mov    (%rax),%edi
call   1130 <fflush@plt>
xor    %edi,%edi
call   1170 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x138a8,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
je     12b0 <main+0x30>
lea    0xd63(%rip),%rsi
lea    0xd6b(%rip),%rcx
mov    $0x1f4,%edi
xor    %edx,%edx
call   1120 <send_error@plt>
mov    0x8(%rbx),%rdi
call   1070 <chdir@plt>
test   %rax,%rax
jns    12d8 <main+0x58>
lea    0xd3b(%rip),%rsi
lea    0xd64(%rip),%rcx
mov    $0x1f4,%edi
xor    %edx,%edx
call   1120 <send_error@plt>
mov    0x2d09(%rip),%r12
mov    (%r12),%edx
lea    0x2730(%rsp),%rdi
mov    $0x2710,%esi
call   10c0 <fgets@plt>
test   %rax,%rax
jne    1314 <main+0x94>
lea    0xd50(%rip),%rsi
lea    0xd55(%rip),%rcx
mov    $0x190,%edi
xor    %edx,%edx
call   1120 <send_error@plt>
lea    0xd54(%rip),%rsi
lea    0x2730(%rsp),%rdi
lea    0x4e40(%rsp),%rdx
lea    0x20(%rsp),%rcx
lea    0x7550(%rsp),%r8
call   1140 <sscanf@plt>
cmp    $0x3,%eax
je     135c <main+0xdc>
lea    0xd08(%rip),%rsi
lea    0xd31(%rip),%rcx
mov    $0x190,%edi
xor    %edx,%edx
call   1120 <send_error@plt>
lea    0x2730(%rsp),%rbx
lea    0xd2c(%rip),%r14
lea    0xd24(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x2710,%esi
call   10c0 <fgets@plt>
test   %rax,%rax
je     13b6 <main+0x136>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10f0 <strcmp@plt>
test   %rax,%rax
je     13b6 <main+0x136>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10f0 <strcmp@plt>
test   %rax,%rax
jne    1380 <main+0x100>
lea    0xcdc(%rip),%rsi
lea    0x4e40(%rsp),%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     13e9 <main+0x169>
lea    0xcc7(%rip),%rsi
lea    0xcd0(%rip),%rcx
mov    $0x1f5,%edi
xor    %edx,%edx
call   1120 <send_error@plt>
cmpb   $0x2f,0x20(%rsp)
je     140a <main+0x18a>
lea    0xc5a(%rip),%rsi
lea    0xccf(%rip),%rcx
mov    $0x190,%edi
xor    %edx,%edx
call   1120 <send_error@plt>
lea    0x21(%rsp),%r14
mov    %r14,%rdi
mov    %r14,%rsi
call   1180 <strdecode@plt>
cmpb   $0x0,0x21(%rsp)
lea    0xcb7(%rip),%rbx
cmovne %r14,%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %rax,%r14
cmpb   $0x2f,(%rbx)
je     1494 <main+0x214>
lea    0xca0(%rip),%rsi
mov    %rbx,%rdi
call   10f0 <strcmp@plt>
test   %rax,%rax
je     1494 <main+0x214>
lea    0xc87(%rip),%rsi
mov    %rbx,%rdi
mov    $0x3,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
je     1494 <main+0x214>
lea    0xc6d(%rip),%rsi
mov    %rbx,%rdi
call   11a0 <strstr@plt>
test   %rax,%rax
jne    1494 <main+0x214>
lea    (%r14,%rbx,1),%rdi
add    $0xfffffffffffffffd,%rdi
lea    0xc56(%rip),%rsi
call   10f0 <strcmp@plt>
test   %rax,%rax
jne    14ae <main+0x22e>
lea    0xbb6(%rip),%rsi
lea    0xc42(%rip),%rcx
mov    $0x190,%edi
xor    %edx,%edx
call   1120 <send_error@plt>
mov    %r14d,%eax
test   %r14d,%r14d
jle    14d4 <main+0x254>
cs nopw 0x0(%rax,%rax,1)
mov    %eax,%ecx
cmpb   $0x3f,(%rbx,%rcx,1)
je     14d4 <main+0x254>
lea    -0x1(%rax),%ecx
cmp    $0x1,%eax
mov    %ecx,%eax
jg     14c0 <main+0x240>
xor    %eax,%eax
cltq
cmpb   $0x3f,(%rbx,%rax,1)
jne    14e3 <main+0x263>
movb   $0x0,(%rbx,%rax,1)
mov    %rax,%r14
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1100 <stat@plt>
test   %rax,%rax
jns    150f <main+0x28f>
lea    0xbfa(%rip),%rsi
lea    0xbfd(%rip),%rcx
mov    $0x194,%edi
xor    %edx,%edx
call   1120 <send_error@plt>
mov    0x10(%rsp),%edi
call   1090 <S_ISDIR@plt>
test   %rax,%rax
jne    1522 <main+0x2a2>
mov    %rbx,%r14
jmp    159b <main+0x31b>
cmpb   $0x2f,-0x1(%r14,%rbx,1)
je     1566 <main+0x2e6>
lea    0xbdf(%rip),%rdx
lea    0x9c60(%rsp),%r14
lea    0x20(%rsp),%rcx
mov    %r14,%rdi
mov    $0x4e20,%esi
call   10a0 <snprintf@plt>
lea    0xba8(%rip),%rsi
lea    0xbc5(%rip),%rcx
mov    $0x12e,%edi
mov    %r14,%rdx
call   1120 <send_error@plt>
lea    0xea80(%rsp),%r14
lea    0xbcc(%rip),%rdx
mov    %r14,%rdi
mov    $0x4e20,%esi
mov    %rbx,%rcx
call   10a0 <snprintf@plt>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1100 <stat@plt>
test   %rax,%rax
js     162a <main+0x3aa>
lea    0xc21(%rip),%rsi
mov    %r14,%rdi
call   1150 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    15cc <main+0x34c>
lea    0xc85(%rip),%rsi
lea    0xc88(%rip),%rcx
mov    $0x193,%edi
xor    %edx,%edx
call   1120 <send_error@plt>
mov    %r14,%rdi
call   10e0 <get_mime_type@plt>
mov    0x8(%rsp),%r8d
mov    0xc(%rsp),%r9d
lea    0xb69(%rip),%rsi
mov    $0xc8,%edi
xor    %edx,%edx
mov    %rax,%rcx
call   10d0 <send_headers@plt>
mov    %rbx,%rdi
call   1190 <getc@plt>
mov    0x29dd(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    (%r14),%eax
je     16a3 <main+0x423>
mov    %eax,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1190 <getc@plt>
jmp    1610 <main+0x390>
mov    0xc(%rsp),%r9d
lea    0xb18(%rip),%rsi
lea    0xb14(%rip),%rcx
mov    $0xc8,%edi
xor    %edx,%edx
mov    $0xffffffff,%r8d
call   10d0 <send_headers@plt>
lea    0xb05(%rip),%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
call   1080 <printf@plt>
mov    0x2960(%rip),%rax
mov    (%rax),%ecx
lea    0x18(%rsp),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   10b0 <scandir@plt>
test   %eax,%eax
jns    16b8 <main+0x438>
lea    0xb39(%rip),%rdi
call   1160 <perror@plt>
lea    0xb35(%rip),%rdi
lea    0xb71(%rip),%rsi
lea    0xb94(%rip),%rdx
call   1080 <printf@plt>
mov    0x2926(%rip),%rax
mov    (%rax),%edi
call   1130 <fflush@plt>
xor    %edi,%edi
call   1170 <exit@plt>
je     1689 <main+0x409>
mov    %eax,%r14d
xor    %r15d,%r15d
mov    0x18(%rsp),%rax
mov    (%rax,%r15,8),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1110 <file_details@plt>
add    $0x1,%r15
cmp    %r15,%r14
jne    16c0 <main+0x440>
jmp    1689 <main+0x409>

LLVM IR (-O0):
%struct.stat = type { i32, i32, i32 }
%struct.dirent = type { i32 }
@.str = [15 x i8] c"Internal Error\00"
@.str.1 = [33 x i8] c"Config error - no dir specified.\00"
@.str.2 = [33 x i8] c"Config error - couldn't chdir().\00"
@stdin = global i32 0
@.str.3 = [12 x i8] c"Bad Request\00"
@.str.4 = [18 x i8] c"No request found.\00"
@.str.5 = [18 x i8] c"%[^ ] %[^ ] %[^ ]\00"
@.str.6 = [21 x i8] c"Can't parse request.\00"
@.str.7 = [2 x i8] c"\0A\00"
@.str.8 = [3 x i8] c"\0D\0A\00"
@.str.9 = [4 x i8] c"get\00"
@.str.10 = [16 x i8] c"Not Implemented\00"
@.str.11 = [32 x i8] c"That method is not implemented.\00"
@.str.12 = [14 x i8] c"Bad filename.\00"
@.str.13 = [3 x i8] c"./\00"
@.str.14 = [3 x i8] c"..\00"
@.str.15 = [4 x i8] c"../\00"
@.str.16 = [5 x i8] c"/../\00"
@.str.17 = [4 x i8] c"/..\00"
@.str.18 = [18 x i8] c"Illegal filename.\00"
@.str.19 = [10 x i8] c"Not Found\00"
@.str.20 = [16 x i8] c"File not found.\00"
@.str.21 = [14 x i8] c"Location: %s/\00"
@.str.22 = [6 x i8] c"Found\00"
@.str.23 = [35 x i8] c"Directories must end with a slash.\00"
@.str.24 = [13 x i8] c"%sindex.html\00"
@.str.25 = [3 x i8] c"Ok\00"
@.str.26 = [10 x i8] c"text/html\00"
@.str.27 = [98 x i8] c"<html><head><title>Index of %s</title></head>\0A<body bgcolor=\22cc99\22><h4>Index of %s</h4>\0A<pre>\0A\00"
@alphasort = global i32 0
@.str.28 = [8 x i8] c"scandir\00"
@.str.29 = [67 x i8] c"</pre>\0A<hr>\0A<address><a href=\22%s\22>%s</a></address>\0A</body></html>\0A\00"
@.str.30 = [42 x i8] c"http://www.acme.com/software/micro_httpd/\00"
@.str.31 = [12 x i8] c"micro_httpd\00"
@.str.32 = [2 x i8] c"r\00"
@.str.33 = [10 x i8] c"Forbidden\00"
@.str.34 = [19 x i8] c"File is protected.\00"
@EOF = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [10000 x i8]
%7 = alloca [10000 x i8]
%8 = alloca [10000 x i8]
%9 = alloca [10000 x i8]
%10 = alloca [20000 x i8]
%11 = alloca [20000 x i8]
%12 = alloca [20000 x i8]
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i32
%16 = alloca %struct.stat
%17 = alloca i32*
%18 = alloca %struct.dirent**
%19 = alloca i32
%20 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 2
br i1 %22, label %23, label %25
23: ; preds = %2
%24 = call i32 @send_error(i32 500, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* null, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i64 @chdir(i8* %28)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = call i32 @send_error(i32 500, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* null, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %25
%34 = getelementptr inbounds [10000 x i8], [10000 x i8]* %6, i64 0, i64 0
%35 = load i32, i32* @stdin
%36 = call i8* @fgets(i8* %34, i32 10000, i32 %35)
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = call i32 @send_error(i32 400, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* null, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %40
40: ; preds = %38, %33
%41 = getelementptr inbounds [10000 x i8], [10000 x i8]* %6, i64 0, i64 0
%42 = getelementptr inbounds [10000 x i8], [10000 x i8]* %7, i64 0, i64 0
%43 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 0
%44 = getelementptr inbounds [10000 x i8], [10000 x i8]* %9, i64 0, i64 0
%45 = call i32 @sscanf(i8* %41, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %42, i8* %43, i8* %44)
%46 = icmp ne i32 %45, 3
br i1 %46, label %47, label %49
47: ; preds = %40
%48 = call i32 @send_error(i32 400, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* null, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %49
49: ; preds = %47, %40
br label %50
50: ; preds = %64, %49
%51 = getelementptr inbounds [10000 x i8], [10000 x i8]* %6, i64 0, i64 0
%52 = load i32, i32* @stdin
%53 = call i8* @fgets(i8* %51, i32 10000, i32 %52)
%54 = icmp ne i8* %53, null
br i1 %54, label %55, label %65
55: ; preds = %50
%56 = getelementptr inbounds [10000 x i8], [10000 x i8]* %6, i64 0, i64 0
%57 = call i64 @strcmp(i8* %56, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%58 = icmp eq i64 %57, 0
br i1 %58, label %63, label %59
59: ; preds = %55
%60 = getelementptr inbounds [10000 x i8], [10000 x i8]* %6, i64 0, i64 0
%61 = call i64 @strcmp(i8* %60, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %64
63: ; preds = %59, %55
br label %65
64: ; preds = %59
br label %50
65: ; preds = %63, %50
%66 = getelementptr inbounds [10000 x i8], [10000 x i8]* %7, i64 0, i64 0
%67 = call i64 @strcasecmp(i8* %66, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %71
69: ; preds = %65
%70 = call i32 @send_error(i32 501, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0), i8* null, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.11, i64 0, i64 0))
br label %71
71: ; preds = %69, %65
%72 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 0
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = icmp ne i32 %74, 47
br i1 %75, label %76, label %78
76: ; preds = %71
%77 = call i32 @send_error(i32 400, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* null, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i64 0, i64 0))
br label %78
78: ; preds = %76, %71
%79 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 1
store i8* %79, i8** %13
%80 = load i8*, i8** %13
%81 = load i8*, i8** %13
%82 = call i32 @strdecode(i8* %80, i8* %81)
%83 = load i8*, i8** %13
%84 = getelementptr inbounds i8, i8* %83, i64 0
%85 = load i8, i8* %84
%86 = sext i8 %85 to i32
%87 = icmp eq i32 %86, 0
br i1 %87, label %88, label %89
88: ; preds = %78
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0), i8** %13
br label %89
89: ; preds = %88, %78
%90 = load i8*, i8** %13
%91 = call i64 @strlen(i8* %90)
store i64 %91, i64* %14
%92 = load i8*, i8** %13
%93 = getelementptr inbounds i8, i8* %92, i64 0
%94 = load i8, i8* %93
%95 = sext i8 %94 to i32
%96 = icmp eq i32 %95, 47
br i1 %96, label %116, label %97
97: ; preds = %89
%98 = load i8*, i8** %13
%99 = call i64 @strcmp(i8* %98, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0))
%100 = icmp eq i64 %99, 0
br i1 %100, label %116, label %101
101: ; preds = %97
%102 = load i8*, i8** %13
%103 = call i64 @strncmp(i8* %102, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0), i32 3)
%104 = icmp eq i64 %103, 0
br i1 %104, label %116, label %105
105: ; preds = %101
%106 = load i8*, i8** %13
%107 = call i8* @strstr(i8* %106, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.16, i64 0, i64 0))
%108 = icmp ne i8* %107, null
br i1 %108, label %116, label %109
109: ; preds = %105
%110 = load i8*, i8** %13
%111 = load i64, i64* %14
%112 = sub i64 %111, 3
%113 = getelementptr inbounds i8, i8* %110, i64 %112
%114 = call i64 @strcmp(i8* %113, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.17, i64 0, i64 0))
%115 = icmp eq i64 %114, 0
br i1 %115, label %116, label %118
116: ; preds = %109, %105, %101, %97, %89
%117 = call i32 @send_error(i32 400, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* null, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.18, i64 0, i64 0))
br label %118
118: ; preds = %116, %109
%119 = load i64, i64* %14
%120 = trunc i64 %119 to i32
store i32 %120, i32* %19
br label %121
121: ; preds = %134, %118
%122 = load i32, i32* %19
%123 = icmp sgt i32 %122, 0
br i1 %123, label %124, label %137
124: ; preds = %121
%125 = load i8*, i8** %13
%126 = load i32, i32* %19
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds i8, i8* %125, i64 %127
%129 = load i8, i8* %128
%130 = sext i8 %129 to i32
%131 = icmp eq i32 %130, 63
br i1 %131, label %132, label %133
132: ; preds = %124
br label %137
133: ; preds = %124
br label %134
134: ; preds = %133
%135 = load i32, i32* %19
%136 = add nsw i32 %135, -1
store i32 %136, i32* %19
br label %121
137: ; preds = %132, %121
%138 = load i8*, i8** %13
%139 = load i32, i32* %19
%140 = sext i32 %139 to i64
%141 = getelementptr inbounds i8, i8* %138, i64 %140
%142 = load i8, i8* %141
%143 = sext i8 %142 to i32
%144 = icmp eq i32 %143, 63
br i1 %144, label %145, label %152
145: ; preds = %137
%146 = load i32, i32* %19
%147 = sext i32 %146 to i64
store i64 %147, i64* %14
%148 = load i8*, i8** %13
%149 = load i32, i32* %19
%150 = sext i32 %149 to i64
%151 = getelementptr inbounds i8, i8* %148, i64 %150
store i8 0, i8* %151
br label %152
152: ; preds = %145, %137
%153 = load i8*, i8** %13
%154 = call i64 @stat(i8* %153, %struct.stat* %16)
%155 = icmp slt i64 %154, 0
br i1 %155, label %156, label %158
156: ; preds = %152
%157 = call i32 @send_error(i32 404, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.19, i64 0, i64 0), i8* null, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.20, i64 0, i64 0))
br label %158
158: ; preds = %156, %152
%159 = getelementptr inbounds %struct.stat, %struct.stat* %16, i32 0, i32 2
%160 = load i32, i32* %159
%161 = call i64 @S_ISDIR(i32 %160)
%162 = icmp ne i64 %161, 0
br i1 %162, label %163, label %221
163: ; preds = %158
%164 = load i8*, i8** %13
%165 = load i64, i64* %14
%166 = sub i64 %165, 1
%167 = getelementptr inbounds i8, i8* %164, i64 %166
%168 = load i8, i8* %167
%169 = sext i8 %168 to i32
%170 = icmp ne i32 %169, 47
br i1 %170, label %171, label %177
171: ; preds = %163
%172 = getelementptr inbounds [20000 x i8], [20000 x i8]* %11, i64 0, i64 0
%173 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 0
%174 = call i32 @snprintf(i8* %172, i32 20000, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.21, i64 0, i64 0), i8* %173)
%175 = getelementptr inbounds [20000 x i8], [20000 x i8]* %11, i64 0, i64 0
%176 = call i32 @send_error(i32 302, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.22, i64 0, i64 0), i8* %175, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.23, i64 0, i64 0))
br label %177
177: ; preds = %171, %163
%178 = getelementptr inbounds [20000 x i8], [20000 x i8]* %10, i64 0, i64 0
%179 = load i8*, i8** %13
%180 = call i32 @snprintf(i8* %178, i32 20000, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.24, i64 0, i64 0), i8* %179)
%181 = getelementptr inbounds [20000 x i8], [20000 x i8]* %10, i64 0, i64 0
%182 = call i64 @stat(i8* %181, %struct.stat* %16)
%183 = icmp sge i64 %182, 0
br i1 %183, label %184, label %186
184: ; preds = %177
%185 = getelementptr inbounds [20000 x i8], [20000 x i8]* %10, i64 0, i64 0
store i8* %185, i8** %13
br label %222
186: ; preds = %177
%187 = getelementptr inbounds %struct.stat, %struct.stat* %16, i32 0, i32 1
%188 = load i32, i32* %187
%189 = call i32 @send_headers(i32 200, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.25, i64 0, i64 0), i8* null, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.26, i64 0, i64 0), i32 -1, i32 %188)
%190 = load i8*, i8** %13
%191 = load i8*, i8** %13
%192 = call i32 @printf(i8* getelementptr inbounds ([98 x i8], [98 x i8]* @.str.27, i64 0, i64 0), i8* %190, i8* %191)
%193 = load i8*, i8** %13
%194 = load i32, i32* @alphasort
%195 = call i32 @scandir(i8* %193, %struct.dirent*** %18, i32* null, i32 %194)
store i32 %195, i32* %20
%196 = load i32, i32* %20
%197 = icmp slt i32 %196, 0
br i1 %197, label %198, label %200
198: ; preds = %186
%199 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.28, i64 0, i64 0))
br label %219
200: ; preds = %186
store i32 0, i32* %19
br label %201
201: ; preds = %215, %200
%202 = load i32, i32* %19
%203 = load i32, i32* %20
%204 = icmp slt i32 %202, %203
br i1 %204, label %205, label %218
205: ; preds = %201
%206 = load i8*, i8** %13
%207 = load %struct.dirent**, %struct.dirent*** %18
%208 = load i32, i32* %19
%209 = sext i32 %208 to i64
%210 = getelementptr inbounds %struct.dirent*, %struct.dirent** %207, i64 %209
%211 = load %struct.dirent*, %struct.dirent** %210
%212 = getelementptr inbounds %struct.dirent, %struct.dirent* %211, i32 0, i32 0
%213 = load i32, i32* %212
%214 = call i32 @file_details(i8* %206, i32 %213)
br label %215
215: ; preds = %205
%216 = load i32, i32* %19
%217 = add nsw i32 %216, 1
store i32 %217, i32* %19
br label %201
218: ; preds = %201
br label %219
219: ; preds = %218, %198
%220 = call i32 @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.29, i64 0, i64 0), i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.30, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.31, i64 0, i64 0))
br label %246
221: ; preds = %158
br label %222
222: ; preds = %221, %184
%223 = load i8*, i8** %13
%224 = call i32* @fopen(i8* %223, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.32, i64 0, i64 0))
store i32* %224, i32** %17
%225 = load i32*, i32** %17
%226 = icmp eq i32* %225, null
br i1 %226, label %227, label %229
227: ; preds = %222
%228 = call i32 @send_error(i32 403, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.33, i64 0, i64 0), i8* null, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.34, i64 0, i64 0))
br label %229
229: ; preds = %227, %222
%230 = load i8*, i8** %13
%231 = call i8* @get_mime_type(i8* %230)
%232 = getelementptr inbounds %struct.stat, %struct.stat* %16, i32 0, i32 0
%233 = load i32, i32* %232
%234 = getelementptr inbounds %struct.stat, %struct.stat* %16, i32 0, i32 1
%235 = load i32, i32* %234
%236 = call i32 @send_headers(i32 200, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.25, i64 0, i64 0), i8* null, i8* %231, i32 %233, i32 %235)
br label %237
237: ; preds = %242, %229
%238 = load i32*, i32** %17
%239 = call i32 @getc(i32* %238)
store i32 %239, i32* %15
%240 = load i32, i32* @EOF
%241 = icmp ne i32 %239, %240
br i1 %241, label %242, label %245
242: ; preds = %237
%243 = load i32, i32* %15
%244 = call i32 @putchar(i32 %243)
br label %237
245: ; preds = %237
br label %246
246: ; preds = %245, %219
%247 = load i32, i32* @stdout
%248 = call i32 @fflush(i32 %247)
%249 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32, i32, i32 }
%struct.dirent = type { i32 }
@.str = [15 x i8] c"Internal Error\00"
@.str.1 = [33 x i8] c"Config error - no dir specified.\00"
@.str.2 = [33 x i8] c"Config error - couldn't chdir().\00"
@stdin = global i32 0
@.str.3 = [12 x i8] c"Bad Request\00"
@.str.4 = [18 x i8] c"No request found.\00"
@.str.5 = [18 x i8] c"%[^ ] %[^ ] %[^ ]\00"
@.str.6 = [21 x i8] c"Can't parse request.\00"
@.str.7 = [2 x i8] c"\0A\00"
@.str.8 = [3 x i8] c"\0D\0A\00"
@.str.9 = [4 x i8] c"get\00"
@.str.10 = [16 x i8] c"Not Implemented\00"
@.str.11 = [32 x i8] c"That method is not implemented.\00"
@.str.12 = [14 x i8] c"Bad filename.\00"
@.str.13 = [3 x i8] c"./\00"
@.str.14 = [3 x i8] c"..\00"
@.str.15 = [4 x i8] c"../\00"
@.str.16 = [5 x i8] c"/../\00"
@.str.17 = [4 x i8] c"/..\00"
@.str.18 = [18 x i8] c"Illegal filename.\00"
@.str.19 = [10 x i8] c"Not Found\00"
@.str.20 = [16 x i8] c"File not found.\00"
@.str.21 = [14 x i8] c"Location: %s/\00"
@.str.22 = [6 x i8] c"Found\00"
@.str.23 = [35 x i8] c"Directories must end with a slash.\00"
@.str.24 = [13 x i8] c"%sindex.html\00"
@.str.25 = [3 x i8] c"Ok\00"
@.str.26 = [10 x i8] c"text/html\00"
@.str.27 = [98 x i8] c"<html><head><title>Index of %s</title></head>\0A<body bgcolor=\22cc99\22><h4>Index of %s</h4>\0A<pre>\0A\00"
@alphasort = global i32 0
@.str.28 = [8 x i8] c"scandir\00"
@.str.29 = [67 x i8] c"</pre>\0A<hr>\0A<address><a href=\22%s\22>%s</a></address>\0A</body></html>\0A\00"
@.str.30 = [42 x i8] c"http://www.acme.com/software/micro_httpd/\00"
@.str.31 = [12 x i8] c"micro_httpd\00"
@.str.32 = [2 x i8] c"r\00"
@.str.33 = [10 x i8] c"Forbidden\00"
@.str.34 = [19 x i8] c"File is protected.\00"
@EOF = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10000 x i8]
%4 = alloca [10000 x i8]
%5 = alloca [10000 x i8]
%6 = alloca [10000 x i8]
%7 = alloca [20000 x i8]
%8 = alloca [20000 x i8]
%9 = alloca %struct.stat
%10 = alloca %struct.dirent**
%11 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 0
%12 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 0
%13 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%14 = getelementptr inbounds [10000 x i8], [10000 x i8]* %6, i64 0, i64 0
%15 = getelementptr inbounds [20000 x i8], [20000 x i8]* %7, i64 0, i64 0
%16 = getelementptr inbounds [20000 x i8], [20000 x i8]* %8, i64 0, i64 0
%17 = bitcast %struct.stat* %9 to i8*
%18 = bitcast %struct.dirent*** %10 to i8*
%19 = icmp eq i32 %0, 2
br i1 %19, label %22, label %20
20: ; preds = %2
%21 = tail call i32 @send_error(i32 500, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* null, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %2
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = tail call i64 @chdir(i8* %24)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = tail call i32 @send_error(i32 500, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* null, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %22
%30 = load i32, i32* @stdin
%31 = call i8* @fgets(i8* %11, i32 10000, i32 %30)
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = call i32 @send_error(i32 400, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* null, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %35
35: ; preds = %33, %29
%36 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %12, i8* %13, i8* %14)
%37 = icmp eq i32 %36, 3
br i1 %37, label %40, label %38
38: ; preds = %35
%39 = call i32 @send_error(i32 400, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* null, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %40
40: ; preds = %38, %35
br label %41
41: ; preds = %40, %48
%42 = load i32, i32* @stdin
%43 = call i8* @fgets(i8* %11, i32 10000, i32 %42)
%44 = icmp eq i8* %43, null
br i1 %44, label %51, label %45
45: ; preds = %41
%46 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%47 = icmp eq i64 %46, 0
br i1 %47, label %51, label %48
48: ; preds = %45
%49 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %41
51: ; preds = %45, %48, %41
%52 = call i64 @strcasecmp(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%53 = icmp eq i64 %52, 0
br i1 %53, label %56, label %54
54: ; preds = %51
%55 = call i32 @send_error(i32 501, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0), i8* null, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.11, i64 0, i64 0))
br label %56
56: ; preds = %54, %51
%57 = load i8, i8* %13
%58 = icmp eq i8 %57, 47
br i1 %58, label %61, label %59
59: ; preds = %56
%60 = call i32 @send_error(i32 400, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* null, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i64 0, i64 0))
br label %61
61: ; preds = %59, %56
%62 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 1
%63 = call i32 @strdecode(i8* %62, i8* %62)
%64 = load i8, i8* %62
%65 = icmp eq i8 %64, 0
%66 = select i1 %65, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0), i8* %62
%67 = call i64 @strlen(i8* dereferenceable(1) %66)
%68 = load i8, i8* %66
%69 = icmp eq i8 %68, 47
br i1 %69, label %84, label %70
70: ; preds = %61
%71 = call i64 @strcmp(i8* %66, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0))
%72 = icmp eq i64 %71, 0
br i1 %72, label %84, label %73
73: ; preds = %70
%74 = call i64 @strncmp(i8* %66, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0), i32 3)
%75 = icmp eq i64 %74, 0
br i1 %75, label %84, label %76
76: ; preds = %73
%77 = call i8* @strstr(i8* %66, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.16, i64 0, i64 0))
%78 = icmp eq i8* %77, null
br i1 %78, label %79, label %84
79: ; preds = %76
%80 = add i64 %67, -3
%81 = getelementptr inbounds i8, i8* %66, i64 %80
%82 = call i64 @strcmp(i8* %81, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.17, i64 0, i64 0))
%83 = icmp eq i64 %82, 0
br i1 %83, label %84, label %86
84: ; preds = %79, %76, %73, %70, %61
%85 = call i32 @send_error(i32 400, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* null, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.18, i64 0, i64 0))
br label %86
86: ; preds = %84, %79
%87 = trunc i64 %67 to i32
%88 = icmp sgt i32 %87, 0
br i1 %88, label %89, label %98
89: ; preds = %86, %95
%90 = phi i32 [ %96, %95 ], [ %87, %86 ]
%91 = zext i32 %90 to i64
%92 = getelementptr inbounds i8, i8* %66, i64 %91
%93 = load i8, i8* %92
%94 = icmp eq i8 %93, 63
br i1 %94, label %98, label %95
95: ; preds = %89
%96 = add nsw i32 %90, -1
%97 = icmp sgt i32 %90, 1
br i1 %97, label %89, label %98
98: ; preds = %95, %89, %86
%99 = phi i32 [ %87, %86 ], [ %90, %89 ], [ 0, %95 ]
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds i8, i8* %66, i64 %100
%102 = load i8, i8* %101
%103 = icmp eq i8 %102, 63
br i1 %103, label %104, label %105
104: ; preds = %98
store i8 0, i8* %101
br label %105
105: ; preds = %104, %98
%106 = phi i64 [ %100, %104 ], [ %67, %98 ]
%107 = call i64 @stat(i8* %66, %struct.stat* %9)
%108 = icmp slt i64 %107, 0
br i1 %108, label %109, label %111
109: ; preds = %105
%110 = call i32 @send_error(i32 404, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.19, i64 0, i64 0), i8* null, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.20, i64 0, i64 0))
br label %111
111: ; preds = %109, %105
%112 = getelementptr inbounds %struct.stat, %struct.stat* %9, i64 0, i32 2
%113 = load i32, i32* %112
%114 = call i64 @S_ISDIR(i32 %113)
%115 = icmp eq i64 %114, 0
br i1 %115, label %154, label %116
116: ; preds = %111
%117 = add i64 %106, -1
%118 = getelementptr inbounds i8, i8* %66, i64 %117
%119 = load i8, i8* %118
%120 = icmp eq i8 %119, 47
br i1 %120, label %124, label %121
121: ; preds = %116
%122 = call i32 @snprintf(i8* %16, i32 20000, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.21, i64 0, i64 0), i8* %13)
%123 = call i32 @send_error(i32 302, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.22, i64 0, i64 0), i8* %16, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.23, i64 0, i64 0))
br label %124
124: ; preds = %121, %116
%125 = call i32 @snprintf(i8* %15, i32 20000, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.24, i64 0, i64 0), i8* %66)
%126 = call i64 @stat(i8* %15, %struct.stat* %9)
%127 = icmp sgt i64 %126, -1
br i1 %127, label %154, label %128
128: ; preds = %124
%129 = getelementptr inbounds %struct.stat, %struct.stat* %9, i64 0, i32 1
%130 = load i32, i32* %129
%131 = call i32 @send_headers(i32 200, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.25, i64 0, i64 0), i8* null, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.26, i64 0, i64 0), i32 -1, i32 %130)
%132 = call i32 @printf(i8* getelementptr inbounds ([98 x i8], [98 x i8]* @.str.27, i64 0, i64 0), i8* %66, i8* %66)
%133 = load i32, i32* @alphasort
%134 = call i32 @scandir(i8* %66, %struct.dirent*** %10, i32* null, i32 %133)
%135 = icmp slt i32 %134, 0
br i1 %135, label %140, label %136
136: ; preds = %128
%137 = icmp eq i32 %134, 0
br i1 %137, label %152, label %138
138: ; preds = %136
%139 = zext i32 %134 to i64
br label %142
140: ; preds = %128
%141 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.28, i64 0, i64 0))
br label %152
142: ; preds = %138, %142
%143 = phi i64 [ 0, %138 ], [ %150, %142 ]
%144 = load %struct.dirent**, %struct.dirent*** %10
%145 = getelementptr inbounds %struct.dirent*, %struct.dirent** %144, i64 %143
%146 = load %struct.dirent*, %struct.dirent** %145
%147 = getelementptr inbounds %struct.dirent, %struct.dirent* %146, i64 0, i32 0
%148 = load i32, i32* %147
%149 = call i32 @file_details(i8* %66, i32 %148)
%150 = add nuw nsw i64 %143, 1
%151 = icmp eq i64 %150, %139
br i1 %151, label %152, label %142
152: ; preds = %142, %136, %140
%153 = call i32 @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.29, i64 0, i64 0), i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.30, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.31, i64 0, i64 0))
br label %176
154: ; preds = %124, %111
%155 = phi i8* [ %66, %111 ], [ %15, %124 ]
%156 = call i32* @fopen(i8* %155, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.32, i64 0, i64 0))
%157 = icmp eq i32* %156, null
br i1 %157, label %158, label %160
158: ; preds = %154
%159 = call i32 @send_error(i32 403, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.33, i64 0, i64 0), i8* null, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.34, i64 0, i64 0))
br label %160
160: ; preds = %158, %154
%161 = call i8* @get_mime_type(i8* %155)
%162 = getelementptr inbounds %struct.stat, %struct.stat* %9, i64 0, i32 0
%163 = load i32, i32* %162
%164 = getelementptr inbounds %struct.stat, %struct.stat* %9, i64 0, i32 1
%165 = load i32, i32* %164
%166 = call i32 @send_headers(i32 200, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.25, i64 0, i64 0), i8* null, i8* %161, i32 %163, i32 %165)
%167 = call i32 @getc(i32* %156)
%168 = load i32, i32* @EOF
%169 = icmp eq i32 %167, %168
br i1 %169, label %176, label %170
170: ; preds = %160, %170
%171 = phi i32 [ %173, %170 ], [ %167, %160 ]
%172 = call i32 @putchar(i32 %171)
%173 = call i32 @getc(i32* %156)
%174 = load i32, i32* @EOF
%175 = icmp eq i32 %173, %174
br i1 %175, label %176, label %170
176: ; preds = %170, %160, %152
%177 = load i32, i32* @stdout
%178 = call i32 @fflush(i32 %177)
%179 = call i32 @exit(i32 0)
unreachable
}