#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 */
typedef int /*<<< orphan*/ yes;
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 socklen_t;
typedef int /*<<< orphan*/ server_addr;
typedef int /*<<< orphan*/ client_info;
typedef int /*<<< orphan*/ client_addr;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int NI_MAXHOST;
int /*<<< orphan*/ NI_NUMERICHOST;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int *);
int atoi(char *);
scalar_t__ bind(int, struct sockaddr *, int);
scalar_t__ chdir(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ getenv(char *);
int /*<<< orphan*/ getnameinfo(struct sockaddr *, int, char *, int,
                               int /*<<< orphan*/ *, int /*<<< orphan*/,
                               int /*<<< orphan*/);
int /*<<< orphan*/ handle_client(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ waitpid(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int server_sock, client_sock, pid, yes = 1,
                                     port = argc > 1 ? atoi(argv[1]) : 8888;
  struct sockaddr_in server_addr, client_addr;
  socklen_t addr_len;
  char client_info[NI_MAXHOST];
  FILE *client_fd;
  if (argc > 2)
    if (chdir(argv[2]) < 0)
      do {
        fprintf(stderr, strerror(errno));
        fprintf(stderr, " - terminated!\n");
        exit(1);
      } while (0);
  server_sock = socket(AF_INET, SOCK_STREAM, 0);
  if (server_sock < 0)
    do {
      fprintf(stderr, strerror(errno));
      fprintf(stderr, " - terminated!\n");
      exit(1);
    } while (0);
  server_addr.sin_family = AF_INET;
  server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  server_addr.sin_port = htons(port);
  if (setsockopt(server_sock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0)
    do {
      fprintf(stderr, strerror(errno));
      fprintf(stderr, " - terminated!\n");
      exit(1);
    } while (0);
  if (bind(server_sock, (struct sockaddr *)&server_addr, sizeof(server_addr)) <
      0)
    do {
      fprintf(stderr, strerror(errno));
      fprintf(stderr, " - terminated!\n");
      exit(1);
    } while (0);
  listen(server_sock, 10);
  while (1) {
    do {
      if (getenv("DEBUG")) {
        fprintf(stderr,
                "\n\n*** Zepto-HTTPD v0.3 - (c)2011 Matthias Goebl "
                "***\nListening at TCP Port %i.",
                port);
        fprintf(stderr, "\n");
      }
    } while (0);
    addr_len = sizeof(client_addr);
    client_sock =
        accept(server_sock, (struct sockaddr *)&client_addr, &addr_len);
    if (client_sock == -1)
      continue;
    getnameinfo((struct sockaddr *)&client_addr, sizeof(client_addr),
                client_info, sizeof(client_info), NULL, 0, NI_NUMERICHOST);
    client_fd = fdopen(client_sock, "r+");
    do {
      if (getenv("DEBUG")) {
        fprintf(stderr, "Connect from %s.", client_info);
        fprintf(stderr, "\n");
      }
    } while (0);
    if (getenv("DEMO"))
      handle_client(client_fd, client_info);
    else {
      if (!(pid = fork())) {
        if (!fork())
          handle_client(client_fd, client_info);
        exit(0);
      }
      waitpid(pid, NULL, 0);
    }
    fclose(client_fd);
    do {
      if (getenv("DEBUG")) {
        fprintf(stderr, "Disconnected from %s.", client_info);
        fprintf(stderr, "\n");
      }
    } while (0);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    126f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1110 <atoi@plt>
mov    %eax,-0x64(%rbp)
jmp    127c <main+0x4c>
mov    $0x22b8,%eax
mov    %eax,-0x64(%rbp)
jmp    127c <main+0x4c>
mov    -0x64(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d17(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x78(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x58(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    1325 <main+0xf5>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <chdir@plt>
cmp    $0x0,%rax
jge    1320 <main+0xf0>
jmp    12d8 <main+0xa8>
mov    0x2ce9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7c(%rbp)
mov    0x2cc5(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    -0x7c(%rbp),%edi
mov    %rax,%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
lea    0xcf1(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
jmp    1325 <main+0xf5>
mov    0x2cb4(%rip),%rax
mov    (%rax),%edi
mov    0x2c8b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1398 <main+0x168>
jmp    1350 <main+0x120>
mov    0x2c71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x80(%rbp)
mov    0x2c4d(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    -0x80(%rbp),%edi
mov    %rax,%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2c4a(%rip),%rax
mov    (%rax),%edi
lea    0xc79(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    0x2c41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2c2d(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%edi
call   1080 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2c1e(%rip),%rax
mov    (%rax),%esi
mov    0x2bd5(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rcx
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
cmp    $0x0,%rax
jge    1441 <main+0x211>
jmp    13f3 <main+0x1c3>
mov    0x2bce(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x84(%rbp)
mov    0x2ba7(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    -0x84(%rbp),%edi
mov    %rax,%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2ba1(%rip),%rax
mov    (%rax),%edi
lea    0xbd0(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
cmp    $0x0,%rax
jge    14af <main+0x27f>
jmp    1461 <main+0x231>
mov    0x2b60(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x88(%rbp)
mov    0x2b39(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    -0x88(%rbp),%edi
mov    %rax,%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2b33(%rip),%rax
mov    (%rax),%edi
lea    0xb62(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0xa,%esi
call   10c0 <listen@plt>
jmp    14c1 <main+0x291>
jmp    14c6 <main+0x296>
lea    0xb43(%rip),%rdi
call   1040 <getenv@plt>
cmp    $0x0,%rax
je     150d <main+0x2dd>
mov    0x2ae5(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xb27(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2acb(%rip),%rax
mov    (%rax),%edi
lea    0xb08(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    1512 <main+0x2e2>
jmp    1517 <main+0x2e7>
movl   $0xc,-0x44(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
lea    -0x44(%rbp),%rdx
call   1100 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1540 <main+0x310>
jmp    14bc <main+0x28c>
mov    -0x70(%rbp),%rdx
mov    -0x78(%rbp),%rax
lea    -0x40(%rbp),%rdi
mov    %eax,%ecx
mov    0x2a63(%rip),%rax
mov    (%rax),%eax
mov    $0xc,%esi
xor    %r8d,%r8d
xor    %r9d,%r9d
sub    $0x10,%rsp
mov    %eax,(%rsp)
call   10a0 <getnameinfo@plt>
add    $0x10,%rsp
mov    -0x18(%rbp),%edi
lea    0xae8(%rip),%rsi
call   10d0 <fdopen@plt>
mov    %rax,-0x60(%rbp)
lea    0xa84(%rip),%rdi
call   1040 <getenv@plt>
cmp    $0x0,%rax
je     15cd <main+0x39d>
mov    -0x70(%rbp),%rdx
mov    0x2a22(%rip),%rax
mov    (%rax),%edi
lea    0xab8(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2a0b(%rip),%rax
mov    (%rax),%edi
lea    0xa48(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    15d2 <main+0x3a2>
jmp    15d7 <main+0x3a7>
lea    0xa9a(%rip),%rdi
call   1040 <getenv@plt>
cmp    $0x0,%rax
je     15ff <main+0x3cf>
mov    -0x70(%rbp),%rsi
mov    -0x60(%rbp),%rdi
call   1030 <handle_client@plt>
jmp    1644 <main+0x414>
mov    $0x0,%al
call   1140 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    1636 <main+0x406>
mov    $0x0,%al
call   1140 <fork@plt>
cmp    $0x0,%eax
jne    162f <main+0x3ff>
mov    -0x70(%rbp),%rsi
mov    -0x60(%rbp),%rdi
call   1030 <handle_client@plt>
xor    %edi,%edi
call   1120 <exit@plt>
mov    -0x1c(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10f0 <waitpid@plt>
mov    -0x60(%rbp),%rdi
call   1060 <fclose@plt>
lea    0x9bc(%rip),%rdi
call   1040 <getenv@plt>
cmp    $0x0,%rax
je     1695 <main+0x465>
mov    -0x70(%rbp),%rdx
mov    0x295a(%rip),%rax
mov    (%rax),%edi
lea    0xa06(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2943(%rip),%rax
mov    (%rax),%edi
lea    0x980(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    169a <main+0x46a>
jmp    169f <main+0x46f>
jmp    14bc <main+0x28c>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
movl   $0x1,-0x40(%rbp)
cmp    $0x1,%edi
jle    1298 <main+0x68>
mov    %rsi,%r14
mov    %edi,%ebx
mov    0x8(%rsi),%rdi
call   1110 <atoi@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2d3b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rax,-0x48(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
cmp    $0x2,%ebx
je     12c1 <main+0x91>
mov    0x10(%r14),%rdi
call   1070 <chdir@plt>
test   %rax,%rax
jns    12c1 <main+0x91>
jmp    1341 <main+0x111>
mov    0x2d01(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rax,-0x48(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
movl   $0x22b8,-0x2c(%rbp)
mov    0x2d18(%rip),%rbx
mov    (%rbx),%edi
mov    0x2cef(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
test   %eax,%eax
js     1341 <main+0x111>
mov    %eax,%r13d
mov    (%rbx),%eax
mov    %eax,-0x50(%rbp)
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,-0x54(%rbp)
mov    -0x2c(%rbp),%edi
call   1080 <htons@plt>
mov    %eax,-0x58(%rbp)
mov    0x2cdf(%rip),%rax
mov    (%rax),%esi
mov    0x2c96(%rip),%rax
mov    (%rax),%edx
lea    -0x40(%rbp),%rcx
mov    %r13d,%edi
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
test   %rax,%rax
js     1341 <main+0x111>
lea    -0x58(%rbp),%rsi
mov    %r13d,%edi
mov    $0xc,%edx
call   10e0 <bind@plt>
test   %rax,%rax
jns    1380 <main+0x150>
mov    0x2c80(%rip),%r14
mov    (%r14),%ebx
mov    0x2c5e(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    %ebx,%edi
mov    %rax,%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    (%r14),%edi
lea    0xc91(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    %r13d,%edi
mov    $0xa,%esi
call   10c0 <listen@plt>
lea    0xc7c(%rip),%r12
mov    0x2c2d(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1040 <getenv@plt>
test   %rax,%rax
je     13d2 <main+0x1a2>
mov    (%r14),%edi
lea    0xc5f(%rip),%rsi
mov    -0x2c(%rbp),%edx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    (%r14),%edi
lea    0xc43(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
movl   $0xc,-0x3c(%rbp)
mov    %r13d,%edi
lea    -0x68(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
call   1100 <accept@plt>
cmp    $0xffffffff,%eax
je     13a0 <main+0x170>
mov    %eax,%ebx
mov    0x2bc1(%rip),%rax
mov    (%rax),%eax
sub    $0x8,%rsp
lea    -0x68(%rbp),%rdi
mov    $0xc,%esi
mov    -0x38(%rbp),%r15
mov    %r15,%rdx
mov    -0x48(%rbp),%rcx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   %rax
call   10a0 <getnameinfo@plt>
add    $0x10,%rsp
mov    %ebx,%edi
mov    %r15,%rbx
lea    0xc37(%rip),%rsi
call   10d0 <fdopen@plt>
mov    %rax,%r15
mov    %r12,%rdi
call   1040 <getenv@plt>
test   %rax,%rax
je     1467 <main+0x237>
mov    (%r14),%edi
lea    0xc1b(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    (%r14),%edi
lea    0xbae(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
lea    0xc0a(%rip),%rdi
call   1040 <getenv@plt>
test   %rax,%rax
je     1490 <main+0x260>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <handle_client@plt>
jmp    14a6 <main+0x276>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1140 <fork@plt>
test   %eax,%eax
je     14ea <main+0x2ba>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10f0 <waitpid@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
mov    %r12,%rdi
call   1040 <getenv@plt>
test   %rax,%rax
je     13a0 <main+0x170>
mov    (%r14),%edi
lea    0xbb4(%rip),%rsi
mov    -0x38(%rbp),%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    (%r14),%edi
lea    0xb30(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    13a0 <main+0x170>
xor    %eax,%eax
call   1140 <fork@plt>
test   %eax,%eax
jne    1500 <main+0x2d0>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <handle_client@plt>
xor    %edi,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@NI_MAXHOST = global i32 0
@stderr = global i32 0
@errno = global i32 0
@.str = [16 x i8] c" - terminated!\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [6 x i8] c"DEBUG\00"
@.str.2 = [78 x i8] c"\0A\0A*** Zepto-HTTPD v0.3 - (c)2011 Matthias Goebl ***\0AListening at TCP Port %i.\00"
@.str.3 = [2 x i8] c"\0A\00"
@NI_NUMERICHOST = global i32 0
@.str.4 = [3 x i8] c"r+\00"
@.str.5 = [17 x i8] c"Connect from %s.\00"
@.str.6 = [5 x i8] c"DEMO\00"
@.str.7 = [22 x i8] c"Disconnected from %s.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.sockaddr_in
%12 = alloca %struct.sockaddr_in
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %9
%17 = load i32, i32* %4
%18 = icmp sgt i32 %17, 1
br i1 %18, label %19, label %24
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
br label %25
24: ; preds = %2
br label %25
25: ; preds = %24, %19
%26 = phi i32 [ %23, %19 ], [ 8888, %24 ]
store i32 %26, i32* %10
%27 = load i32, i32* @NI_MAXHOST
%28 = zext i32 %27 to i64
%29 = call i8* @llvm.stacksave()
store i8* %29, i8** %14
%30 = alloca i8, i64 %28
store i64 %28, i64* %15
%31 = load i32, i32* %4
%32 = icmp sgt i32 %31, 2
br i1 %32, label %33, label %51
33: ; preds = %25
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
%37 = call i64 @chdir(i8* %36)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %50
39: ; preds = %33
br label %40
40: ; preds = %39
%41 = load i32, i32* @stderr
%42 = load i32, i32* @errno
%43 = call i8* @strerror(i32 %42)
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* %43)
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; No predecessors!
br label %49
49: ; preds = %48
br label %50
50: ; preds = %49, %33
br label %51
51: ; preds = %50, %25
%52 = load i32, i32* @AF_INET
%53 = load i32, i32* @SOCK_STREAM
%54 = call i32 @socket(i32 %52, i32 %53, i32 0)
store i32 %54, i32* %6
%55 = load i32, i32* %6
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %68
57: ; preds = %51
br label %58
58: ; preds = %57
%59 = load i32, i32* @stderr
%60 = load i32, i32* @errno
%61 = call i8* @strerror(i32 %60)
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* %61)
%63 = load i32, i32* @stderr
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%65 = call i32 @exit(i32 1)
unreachable
66: ; No predecessors!
br label %67
67: ; preds = %66
br label %68
68: ; preds = %67, %51
%69 = load i32, i32* @AF_INET
%70 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %69, i32* %70
%71 = load i32, i32* @INADDR_ANY
%72 = call i32 @htonl(i32 %71)
%73 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
%74 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %73, i32 0, i32 0
store i32 %72, i32* %74
%75 = load i32, i32* %10
%76 = call i32 @htons(i32 %75)
%77 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
store i32 %76, i32* %77
%78 = load i32, i32* %6
%79 = load i32, i32* @SOL_SOCKET
%80 = load i32, i32* @SO_REUSEADDR
%81 = call i64 @setsockopt(i32 %78, i32 %79, i32 %80, i32* %9, i32 4)
%82 = icmp slt i64 %81, 0
br i1 %82, label %83, label %94
83: ; preds = %68
br label %84
84: ; preds = %83
%85 = load i32, i32* @stderr
%86 = load i32, i32* @errno
%87 = call i8* @strerror(i32 %86)
%88 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* %87)
%89 = load i32, i32* @stderr
%90 = call i32 (i32, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%91 = call i32 @exit(i32 1)
unreachable
92: ; No predecessors!
br label %93
93: ; preds = %92
br label %94
94: ; preds = %93, %68
%95 = load i32, i32* %6
%96 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%97 = call i64 @bind(i32 %95, %struct.sockaddr* %96, i32 12)
%98 = icmp slt i64 %97, 0
br i1 %98, label %99, label %110
99: ; preds = %94
br label %100
100: ; preds = %99
%101 = load i32, i32* @stderr
%102 = load i32, i32* @errno
%103 = call i8* @strerror(i32 %102)
%104 = call i32 (i32, i8*, ...) @fprintf(i32 %101, i8* %103)
%105 = load i32, i32* @stderr
%106 = call i32 (i32, i8*, ...) @fprintf(i32 %105, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%107 = call i32 @exit(i32 1)
unreachable
108: ; No predecessors!
br label %109
109: ; preds = %108
br label %110
110: ; preds = %109, %94
%111 = load i32, i32* %6
%112 = call i32 @listen(i32 %111, i32 10)
br label %113
113: ; preds = %183, %132, %110
br label %114
114: ; preds = %113
br label %115
115: ; preds = %114
%116 = call i64 @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%117 = icmp ne i64 %116, 0
br i1 %117, label %118, label %124
118: ; preds = %115
%119 = load i32, i32* @stderr
%120 = load i32, i32* %10
%121 = call i32 (i32, i8*, ...) @fprintf(i32 %119, i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.2, i64 0, i64 0), i32 %120)
%122 = load i32, i32* @stderr
%123 = call i32 (i32, i8*, ...) @fprintf(i32 %122, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %124
124: ; preds = %118, %115
br label %125
125: ; preds = %124
br label %126
126: ; preds = %125
store i32 12, i32* %13
%127 = load i32, i32* %6
%128 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%129 = call i32 @accept(i32 %127, %struct.sockaddr* %128, i32* %13)
store i32 %129, i32* %7
%130 = load i32, i32* %7
%131 = icmp eq i32 %130, -1
br i1 %131, label %132, label %133
132: ; preds = %126
br label %113
133: ; preds = %126
%134 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%135 = trunc i64 %28 to i32
%136 = load i32, i32* @NI_NUMERICHOST
%137 = call i32 @getnameinfo(%struct.sockaddr* %134, i32 12, i8* %30, i32 %135, i32* null, i32 0, i32 %136)
%138 = load i32, i32* %7
%139 = call i32* @fdopen(i32 %138, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %139, i32** %16
br label %140
140: ; preds = %133
%141 = call i64 @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%142 = icmp ne i64 %141, 0
br i1 %142, label %143, label %148
143: ; preds = %140
%144 = load i32, i32* @stderr
%145 = call i32 (i32, i8*, ...) @fprintf(i32 %144, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %30)
%146 = load i32, i32* @stderr
%147 = call i32 (i32, i8*, ...) @fprintf(i32 %146, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %148
148: ; preds = %143, %140
br label %149
149: ; preds = %148
br label %150
150: ; preds = %149
%151 = call i64 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%152 = icmp ne i64 %151, 0
br i1 %152, label %153, label %156
153: ; preds = %150
%154 = load i32*, i32** %16
%155 = call i32 @handle_client(i32* %154, i8* %30)
br label %170
156: ; preds = %150
%157 = call i32 (...) @fork()
store i32 %157, i32* %8
%158 = icmp ne i32 %157, 0
br i1 %158, label %167, label %159
159: ; preds = %156
%160 = call i32 (...) @fork()
%161 = icmp ne i32 %160, 0
br i1 %161, label %165, label %162
162: ; preds = %159
%163 = load i32*, i32** %16
%164 = call i32 @handle_client(i32* %163, i8* %30)
br label %165
165: ; preds = %162, %159
%166 = call i32 @exit(i32 0)
unreachable
167: ; preds = %156
%168 = load i32, i32* %8
%169 = call i32 @waitpid(i32 %168, i32* null, i32 0)
br label %170
170: ; preds = %167, %153
%171 = load i32*, i32** %16
%172 = call i32 @fclose(i32* %171)
br label %173
173: ; preds = %170
%174 = call i64 @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%175 = icmp ne i64 %174, 0
br i1 %175, label %176, label %181
176: ; preds = %173
%177 = load i32, i32* @stderr
%178 = call i32 (i32, i8*, ...) @fprintf(i32 %177, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i8* %30)
%179 = load i32, i32* @stderr
%180 = call i32 (i32, i8*, ...) @fprintf(i32 %179, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %181
181: ; preds = %176, %173
br label %182
182: ; preds = %181
br label %183
183: ; preds = %182
br label %113
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@NI_MAXHOST = global i32 0
@stderr = global i32 0
@errno = global i32 0
@.str = [16 x i8] c" - terminated!\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [6 x i8] c"DEBUG\00"
@.str.2 = [78 x i8] c"\0A\0A*** Zepto-HTTPD v0.3 - (c)2011 Matthias Goebl ***\0AListening at TCP Port %i.\00"
@.str.3 = [2 x i8] c"\0A\00"
@NI_NUMERICHOST = global i32 0
@.str.4 = [3 x i8] c"r+\00"
@.str.5 = [17 x i8] c"Connect from %s.\00"
@.str.6 = [5 x i8] c"DEMO\00"
@.str.7 = [22 x i8] c"Disconnected from %s.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%8 = icmp sgt i32 %0, 1
br i1 %8, label %16, label %9
9: ; preds = %2
%10 = bitcast %struct.sockaddr_in* %4 to i8*
%11 = bitcast %struct.sockaddr_in* %5 to i8*
%12 = bitcast i32* %6 to i8*
%13 = load i32, i32* @NI_MAXHOST
%14 = zext i32 %13 to i64
%15 = alloca i8, i64 %14
br label %40
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
%20 = bitcast %struct.sockaddr_in* %4 to i8*
%21 = bitcast %struct.sockaddr_in* %5 to i8*
%22 = bitcast i32* %6 to i8*
%23 = load i32, i32* @NI_MAXHOST
%24 = zext i32 %23 to i64
%25 = alloca i8, i64 %24
%26 = icmp eq i32 %0, 2
br i1 %26, label %40, label %27
27: ; preds = %16
%28 = getelementptr inbounds i8*, i8** %1, i64 2
%29 = load i8*, i8** %28
%30 = tail call i64 @chdir(i8* %29)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %40
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = load i32, i32* @errno
%35 = tail call i8* @strerror(i32 %34)
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* %35)
%37 = load i32, i32* @stderr
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%39 = tail call i32 @exit(i32 1)
unreachable
40: ; preds = %9, %27, %16
%41 = phi i8* [ %15, %9 ], [ %25, %27 ], [ %25, %16 ]
%42 = phi i32 [ %13, %9 ], [ %23, %27 ], [ %23, %16 ]
%43 = phi i32 [ 8888, %9 ], [ %19, %27 ], [ %19, %16 ]
%44 = load i32, i32* @AF_INET
%45 = load i32, i32* @SOCK_STREAM
%46 = tail call i32 @socket(i32 %44, i32 %45, i32 0)
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %56
48: ; preds = %40
%49 = load i32, i32* @stderr
%50 = load i32, i32* @errno
%51 = tail call i8* @strerror(i32 %50)
%52 = tail call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* %51)
%53 = load i32, i32* @stderr
%54 = tail call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%55 = tail call i32 @exit(i32 1)
unreachable
56: ; preds = %40
%57 = load i32, i32* @AF_INET
%58 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %57, i32* %58
%59 = load i32, i32* @INADDR_ANY
%60 = tail call i32 @htonl(i32 %59)
%61 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %60, i32* %61
%62 = tail call i32 @htons(i32 %43)
%63 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %62, i32* %63
%64 = load i32, i32* @SOL_SOCKET
%65 = load i32, i32* @SO_REUSEADDR
%66 = call i64 @setsockopt(i32 %46, i32 %64, i32 %65, i32* %3, i32 4)
%67 = icmp slt i64 %66, 0
br i1 %67, label %68, label %76
68: ; preds = %56
%69 = load i32, i32* @stderr
%70 = load i32, i32* @errno
%71 = call i8* @strerror(i32 %70)
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* %71)
%73 = load i32, i32* @stderr
%74 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %56
%77 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%78 = call i64 @bind(i32 %46, %struct.sockaddr* %77, i32 12)
%79 = icmp slt i64 %78, 0
br i1 %79, label %80, label %88
80: ; preds = %76
%81 = load i32, i32* @stderr
%82 = load i32, i32* @errno
%83 = call i8* @strerror(i32 %82)
%84 = call i32 (i32, i8*, ...) @fprintf(i32 %81, i8* %83)
%85 = load i32, i32* @stderr
%86 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%87 = call i32 @exit(i32 1)
unreachable
88: ; preds = %76
%89 = call i32 @listen(i32 %46, i32 10)
%90 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
br label %91
91: ; preds = %134, %88
%92 = call i64 @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%93 = icmp eq i64 %92, 0
br i1 %93, label %99, label %94
94: ; preds = %91
%95 = load i32, i32* @stderr
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.2, i64 0, i64 0), i32 %43)
%97 = load i32, i32* @stderr
%98 = call i32 (i32, i8*, ...) @fprintf(i32 %97, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %99
99: ; preds = %94, %91
store i32 12, i32* %6
%100 = call i32 @accept(i32 %46, %struct.sockaddr* %90, i32* %6)
%101 = icmp eq i32 %100, -1
br i1 %101, label %134, label %102
102: ; preds = %99
%103 = load i32, i32* @NI_NUMERICHOST
%104 = call i32 @getnameinfo(%struct.sockaddr* %90, i32 12, i8* %41, i32 %42, i32* null, i32 0, i32 %103)
%105 = call i32* @fdopen(i32 %100, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%106 = call i64 @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%107 = icmp eq i64 %106, 0
br i1 %107, label %113, label %108
108: ; preds = %102
%109 = load i32, i32* @stderr
%110 = call i32 (i32, i8*, ...) @fprintf(i32 %109, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %41)
%111 = load i32, i32* @stderr
%112 = call i32 (i32, i8*, ...) @fprintf(i32 %111, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %113
113: ; preds = %108, %102
%114 = call i64 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%115 = icmp eq i64 %114, 0
br i1 %115, label %118, label %116
116: ; preds = %113
%117 = call i32 @handle_client(i32* %105, i8* %41)
br label %130
118: ; preds = %113
%119 = call i32 (...) @fork()
%120 = icmp eq i32 %119, 0
br i1 %120, label %121, label %128
121: ; preds = %118
%122 = call i32 (...) @fork()
%123 = icmp eq i32 %122, 0
br i1 %123, label %124, label %126
124: ; preds = %121
%125 = call i32 @handle_client(i32* %105, i8* %41)
br label %126
126: ; preds = %124, %121
%127 = call i32 @exit(i32 0)
unreachable
128: ; preds = %118
%129 = call i32 @waitpid(i32 %119, i32* null, i32 0)
br label %130
130: ; preds = %128, %116
%131 = call i32 @fclose(i32* %105)
%132 = call i64 @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%133 = icmp eq i64 %132, 0
br i1 %133, label %134, label %135
134: ; preds = %130, %135, %99
br label %91
135: ; preds = %130
%136 = load i32, i32* @stderr
%137 = call i32 (i32, i8*, ...) @fprintf(i32 %136, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i8* %41)
%138 = load i32, i32* @stderr
%139 = call i32 (i32, i8*, ...) @fprintf(i32 %138, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %134
}