#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ server;
typedef int /*<<< orphan*/ reuseaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ drop(int, char *);
int /*<<< orphan*/ drop2(char *, char *);
scalar_t__ filesize(int);
int /*<<< orphan*/ free(char *);
char *getmime(char *);
int /*<<< orphan*/ htons(int);
int listen(int, int);
char *malloc(scalar_t__);
int open(char *, int /*<<< orphan*/);
int read(int, char *, scalar_t__);
int recv(int, char *, int, int /*<<< orphan*/);
char *response(int);
int send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int /*<<< orphan*/ shutdown(int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
char *strstr(char *, char *);
char *strtok(char *, char *);
int main(void) {
  char *httpMimeType, *data;
  int code, webpage = -1;
  char buf[10000];
  int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  drop(sock, "socket error");
  int reuseaddr = 1;
  setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(reuseaddr));
  struct sockaddr_in server = {.sin_family = AF_INET,
                               .sin_addr.s_addr = INADDR_ANY,
                               .sin_port = htons(1100)};
  drop(bind(sock, (struct sockaddr *)&server, sizeof(server)), "bind error");
  drop(listen(sock, 10), "listen error");
  while (1) {
    int msgsock = accept(sock, NULL, NULL);
    drop(msgsock, "accept error");
    int numread = recv(msgsock, buf, 10000, 0);
    drop(numread, "recv error");
    buf[numread] = '\0';
    char *method = strtok(buf, " ");
    char *page = strtok(NULL, " ");
    char *buf2 = strtok(NULL, "");
    if (strcmp(page, "/") == 0)
      page = "/index.html";
    if (strcmp(page, "/special") == 0) {
      code = 200;
      data = "<!doctype html><html><head><title>Special "
             "page</title></head><body><p>you're special</p></body></html>";
      httpMimeType = getmime(".html");
    } else if (strcmp(page, "/getopt") == 0) {
      code = 200;
      data = strstr(buf2, "\r\n\r\n") + 4;
      httpMimeType = getmime(".txt");
    } else if (strcmp(page, "/setopt") == 0) {
      code = 200;
      data = strstr(buf2, "\r\n\r\n") + 4;
      httpMimeType = getmime(".txt");
    } else {
      webpage = open(&page[1], O_RDONLY);
      if (webpage == -1) {
        code = 404;
        data = "<!doctype html><html><head><title>404 Not "
               "Found</title></head><body><p>page not found</p></body></html>";
        httpMimeType = getmime(".html");
      } else {
        code = 200;
        data = malloc(filesize(webpage) + 1);
        drop2(data, "out of memory");
        numread = read(webpage, data, filesize(webpage) + 1);
        drop(numread, "read error");
        data[numread] = '\0';
        close(webpage);
        httpMimeType = getmime(page);
      }
    }
    drop(send(msgsock, response(code), strlen(response(code)), 0),
         "send response error");
    drop(send(msgsock, httpMimeType, strlen(httpMimeType), 0),
         "send mime type error");
    drop(send(msgsock, data, strlen(data), 0), "send webpage error");
    if (webpage != -1) {
      free(data);
      data = NULL;
      webpage = -1;
    }
    shutdown(msgsock, 2);
    close(msgsock);
  }
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x27b0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x20(%rbp)
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
mov    0x2d1f(%rip),%rax
mov    (%rax),%esi
mov    0x2d26(%rip),%rax
mov    (%rax),%edx
call   1190 <socket@plt>
mov    %eax,-0x2734(%rbp)
mov    -0x2734(%rbp),%edi
lea    0xd44(%rip),%rsi
call   1100 <drop@plt>
movl   $0x1,-0x2738(%rbp)
mov    -0x2734(%rbp),%edi
mov    0x2d10(%rip),%rax
mov    (%rax),%esi
mov    0x2ccf(%rip),%rax
mov    (%rax),%edx
lea    -0x2738(%rbp),%rcx
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
mov    $0x44c,%edi
call   1080 <htons@plt>
mov    %eax,-0x2748(%rbp)
mov    0x2cc4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2744(%rbp)
mov    0x2cc5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2740(%rbp)
mov    -0x2734(%rbp),%edi
lea    -0x2748(%rbp),%rsi
mov    $0xc,%edx
call   10f0 <bind@plt>
mov    %eax,%edi
lea    0xcca(%rip),%rsi
call   1100 <drop@plt>
mov    -0x2734(%rbp),%edi
mov    $0xa,%esi
call   10e0 <listen@plt>
mov    %eax,%edi
lea    0xcb7(%rip),%rsi
call   1100 <drop@plt>
mov    -0x2734(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1140 <accept@plt>
mov    %eax,-0x274c(%rbp)
mov    -0x274c(%rbp),%edi
lea    0xc9a(%rip),%rsi
call   1100 <drop@plt>
mov    -0x274c(%rbp),%edi
lea    -0x2730(%rbp),%rsi
mov    $0x2710,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,-0x2750(%rbp)
mov    -0x2750(%rbp),%edi
lea    0xc76(%rip),%rsi
call   1100 <drop@plt>
movslq -0x2750(%rbp),%rax
movb   $0x0,-0x2730(%rbp,%rax,1)
lea    -0x2730(%rbp),%rdi
lea    0xc5f(%rip),%rsi
call   1130 <strtok@plt>
mov    %rax,-0x2758(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xc48(%rip),%rsi
call   1130 <strtok@plt>
mov    %rax,-0x2760(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xcbd(%rip),%rsi
call   1130 <strtok@plt>
mov    %rax,-0x2768(%rbp)
mov    -0x2760(%rbp),%rdi
lea    0xc19(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    1443 <main+0x1d3>
lea    0xc05(%rip),%rax
mov    %rax,-0x2760(%rbp)
mov    -0x2760(%rbp),%rdi
lea    0xbfc(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    1487 <main+0x217>
movl   $0xc8,-0x1c(%rbp)
lea    0xbe8(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xbce(%rip),%rdi
call   1170 <getmime@plt>
mov    %rax,-0x10(%rbp)
jmp    162e <main+0x3be>
mov    -0x2760(%rbp),%rdi
lea    0xc28(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    14db <main+0x26b>
movl   $0xc8,-0x1c(%rbp)
mov    -0x2768(%rbp),%rdi
lea    0xc0c(%rip),%rsi
call   1180 <strstr@plt>
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
lea    0xbfd(%rip),%rdi
call   1170 <getmime@plt>
mov    %rax,-0x10(%rbp)
jmp    1629 <main+0x3b9>
mov    -0x2760(%rbp),%rdi
lea    0xbe6(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    152f <main+0x2bf>
movl   $0xc8,-0x1c(%rbp)
mov    -0x2768(%rbp),%rdi
lea    0xbb8(%rip),%rsi
call   1180 <strstr@plt>
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
lea    0xba9(%rip),%rdi
call   1170 <getmime@plt>
mov    %rax,-0x10(%rbp)
jmp    1624 <main+0x3b4>
mov    -0x2760(%rbp),%rdi
add    $0x1,%rdi
mov    0x2a97(%rip),%rax
mov    (%rax),%esi
call   1110 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    157c <main+0x30c>
movl   $0x194,-0x1c(%rbp)
lea    0xb74(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xad9(%rip),%rdi
call   1170 <getmime@plt>
mov    %rax,-0x10(%rbp)
jmp    161f <main+0x3af>
movl   $0xc8,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
call   1120 <filesize@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   10d0 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xb99(%rip),%rsi
call   1160 <drop2@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x2774(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x2770(%rbp)
mov    -0x20(%rbp),%edi
call   1120 <filesize@plt>
mov    -0x2774(%rbp),%edi
mov    -0x2770(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   10b0 <read@plt>
mov    %eax,-0x2750(%rbp)
mov    -0x2750(%rbp),%edi
lea    0xb5a(%rip),%rsi
call   1100 <drop@plt>
mov    -0x18(%rbp),%rax
movslq -0x2750(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%edi
call   10a0 <close@plt>
mov    -0x2760(%rbp),%rdi
call   1170 <getmime@plt>
mov    %rax,-0x10(%rbp)
jmp    1624 <main+0x3b4>
jmp    1629 <main+0x3b9>
jmp    162e <main+0x3be>
mov    -0x274c(%rbp),%eax
mov    %eax,-0x27a4(%rbp)
mov    -0x1c(%rbp),%edi
call   1150 <response@plt>
mov    %rax,-0x27a0(%rbp)
mov    -0x1c(%rbp),%edi
call   1150 <response@plt>
mov    %rax,%rdi
call   1070 <strlen@plt>
mov    -0x27a4(%rbp),%edi
mov    -0x27a0(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
mov    %eax,%edi
lea    0xae0(%rip),%rsi
call   1100 <drop@plt>
mov    -0x274c(%rbp),%eax
mov    %eax,-0x2794(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x2790(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x2794(%rbp),%edi
mov    -0x2790(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
mov    %eax,%edi
lea    0xab0(%rip),%rsi
call   1100 <drop@plt>
mov    -0x274c(%rbp),%eax
mov    %eax,-0x2784(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x2780(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x2784(%rbp),%edi
mov    -0x2780(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
mov    %eax,%edi
lea    0xa81(%rip),%rsi
call   1100 <drop@plt>
cmpl   $0xffffffff,-0x20(%rbp)
je     1727 <main+0x4b7>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
movl   $0xffffffff,-0x20(%rbp)
mov    -0x274c(%rbp),%edi
mov    $0x2,%esi
call   1060 <shutdown@plt>
mov    -0x274c(%rbp),%edi
call   10a0 <close@plt>
jmp    1366 <main+0xf6>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2738,%rsp
mov    0x2d58(%rip),%rbx
mov    (%rbx),%edi
mov    0x2d27(%rip),%rax
mov    (%rax),%esi
mov    0x2d2e(%rip),%rax
mov    (%rax),%edx
call   1190 <socket@plt>
mov    %eax,%ebp
lea    0xd56(%rip),%rsi
mov    %eax,%edi
call   1100 <drop@plt>
movl   $0x1,0xc(%rsp)
mov    0x2d28(%rip),%rax
mov    (%rax),%esi
mov    0x2ce7(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
mov    $0x44c,%edi
call   1080 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x2cde(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   10f0 <bind@plt>
lea    0xcf7(%rip),%rsi
mov    %eax,%edi
call   1100 <drop@plt>
mov    %ebp,0x8(%rsp)
mov    %ebp,%edi
mov    $0xa,%esi
call   10e0 <listen@plt>
lea    0xce4(%rip),%rsi
mov    %eax,%edi
call   1100 <drop@plt>
jmp    1355 <main+0xe5>
nopl   (%rax)
mov    %r13d,%edi
mov    $0x2,%esi
call   1060 <shutdown@plt>
mov    %r13d,%edi
call   10a0 <close@plt>
mov    0x8(%rsp),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1140 <accept@plt>
mov    %eax,%r13d
mov    %eax,%edi
lea    0xcb7(%rip),%rsi
call   1100 <drop@plt>
mov    %r13d,%edi
lea    0x20(%rsp),%rbp
mov    %rbp,%rsi
mov    $0x2710,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,%ebx
mov    %eax,%edi
lea    0xc9d(%rip),%rsi
call   1100 <drop@plt>
movslq %ebx,%rax
movb   $0x0,0x20(%rsp,%rax,1)
mov    %rbp,%rdi
lea    0xc91(%rip),%rbx
mov    %rbx,%rsi
call   1130 <strtok@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1130 <strtok@plt>
mov    %rax,%rbp
xor    %edi,%edi
lea    0xcff(%rip),%rsi
call   1130 <strtok@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
lea    0xc63(%rip),%rsi
call   10c0 <strcmp@plt>
lea    0xc59(%rip),%r12
test   %rax,%rax
je     13f0 <main+0x180>
mov    %rbp,%r12
mov    %r12,%rdi
lea    0xc53(%rip),%rsi
call   10c0 <strcmp@plt>
mov    $0xc8,%r14d
test   %rax,%rax
je     14f0 <main+0x280>
mov    %r12,%rdi
lea    0xca5(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     14c0 <main+0x250>
mov    %r12,%rdi
lea    0xc9f(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     14c0 <main+0x250>
lea    0x1(%r12),%rdi
mov    0x2b8e(%rip),%rax
mov    (%rax),%esi
call   1110 <open@plt>
cmp    $0xffffffff,%eax
je     15ab <main+0x33b>
mov    %eax,%ebx
mov    %eax,%edi
call   1120 <filesize@plt>
lea    0x1(%rax),%rdi
call   10d0 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
lea    0xcc6(%rip),%rsi
call   1160 <drop2@plt>
mov    %ebx,%edi
call   1120 <filesize@plt>
lea    0x1(%rax),%rdx
mov    %ebx,%edi
mov    %r15,%rsi
call   10b0 <read@plt>
mov    %eax,%ebp
mov    %eax,%edi
lea    0xcaf(%rip),%rsi
call   1100 <drop@plt>
movslq %ebp,%rax
movb   $0x0,(%r15,%rax,1)
mov    %ebx,%edi
call   10a0 <close@plt>
mov    %ebx,0x4(%rsp)
jmp    1506 <main+0x296>
nopl   0x0(%rax,%rax,1)
movl   $0xffffffff,0x4(%rsp)
ff
mov    %rbx,%rdi
lea    0xbf3(%rip),%rsi
call   1180 <strstr@plt>
mov    %rax,%r15
add    $0x4,%r15
lea    0xbe5(%rip),%r12
jmp    1506 <main+0x296>
nopw   0x0(%rax,%rax,1)
movl   $0xffffffff,0x4(%rsp)
ff
lea    0xb48(%rip),%r12
lea    0xb50(%rip),%r15
mov    %r12,%rdi
call   1170 <getmime@plt>
mov    %rax,%rbx
mov    %r14d,%edi
call   1150 <response@plt>
mov    %rax,%rbp
mov    %r14d,%edi
call   1150 <response@plt>
mov    %rax,%rdi
call   1070 <strlen@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
mov    %eax,%edi
lea    0xc14(%rip),%rsi
call   1100 <drop@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
mov    %eax,%edi
lea    0xc03(%rip),%rsi
call   1100 <drop@plt>
mov    %r15,%rdi
call   1070 <strlen@plt>
mov    %r13d,%edi
mov    %r15,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
mov    %eax,%edi
lea    0xbf3(%rip),%rsi
call   1100 <drop@plt>
cmpl   $0xffffffff,0x4(%rsp)
je     1340 <main+0xd0>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    1340 <main+0xd0>
movl   $0xffffffff,0x4(%rsp)
ff
mov    $0x194,%r14d
lea    0xa87(%rip),%r12
lea    0xb10(%rip),%r15
jmp    1506 <main+0x296>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [13 x i8] c"socket error\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [11 x i8] c"bind error\00"
@.str.2 = [13 x i8] c"listen error\00"
@.str.3 = [13 x i8] c"accept error\00"
@.str.4 = [11 x i8] c"recv error\00"
@.str.5 = [2 x i8] c" \00"
@.str.6 = [1 x i8] zeroinitializer
@.str.7 = [2 x i8] c"/\00"
@.str.8 = [12 x i8] c"/index.html\00"
@.str.9 = [9 x i8] c"/special\00"
@.str.10 = [103 x i8] c"<!doctype html><html><head><title>Special page</title></head><body><p>you're special</p></body></html>\00"
@.str.11 = [6 x i8] c".html\00"
@.str.12 = [8 x i8] c"/getopt\00"
@.str.13 = [5 x i8] c"\0D\0A\0D\0A\00"
@.str.14 = [5 x i8] c".txt\00"
@.str.15 = [8 x i8] c"/setopt\00"
@O_RDONLY = global i32 0
@.str.16 = [104 x i8] c"<!doctype html><html><head><title>404 Not Found</title></head><body><p>page not found</p></body></html>\00"
@.str.17 = [14 x i8] c"out of memory\00"
@.str.18 = [11 x i8] c"read error\00"
@.str.19 = [20 x i8] c"send response error\00"
@.str.20 = [21 x i8] c"send mime type error\00"
@.str.21 = [19 x i8] c"send webpage error\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [10000 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
store i32 0, i32* %1
store i32 -1, i32* %5
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_STREAM
%17 = load i32, i32* @IPPROTO_TCP
%18 = call i32 @socket(i32 %15, i32 %16, i32 %17)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = call i32 @drop(i32 %19, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %8
%21 = load i32, i32* %7
%22 = load i32, i32* @SOL_SOCKET
%23 = load i32, i32* @SO_REUSEADDR
%24 = call i32 @setsockopt(i32 %21, i32 %22, i32 %23, i32* %8, i32 4)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%26 = call i32 @htons(i32 1100)
store i32 %26, i32* %25
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%28 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %27, i32 0, i32 0
%29 = load i32, i32* @INADDR_ANY
store i32 %29, i32* %28
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
%31 = load i32, i32* @AF_INET
store i32 %31, i32* %30
%32 = load i32, i32* %7
%33 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%34 = call i32 @bind(i32 %32, %struct.sockaddr* %33, i32 12)
%35 = call i32 @drop(i32 %34, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%36 = load i32, i32* %7
%37 = call i32 @listen(i32 %36, i32 10)
%38 = call i32 @drop(i32 %37, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %0, %145
%40 = load i32, i32* %7
%41 = call i32 @accept(i32 %40, i32* null, i32* null)
store i32 %41, i32* %10
%42 = load i32, i32* %10
%43 = call i32 @drop(i32 %42, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%44 = load i32, i32* %10
%45 = getelementptr inbounds [10000 x i8], [10000 x i8]* %6, i64 0, i64 0
%46 = call i32 @recv(i32 %44, i8* %45, i32 10000, i32 0)
store i32 %46, i32* %11
%47 = load i32, i32* %11
%48 = call i32 @drop(i32 %47, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%49 = load i32, i32* %11
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [10000 x i8], [10000 x i8]* %6, i64 0, i64 %50
store i8 0, i8* %51
%52 = getelementptr inbounds [10000 x i8], [10000 x i8]* %6, i64 0, i64 0
%53 = call i8* @strtok(i8* %52, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i8* %53, i8** %12
%54 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i8* %54, i8** %13
%55 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0))
store i8* %55, i8** %14
%56 = load i8*, i8** %13
%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 %59, label %60
59: ; preds = %39
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i8** %13
br label %60
60: ; preds = %59, %39
%61 = load i8*, i8** %13
%62 = call i64 @strcmp(i8* %61, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0))
%63 = icmp eq i64 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %60
store i32 200, i32* %4
store i8* getelementptr inbounds ([103 x i8], [103 x i8]* @.str.10, i64 0, i64 0), i8** %3
%65 = call i8* @getmime(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0))
store i8* %65, i8** %2
br label %119
66: ; preds = %60
%67 = load i8*, i8** %13
%68 = call i64 @strcmp(i8* %67, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0))
%69 = icmp eq i64 %68, 0
br i1 %69, label %70, label %75
70: ; preds = %66
store i32 200, i32* %4
%71 = load i8*, i8** %14
%72 = call i8* @strstr(i8* %71, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0))
%73 = getelementptr inbounds i8, i8* %72, i64 4
store i8* %73, i8** %3
%74 = call i8* @getmime(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0))
store i8* %74, i8** %2
br label %118
75: ; preds = %66
%76 = load i8*, i8** %13
%77 = call i64 @strcmp(i8* %76, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.15, i64 0, i64 0))
%78 = icmp eq i64 %77, 0
br i1 %78, label %79, label %84
79: ; preds = %75
store i32 200, i32* %4
%80 = load i8*, i8** %14
%81 = call i8* @strstr(i8* %80, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0))
%82 = getelementptr inbounds i8, i8* %81, i64 4
store i8* %82, i8** %3
%83 = call i8* @getmime(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0))
store i8* %83, i8** %2
br label %117
84: ; preds = %75
%85 = load i8*, i8** %13
%86 = getelementptr inbounds i8, i8* %85, i64 1
%87 = load i32, i32* @O_RDONLY
%88 = call i32 @open(i8* %86, i32 %87)
store i32 %88, i32* %5
%89 = load i32, i32* %5
%90 = icmp eq i32 %89, -1
br i1 %90, label %91, label %93
91: ; preds = %84
store i32 404, i32* %4
store i8* getelementptr inbounds ([104 x i8], [104 x i8]* @.str.16, i64 0, i64 0), i8** %3
%92 = call i8* @getmime(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0))
store i8* %92, i8** %2
br label %116
93: ; preds = %84
store i32 200, i32* %4
%94 = load i32, i32* %5
%95 = call i64 @filesize(i32 %94)
%96 = add nsw i64 %95, 1
%97 = call i8* @malloc(i64 %96)
store i8* %97, i8** %3
%98 = load i8*, i8** %3
%99 = call i32 @drop2(i8* %98, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.17, i64 0, i64 0))
%100 = load i32, i32* %5
%101 = load i8*, i8** %3
%102 = load i32, i32* %5
%103 = call i64 @filesize(i32 %102)
%104 = add nsw i64 %103, 1
%105 = call i32 @read(i32 %100, i8* %101, i64 %104)
store i32 %105, i32* %11
%106 = load i32, i32* %11
%107 = call i32 @drop(i32 %106, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.18, i64 0, i64 0))
%108 = load i8*, i8** %3
%109 = load i32, i32* %11
%110 = sext i32 %109 to i64
%111 = getelementptr inbounds i8, i8* %108, i64 %110
store i8 0, i8* %111
%112 = load i32, i32* %5
%113 = call i32 @close(i32 %112)
%114 = load i8*, i8** %13
%115 = call i8* @getmime(i8* %114)
store i8* %115, i8** %2
br label %116
116: ; preds = %93, %91
br label %117
117: ; preds = %116, %79
br label %118
118: ; preds = %117, %70
br label %119
119: ; preds = %118, %64
%120 = load i32, i32* %10
%121 = load i32, i32* %4
%122 = call i8* @response(i32 %121)
%123 = load i32, i32* %4
%124 = call i8* @response(i32 %123)
%125 = call i32 @strlen(i8* %124)
%126 = call i32 @send(i32 %120, i8* %122, i32 %125, i32 0)
%127 = call i32 @drop(i32 %126, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.19, i64 0, i64 0))
%128 = load i32, i32* %10
%129 = load i8*, i8** %2
%130 = load i8*, i8** %2
%131 = call i32 @strlen(i8* %130)
%132 = call i32 @send(i32 %128, i8* %129, i32 %131, i32 0)
%133 = call i32 @drop(i32 %132, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.20, i64 0, i64 0))
%134 = load i32, i32* %10
%135 = load i8*, i8** %3
%136 = load i8*, i8** %3
%137 = call i32 @strlen(i8* %136)
%138 = call i32 @send(i32 %134, i8* %135, i32 %137, i32 0)
%139 = call i32 @drop(i32 %138, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.21, i64 0, i64 0))
%140 = load i32, i32* %5
%141 = icmp ne i32 %140, -1
br i1 %141, label %142, label %145
142: ; preds = %119
%143 = load i8*, i8** %3
%144 = call i32 @free(i8* %143)
store i8* null, i8** %3
store i32 -1, i32* %5
br label %145
145: ; preds = %142, %119
%146 = load i32, i32* %10
%147 = call i32 @shutdown(i32 %146, i32 2)
%148 = load i32, i32* %10
%149 = call i32 @close(i32 %148)
br label %39
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [13 x i8] c"socket error\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [11 x i8] c"bind error\00"
@.str.2 = [13 x i8] c"listen error\00"
@.str.3 = [13 x i8] c"accept error\00"
@.str.4 = [11 x i8] c"recv error\00"
@.str.5 = [2 x i8] c" \00"
@.str.6 = [1 x i8] zeroinitializer
@.str.7 = [2 x i8] c"/\00"
@.str.8 = [12 x i8] c"/index.html\00"
@.str.9 = [9 x i8] c"/special\00"
@.str.10 = [103 x i8] c"<!doctype html><html><head><title>Special page</title></head><body><p>you're special</p></body></html>\00"
@.str.11 = [6 x i8] c".html\00"
@.str.12 = [8 x i8] c"/getopt\00"
@.str.13 = [5 x i8] c"\0D\0A\0D\0A\00"
@.str.14 = [5 x i8] c".txt\00"
@.str.15 = [8 x i8] c"/setopt\00"
@O_RDONLY = global i32 0
@.str.16 = [104 x i8] c"<!doctype html><html><head><title>404 Not Found</title></head><body><p>page not found</p></body></html>\00"
@.str.17 = [14 x i8] c"out of memory\00"
@.str.18 = [11 x i8] c"read error\00"
@.str.19 = [20 x i8] c"send response error\00"
@.str.20 = [21 x i8] c"send mime type error\00"
@.str.21 = [19 x i8] c"send webpage error\00"
define i32 @main() {
%1 = alloca [10000 x i8]
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = getelementptr inbounds [10000 x i8], [10000 x i8]* %1, i64 0, i64 0
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = load i32, i32* @IPPROTO_TCP
%8 = tail call i32 @socket(i32 %5, i32 %6, i32 %7)
%9 = tail call i32 @drop(i32 %8, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%10 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%11 = load i32, i32* @SOL_SOCKET
%12 = load i32, i32* @SO_REUSEADDR
%13 = call i32 @setsockopt(i32 %8, i32 %11, i32 %12, i32* %2, i32 4)
%14 = bitcast %struct.sockaddr_in* %3 to i8*
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%16 = call i32 @htons(i32 1100)
store i32 %16, i32* %15
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%18 = load i32, i32* @INADDR_ANY
store i32 %18, i32* %17
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
%20 = load i32, i32* @AF_INET
store i32 %20, i32* %19
%21 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%22 = call i32 @bind(i32 %8, %struct.sockaddr* %21, i32 12)
%23 = call i32 @drop(i32 %22, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @listen(i32 %8, i32 10)
%25 = call i32 @drop(i32 %24, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %90, %0
%27 = call i32 @accept(i32 %8, i32* null, i32* null)
%28 = call i32 @drop(i32 %27, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%29 = call i32 @recv(i32 %27, i8* %4, i32 10000, i32 0)
%30 = call i32 @drop(i32 %29, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds [10000 x i8], [10000 x i8]* %1, i64 0, i64 %31
store i8 0, i8* %32
%33 = call i8* @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%34 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%35 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0))
%36 = call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
%38 = select i1 %37, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i8* %34
%39 = call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %70, label %41
41: ; preds = %26
%42 = call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = call i8* @strstr(i8* dereferenceable(1) %35, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0))
%46 = getelementptr inbounds i8, i8* %45, i64 4
br label %70
47: ; preds = %41
%48 = call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.15, i64 0, i64 0))
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = call i8* @strstr(i8* dereferenceable(1) %35, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0))
%52 = getelementptr inbounds i8, i8* %51, i64 4
br label %70
53: ; preds = %47
%54 = getelementptr inbounds i8, i8* %38, i64 1
%55 = load i32, i32* @O_RDONLY
%56 = call i32 @open(i8* %54, i32 %55)
%57 = icmp eq i32 %56, -1
br i1 %57, label %70, label %58
58: ; preds = %53
%59 = call i64 @filesize(i32 %56)
%60 = add nsw i64 %59, 1
%61 = call i8* @malloc(i64 %60)
%62 = call i32 @drop2(i8* %61, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.17, i64 0, i64 0))
%63 = call i64 @filesize(i32 %56)
%64 = add nsw i64 %63, 1
%65 = call i32 @read(i32 %56, i8* %61, i64 %64)
%66 = call i32 @drop(i32 %65, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.18, i64 0, i64 0))
%67 = sext i32 %65 to i64
%68 = getelementptr inbounds i8, i8* %61, i64 %67
store i8 0, i8* %68
%69 = call i32 @close(i32 %56)
br label %70
70: ; preds = %53, %26, %44, %58, %50
%71 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0), %44 ], [ %38, %58 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0), %50 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), %26 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), %53 ]
%72 = phi i32 [ -1, %44 ], [ %56, %58 ], [ -1, %50 ], [ -1, %26 ], [ -1, %53 ]
%73 = phi i32 [ 200, %44 ], [ 200, %58 ], [ 200, %50 ], [ 200, %26 ], [ 404, %53 ]
%74 = phi i8* [ %46, %44 ], [ %61, %58 ], [ %52, %50 ], [ getelementptr inbounds ([103 x i8], [103 x i8]* @.str.10, i64 0, i64 0), %26 ], [ getelementptr inbounds ([104 x i8], [104 x i8]* @.str.16, i64 0, i64 0), %53 ]
%75 = call i8* @getmime(i8* %71)
%76 = call i8* @response(i32 %73)
%77 = call i8* @response(i32 %73)
%78 = call i32 @strlen(i8* %77)
%79 = call i32 @send(i32 %27, i8* %76, i32 %78, i32 0)
%80 = call i32 @drop(i32 %79, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.19, i64 0, i64 0))
%81 = call i32 @strlen(i8* %75)
%82 = call i32 @send(i32 %27, i8* %75, i32 %81, i32 0)
%83 = call i32 @drop(i32 %82, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.20, i64 0, i64 0))
%84 = call i32 @strlen(i8* %74)
%85 = call i32 @send(i32 %27, i8* %74, i32 %84, i32 0)
%86 = call i32 @drop(i32 %85, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.21, i64 0, i64 0))
%87 = icmp eq i32 %72, -1
br i1 %87, label %90, label %88
88: ; preds = %70
%89 = call i32 @free(i8* %74)
br label %90
90: ; preds = %88, %70
%91 = call i32 @shutdown(i32 %27, i32 2)
%92 = call i32 @close(i32 %27)
br label %26
}