#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;
};

/* Variables and functions */
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
char *calloc(size_t, int);
int chdir(char const *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int fstat(int, struct stat *);
int /*<<< orphan*/ log_request(char const *, char const *, char *);
char *mmap(int /*<<< orphan*/ *, int, int /*<<< orphan*/, int /*<<< orphan*/,
           int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(void *, int);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ read_line(char *, size_t *);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ transmit(char const *, int);
int main(int argc, char **argv) {
  if (argc != 1) {
    fprintf(stderr, "usage: %s", argv[0]);
    exit(1);
  }
  const char *path = NULL;
  const char *host = NULL;
  size_t buf_size = 4096;
  char *buffer = calloc(buf_size, sizeof(*buffer));
  if (!read_line(buffer, &buf_size)) {
    goto invalid;
  }
  if (strncmp(buffer, "GET /", sizeof("GET /") - 1) != 0) {
    goto invalid;
  }
  buffer += sizeof("GET /") - 1;
  buf_size -= sizeof("GET /") - 1;
  path = buffer;
  char *space = strchr(buffer, ' ');
  if (space == NULL) {
    goto invalid;
  }
  buf_size -= space - buffer;
  buffer = space;
  *buffer = 0;
  buffer += 1;
  buf_size -= 1;
  if ((strncmp(buffer, "HTTP/1.0\r\n", sizeof("HTTP/1.0\r\n") - 1) != 0) &&
      (strncmp(buffer, "HTTP/1.1\r\n", sizeof("HTTP/1.1\r\n") - 1) != 0)) {
    goto invalid;
  }
  buffer += sizeof("HTTP/1.0\r\n") - 1;
  buf_size -= sizeof("HTTP/1.0\r\n") - 1;
  for (;;) {
    if (!read_line(buffer, &buf_size)) {
      goto invalid;
    }
    if (*buffer == '\r') {
      goto invalid;
    }
    if (strncmp(buffer, "Host: ", sizeof("Host: ") - 1) == 0) {
      break;
    }
    char *eol = strchr(buffer, '\r');
    buf_size -= eol - buffer - 2;
    buffer = eol + 2;
  }
  buffer += sizeof("Host: ") - 1;
  buf_size -= sizeof("Host: ") - 1;
  host = buffer;
  char *cr = strchr(buffer, '\r');
  *cr = 0;
  if (chdir("www-data") == -1) {
    perror("chdir");
    exit(2);
  }
  if (chdir(host) == -1) {
    goto _404;
  }
  int fd = open(path, O_RDONLY);
  if (fd == -1) {
    goto _404;
  }
  struct stat stat;
  if (fstat(fd, &stat) == -1) {
    goto _404;
  }
  const char *file = mmap(NULL, stat.st_size, PROT_READ, MAP_SHARED, fd, 0);
  if (file == NULL) {
    goto _404;
  }
  close(fd);
  log_request(host, path, "200");
  transmit("HTTP/1.0 200 OK\r\n\r\n", sizeof("HTTP/1.0 200 OK\r\n\r\n") - 1);
  transmit(file, stat.st_size);
  munmap((void *)file, stat.st_size);
  exit(0);
invalid:
  log_request(host, path, "400");
  transmit("HTTP/1.0 400 Bad Request\r\n\r\n",
           sizeof("HTTP/1.0 400 Bad Request\r\n\r\n") - 1);
  exit(0);
_404:
  log_request(host, path, "404");
  transmit("HTTP/1.0 404 Not Found\r\n\r\n",
           sizeof("HTTP/1.0 404 Not Found\r\n\r\n") - 1);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     1236 <main+0x46>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdd9(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x1000,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   10c0 <read_line@plt>
cmp    $0x0,%eax
jne    127b <main+0x8b>
jmp    1548 <main+0x358>
mov    -0x30(%rbp),%rdi
lea    0xd84(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     129f <main+0xaf>
jmp    1548 <main+0x358>
mov    -0x30(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
sub    $0x5,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    12e1 <main+0xf1>
jmp    1548 <main+0x358>
mov    -0x38(%rbp),%rcx
mov    -0x30(%rbp),%rax
sub    %rax,%rcx
mov    -0x28(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xce7(%rip),%rsi
mov    $0xa,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1361 <main+0x171>
mov    -0x30(%rbp),%rdi
lea    0xcd3(%rip),%rsi
mov    $0xa,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1361 <main+0x171>
jmp    1548 <main+0x358>
mov    -0x30(%rbp),%rax
add    $0xa,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
sub    $0xa,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   10c0 <read_line@plt>
cmp    $0x0,%eax
jne    1394 <main+0x1a4>
jmp    1548 <main+0x358>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
jne    13a9 <main+0x1b9>
jmp    1548 <main+0x358>
mov    -0x30(%rbp),%rdi
lea    0xc72(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    13cd <main+0x1dd>
jmp    140a <main+0x21a>
mov    -0x30(%rbp),%rdi
mov    $0xd,%esi
call   1060 <strchr@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rcx
mov    -0x30(%rbp),%rax
sub    %rax,%rcx
sub    $0x2,%rcx
mov    -0x28(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x40(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x30(%rbp)
jmp    1379 <main+0x189>
mov    -0x30(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
sub    $0x6,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0xd,%esi
call   1060 <strchr@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
movb   $0x0,(%rax)
lea    0xbe3(%rip),%rdi
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
jne    146e <main+0x27e>
lea    0xbd7(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x2,%edi
call   1100 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
jne    1485 <main+0x295>
jmp    1574 <main+0x384>
mov    -0x18(%rbp),%rdi
mov    0x2b48(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0xffffffff,-0x4c(%rbp)
jne    14a9 <main+0x2b9>
jmp    1574 <main+0x384>
mov    -0x4c(%rbp),%edi
lea    -0x50(%rbp),%rsi
call   1110 <fstat@plt>
cmp    $0xffffffff,%eax
jne    14c3 <main+0x2d3>
jmp    1574 <main+0x384>
mov    -0x50(%rbp),%esi
mov    0x2b2b(%rip),%rax
mov    (%rax),%edx
mov    0x2b12(%rip),%rax
mov    (%rax),%ecx
mov    -0x4c(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    14fc <main+0x30c>
jmp    1574 <main+0x384>
mov    -0x4c(%rbp),%edi
call   1070 <close@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xb29(%rip),%rdx
call   10f0 <log_request@plt>
lea    0xb21(%rip),%rdi
mov    $0x13,%esi
call   10a0 <transmit@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%esi
call   10a0 <transmit@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%esi
call   10b0 <munmap@plt>
xor    %edi,%edi
call   1100 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xafd(%rip),%rdx
call   10f0 <log_request@plt>
lea    0xaf5(%rip),%rdi
mov    $0x1c,%esi
call   10a0 <transmit@plt>
xor    %edi,%edi
call   1100 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xaf2(%rip),%rdx
call   10f0 <log_request@plt>
lea    0xaea(%rip),%rdi
mov    $0x1a,%esi
call   10a0 <transmit@plt>
xor    %edi,%edi
call   1100 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x1,%edi
jne    1349 <main+0x159>
movq   $0x1000,(%rsp)
mov    $0x1000,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,%r14
mov    %rsp,%rsi
mov    %rax,%rdi
call   10c0 <read_line@plt>
test   %eax,%eax
je     136b <main+0x17b>
lea    0xdd1(%rip),%rsi
mov    %r14,%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    136b <main+0x17b>
add    $0x5,%r14
mov    (%rsp),%rbx
add    $0xfffffffffffffffb,%rbx
mov    %rbx,(%rsp)
mov    %r14,%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     136e <main+0x17e>
mov    %rax,%rbp
add    %r14,%rbx
sub    %rax,%rbx
mov    %rbx,(%rsp)
movb   $0x0,(%rax)
lea    0x1(%rax),%rbx
addq   $0xffffffffffffffff,(%rsp)
lea    0xd7b(%rip),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     12c4 <main+0xd4>
lea    0xd6d(%rip),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    136e <main+0x17e>
add    $0xb,%rbp
addq   $0xfffffffffffffff6,(%rsp)
mov    %rsp,%rsi
mov    %rbp,%rdi
call   10c0 <read_line@plt>
test   %eax,%eax
je     136e <main+0x17e>
lea    0xd3f(%rip),%r15
mov    %rsp,%r12
nopw   0x0(%rax,%rax,1)
cmpb   $0xd,0x0(%rbp)
je     136e <main+0x17e>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1397 <main+0x1a7>
mov    %rbp,%rdi
mov    $0xd,%esi
call   1060 <strchr@plt>
mov    %rax,%rbx
mov    (%rsp),%rax
sub    %rbx,%rbp
add    %rbp,%rax
add    $0x2,%rax
mov    %rax,(%rsp)
add    $0x2,%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
call   10c0 <read_line@plt>
mov    %rbx,%rbp
test   %eax,%eax
jne    12f0 <main+0x100>
jmp    136e <main+0x17e>
mov    0x2c78(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xca4(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
xor    %r14d,%r14d
lea    0xcdf(%rip),%rdx
xor    %edi,%edi
mov    %r14,%rsi
call   10f0 <log_request@plt>
lea    0xcd2(%rip),%rdi
mov    $0x1c,%esi
call   10a0 <transmit@plt>
xor    %edi,%edi
call   1100 <exit@plt>
add    $0x6,%rbp
addq   $0xfffffffffffffffa,(%rsp)
mov    %rbp,%rdi
mov    $0xd,%esi
call   1060 <strchr@plt>
movb   $0x0,(%rax)
lea    0xc76(%rip),%rdi
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
jne    13d7 <main+0x1e7>
lea    0xc6e(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x2,%edi
call   1100 <exit@plt>
mov    %rbp,%rdi
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
je     1439 <main+0x249>
mov    0x2bed(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     1439 <main+0x249>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   1110 <fstat@plt>
cmp    $0xffffffff,%eax
je     1439 <main+0x249>
mov    0x8(%rsp),%r15d
mov    0x2bdf(%rip),%rax
mov    (%rax),%edx
mov    0x2bc6(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r15d,%esi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
test   %rax,%rax
jne    145c <main+0x26c>
lea    0xc35(%rip),%rdx
mov    %rbp,%rdi
mov    %r14,%rsi
call   10f0 <log_request@plt>
lea    0xc27(%rip),%rdi
mov    $0x1a,%esi
jmp    138b <main+0x19b>
mov    %rax,%r12
mov    %ebx,%edi
call   1070 <close@plt>
lea    0xbcf(%rip),%rdx
mov    %rbp,%rdi
mov    %r14,%rsi
call   10f0 <log_request@plt>
lea    0xbc1(%rip),%rdi
mov    $0x13,%esi
call   10a0 <transmit@plt>
mov    %r12,%rdi
mov    %r15d,%esi
call   10a0 <transmit@plt>
mov    %r12,%rdi
mov    %r15d,%esi
call   10b0 <munmap@plt>
xor    %edi,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [10 x i8] c"usage: %s\00"
@.str.1 = [6 x i8] c"GET /\00"
@.str.2 = [11 x i8] c"HTTP/1.0\0D\0A\00"
@.str.3 = [11 x i8] c"HTTP/1.1\0D\0A\00"
@.str.4 = [7 x i8] c"Host: \00"
@.str.5 = [9 x i8] c"www-data\00"
@.str.6 = [6 x i8] c"chdir\00"
@O_RDONLY = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@.str.7 = [4 x i8] c"200\00"
@.str.8 = [20 x i8] c"HTTP/1.0 200 OK\0D\0A\0D\0A\00"
@.str.9 = [4 x i8] c"400\00"
@.str.10 = [29 x i8] c"HTTP/1.0 400 Bad Request\0D\0A\0D\0A\00"
@.str.11 = [4 x i8] c"404\00"
@.str.12 = [27 x i8] c"HTTP/1.0 404 Not Found\0D\0A\0D\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca %struct.stat
%15 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 1
br i1 %17, label %18, label %25
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %2
store i8* null, i8** %6
store i8* null, i8** %7
store i64 4096, i64* %8
%26 = load i64, i64* %8
%27 = call i8* @calloc(i64 %26, i32 1)
store i8* %27, i8** %9
%28 = load i8*, i8** %9
%29 = call i32 @read_line(i8* %28, i64* %8)
%30 = icmp ne i32 %29, 0
br i1 %30, label %32, label %31
31: ; preds = %25
br label %161
32: ; preds = %25
%33 = load i8*, i8** %9
%34 = call i64 @strncmp(i8* %33, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %32
br label %161
37: ; preds = %32
%38 = load i8*, i8** %9
%39 = getelementptr inbounds i8, i8* %38, i64 5
store i8* %39, i8** %9
%40 = load i64, i64* %8
%41 = sub i64 %40, 5
store i64 %41, i64* %8
%42 = load i8*, i8** %9
store i8* %42, i8** %6
%43 = load i8*, i8** %9
%44 = call i8* @strchr(i8* %43, i8 signext 32)
store i8* %44, i8** %10
%45 = load i8*, i8** %10
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %48
47: ; preds = %37
br label %161
48: ; preds = %37
%49 = load i8*, i8** %10
%50 = load i8*, i8** %9
%51 = ptrtoint i8* %49 to i64
%52 = ptrtoint i8* %50 to i64
%53 = sub i64 %51, %52
%54 = load i64, i64* %8
%55 = sub i64 %54, %53
store i64 %55, i64* %8
%56 = load i8*, i8** %10
store i8* %56, i8** %9
%57 = load i8*, i8** %9
store i8 0, i8* %57
%58 = load i8*, i8** %9
%59 = getelementptr inbounds i8, i8* %58, i64 1
store i8* %59, i8** %9
%60 = load i64, i64* %8
%61 = sub i64 %60, 1
store i64 %61, i64* %8
%62 = load i8*, i8** %9
%63 = call i64 @strncmp(i8* %62, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 10)
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %70
65: ; preds = %48
%66 = load i8*, i8** %9
%67 = call i64 @strncmp(i8* %66, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 10)
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %70
69: ; preds = %65
br label %161
70: ; preds = %65, %48
%71 = load i8*, i8** %9
%72 = getelementptr inbounds i8, i8* %71, i64 10
store i8* %72, i8** %9
%73 = load i64, i64* %8
%74 = sub i64 %73, 10
store i64 %74, i64* %8
br label %75
75: ; preds = %91, %70
%76 = load i8*, i8** %9
%77 = call i32 @read_line(i8* %76, i64* %8)
%78 = icmp ne i32 %77, 0
br i1 %78, label %80, label %79
79: ; preds = %75
br label %161
80: ; preds = %75
%81 = load i8*, i8** %9
%82 = load i8, i8* %81
%83 = sext i8 %82 to i32
%84 = icmp eq i32 %83, 13
br i1 %84, label %85, label %86
85: ; preds = %80
br label %161
86: ; preds = %80
%87 = load i8*, i8** %9
%88 = call i64 @strncmp(i8* %87, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 6)
%89 = icmp eq i64 %88, 0
br i1 %89, label %90, label %91
90: ; preds = %86
br label %104
91: ; preds = %86
%92 = load i8*, i8** %9
%93 = call i8* @strchr(i8* %92, i8 signext 13)
store i8* %93, i8** %11
%94 = load i8*, i8** %11
%95 = load i8*, i8** %9
%96 = ptrtoint i8* %94 to i64
%97 = ptrtoint i8* %95 to i64
%98 = sub i64 %96, %97
%99 = sub nsw i64 %98, 2
%100 = load i64, i64* %8
%101 = sub i64 %100, %99
store i64 %101, i64* %8
%102 = load i8*, i8** %11
%103 = getelementptr inbounds i8, i8* %102, i64 2
store i8* %103, i8** %9
br label %75
104: ; preds = %90
%105 = load i8*, i8** %9
%106 = getelementptr inbounds i8, i8* %105, i64 6
store i8* %106, i8** %9
%107 = load i64, i64* %8
%108 = sub i64 %107, 6
store i64 %108, i64* %8
%109 = load i8*, i8** %9
store i8* %109, i8** %7
%110 = load i8*, i8** %9
%111 = call i8* @strchr(i8* %110, i8 signext 13)
store i8* %111, i8** %12
%112 = load i8*, i8** %12
store i8 0, i8* %112
%113 = call i32 @chdir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%114 = icmp eq i32 %113, -1
br i1 %114, label %115, label %118
115: ; preds = %104
%116 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%117 = call i32 @exit(i32 2)
unreachable
118: ; preds = %104
%119 = load i8*, i8** %7
%120 = call i32 @chdir(i8* %119)
%121 = icmp eq i32 %120, -1
br i1 %121, label %122, label %123
122: ; preds = %118
br label %167
123: ; preds = %118
%124 = load i8*, i8** %6
%125 = load i32, i32* @O_RDONLY
%126 = call i32 @open(i8* %124, i32 %125)
store i32 %126, i32* %13
%127 = load i32, i32* %13
%128 = icmp eq i32 %127, -1
br i1 %128, label %129, label %130
129: ; preds = %123
br label %167
130: ; preds = %123
%131 = load i32, i32* %13
%132 = call i32 @fstat(i32 %131, %struct.stat* %14)
%133 = icmp eq i32 %132, -1
br i1 %133, label %134, label %135
134: ; preds = %130
br label %167
135: ; preds = %130
%136 = getelementptr inbounds %struct.stat, %struct.stat* %14, i32 0, i32 0
%137 = load i32, i32* %136
%138 = load i32, i32* @PROT_READ
%139 = load i32, i32* @MAP_SHARED
%140 = load i32, i32* %13
%141 = call i8* @mmap(i32* null, i32 %137, i32 %138, i32 %139, i32 %140, i32 0)
store i8* %141, i8** %15
%142 = load i8*, i8** %15
%143 = icmp eq i8* %142, null
br i1 %143, label %144, label %145
144: ; preds = %135
br label %167
145: ; preds = %135
%146 = load i32, i32* %13
%147 = call i32 @close(i32 %146)
%148 = load i8*, i8** %7
%149 = load i8*, i8** %6
%150 = call i32 @log_request(i8* %148, i8* %149, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%151 = call i32 @transmit(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i32 19)
%152 = load i8*, i8** %15
%153 = getelementptr inbounds %struct.stat, %struct.stat* %14, i32 0, i32 0
%154 = load i32, i32* %153
%155 = call i32 @transmit(i8* %152, i32 %154)
%156 = load i8*, i8** %15
%157 = getelementptr inbounds %struct.stat, %struct.stat* %14, i32 0, i32 0
%158 = load i32, i32* %157
%159 = call i32 @munmap(i8* %156, i32 %158)
%160 = call i32 @exit(i32 0)
unreachable
161: ; preds = %85, %79, %69, %47, %36, %31
%162 = load i8*, i8** %7
%163 = load i8*, i8** %6
%164 = call i32 @log_request(i8* %162, i8* %163, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%165 = call i32 @transmit(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0), i32 28)
%166 = call i32 @exit(i32 0)
unreachable
167: ; preds = %144, %134, %129, %122
%168 = load i8*, i8** %7
%169 = load i8*, i8** %6
%170 = call i32 @log_request(i8* %168, i8* %169, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0))
%171 = call i32 @transmit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.12, i64 0, i64 0), i32 26)
%172 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [10 x i8] c"usage: %s\00"
@.str.1 = [6 x i8] c"GET /\00"
@.str.2 = [11 x i8] c"HTTP/1.0\0D\0A\00"
@.str.3 = [11 x i8] c"HTTP/1.1\0D\0A\00"
@.str.4 = [7 x i8] c"Host: \00"
@.str.5 = [9 x i8] c"www-data\00"
@.str.6 = [6 x i8] c"chdir\00"
@O_RDONLY = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@.str.7 = [4 x i8] c"200\00"
@.str.8 = [20 x i8] c"HTTP/1.0 200 OK\0D\0A\0D\0A\00"
@.str.9 = [4 x i8] c"400\00"
@.str.10 = [29 x i8] c"HTTP/1.0 400 Bad Request\0D\0A\0D\0A\00"
@.str.11 = [4 x i8] c"404\00"
@.str.12 = [27 x i8] c"HTTP/1.0 404 Not Found\0D\0A\0D\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = alloca %struct.stat
%5 = icmp eq i32 %0, 1
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = bitcast i64* %3 to i8*
store i64 4096, i64* %3
%13 = tail call i8* @calloc(i64 4096, i32 1)
%14 = call i32 @read_line(i8* %13, i64* %3)
%15 = icmp eq i32 %14, 0
br i1 %15, label %96, label %16
16: ; preds = %11
%17 = call i64 @strncmp(i8* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %96
19: ; preds = %16
%20 = getelementptr inbounds i8, i8* %13, i64 5
%21 = load i64, i64* %3
%22 = add i64 %21, -5
store i64 %22, i64* %3
%23 = call i8* @strchr(i8* %20, i8 signext 32)
%24 = icmp eq i8* %23, null
br i1 %24, label %96, label %25
25: ; preds = %19
%26 = ptrtoint i8* %23 to i64
%27 = ptrtoint i8* %20 to i64
%28 = add i64 %22, %27
%29 = sub i64 %28, %26
store i64 %29, i64* %3
store i8 0, i8* %23
%30 = getelementptr inbounds i8, i8* %23, i64 1
%31 = load i64, i64* %3
%32 = add i64 %31, -1
store i64 %32, i64* %3
%33 = call i64 @strncmp(i8* %30, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 10)
%34 = icmp eq i64 %33, 0
br i1 %34, label %38, label %35
35: ; preds = %25
%36 = call i64 @strncmp(i8* %30, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 10)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %96
38: ; preds = %35, %25
%39 = getelementptr inbounds i8, i8* %23, i64 11
%40 = load i64, i64* %3
%41 = add i64 %40, -10
store i64 %41, i64* %3
%42 = call i32 @read_line(i8* %39, i64* %3)
%43 = icmp eq i32 %42, 0
br i1 %43, label %96, label %44
44: ; preds = %38, %51
%45 = phi i8* [ %59, %51 ], [ %39, %38 ]
%46 = load i8, i8* %45
%47 = icmp eq i8 %46, 13
br i1 %47, label %96, label %48
48: ; preds = %44
%49 = call i64 @strncmp(i8* %45, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 6)
%50 = icmp eq i64 %49, 0
br i1 %50, label %62, label %51
51: ; preds = %48
%52 = call i8* @strchr(i8* %45, i8 signext 13)
%53 = ptrtoint i8* %52 to i64
%54 = ptrtoint i8* %45 to i64
%55 = load i64, i64* %3
%56 = add i64 %54, 2
%57 = sub i64 %56, %53
%58 = add i64 %57, %55
store i64 %58, i64* %3
%59 = getelementptr inbounds i8, i8* %52, i64 2
%60 = call i32 @read_line(i8* %59, i64* %3)
%61 = icmp eq i32 %60, 0
br i1 %61, label %96, label %44
62: ; preds = %48
%63 = getelementptr inbounds i8, i8* %45, i64 6
%64 = load i64, i64* %3
%65 = add i64 %64, -6
store i64 %65, i64* %3
%66 = call i8* @strchr(i8* %63, i8 signext 13)
store i8 0, i8* %66
%67 = call i32 @chdir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%68 = icmp eq i32 %67, -1
br i1 %68, label %69, label %72
69: ; preds = %62
%70 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%71 = call i32 @exit(i32 2)
unreachable
72: ; preds = %62
%73 = call i32 @chdir(i8* %63)
%74 = icmp eq i32 %73, -1
br i1 %74, label %101, label %75
75: ; preds = %72
%76 = load i32, i32* @O_RDONLY
%77 = call i32 @open(i8* %20, i32 %76)
%78 = icmp eq i32 %77, -1
br i1 %78, label %101, label %79
79: ; preds = %75
%80 = call i32 @fstat(i32 %77, %struct.stat* %4)
%81 = icmp eq i32 %80, -1
br i1 %81, label %101, label %82
82: ; preds = %79
%83 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%84 = load i32, i32* %83
%85 = load i32, i32* @PROT_READ
%86 = load i32, i32* @MAP_SHARED
%87 = call i8* @mmap(i32* null, i32 %84, i32 %85, i32 %86, i32 %77, i32 0)
%88 = icmp eq i8* %87, null
br i1 %88, label %101, label %89
89: ; preds = %82
%90 = call i32 @close(i32 %77)
%91 = call i32 @log_request(i8* %63, i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%92 = call i32 @transmit(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i32 19)
%93 = call i32 @transmit(i8* %87, i32 %84)
%94 = call i32 @munmap(i8* %87, i32 %84)
%95 = call i32 @exit(i32 0)
unreachable
96: ; preds = %51, %44, %38, %35, %19, %16, %11
%97 = phi i8* [ null, %16 ], [ %20, %19 ], [ %20, %35 ], [ null, %11 ], [ %20, %38 ], [ %20, %44 ], [ %20, %51 ]
%98 = call i32 @log_request(i8* null, i8* %97, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%99 = call i32 @transmit(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0), i32 28)
%100 = call i32 @exit(i32 0)
unreachable
101: ; preds = %82, %79, %75, %72
%102 = call i32 @log_request(i8* %63, i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0))
%103 = call i32 @transmit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.12, i64 0, i64 0), i32 26)
%104 = call i32 @exit(i32 0)
unreachable
}