#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 socklen_t;
typedef int /*<<< orphan*/ serv_addr;
typedef scalar_t__ pid_t;
typedef int /*<<< orphan*/ cli_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SIGCHLD;
int /*<<< orphan*/ SIGHUP;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, struct sockaddr *, int);
int chdir(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
void *fork();
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ logger(int, char *, ...);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strncmp(char *, char *, int);
int /*<<< orphan*/ web(int, int);
pid_t serveFiles(char *dir, int port) {
  int i, pid, listenfd, socketfd, hit;
  socklen_t length;
  static struct sockaddr_in cli_addr;
  static struct sockaddr_in serv_addr;
  if (!strncmp(dir, "/", 2) || !strncmp(dir, "/etc", 5) ||
      !strncmp(dir, "/bin", 5) || !strncmp(dir, "/lib", 5) ||
      !strncmp(dir, "/tmp", 5) || !strncmp(dir, "/usr", 5) ||
      !strncmp(dir, "/dev", 5) || !strncmp(dir, "/sbin", 6)) {
    (void)printf("ERROR: Bad top directory %s, see nweb -?\n", dir);
    exit(3);
  }
  if (chdir(dir) == -1) {
    (void)printf("ERROR: Can't Change to directory %s\n", dir);
    exit(4);
  }
  pid_t childPid = fork();
  if (childPid != 0) {
    return childPid;
  }
  (void)signal(SIGCHLD, SIG_IGN);
  (void)signal(SIGHUP, SIG_IGN);
  for (i = 0; i < 32; i++)
    (void)close(i);
  logger(44, "nweb starting", port, getpid());
  if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
    logger(42, "system call", "socket", 0);
  if (port < 0 || port > 60000)
    logger(42, "Invalid port number (try 1->60000)", port, 0);
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  serv_addr.sin_port = htons(port);
  if (bind(listenfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
    logger(42, "system call", "bind", 0);
  if (listen(listenfd, 64) < 0)
    logger(42, "system call", "listen", 0);
  for (hit = 1;; hit++) {
    length = sizeof(cli_addr);
    if ((socketfd = accept(listenfd, (struct sockaddr *)&cli_addr, &length)) <
        0)
      logger(42, "system call", "accept", 0);
    if ((pid = fork()) < 0) {
      logger(42, "system call", "fork", 0);
    } else {
      if (pid == 0) {
        (void)close(listenfd);
        web(socketfd, hit);
      } else {
        (void)close(socketfd);
      }
    }
  }
}


x86 assembly (clang, -O0):
<serveFiles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xde6(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
je     12ff <serveFiles+0xff>
mov    -0x8(%rbp),%rdi
lea    0xdca(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
je     12ff <serveFiles+0xff>
mov    -0x8(%rbp),%rdi
lea    0xdb1(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
je     12ff <serveFiles+0xff>
mov    -0x8(%rbp),%rdi
lea    0xd98(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
je     12ff <serveFiles+0xff>
mov    -0x8(%rbp),%rdi
lea    0xd7f(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
je     12ff <serveFiles+0xff>
mov    -0x8(%rbp),%rdi
lea    0xd66(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
je     12ff <serveFiles+0xff>
mov    -0x8(%rbp),%rdi
lea    0xd4d(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
je     12ff <serveFiles+0xff>
mov    -0x8(%rbp),%rdi
lea    0xd34(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1319 <serveFiles+0x119>
mov    -0x8(%rbp),%rsi
lea    0xd1c(%rip),%rdi
call   1080 <printf@plt>
mov    $0x3,%edi
call   1100 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1060 <chdir@plt>
cmp    $0xffffffff,%eax
jne    1345 <serveFiles+0x145>
mov    -0x8(%rbp),%rsi
lea    0xd1a(%rip),%rdi
call   1080 <printf@plt>
mov    $0x4,%edi
call   1100 <exit@plt>
mov    $0x0,%al
call   1110 <fork@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1365 <serveFiles+0x165>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret
mov    0x2c64(%rip),%rax
mov    (%rax),%edi
mov    0x2c53(%rip),%rax
mov    (%rax),%esi
call   10b0 <signal@plt>
mov    0x2c6d(%rip),%rax
mov    (%rax),%edi
mov    0x2c3c(%rip),%rax
mov    (%rax),%esi
call   10b0 <signal@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x20,-0x10(%rbp)
jge    13ba <serveFiles+0x1ba>
mov    -0x10(%rbp),%edi
call   10a0 <close@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    139a <serveFiles+0x19a>
mov    -0xc(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    -0x34(%rbp),%edx
mov    %eax,%ecx
mov    $0x2c,%edi
lea    0xc9d(%rip),%rsi
mov    $0x0,%al
call   10c0 <logger@plt>
mov    0x2bfa(%rip),%rax
mov    (%rax),%edi
mov    0x2bc9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1420 <serveFiles+0x220>
mov    $0x2a,%edi
lea    0xc73(%rip),%rsi
lea    0xc78(%rip),%rdx
xor    %ecx,%ecx
mov    $0x0,%al
call   10c0 <logger@plt>
cmpl   $0x0,-0xc(%rbp)
jl     1437 <serveFiles+0x237>
cmpl   $0xea60,-0xc(%rbp)
jle    144f <serveFiles+0x24f>
mov    -0xc(%rbp),%edx
mov    $0x2a,%edi
lea    0xc50(%rip),%rsi
xor    %ecx,%ecx
mov    $0x0,%al
call   10c0 <logger@plt>
mov    0x2b8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x2c5a(%rip)
mov    0x2b73(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,0x2c42(%rip)
mov    -0xc(%rbp),%edi
call   1070 <htons@plt>
mov    %eax,0x2c30(%rip)
mov    -0x18(%rbp),%edi
lea    0x2c26(%rip),%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
cmp    $0x0,%rax
jge    14ba <serveFiles+0x2ba>
mov    $0x2a,%edi
lea    0xbd9(%rip),%rsi
lea    0xc08(%rip),%rdx
xor    %ecx,%ecx
mov    $0x0,%al
call   10c0 <logger@plt>
mov    -0x18(%rbp),%edi
mov    $0x40,%esi
call   10d0 <listen@plt>
cmp    $0x0,%rax
jge    14ed <serveFiles+0x2ed>
mov    $0x2a,%edi
lea    0xba6(%rip),%rsi
lea    0xbda(%rip),%rdx
xor    %ecx,%ecx
mov    $0x0,%al
call   10c0 <logger@plt>
movl   $0x1,-0x20(%rbp)
movl   $0xc,-0x24(%rbp)
mov    -0x18(%rbp),%edi
lea    0x2b9f(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   10f0 <accept@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1536 <serveFiles+0x336>
mov    $0x2a,%edi
lea    0xb5d(%rip),%rsi
lea    0xb98(%rip),%rdx
xor    %ecx,%ecx
mov    $0x0,%al
call   10c0 <logger@plt>
mov    $0x0,%al
call   1110 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    156a <serveFiles+0x36a>
mov    $0x2a,%edi
lea    0xb2e(%rip),%rsi
lea    0xb70(%rip),%rdx
xor    %ecx,%ecx
mov    $0x0,%al
call   10c0 <logger@plt>
jmp    1599 <serveFiles+0x399>
cmpl   $0x0,-0x14(%rbp)
jne    158c <serveFiles+0x38c>
mov    -0x18(%rbp),%edi
call   10a0 <close@plt>
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1040 <web@plt>
jmp    1594 <serveFiles+0x394>
mov    -0x1c(%rbp),%edi
call   10a0 <close@plt>
jmp    1599 <serveFiles+0x399>
jmp    159e <serveFiles+0x39e>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    14f4 <serveFiles+0x2f4>

x86 assembly (clang, -O2):
<serveFiles>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbp
lea    0xde8(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1644 <serveFiles+0x444>
lea    0xdd1(%rip),%rsi
mov    %rbp,%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1644 <serveFiles+0x444>
lea    0xdba(%rip),%rsi
mov    %rbp,%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1644 <serveFiles+0x444>
lea    0xda3(%rip),%rsi
mov    %rbp,%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1644 <serveFiles+0x444>
lea    0xd8c(%rip),%rsi
mov    %rbp,%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1644 <serveFiles+0x444>
lea    0xd75(%rip),%rsi
mov    %rbp,%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1644 <serveFiles+0x444>
lea    0xd5e(%rip),%rsi
mov    %rbp,%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1644 <serveFiles+0x444>
lea    0xd47(%rip),%rsi
mov    %rbp,%rdi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1644 <serveFiles+0x444>
mov    %rbp,%rdi
call   1060 <chdir@plt>
cmp    $0xffffffff,%eax
je     165d <serveFiles+0x45d>
xor    %eax,%eax
call   1110 <fork@plt>
test   %rax,%rax
je     131a <serveFiles+0x11a>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2caf(%rip),%rax
mov    (%rax),%edi
mov    0x2c9e(%rip),%rbx
mov    (%rbx),%esi
call   10b0 <signal@plt>
mov    0x2cb8(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
call   10b0 <signal@plt>
xor    %edi,%edi
call   10a0 <close@plt>
mov    $0x1,%edi
call   10a0 <close@plt>
mov    $0x2,%edi
call   10a0 <close@plt>
mov    $0x3,%edi
call   10a0 <close@plt>
mov    $0x4,%edi
call   10a0 <close@plt>
mov    $0x5,%edi
call   10a0 <close@plt>
mov    $0x6,%edi
call   10a0 <close@plt>
mov    $0x7,%edi
call   10a0 <close@plt>
mov    $0x8,%edi
call   10a0 <close@plt>
mov    $0x9,%edi
call   10a0 <close@plt>
mov    $0xa,%edi
call   10a0 <close@plt>
mov    $0xb,%edi
call   10a0 <close@plt>
mov    $0xc,%edi
call   10a0 <close@plt>
mov    $0xd,%edi
call   10a0 <close@plt>
mov    $0xe,%edi
call   10a0 <close@plt>
mov    $0xf,%edi
call   10a0 <close@plt>
mov    $0x10,%edi
call   10a0 <close@plt>
mov    $0x11,%edi
call   10a0 <close@plt>
mov    $0x12,%edi
call   10a0 <close@plt>
mov    $0x13,%edi
call   10a0 <close@plt>
mov    $0x14,%edi
call   10a0 <close@plt>
mov    $0x15,%edi
call   10a0 <close@plt>
mov    $0x16,%edi
call   10a0 <close@plt>
mov    $0x17,%edi
call   10a0 <close@plt>
mov    $0x18,%edi
call   10a0 <close@plt>
mov    $0x19,%edi
call   10a0 <close@plt>
mov    $0x1a,%edi
call   10a0 <close@plt>
mov    $0x1b,%edi
call   10a0 <close@plt>
mov    $0x1c,%edi
call   10a0 <close@plt>
mov    $0x1d,%edi
call   10a0 <close@plt>
mov    $0x1e,%edi
call   10a0 <close@plt>
mov    $0x1f,%edi
call   10a0 <close@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xbe9(%rip),%rsi
mov    $0x2c,%edi
mov    %r14d,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   10c0 <logger@plt>
mov    0x2b3c(%rip),%rbx
mov    (%rbx),%edi
mov    0x2b0b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1616 <serveFiles+0x416>
cmp    $0xea61,%r14d
jb     14e1 <serveFiles+0x2e1>
lea    0xbc6(%rip),%rsi
mov    $0x2a,%edi
mov    %r14d,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   10c0 <logger@plt>
mov    (%rbx),%eax
mov    %eax,0x2bcf(%rip)
lea    0x2bc0(%rip),%rbx
mov    0x2ae1(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,0x2bb0(%rip)
mov    %r14d,%edi
call   1070 <htons@plt>
mov    %eax,0x2b9e(%rip)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
test   %rax,%rax
jns    1542 <serveFiles+0x342>
lea    0xb56(%rip),%rsi
lea    0xb85(%rip),%rdx
mov    $0x2a,%edi
xor    %ecx,%ecx
xor    %eax,%eax
call   10c0 <logger@plt>
mov    %ebp,%edi
mov    $0x40,%esi
call   10d0 <listen@plt>
test   %rax,%rax
jns    156f <serveFiles+0x36f>
lea    0xb29(%rip),%rsi
lea    0xb5d(%rip),%rdx
mov    $0x2a,%edi
xor    %ecx,%ecx
xor    %eax,%eax
call   10c0 <logger@plt>
mov    $0x1,%ebx
lea    0x2b29(%rip),%r14
lea    0x4(%rsp),%r15
lea    0xafc(%rip),%r12
jmp    15ab <serveFiles+0x3ab>
nopl   0x0(%rax)
mov    $0x2a,%edi
mov    %r12,%rsi
lea    0xb2d(%rip),%rdx
xor    %ecx,%ecx
xor    %eax,%eax
call   10c0 <logger@plt>
add    $0x1,%ebx
movl   $0xc,0x4(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   10f0 <accept@plt>
mov    %eax,%r13d
test   %eax,%eax
jns    15df <serveFiles+0x3df>
mov    $0x2a,%edi
mov    %r12,%rsi
lea    0xaef(%rip),%rdx
xor    %ecx,%ecx
xor    %eax,%eax
call   10c0 <logger@plt>
xor    %eax,%eax
call   1110 <fork@plt>
test   %eax,%eax
js     1590 <serveFiles+0x390>
je     1600 <serveFiles+0x400>
mov    %r13d,%edi
call   10a0 <close@plt>
add    $0x1,%ebx
jmp    15ab <serveFiles+0x3ab>
nopl   0x0(%rax)
mov    %ebp,%edi
call   10a0 <close@plt>
mov    %r13d,%edi
mov    %ebx,%esi
call   1040 <web@plt>
add    $0x1,%ebx
jmp    15ab <serveFiles+0x3ab>
lea    0xa66(%rip),%rsi
lea    0xa6b(%rip),%rdx
mov    $0x2a,%edi
xor    %ecx,%ecx
xor    %eax,%eax
call   10c0 <logger@plt>
cmp    $0xea61,%r14d
jae    14c9 <serveFiles+0x2c9>
jmp    14e1 <serveFiles+0x2e1>
lea    0x9db(%rip),%rdi
mov    %rbp,%rsi
call   1080 <printf@plt>
mov    $0x3,%edi
call   1100 <exit@plt>
lea    0x9ec(%rip),%rdi
mov    %rbp,%rsi
call   1080 <printf@plt>
mov    $0x4,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@serveFiles.cli_addr = internal global %struct.sockaddr_in zeroinitializer
@serveFiles.serv_addr = internal global %struct.sockaddr_in zeroinitializer
@.str = [2 x i8] c"/\00"
@.str.1 = [5 x i8] c"/etc\00"
@.str.2 = [5 x i8] c"/bin\00"
@.str.3 = [5 x i8] c"/lib\00"
@.str.4 = [5 x i8] c"/tmp\00"
@.str.5 = [5 x i8] c"/usr\00"
@.str.6 = [5 x i8] c"/dev\00"
@.str.7 = [6 x i8] c"/sbin\00"
@.str.8 = [42 x i8] c"ERROR: Bad top directory %s, see nweb -?\0A\00"
@.str.9 = [37 x i8] c"ERROR: Can't Change to directory %s\0A\00"
@SIGCHLD = global i32 0
@SIG_IGN = global i32 0
@SIGHUP = global i32 0
@.str.10 = [14 x i8] c"nweb starting\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.11 = [12 x i8] c"system call\00"
@.str.12 = [7 x i8] c"socket\00"
@.str.13 = [35 x i8] c"Invalid port number (try 1->60000)\00"
@INADDR_ANY = global i32 0
@.str.14 = [5 x i8] c"bind\00"
@.str.15 = [7 x i8] c"listen\00"
@.str.16 = [7 x i8] c"accept\00"
@.str.17 = [5 x i8] c"fork\00"
define i64 @serveFiles(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
store i8* %0, i8** %3
store i32 %1, i32* %4
%12 = load i8*, i8** %3
%13 = call i32 @strncmp(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 2)
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %43
15: ; preds = %2
%16 = load i8*, i8** %3
%17 = call i32 @strncmp(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 5)
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %43
19: ; preds = %15
%20 = load i8*, i8** %3
%21 = call i32 @strncmp(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 5)
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %43
23: ; preds = %19
%24 = load i8*, i8** %3
%25 = call i32 @strncmp(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 5)
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %43
27: ; preds = %23
%28 = load i8*, i8** %3
%29 = call i32 @strncmp(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 5)
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %43
31: ; preds = %27
%32 = load i8*, i8** %3
%33 = call i32 @strncmp(i8* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 5)
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %43
35: ; preds = %31
%36 = load i8*, i8** %3
%37 = call i32 @strncmp(i8* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 5)
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %35
%40 = load i8*, i8** %3
%41 = call i32 @strncmp(i8* %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 6)
%42 = icmp ne i32 %41, 0
br i1 %42, label %47, label %43
43: ; preds = %39, %35, %31, %27, %23, %19, %15, %2
%44 = load i8*, i8** %3
%45 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.8, i64 0, i64 0), i8* %44)
%46 = call i32 @exit(i32 3)
unreachable
47: ; preds = %39
%48 = load i8*, i8** %3
%49 = call i32 @chdir(i8* %48)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %55
51: ; preds = %47
%52 = load i8*, i8** %3
%53 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.9, i64 0, i64 0), i8* %52)
%54 = call i32 @exit(i32 4)
unreachable
55: ; preds = %47
%56 = call i8* (...) @fork()
%57 = ptrtoint i8* %56 to i64
store i64 %57, i64* %11
%58 = load i64, i64* %11
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %55
%61 = load i64, i64* %11
ret i64 %61
62: ; preds = %55
%63 = load i32, i32* @SIGCHLD
%64 = load i32, i32* @SIG_IGN
%65 = call i32 @signal(i32 %63, i32 %64)
%66 = load i32, i32* @SIGHUP
%67 = load i32, i32* @SIG_IGN
%68 = call i32 @signal(i32 %66, i32 %67)
store i32 0, i32* %5
br label %69
69: ; preds = %75, %62
%70 = load i32, i32* %5
%71 = icmp slt i32 %70, 32
br i1 %71, label %72, label %78
72: ; preds = %69
%73 = load i32, i32* %5
%74 = call i32 @close(i32 %73)
br label %75
75: ; preds = %72
%76 = load i32, i32* %5
%77 = add nsw i32 %76, 1
store i32 %77, i32* %5
br label %69
78: ; preds = %69
%79 = load i32, i32* %4
%80 = call i32 (...) @getpid()
%81 = call i32 (i32, i8*, ...) @logger(i32 44, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0), i32 %79, i32 %80)
%82 = load i32, i32* @AF_INET
%83 = load i32, i32* @SOCK_STREAM
%84 = call i32 @socket(i32 %82, i32 %83, i32 0)
store i32 %84, i32* %7
%85 = icmp slt i32 %84, 0
br i1 %85, label %86, label %88
86: ; preds = %78
%87 = call i32 (i32, i8*, ...) @logger(i32 42, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0), i32 0)
br label %88
88: ; preds = %86, %78
%89 = load i32, i32* %4
%90 = icmp slt i32 %89, 0
br i1 %90, label %94, label %91
91: ; preds = %88
%92 = load i32, i32* %4
%93 = icmp sgt i32 %92, 60000
br i1 %93, label %94, label %97
94: ; preds = %91, %88
%95 = load i32, i32* %4
%96 = call i32 (i32, i8*, ...) @logger(i32 42, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.13, i64 0, i64 0), i32 %95, i32 0)
br label %97
97: ; preds = %94, %91
%98 = load i32, i32* @AF_INET
store i32 %98, i32* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @serveFiles.serv_addr, i32 0, i32 2)
%99 = load i32, i32* @INADDR_ANY
%100 = call i32 @htonl(i32 %99)
store i32 %100, i32* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @serveFiles.serv_addr, i32 0, i32 1, i32 0)
%101 = load i32, i32* %4
%102 = call i32 @htons(i32 %101)
store i32 %102, i32* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @serveFiles.serv_addr, i32 0, i32 0)
%103 = load i32, i32* %7
%104 = call i64 @bind(i32 %103, %struct.sockaddr* bitcast (%struct.sockaddr_in* @serveFiles.serv_addr to %struct.sockaddr*), i32 12)
%105 = icmp slt i64 %104, 0
br i1 %105, label %106, label %108
106: ; preds = %97
%107 = call i32 (i32, i8*, ...) @logger(i32 42, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0), i32 0)
br label %108
108: ; preds = %106, %97
%109 = load i32, i32* %7
%110 = call i64 @listen(i32 %109, i32 64)
%111 = icmp slt i64 %110, 0
br i1 %111, label %112, label %114
112: ; preds = %108
%113 = call i32 (i32, i8*, ...) @logger(i32 42, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.15, i64 0, i64 0), i32 0)
br label %114
114: ; preds = %112, %108
store i32 1, i32* %9
br label %115
115: ; preds = %141, %114
store i32 12, i32* %10
%116 = load i32, i32* %7
%117 = call i32 @accept(i32 %116, %struct.sockaddr* bitcast (%struct.sockaddr_in* @serveFiles.cli_addr to %struct.sockaddr*), i32* %10)
store i32 %117, i32* %8
%118 = icmp slt i32 %117, 0
br i1 %118, label %119, label %121
119: ; preds = %115
%120 = call i32 (i32, i8*, ...) @logger(i32 42, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.16, i64 0, i64 0), i32 0)
br label %121
121: ; preds = %119, %115
%122 = call i8* (...) @fork()
%123 = ptrtoint i8* %122 to i32
store i32 %123, i32* %6
%124 = icmp slt i32 %123, 0
br i1 %124, label %125, label %127
125: ; preds = %121
%126 = call i32 (i32, i8*, ...) @logger(i32 42, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.17, i64 0, i64 0), i32 0)
br label %140
127: ; preds = %121
%128 = load i32, i32* %6
%129 = icmp eq i32 %128, 0
br i1 %129, label %130, label %136
130: ; preds = %127
%131 = load i32, i32* %7
%132 = call i32 @close(i32 %131)
%133 = load i32, i32* %8
%134 = load i32, i32* %9
%135 = call i32 @web(i32 %133, i32 %134)
br label %139
136: ; preds = %127
%137 = load i32, i32* %8
%138 = call i32 @close(i32 %137)
br label %139
139: ; preds = %136, %130
br label %140
140: ; preds = %139, %125
br label %141
141: ; preds = %140
%142 = load i32, i32* %9
%143 = add nsw i32 %142, 1
store i32 %143, i32* %9
br label %115
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@serveFiles.cli_addr = internal global %struct.sockaddr_in zeroinitializer
@serveFiles.serv_addr = internal global %struct.sockaddr_in zeroinitializer
@.str = [2 x i8] c"/\00"
@.str.1 = [5 x i8] c"/etc\00"
@.str.2 = [5 x i8] c"/bin\00"
@.str.3 = [5 x i8] c"/lib\00"
@.str.4 = [5 x i8] c"/tmp\00"
@.str.5 = [5 x i8] c"/usr\00"
@.str.6 = [5 x i8] c"/dev\00"
@.str.7 = [6 x i8] c"/sbin\00"
@.str.8 = [42 x i8] c"ERROR: Bad top directory %s, see nweb -?\0A\00"
@.str.9 = [37 x i8] c"ERROR: Can't Change to directory %s\0A\00"
@SIGCHLD = global i32 0
@SIG_IGN = global i32 0
@SIGHUP = global i32 0
@.str.10 = [14 x i8] c"nweb starting\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.11 = [12 x i8] c"system call\00"
@.str.12 = [7 x i8] c"socket\00"
@.str.13 = [35 x i8] c"Invalid port number (try 1->60000)\00"
@INADDR_ANY = global i32 0
@.str.14 = [5 x i8] c"bind\00"
@.str.15 = [7 x i8] c"listen\00"
@.str.16 = [7 x i8] c"accept\00"
@.str.17 = [5 x i8] c"fork\00"
define i64 @serveFiles(i8* %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 2)
%6 = icmp eq i32 %5, 0
br i1 %6, label %28, label %7
7: ; preds = %2
%8 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 5)
%9 = icmp eq i32 %8, 0
br i1 %9, label %28, label %10
10: ; preds = %7
%11 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 5)
%12 = icmp eq i32 %11, 0
br i1 %12, label %28, label %13
13: ; preds = %10
%14 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 5)
%15 = icmp eq i32 %14, 0
br i1 %15, label %28, label %16
16: ; preds = %13
%17 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 5)
%18 = icmp eq i32 %17, 0
br i1 %18, label %28, label %19
19: ; preds = %16
%20 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 5)
%21 = icmp eq i32 %20, 0
br i1 %21, label %28, label %22
22: ; preds = %19
%23 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 5)
%24 = icmp eq i32 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 6)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25, %22, %19, %16, %13, %10, %7, %2
%29 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.8, i64 0, i64 0), i8* %0)
%30 = tail call i32 @exit(i32 3)
unreachable
31: ; preds = %25
%32 = tail call i32 @chdir(i8* %0)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.9, i64 0, i64 0), i8* %0)
%36 = tail call i32 @exit(i32 4)
unreachable
37: ; preds = %31
%38 = tail call i8* (...) @fork()
%39 = icmp eq i8* %38, null
br i1 %39, label %42, label %40
40: ; preds = %37
%41 = ptrtoint i8* %38 to i64
ret i64 %41
42: ; preds = %37
%43 = load i32, i32* @SIGCHLD
%44 = load i32, i32* @SIG_IGN
%45 = tail call i32 @signal(i32 %43, i32 %44)
%46 = load i32, i32* @SIGHUP
%47 = load i32, i32* @SIG_IGN
%48 = tail call i32 @signal(i32 %46, i32 %47)
%49 = tail call i32 @close(i32 0)
%50 = tail call i32 @close(i32 1)
%51 = tail call i32 @close(i32 2)
%52 = tail call i32 @close(i32 3)
%53 = tail call i32 @close(i32 4)
%54 = tail call i32 @close(i32 5)
%55 = tail call i32 @close(i32 6)
%56 = tail call i32 @close(i32 7)
%57 = tail call i32 @close(i32 8)
%58 = tail call i32 @close(i32 9)
%59 = tail call i32 @close(i32 10)
%60 = tail call i32 @close(i32 11)
%61 = tail call i32 @close(i32 12)
%62 = tail call i32 @close(i32 13)
%63 = tail call i32 @close(i32 14)
%64 = tail call i32 @close(i32 15)
%65 = tail call i32 @close(i32 16)
%66 = tail call i32 @close(i32 17)
%67 = tail call i32 @close(i32 18)
%68 = tail call i32 @close(i32 19)
%69 = tail call i32 @close(i32 20)
%70 = tail call i32 @close(i32 21)
%71 = tail call i32 @close(i32 22)
%72 = tail call i32 @close(i32 23)
%73 = tail call i32 @close(i32 24)
%74 = tail call i32 @close(i32 25)
%75 = tail call i32 @close(i32 26)
%76 = tail call i32 @close(i32 27)
%77 = tail call i32 @close(i32 28)
%78 = tail call i32 @close(i32 29)
%79 = tail call i32 @close(i32 30)
%80 = tail call i32 @close(i32 31)
%81 = tail call i32 (...) @getpid()
%82 = tail call i32 (i32, i8*, ...) @logger(i32 44, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0), i32 %1, i32 %81)
%83 = load i32, i32* @AF_INET
%84 = load i32, i32* @SOCK_STREAM
%85 = tail call i32 @socket(i32 %83, i32 %84, i32 0)
%86 = icmp slt i32 %85, 0
br i1 %86, label %87, label %89
87: ; preds = %42
%88 = tail call i32 (i32, i8*, ...) @logger(i32 42, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0), i32 0)
br label %89
89: ; preds = %87, %42
%90 = icmp ugt i32 %1, 60000
br i1 %90, label %91, label %93
91: ; preds = %89
%92 = tail call i32 (i32, i8*, ...) @logger(i32 42, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.13, i64 0, i64 0), i32 %1, i32 0)
br label %93
93: ; preds = %89, %91
%94 = load i32, i32* @AF_INET
store i32 %94, i32* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @serveFiles.serv_addr, i64 0, i32 2)
%95 = load i32, i32* @INADDR_ANY
%96 = tail call i32 @htonl(i32 %95)
store i32 %96, i32* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @serveFiles.serv_addr, i64 0, i32 1, i32 0)
%97 = tail call i32 @htons(i32 %1)
store i32 %97, i32* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @serveFiles.serv_addr, i64 0, i32 0)
%98 = tail call i64 @bind(i32 %85, %struct.sockaddr* bitcast (%struct.sockaddr_in* @serveFiles.serv_addr to %struct.sockaddr*), i32 12)
%99 = icmp slt i64 %98, 0
br i1 %99, label %100, label %102
100: ; preds = %93
%101 = tail call i32 (i32, i8*, ...) @logger(i32 42, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0), i32 0)
br label %102
102: ; preds = %100, %93
%103 = tail call i64 @listen(i32 %85, i32 64)
%104 = icmp slt i64 %103, 0
br i1 %104, label %105, label %107
105: ; preds = %102
%106 = tail call i32 (i32, i8*, ...) @logger(i32 42, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.15, i64 0, i64 0), i32 0)
br label %107
107: ; preds = %105, %102
br label %108
108: ; preds = %107, %128
%109 = phi i32 [ %129, %128 ], [ 1, %107 ]
store i32 12, i32* %3
%110 = call i32 @accept(i32 %85, %struct.sockaddr* bitcast (%struct.sockaddr_in* @serveFiles.cli_addr to %struct.sockaddr*), i32* %3)
%111 = icmp slt i32 %110, 0
br i1 %111, label %112, label %114
112: ; preds = %108
%113 = call i32 (i32, i8*, ...) @logger(i32 42, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.16, i64 0, i64 0), i32 0)
br label %114
114: ; preds = %112, %108
%115 = call i8* (...) @fork()
%116 = ptrtoint i8* %115 to i64
%117 = trunc i64 %116 to i32
%118 = icmp slt i32 %117, 0
br i1 %118, label %119, label %121
119: ; preds = %114
%120 = call i32 (i32, i8*, ...) @logger(i32 42, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.17, i64 0, i64 0), i32 0)
br label %128
121: ; preds = %114
%122 = icmp eq i32 %117, 0
br i1 %122, label %123, label %126
123: ; preds = %121
%124 = call i32 @close(i32 %85)
%125 = call i32 @web(i32 %110, i32 %109)
br label %128
126: ; preds = %121
%127 = call i32 @close(i32 %110)
br label %128
128: ; preds = %119, %126, %123
%129 = add nuw nsw i32 %109, 1
br label %108
}