#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 {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int pid_t;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EISDIR;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ MSG_MORE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int read(int, char *, int);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int sock, listener;
  struct sockaddr_in addr;
  char buf[10024];
  int bytes_read;
  int port = 10800;
  if (argc >= 2) {
    sscanf(argv[1], "%d", &port);
  }
  listener = socket(AF_INET, SOCK_STREAM, 0);
  if (listener < 0) {
    perror("socket");
    exit(1);
  }
  addr.sin_family = AF_INET;
  addr.sin_port = htons(port);
  addr.sin_addr.s_addr = INADDR_ANY;
  if (bind(listener, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
    perror("bind");
    exit(2);
  }
  listen(listener, 1);
  printf("Locked and loaded!\n");
  printf("Listening %d port\n\n", port);
  while (1) {
    sock = accept(listener, NULL, NULL);
    if (sock < 0) {
      perror("accept");
      exit(3);
    }
    pid_t fork_ans = fork();
    switch (fork_ans) {
    case -1:
      perror("fork");
      break;
    case 0:
      close(listener);
      while (1) {
        bytes_read = recv(sock, buf, 10024, 0);
        if (bytes_read <= 0) {
          break;
        }
        write(1, "New query\n", 10);
        int fd = open(buf, O_RDONLY);
        if (fd == -1) {
          perror("open");
          send(sock, "404 not found", 13, 0);
          puts(buf);
          break;
        }
        int cur = 0;
        while (cur = read(fd, buf, 1024)) {
          int errsv = errno;
          if (errno == EISDIR) {
            send(sock, "Is a directory\n", 15, 0);
          }
          if (cur == -1) {
            perror("read");
            break;
          }
          send(sock, buf, cur, MSG_MORE);
        }
        memset(buf, 0, 10024);
        send(sock, buf, 1024, 0);
        write(1, "Server done\n", 12);
        close(fd);
      }
      close(sock);
      exit(0);
    default:
      close(sock);
    }
  }
  close(listener);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2770,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x2a30,-0x2758(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     1268 <main+0x48>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xda4(%rip),%rsi
lea    -0x2758(%rbp),%rdx
call   10d0 <sscanf@plt>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
mov    0x2d48(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    12a4 <main+0x84>
lea    0xd6e(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    0x2d3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x2758(%rbp),%edi
call   1060 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    0x2d0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
cmp    $0x0,%rax
jge    12fb <main+0xdb>
lea    0xd1e(%rip),%rdi
call   1100 <perror@plt>
mov    $0x2,%edi
call   1120 <exit@plt>
mov    -0x18(%rbp),%edi
mov    $0x1,%esi
call   10c0 <listen@plt>
lea    0xd00(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x2758(%rbp),%esi
lea    0xd00(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x18(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1110 <accept@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    135c <main+0x13c>
lea    0xcea(%rip),%rdi
call   1100 <perror@plt>
mov    $0x3,%edi
call   1120 <exit@plt>
xor    %eax,%eax
call   1130 <fork@plt>
mov    %eax,-0x275c(%rbp)
mov    -0x275c(%rbp),%eax
mov    %eax,-0x276c(%rbp)
sub    $0xffffffff,%eax
je     1396 <main+0x176>
jmp    1383 <main+0x163>
mov    -0x276c(%rbp),%eax
test   %eax,%eax
je     13a7 <main+0x187>
jmp    155a <main+0x33a>
lea    0xca1(%rip),%rdi
call   1100 <perror@plt>
jmp    1562 <main+0x342>
mov    -0x18(%rbp),%edi
call   10a0 <close@plt>
mov    -0x14(%rbp),%edi
lea    -0x2750(%rbp),%rsi
mov    $0x2728,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x2754(%rbp)
cmpl   $0x0,-0x2754(%rbp)
jg     13dd <main+0x1bd>
jmp    154b <main+0x32b>
mov    $0x1,%edi
lea    0xc5a(%rip),%rsi
mov    $0xa,%edx
call   1050 <write@plt>
lea    -0x2750(%rbp),%rdi
mov    0x2bd7(%rip),%rax
mov    (%rax),%esi
call   10f0 <open@plt>
mov    %eax,-0x2760(%rbp)
cmpl   $0xffffffff,-0x2760(%rbp)
jne    144e <main+0x22e>
lea    0xc2c(%rip),%rdi
call   1100 <perror@plt>
mov    -0x14(%rbp),%edi
lea    0xc22(%rip),%rsi
mov    $0xd,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
lea    -0x2750(%rbp),%rdi
call   1040 <puts@plt>
jmp    154b <main+0x32b>
movl   $0x0,-0x2764(%rbp)
mov    -0x2760(%rbp),%edi
lea    -0x2750(%rbp),%rsi
mov    $0x400,%edx
call   10b0 <read@plt>
mov    %eax,-0x2764(%rbp)
cmp    $0x0,%eax
je     14fc <main+0x2dc>
mov    0x2b2b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2768(%rbp)
mov    0x2b1c(%rip),%rax
mov    (%rax),%eax
mov    0x2b43(%rip),%rcx
cmp    (%rcx),%eax
jne    14bb <main+0x29b>
mov    -0x14(%rbp),%edi
lea    0xbb2(%rip),%rsi
mov    $0xf,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
cmpl   $0xffffffff,-0x2764(%rbp)
jne    14d9 <main+0x2b9>
lea    0xba2(%rip),%rdi
call   1100 <perror@plt>
jmp    14fc <main+0x2dc>
mov    -0x14(%rbp),%edi
lea    -0x2750(%rbp),%rsi
mov    -0x2764(%rbp),%edx
mov    0x2ac8(%rip),%rax
mov    (%rax),%ecx
call   1070 <send@plt>
jmp    1458 <main+0x238>
lea    -0x2750(%rbp),%rdi
xor    %esi,%esi
mov    $0x2728,%edx
call   1090 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x2750(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    $0x1,%edi
lea    0xb45(%rip),%rsi
mov    $0xc,%edx
call   1050 <write@plt>
mov    -0x2760(%rbp),%edi
call   10a0 <close@plt>
jmp    13af <main+0x18f>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
xor    %edi,%edi
call   1120 <exit@plt>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
jmp    132a <main+0x10a>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2748,%rsp
movl   $0x2a30,0xc(%rsp)
cmp    $0x2,%edi
jl     1253 <main+0x33>
mov    0x8(%rsi),%rdi
lea    0xdb7(%rip),%rsi
lea    0xc(%rsp),%rdx
call   10d0 <sscanf@plt>
mov    0x2d8e(%rip),%rbx
mov    (%rbx),%edi
mov    0x2d5d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
test   %eax,%eax
jns    1286 <main+0x66>
lea    0xd8c(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    %eax,%ebp
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    0xc(%rsp),%edi
call   1060 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2d2e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   10e0 <bind@plt>
test   %rax,%rax
jns    12d4 <main+0xb4>
lea    0xd45(%rip),%rdi
call   1100 <perror@plt>
mov    $0x2,%edi
call   1120 <exit@plt>
mov    %ebp,%edi
mov    $0x1,%esi
call   10c0 <listen@plt>
lea    0xd88(%rip),%rdi
call   1040 <puts@plt>
mov    0xc(%rsp),%esi
lea    0xd18(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1110 <accept@plt>
test   %eax,%eax
jns    1323 <main+0x103>
lea    0xd0f(%rip),%rdi
call   1100 <perror@plt>
mov    $0x3,%edi
call   1120 <exit@plt>
mov    %eax,%ebx
lea    0xcfe(%rip),%r14
jmp    1351 <main+0x131>
mov    %r14,%rdi
call   1100 <perror@plt>
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1110 <accept@plt>
mov    %eax,%ebx
test   %eax,%eax
js     130d <main+0xed>
xor    %eax,%eax
call   1130 <fork@plt>
cmp    $0xffffffff,%eax
je     132e <main+0x10e>
test   %eax,%eax
je     136a <main+0x14a>
mov    %ebx,%edi
call   10a0 <close@plt>
jmp    1340 <main+0x120>
mov    %ebp,%edi
call   10a0 <close@plt>
lea    0x20(%rsp),%rsi
mov    %ebx,%edi
mov    $0x2728,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    14c6 <main+0x2a6>
lea    0x20(%rsp),%r15
mov    0x2c48(%rip),%r13
mov    0x2c19(%rip),%r12
jmp    1406 <main+0x1e6>
lea    0xcb5(%rip),%rdi
call   1100 <perror@plt>
nopl   (%rax)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x2728,%edx
call   1090 <memset@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    $0x1,%edi
lea    0xc86(%rip),%rsi
mov    $0xc,%edx
call   1050 <write@plt>
mov    %ebp,%edi
call   10a0 <close@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x2728,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    14c6 <main+0x2a6>
mov    $0x1,%edi
lea    0xc1d(%rip),%rsi
mov    $0xa,%edx
call   1050 <write@plt>
mov    0x2bb5(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   10f0 <open@plt>
cmp    $0xffffffff,%eax
je     149b <main+0x27b>
mov    %eax,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x400,%edx
call   10b0 <read@plt>
mov    %eax,%r14d
test   %eax,%eax
je     13b0 <main+0x190>
mov    0x2b4f(%rip),%rax
mov    (%rax),%eax
cmp    0x0(%r13),%eax
jne    147e <main+0x25e>
mov    %ebx,%edi
lea    0xbdb(%rip),%rsi
mov    $0xf,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
cmp    $0xffffffff,%r14d
je     13a1 <main+0x181>
mov    (%r12),%ecx
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1070 <send@plt>
jmp    1440 <main+0x220>
lea    0xb98(%rip),%rdi
call   1100 <perror@plt>
lea    0xb91(%rip),%rsi
mov    %ebx,%edi
mov    $0xd,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
lea    0x20(%rsp),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
call   10a0 <close@plt>
xor    %edi,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [3 x i8] c"%d\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@INADDR_ANY = global i32 0
@.str.2 = [5 x i8] c"bind\00"
@.str.3 = [20 x i8] c"Locked and loaded!\0A\00"
@.str.4 = [20 x i8] c"Listening %d port\0A\0A\00"
@.str.5 = [7 x i8] c"accept\00"
@.str.6 = [5 x i8] c"fork\00"
@.str.7 = [11 x i8] c"New query\0A\00"
@O_RDONLY = global i32 0
@.str.8 = [5 x i8] c"open\00"
@.str.9 = [14 x i8] c"404 not found\00"
@errno = global i32 0
@EISDIR = global i32 0
@.str.10 = [16 x i8] c"Is a directory\0A\00"
@.str.11 = [5 x i8] c"read\00"
@MSG_MORE = global i32 0
@.str.12 = [13 x i8] c"Server done\0A\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 %struct.sockaddr_in
%9 = alloca [10024 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 10800, i32* %11
%16 = load i32, i32* %4
%17 = icmp sge i32 %16, 2
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 @sscanf(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %11)
br label %23
23: ; preds = %18, %2
%24 = load i32, i32* @AF_INET
%25 = load i32, i32* @SOCK_STREAM
%26 = call i32 @socket(i32 %24, i32 %25, i32 0)
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %23
%30 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %23
%33 = load i32, i32* @AF_INET
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %33, i32* %34
%35 = load i32, i32* %11
%36 = call i32 @htons(i32 %35)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %36, i32* %37
%38 = load i32, i32* @INADDR_ANY
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%40 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %39, i32 0, i32 0
store i32 %38, i32* %40
%41 = load i32, i32* %7
%42 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%43 = call i64 @bind(i32 %41, %struct.sockaddr* %42, i32 12)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %32
%46 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%47 = call i32 @exit(i32 2)
unreachable
48: ; preds = %32
%49 = load i32, i32* %7
%50 = call i32 @listen(i32 %49, i32 1)
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%52 = load i32, i32* %11
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %52)
br label %54
54: ; preds = %48, %131
%55 = load i32, i32* %7
%56 = call i32 @accept(i32 %55, i32* null, i32* null)
store i32 %56, i32* %6
%57 = load i32, i32* %6
%58 = icmp slt i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %54
%60 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%61 = call i32 @exit(i32 3)
unreachable
62: ; preds = %54
%63 = call i32 (...) @fork()
store i32 %63, i32* %12
%64 = load i32, i32* %12
switch i32 %64, label %128 [
i32 -1, label %65
i32 0, label %67
]
65: ; preds = %62
%66 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %131
67: ; preds = %62
%68 = load i32, i32* %7
%69 = call i32 @close(i32 %68)
br label %70
70: ; preds = %67, %115
%71 = load i32, i32* %6
%72 = getelementptr inbounds [10024 x i8], [10024 x i8]* %9, i64 0, i64 0
%73 = call i32 @recv(i32 %71, i8* %72, i32 10024, i32 0)
store i32 %73, i32* %10
%74 = load i32, i32* %10
%75 = icmp sle i32 %74, 0
br i1 %75, label %76, label %77
76: ; preds = %70
br label %124
77: ; preds = %70
%78 = call i32 @write(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i32 10)
%79 = getelementptr inbounds [10024 x i8], [10024 x i8]* %9, i64 0, i64 0
%80 = load i32, i32* @O_RDONLY
%81 = call i32 @open(i8* %79, i32 %80)
store i32 %81, i32* %13
%82 = load i32, i32* %13
%83 = icmp eq i32 %82, -1
br i1 %83, label %84, label %90
84: ; preds = %77
%85 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%86 = load i32, i32* %6
%87 = call i32 @send(i32 %86, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0), i32 13, i32 0)
%88 = getelementptr inbounds [10024 x i8], [10024 x i8]* %9, i64 0, i64 0
%89 = call i32 @puts(i8* %88)
br label %124
90: ; preds = %77
store i32 0, i32* %14
br label %91
91: ; preds = %109, %90
%92 = load i32, i32* %13
%93 = getelementptr inbounds [10024 x i8], [10024 x i8]* %9, i64 0, i64 0
%94 = call i32 @read(i32 %92, i8* %93, i32 1024)
store i32 %94, i32* %14
%95 = icmp ne i32 %94, 0
br i1 %95, label %96, label %115
96: ; preds = %91
%97 = load i32, i32* @errno
store i32 %97, i32* %15
%98 = load i32, i32* @errno
%99 = load i32, i32* @EISDIR
%100 = icmp eq i32 %98, %99
br i1 %100, label %101, label %104
101: ; preds = %96
%102 = load i32, i32* %6
%103 = call i32 @send(i32 %102, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0), i32 15, i32 0)
br label %104
104: ; preds = %101, %96
%105 = load i32, i32* %14
%106 = icmp eq i32 %105, -1
br i1 %106, label %107, label %109
107: ; preds = %104
%108 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
br label %115
109: ; preds = %104
%110 = load i32, i32* %6
%111 = getelementptr inbounds [10024 x i8], [10024 x i8]* %9, i64 0, i64 0
%112 = load i32, i32* %14
%113 = load i32, i32* @MSG_MORE
%114 = call i32 @send(i32 %110, i8* %111, i32 %112, i32 %113)
br label %91
115: ; preds = %107, %91
%116 = getelementptr inbounds [10024 x i8], [10024 x i8]* %9, i64 0, i64 0
%117 = call i32 @memset(i8* %116, i32 0, i32 10024)
%118 = load i32, i32* %6
%119 = getelementptr inbounds [10024 x i8], [10024 x i8]* %9, i64 0, i64 0
%120 = call i32 @send(i32 %118, i8* %119, i32 1024, i32 0)
%121 = call i32 @write(i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0), i32 12)
%122 = load i32, i32* %13
%123 = call i32 @close(i32 %122)
br label %70
124: ; preds = %84, %76
%125 = load i32, i32* %6
%126 = call i32 @close(i32 %125)
%127 = call i32 @exit(i32 0)
unreachable
128: ; preds = %62
%129 = load i32, i32* %6
%130 = call i32 @close(i32 %129)
br label %131
131: ; preds = %128, %65
br label %54
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [3 x i8] c"%d\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@INADDR_ANY = global i32 0
@.str.2 = [5 x i8] c"bind\00"
@.str.4 = [20 x i8] c"Listening %d port\0A\0A\00"
@.str.5 = [7 x i8] c"accept\00"
@.str.6 = [5 x i8] c"fork\00"
@.str.7 = [11 x i8] c"New query\0A\00"
@O_RDONLY = global i32 0
@.str.8 = [5 x i8] c"open\00"
@.str.9 = [14 x i8] c"404 not found\00"
@errno = global i32 0
@EISDIR = global i32 0
@.str.10 = [16 x i8] c"Is a directory\0A\00"
@.str.11 = [5 x i8] c"read\00"
@MSG_MORE = global i32 0
@.str.12 = [13 x i8] c"Server done\0A\00"
@str = [19 x i8] c"Locked and loaded!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [10024 x i8]
%5 = alloca i32
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = getelementptr inbounds [10024 x i8], [10024 x i8]* %4, i64 0, i64 0
%8 = bitcast i32* %5 to i8*
store i32 10800, i32* %5
%9 = icmp sgt i32 %0, 1
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
br label %14
14: ; preds = %10, %2
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_STREAM
%17 = call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %14
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %23, i32* %24
%25 = load i32, i32* %5
%26 = call i32 @htons(i32 %25)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %26, i32* %27
%28 = load i32, i32* @INADDR_ANY
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %28, i32* %29
%30 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%31 = call i64 @bind(i32 %17, %struct.sockaddr* %30, i32 12)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %22
%34 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%35 = call i32 @exit(i32 2)
unreachable
36: ; preds = %22
%37 = call i32 @listen(i32 %17, i32 1)
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%39 = load i32, i32* %5
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %39)
%41 = call i32 @accept(i32 %17, i32* null, i32* null)
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %95, %36
%44 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%45 = call i32 @exit(i32 3)
unreachable
46: ; preds = %36, %95
%47 = phi i32 [ %96, %95 ], [ %41, %36 ]
%48 = call i32 (...) @fork()
switch i32 %48, label %93 [
i32 -1, label %49
i32 0, label %51
]
49: ; preds = %46
%50 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %95
51: ; preds = %46
%52 = call i32 @close(i32 %17)
%53 = call i32 @recv(i32 %47, i8* %7, i32 10024, i32 0)
%54 = icmp slt i32 %53, 1
br i1 %54, label %90, label %55
55: ; preds = %51, %83
%56 = call i32 @write(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i32 10)
%57 = load i32, i32* @O_RDONLY
%58 = call i32 @open(i8* %7, i32 %57)
%59 = icmp eq i32 %58, -1
br i1 %59, label %63, label %60
60: ; preds = %55
%61 = call i32 @read(i32 %58, i8* %7, i32 1024)
%62 = icmp eq i32 %61, 0
br i1 %62, label %83, label %67
63: ; preds = %55
%64 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%65 = call i32 @send(i32 %47, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0), i32 13, i32 0)
%66 = call i32 @puts(i8* %7)
br label %90
67: ; preds = %60, %78
%68 = phi i32 [ %81, %78 ], [ %61, %60 ]
%69 = load i32, i32* @errno
%70 = load i32, i32* @EISDIR
%71 = icmp eq i32 %69, %70
br i1 %71, label %72, label %74
72: ; preds = %67
%73 = call i32 @send(i32 %47, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0), i32 15, i32 0)
br label %74
74: ; preds = %72, %67
%75 = icmp eq i32 %68, -1
br i1 %75, label %76, label %78
76: ; preds = %74
%77 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
br label %83
78: ; preds = %74
%79 = load i32, i32* @MSG_MORE
%80 = call i32 @send(i32 %47, i8* %7, i32 %68, i32 %79)
%81 = call i32 @read(i32 %58, i8* %7, i32 1024)
%82 = icmp eq i32 %81, 0
br i1 %82, label %83, label %67
83: ; preds = %78, %60, %76
%84 = call i32 @memset(i8* %7, i32 0, i32 10024)
%85 = call i32 @send(i32 %47, i8* %7, i32 1024, i32 0)
%86 = call i32 @write(i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0), i32 12)
%87 = call i32 @close(i32 %58)
%88 = call i32 @recv(i32 %47, i8* %7, i32 10024, i32 0)
%89 = icmp slt i32 %88, 1
br i1 %89, label %90, label %55
90: ; preds = %83, %51, %63
%91 = call i32 @close(i32 %47)
%92 = call i32 @exit(i32 0)
unreachable
93: ; preds = %46
%94 = call i32 @close(i32 %47)
br label %95
95: ; preds = %93, %49
%96 = call i32 @accept(i32 %17, i32* null, i32* null)
%97 = icmp slt i32 %96, 0
br i1 %97, label %43, label %46
}