#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ getenv(char *);
int /*<<< orphan*/ getnameinfo(struct sockaddr *, int, char *, int,
                               int /*<<< orphan*/ *, int /*<<< orphan*/,
                               int /*<<< orphan*/);
int /*<<< orphan*/ handle_client(int /*<<< orphan*/ *);
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 main(int argc, char **argv) {
  int server_sock, client_sock, 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("QUIET")) {
        fprintf(stderr,
                "\n\n*** Zepto-HTTPD v0.1 - (c)2010 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);
    do {
      if (!getenv("QUIET")) {
        fprintf(stderr, "Connect from %s.", client_info);
        fprintf(stderr, "\n");
      }
    } while (0);
    client_fd = fdopen(client_sock, "r+");
    handle_client(client_fd);
    fclose(client_fd);
    do {
      if (!getenv("QUIET")) {
        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,-0x1c(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    124f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1100 <atoi@plt>
mov    %eax,-0x64(%rbp)
jmp    125c <main+0x4c>
mov    $0x22b8,%eax
mov    %eax,-0x64(%rbp)
jmp    125c <main+0x4c>
mov    -0x64(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d37(%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    1305 <main+0xf5>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <chdir@plt>
cmp    $0x0,%rax
jge    1300 <main+0xf0>
jmp    12b8 <main+0xa8>
mov    0x2d09(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7c(%rbp)
mov    0x2ce5(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x7c(%rbp),%edi
mov    %rax,%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2ce2(%rip),%rax
mov    (%rax),%edi
lea    0xd11(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
jmp    1305 <main+0xf5>
mov    0x2cd4(%rip),%rax
mov    (%rax),%edi
mov    0x2cab(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1378 <main+0x168>
jmp    1330 <main+0x120>
mov    0x2c91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x80(%rbp)
mov    0x2c6d(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x80(%rbp),%edi
mov    %rax,%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2c6a(%rip),%rax
mov    (%rax),%edi
lea    0xc99(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    0x2c61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2c4d(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%edi
call   1080 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2c3e(%rip),%rax
mov    (%rax),%esi
mov    0x2bf5(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
cmp    $0x0,%rax
jge    1421 <main+0x211>
jmp    13d3 <main+0x1c3>
mov    0x2bee(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x84(%rbp)
mov    0x2bc7(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x84(%rbp),%edi
mov    %rax,%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2bc1(%rip),%rax
mov    (%rax),%edi
lea    0xbf0(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
cmp    $0x0,%rax
jge    148f <main+0x27f>
jmp    1441 <main+0x231>
mov    0x2b80(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x88(%rbp)
mov    0x2b59(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    -0x88(%rbp),%edi
mov    %rax,%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2b53(%rip),%rax
mov    (%rax),%edi
lea    0xb82(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0xa,%esi
call   10c0 <listen@plt>
jmp    14a1 <main+0x291>
jmp    14a6 <main+0x296>
lea    0xb63(%rip),%rdi
call   1040 <getenv@plt>
cmp    $0x0,%eax
jne    14ec <main+0x2dc>
mov    0x2b06(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xb48(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2aec(%rip),%rax
mov    (%rax),%edi
lea    0xb29(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    14f1 <main+0x2e1>
jmp    14f6 <main+0x2e6>
movl   $0xc,-0x44(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
lea    -0x44(%rbp),%rdx
call   10f0 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    151f <main+0x30f>
jmp    149c <main+0x28c>
mov    -0x70(%rbp),%rdx
mov    -0x78(%rbp),%rax
lea    -0x40(%rbp),%rdi
mov    %eax,%ecx
mov    0x2a84(%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
lea    0xab8(%rip),%rdi
call   1040 <getenv@plt>
cmp    $0x0,%eax
jne    1598 <main+0x388>
mov    -0x70(%rbp),%rdx
mov    0x2a57(%rip),%rax
mov    (%rax),%edi
lea    0xaea(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2a40(%rip),%rax
mov    (%rax),%edi
lea    0xa7d(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    159d <main+0x38d>
jmp    15a2 <main+0x392>
mov    -0x18(%rbp),%edi
lea    0xac9(%rip),%rsi
call   10d0 <fdopen@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rdi
call   1030 <handle_client@plt>
mov    -0x60(%rbp),%rdi
call   1060 <fclose@plt>
lea    0xa42(%rip),%rdi
call   1040 <getenv@plt>
cmp    $0x0,%eax
jne    160e <main+0x3fe>
mov    -0x70(%rbp),%rdx
mov    0x29e1(%rip),%rax
mov    (%rax),%edi
lea    0xa88(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x29ca(%rip),%rax
mov    (%rax),%edi
lea    0xa07(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    1613 <main+0x403>
jmp    1618 <main+0x408>
jmp    149c <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    1278 <main+0x68>
mov    %rsi,%r14
mov    %edi,%ebx
mov    0x8(%rsi),%rdi
call   1100 <atoi@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2d5b(%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     12a1 <main+0x91>
mov    0x10(%r14),%rdi
call   1070 <chdir@plt>
test   %rax,%rax
jns    12a1 <main+0x91>
jmp    1463 <main+0x253>
mov    0x2d21(%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    0x2d38(%rip),%r14
mov    (%r14),%edi
mov    0x2d0e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
test   %eax,%eax
js     1463 <main+0x253>
mov    %eax,%r15d
mov    (%r14),%eax
mov    %eax,-0x50(%rbp)
mov    0x2d05(%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    0x2cf9(%rip),%rax
mov    (%rax),%esi
mov    0x2cb0(%rip),%rax
mov    (%rax),%edx
lea    -0x40(%rbp),%rcx
mov    %r15d,%edi
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
test   %rax,%rax
js     1463 <main+0x253>
lea    -0x58(%rbp),%rsi
mov    %r15d,%edi
mov    $0xc,%edx
call   10e0 <bind@plt>
test   %rax,%rax
js     1463 <main+0x253>
mov    %r15d,%edi
mov    $0xa,%esi
call   10c0 <listen@plt>
lea    0xccd(%rip),%r12
mov    0x2c7e(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1040 <getenv@plt>
test   %eax,%eax
jne    1383 <main+0x173>
mov    0x0(%r13),%edi
lea    0xcaf(%rip),%rsi
mov    -0x2c(%rbp),%edx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xc92(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
movl   $0xc,-0x3c(%rbp)
mov    %r15d,%edi
lea    -0x68(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
call   10f0 <accept@plt>
cmp    $0xffffffff,%eax
je     1350 <main+0x140>
mov    %eax,%r14d
mov    0x2c0f(%rip),%rax
mov    (%rax),%eax
sub    $0x8,%rsp
lea    -0x68(%rbp),%rdi
mov    $0xc,%esi
mov    -0x38(%rbp),%rdx
mov    -0x48(%rbp),%rcx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   %rax
call   10a0 <getnameinfo@plt>
add    $0x10,%rsp
mov    %r12,%rdi
call   1040 <getenv@plt>
test   %eax,%eax
jne    1404 <main+0x1f4>
mov    0x0(%r13),%edi
lea    0xc7d(%rip),%rsi
mov    -0x38(%rbp),%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xc11(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %r14d,%edi
lea    0xc67(%rip),%rsi
call   10d0 <fdopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <handle_client@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r12,%rdi
call   1040 <getenv@plt>
test   %eax,%eax
jne    1350 <main+0x140>
mov    0x0(%r13),%edi
lea    0xc37(%rip),%rsi
mov    -0x38(%rbp),%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xbb7(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    1350 <main+0x140>
mov    0x2b5e(%rip),%r14
mov    (%r14),%ebx
mov    0x2b3c(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    %ebx,%edi
mov    %rax,%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    (%r14),%edi
lea    0xb6f(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <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"QUIET\00"
@.str.2 = [78 x i8] c"\0A\0A*** Zepto-HTTPD v0.1 - (c)2010 Matthias Goebl ***\0AListening at TCP Port %i.\00"
@.str.3 = [2 x i8] c"\0A\00"
@NI_NUMERICHOST = global i32 0
@.str.4 = [17 x i8] c"Connect from %s.\00"
@.str.5 = [3 x i8] c"r+\00"
@.str.6 = [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 %struct.sockaddr_in
%11 = alloca %struct.sockaddr_in
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %8
%16 = load i32, i32* %4
%17 = icmp sgt i32 %16, 1
br i1 %17, label %18, label %23
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
br label %24
23: ; preds = %2
br label %24
24: ; preds = %23, %18
%25 = phi i32 [ %22, %18 ], [ 8888, %23 ]
store i32 %25, i32* %9
%26 = load i32, i32* @NI_MAXHOST
%27 = zext i32 %26 to i64
%28 = call i8* @llvm.stacksave()
store i8* %28, i8** %13
%29 = alloca i8, i64 %27
store i64 %27, i64* %14
%30 = load i32, i32* %4
%31 = icmp sgt i32 %30, 2
br i1 %31, label %32, label %50
32: ; preds = %24
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i64 @chdir(i8* %35)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %49
38: ; preds = %32
br label %39
39: ; preds = %38
%40 = load i32, i32* @stderr
%41 = load i32, i32* @errno
%42 = call i8* @strerror(i32 %41)
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* %42)
%44 = load i32, i32* @stderr
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; No predecessors!
br label %48
48: ; preds = %47
br label %49
49: ; preds = %48, %32
br label %50
50: ; preds = %49, %24
%51 = load i32, i32* @AF_INET
%52 = load i32, i32* @SOCK_STREAM
%53 = call i32 @socket(i32 %51, i32 %52, i32 0)
store i32 %53, i32* %6
%54 = load i32, i32* %6
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %67
56: ; preds = %50
br label %57
57: ; preds = %56
%58 = load i32, i32* @stderr
%59 = load i32, i32* @errno
%60 = call i8* @strerror(i32 %59)
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* %60)
%62 = load i32, i32* @stderr
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%64 = call i32 @exit(i32 1)
unreachable
65: ; No predecessors!
br label %66
66: ; preds = %65
br label %67
67: ; preds = %66, %50
%68 = load i32, i32* @AF_INET
%69 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %68, i32* %69
%70 = load i32, i32* @INADDR_ANY
%71 = call i32 @htonl(i32 %70)
%72 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%73 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %72, i32 0, i32 0
store i32 %71, i32* %73
%74 = load i32, i32* %9
%75 = call i32 @htons(i32 %74)
%76 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i32 %75, i32* %76
%77 = load i32, i32* %6
%78 = load i32, i32* @SOL_SOCKET
%79 = load i32, i32* @SO_REUSEADDR
%80 = call i64 @setsockopt(i32 %77, i32 %78, i32 %79, i32* %8, i32 4)
%81 = icmp slt i64 %80, 0
br i1 %81, label %82, label %93
82: ; preds = %67
br label %83
83: ; preds = %82
%84 = load i32, i32* @stderr
%85 = load i32, i32* @errno
%86 = call i8* @strerror(i32 %85)
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* %86)
%88 = load i32, i32* @stderr
%89 = call i32 (i32, i8*, ...) @fprintf(i32 %88, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%90 = call i32 @exit(i32 1)
unreachable
91: ; No predecessors!
br label %92
92: ; preds = %91
br label %93
93: ; preds = %92, %67
%94 = load i32, i32* %6
%95 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%96 = call i64 @bind(i32 %94, %struct.sockaddr* %95, i32 12)
%97 = icmp slt i64 %96, 0
br i1 %97, label %98, label %109
98: ; preds = %93
br label %99
99: ; preds = %98
%100 = load i32, i32* @stderr
%101 = load i32, i32* @errno
%102 = call i8* @strerror(i32 %101)
%103 = call i32 (i32, i8*, ...) @fprintf(i32 %100, i8* %102)
%104 = load i32, i32* @stderr
%105 = call i32 (i32, i8*, ...) @fprintf(i32 %104, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%106 = call i32 @exit(i32 1)
unreachable
107: ; No predecessors!
br label %108
108: ; preds = %107
br label %109
109: ; preds = %108, %93
%110 = load i32, i32* %6
%111 = call i32 @listen(i32 %110, i32 10)
br label %112
112: ; preds = %164, %131, %109
br label %113
113: ; preds = %112
br label %114
114: ; preds = %113
%115 = call i32 @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%116 = icmp ne i32 %115, 0
br i1 %116, label %123, label %117
117: ; preds = %114
%118 = load i32, i32* @stderr
%119 = load i32, i32* %9
%120 = call i32 (i32, i8*, ...) @fprintf(i32 %118, i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.2, i64 0, i64 0), i32 %119)
%121 = load i32, i32* @stderr
%122 = call i32 (i32, i8*, ...) @fprintf(i32 %121, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %123
123: ; preds = %117, %114
br label %124
124: ; preds = %123
br label %125
125: ; preds = %124
store i32 12, i32* %12
%126 = load i32, i32* %6
%127 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%128 = call i32 @accept(i32 %126, %struct.sockaddr* %127, i32* %12)
store i32 %128, i32* %7
%129 = load i32, i32* %7
%130 = icmp eq i32 %129, -1
br i1 %130, label %131, label %132
131: ; preds = %125
br label %112
132: ; preds = %125
%133 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%134 = trunc i64 %27 to i32
%135 = load i32, i32* @NI_NUMERICHOST
%136 = call i32 @getnameinfo(%struct.sockaddr* %133, i32 12, i8* %29, i32 %134, i32* null, i32 0, i32 %135)
br label %137
137: ; preds = %132
%138 = call i32 @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%139 = icmp ne i32 %138, 0
br i1 %139, label %145, label %140
140: ; preds = %137
%141 = load i32, i32* @stderr
%142 = call i32 (i32, i8*, ...) @fprintf(i32 %141, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %29)
%143 = load i32, i32* @stderr
%144 = call i32 (i32, i8*, ...) @fprintf(i32 %143, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %145
145: ; preds = %140, %137
br label %146
146: ; preds = %145
br label %147
147: ; preds = %146
%148 = load i32, i32* %7
%149 = call i32* @fdopen(i32 %148, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %149, i32** %15
%150 = load i32*, i32** %15
%151 = call i32 @handle_client(i32* %150)
%152 = load i32*, i32** %15
%153 = call i32 @fclose(i32* %152)
br label %154
154: ; preds = %147
%155 = call i32 @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%156 = icmp ne i32 %155, 0
br i1 %156, label %162, label %157
157: ; preds = %154
%158 = load i32, i32* @stderr
%159 = call i32 (i32, i8*, ...) @fprintf(i32 %158, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8* %29)
%160 = load i32, i32* @stderr
%161 = call i32 (i32, i8*, ...) @fprintf(i32 %160, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %162
162: ; preds = %157, %154
br label %163
163: ; preds = %162
br label %164
164: ; preds = %163
br label %112
}

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"QUIET\00"
@.str.2 = [78 x i8] c"\0A\0A*** Zepto-HTTPD v0.1 - (c)2010 Matthias Goebl ***\0AListening at TCP Port %i.\00"
@.str.3 = [2 x i8] c"\0A\00"
@NI_NUMERICHOST = global i32 0
@.str.4 = [17 x i8] c"Connect from %s.\00"
@.str.5 = [3 x i8] c"r+\00"
@.str.6 = [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 = %118, %88
%92 = call i32 @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%93 = icmp eq i32 %92, 0
br i1 %93, label %94, label %99
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 %118, 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 @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%106 = icmp eq i32 %105, 0
br i1 %106, label %107, label %112
107: ; preds = %102
%108 = load i32, i32* @stderr
%109 = call i32 (i32, i8*, ...) @fprintf(i32 %108, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %41)
%110 = load i32, i32* @stderr
%111 = call i32 (i32, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %112
112: ; preds = %107, %102
%113 = call i32* @fdopen(i32 %100, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%114 = call i32 @handle_client(i32* %113)
%115 = call i32 @fclose(i32* %113)
%116 = call i32 @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%117 = icmp eq i32 %116, 0
br i1 %117, label %119, label %118
118: ; preds = %112, %119, %99
br label %91
119: ; preds = %112
%120 = load i32, i32* @stderr
%121 = call i32 (i32, i8*, ...) @fprintf(i32 %120, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8* %41)
%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 %118
}