#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__ {
  void *s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  void *sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ my_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ antp_handleRequest(int, char *);
scalar_t__ antp_validateAddr(struct sockaddr_in);
int atoi(char *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int fork();
void *htons(int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ setlinebuf(int /*<<< orphan*/);
int /*<<< orphan*/ setpgid(int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int wait(int /*<<< orphan*/ *);
void main(int argc, char *argv[]) {
  int sockfd;
  struct sockaddr_in my_addr;
  int MyPort;
  char BaseDir[256];
  int pid;
  setlinebuf(stdout);
  if (argc != 3) {
    printf("Usage: %s <Port> <BaseDir>\n	Starts server which listens to "
           "port <Port> and handles %s requests\n	for files in the "
           "directory <BaseDir>\n",
           argv[0], "ANTP/1.0");
    exit(0);
  }
  MyPort = atoi(argv[1]);
  if (strlen(argv[2]) > 256 - 11) {
    printf("Usage: %s <Port> <BaseDir>\n	<BaseDir> to long (%d "
           "characters max)\n",
           argv[0], 256 - 11);
    exit(1);
  }
  strcpy(BaseDir, argv[2]);
  if (BaseDir[strlen(BaseDir) - 1] != '/')
    strcat(BaseDir, "/");
  if (MyPort < 0) {
    printf("Usage: %s <Port> <BaseDir>\n	Invalid <Port>\n", argv[0]);
    exit(1);
  }
  printf("server: starting %s %d %s\n", argv[0], MyPort, BaseDir);
  close(0);
  ;
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    ;
    exit(1);
  };
  memset(&my_addr, 0, sizeof(my_addr));
  my_addr.sin_family = AF_INET;
  my_addr.sin_port = htons(MyPort);
  my_addr.sin_addr.s_addr = htons(INADDR_ANY);
  if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof(my_addr)) < 0) {
    ;
    exit(1);
  };
  if (listen(sockfd, 5) < 0) {
    ;
    exit(1);
  }
  while (1) {
    int newsock;
    struct sockaddr_in client_addr;
    int client_addrlen;
    ;
    newsock = accept(sockfd, (struct sockaddr *)&client_addr, &client_addrlen);
    if (newsock < 0) {
      ;
      exit(1);
    };
    if (antp_validateAddr(client_addr)) {
      switch (pid = fork()) {
      case -1:;
        exit(1);
      case 0:
        close(sockfd);
        if (setpgid(0, 0) != 0) {
          ;
          exit(1);
        }
        close(1);
        close(2);
        switch (pid = fork()) {
        case -1:
          exit(1);
        case 0:
          break;
        default:
          exit(0);
        }
        antp_handleRequest(newsock, BaseDir);
        close(newsock);
        exit(0);
        break;
      default:
        close(newsock);
        if (wait(NULL) != pid) {
          ;
          exit(1);
        }
        break;
      }
    } else {
      close(newsock);
      ;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x190,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
call   1070 <setlinebuf@plt>
cmpl   $0x3,-0x4(%rbp)
je     127d <main+0x4d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd98(%rip),%rdi
lea    0xe17(%rip),%rdx
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   1120 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <strlen@plt>
cmp    $0xf5,%eax
jle    12c9 <main+0x99>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xddc(%rip),%rdi
mov    $0xf5,%edx
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
lea    -0x140(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1030 <strcpy@plt>
lea    -0x140(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x140(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
je     1312 <main+0xe2>
lea    -0x140(%rbp),%rdi
lea    0xdc5(%rip),%rsi
call   1100 <strcat@plt>
cmpl   $0x0,-0x34(%rbp)
jge    133b <main+0x10b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x34(%rbp),%edx
lea    -0x140(%rbp),%rcx
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   1090 <close@plt>
mov    0x2c80(%rip),%rax
mov    (%rax),%edi
mov    0x2c5f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1390 <main+0x160>
mov    $0x1,%edi
call   1120 <exit@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1080 <memset@plt>
mov    0x2c41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x34(%rbp),%edi
call   1050 <htons@plt>
mov    %rax,-0x28(%rbp)
mov    0x2c21(%rip),%rax
mov    (%rax),%edi
call   1050 <htons@plt>
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x18,%edx
call   10c0 <bind@plt>
cmp    $0x0,%rax
jge    13ef <main+0x1bf>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
cmp    $0x0,%rax
jge    1410 <main+0x1e0>
mov    $0x1,%edi
call   1120 <exit@plt>
jmp    1415 <main+0x1e5>
mov    -0x14(%rbp),%edi
lea    -0x160(%rbp),%rsi
lea    -0x164(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,-0x148(%rbp)
cmpl   $0x0,-0x148(%rbp)
jge    1448 <main+0x218>
mov    $0x1,%edi
call   1120 <exit@plt>
lea    -0x160(%rbp),%rax
mov    (%rax),%rcx
mov    %rcx,(%rsp)
mov    0x8(%rax),%rcx
mov    %rcx,0x8(%rsp)
mov    0x10(%rax),%rax
mov    %rax,0x10(%rsp)
call   10d0 <antp_validateAddr@plt>
cmp    $0x0,%rax
je     1593 <main+0x363>
xor    %eax,%eax
call   1140 <fork@plt>
mov    %eax,-0x144(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x168(%rbp)
sub    $0xffffffff,%eax
je     14ad <main+0x27d>
jmp    149a <main+0x26a>
mov    -0x168(%rbp),%eax
test   %eax,%eax
je     14b7 <main+0x287>
jmp    155f <main+0x32f>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
xor    %esi,%esi
mov    %esi,%edi
call   1110 <setpgid@plt>
cmp    $0x0,%eax
je     14db <main+0x2ab>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    $0x1,%edi
call   1090 <close@plt>
mov    $0x2,%edi
call   1090 <close@plt>
xor    %eax,%eax
call   1140 <fork@plt>
mov    %eax,-0x144(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x16c(%rbp)
sub    $0xffffffff,%eax
je     1525 <main+0x2f5>
jmp    1512 <main+0x2e2>
mov    -0x16c(%rbp),%eax
test   %eax,%eax
je     152f <main+0x2ff>
jmp    1534 <main+0x304>
mov    $0x1,%edi
call   1120 <exit@plt>
jmp    153b <main+0x30b>
xor    %edi,%edi
call   1120 <exit@plt>
mov    -0x148(%rbp),%edi
lea    -0x140(%rbp),%rsi
call   10b0 <antp_handleRequest@plt>
mov    -0x148(%rbp),%edi
call   1090 <close@plt>
xor    %edi,%edi
call   1120 <exit@plt>
mov    -0x148(%rbp),%edi
call   1090 <close@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1130 <wait@plt>
cmp    -0x144(%rbp),%eax
je     1589 <main+0x359>
mov    $0x1,%edi
call   1120 <exit@plt>
jmp    158e <main+0x35e>
jmp    159e <main+0x36e>
mov    -0x148(%rbp),%edi
call   1090 <close@plt>
jmp    1415 <main+0x1e5>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x150,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
call   1070 <setlinebuf@plt>
cmp    $0x3,%ebp
jne    1293 <main+0x63>
mov    0x8(%rbx),%rdi
call   10f0 <atoi@plt>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
call   1040 <strlen@plt>
cmp    $0xf6,%eax
jl     12b2 <main+0x82>
mov    (%rbx),%rsi
lea    0xe12(%rip),%rdi
mov    $0xf5,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    (%rbx),%rsi
lea    0xd63(%rip),%rdi
lea    0xde2(%rip),%rdx
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   1120 <exit@plt>
mov    0x10(%rbx),%rsi
lea    0x50(%rsp),%rbp
mov    %rbp,%rdi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbp,1)
je     12e5 <main+0xb5>
lea    0xdf7(%rip),%rsi
lea    0x50(%rsp),%rdi
call   1100 <strcat@plt>
mov    (%rbx),%rsi
test   %r14d,%r14d
jns    1305 <main+0xd5>
lea    0xde0(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
lea    0xdf4(%rip),%rdi
lea    0x50(%rsp),%rcx
mov    %r14d,%edx
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   1090 <close@plt>
mov    0x2cbf(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2c9d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
test   %eax,%eax
js     13bb <main+0x18b>
mov    %eax,%r12d
lea    0x38(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1080 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x48(%rsp)
mov    %r14d,%edi
call   1050 <htons@plt>
mov    %rax,0x40(%rsp)
mov    0x2c6e(%rip),%rax
mov    (%rax),%edi
call   1050 <htons@plt>
mov    %rax,0x38(%rsp)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x18,%edx
call   10c0 <bind@plt>
test   %rax,%rax
js     13bb <main+0x18b>
mov    %r12d,%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
test   %rax,%rax
js     13bb <main+0x18b>
lea    0x20(%rsp),%rsi
lea    0x1c(%rsp),%rdx
mov    %r12d,%edi
call   10e0 <accept@plt>
test   %eax,%eax
jns    13c5 <main+0x195>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    %eax,%ebp
lea    0x20(%rsp),%r14
lea    0x1c(%rsp),%r15
jmp    13fb <main+0x1cb>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%edi
call   1090 <close@plt>
mov    %r12d,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   10e0 <accept@plt>
mov    %eax,%ebp
test   %eax,%eax
js     13bb <main+0x18b>
mov    0x30(%rsp),%rax
mov    %rax,0x10(%rsp)
movups 0x20(%rsp),%xmm0
movups %xmm0,(%rsp)
call   10d0 <antp_validateAddr@plt>
test   %rax,%rax
je     13e0 <main+0x1b0>
xor    %eax,%eax
call   1140 <fork@plt>
test   %eax,%eax
je     1441 <main+0x211>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     13bb <main+0x18b>
mov    %ebp,%edi
call   1090 <close@plt>
xor    %edi,%edi
call   1130 <wait@plt>
cmp    %ebx,%eax
je     13e7 <main+0x1b7>
jmp    13bb <main+0x18b>
mov    %r12d,%edi
call   1090 <close@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1110 <setpgid@plt>
test   %eax,%eax
jne    13bb <main+0x18b>
mov    $0x1,%edi
call   1090 <close@plt>
mov    $0x2,%edi
call   1090 <close@plt>
xor    %eax,%eax
call   1140 <fork@plt>
test   %eax,%eax
je     1489 <main+0x259>
cmp    $0xffffffff,%eax
je     13bb <main+0x18b>
xor    %edi,%edi
call   1120 <exit@plt>
lea    0x50(%rsp),%rsi
mov    %ebp,%edi
call   10b0 <antp_handleRequest@plt>
mov    %ebp,%edi
call   1090 <close@plt>
xor    %edi,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i32 }
%struct.TYPE_2__ = type { i8* }
%struct.sockaddr = type { i32 }
@stdout = global i32 0
@.str = [134 x i8] c"Usage: %s <Port> <BaseDir>\0A\09Starts server which listens to port <Port> and handles %s requests\0A\09for files in the directory <BaseDir>\0A\00"
@.str.1 = [9 x i8] c"ANTP/1.0\00"
@.str.2 = [67 x i8] c"Usage: %s <Port> <BaseDir>\0A\09<BaseDir> to long (%d characters max)\0A\00"
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [44 x i8] c"Usage: %s <Port> <BaseDir>\0A\09Invalid <Port>\0A\00"
@.str.5 = [27 x i8] c"server: starting %s %d %s\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca [256 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.sockaddr_in
%12 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%13 = load i32, i32* @stdout
%14 = call i32 @setlinebuf(i32 %13)
%15 = load i32, i32* %3
%16 = icmp ne i32 %15, 3
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i8**, i8*** %4
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i8* %20, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 0)
unreachable
23: ; preds = %2
%24 = load i8**, i8*** %4
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %7
%28 = load i8**, i8*** %4
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32 @strlen(i8* %30)
%32 = icmp sgt i32 %31, 245
br i1 %32, label %33, label %39
33: ; preds = %23
%34 = load i8**, i8*** %4
%35 = getelementptr inbounds i8*, i8** %34, i64 0
%36 = load i8*, i8** %35
%37 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.2, i64 0, i64 0), i8* %36, i32 245)
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %23
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%41 = load i8**, i8*** %4
%42 = getelementptr inbounds i8*, i8** %41, i64 2
%43 = load i8*, i8** %42
%44 = call i32 @strcpy(i8* %40, i8* %43)
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%46 = call i32 @strlen(i8* %45)
%47 = sub nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 %48
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp ne i32 %51, 47
br i1 %52, label %53, label %56
53: ; preds = %39
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%55 = call i32 @strcat(i8* %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %56
56: ; preds = %53, %39
%57 = load i32, i32* %7
%58 = icmp slt i32 %57, 0
br i1 %58, label %59, label %65
59: ; preds = %56
%60 = load i8**, i8*** %4
%61 = getelementptr inbounds i8*, i8** %60, i64 0
%62 = load i8*, i8** %61
%63 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i8* %62)
%64 = call i32 @exit(i32 1)
unreachable
65: ; preds = %56
%66 = load i8**, i8*** %4
%67 = getelementptr inbounds i8*, i8** %66, i64 0
%68 = load i8*, i8** %67
%69 = load i32, i32* %7
%70 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%71 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %68, i32 %69, i8* %70)
%72 = call i32 @close(i32 0)
%73 = load i32, i32* @AF_INET
%74 = load i32, i32* @SOCK_STREAM
%75 = call i32 @socket(i32 %73, i32 %74, i32 0)
store i32 %75, i32* %5
%76 = icmp slt i32 %75, 0
br i1 %76, label %77, label %79
77: ; preds = %65
%78 = call i32 @exit(i32 1)
unreachable
79: ; preds = %65
%80 = call i32 @memset(%struct.sockaddr_in* %6, i32 0, i32 24)
%81 = load i32, i32* @AF_INET
%82 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %81, i32* %82
%83 = load i32, i32* %7
%84 = call i8* @htons(i32 %83)
%85 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i8* %84, i8** %85
%86 = load i32, i32* @INADDR_ANY
%87 = call i8* @htons(i32 %86)
%88 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%89 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %88, i32 0, i32 0
store i8* %87, i8** %89
%90 = load i32, i32* %5
%91 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%92 = call i64 @bind(i32 %90, %struct.sockaddr* %91, i32 24)
%93 = icmp slt i64 %92, 0
br i1 %93, label %94, label %96
94: ; preds = %79
%95 = call i32 @exit(i32 1)
unreachable
96: ; preds = %79
%97 = load i32, i32* %5
%98 = call i64 @listen(i32 %97, i32 5)
%99 = icmp slt i64 %98, 0
br i1 %99, label %100, label %102
100: ; preds = %96
%101 = call i32 @exit(i32 1)
unreachable
102: ; preds = %96
br label %103
103: ; preds = %102, %154
%104 = load i32, i32* %5
%105 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%106 = call i32 @accept(i32 %104, %struct.sockaddr* %105, i32* %12)
store i32 %106, i32* %10
%107 = load i32, i32* %10
%108 = icmp slt i32 %107, 0
br i1 %108, label %109, label %111
109: ; preds = %103
%110 = call i32 @exit(i32 1)
unreachable
111: ; preds = %103
%112 = call i64 @antp_validateAddr(%struct.sockaddr_in* byval(%struct.sockaddr_in) align 8 %11)
%113 = icmp ne i64 %112, 0
br i1 %113, label %114, label %151
114: ; preds = %111
%115 = call i32 (...) @fork()
store i32 %115, i32* %9
switch i32 %115, label %141 [
i32 -1, label %116
i32 0, label %118
]
116: ; preds = %114
%117 = call i32 @exit(i32 1)
unreachable
118: ; preds = %114
%119 = load i32, i32* %5
%120 = call i32 @close(i32 %119)
%121 = call i32 @setpgid(i32 0, i32 0)
%122 = icmp ne i32 %121, 0
br i1 %122, label %123, label %125
123: ; preds = %118
%124 = call i32 @exit(i32 1)
unreachable
125: ; preds = %118
%126 = call i32 @close(i32 1)
%127 = call i32 @close(i32 2)
%128 = call i32 (...) @fork()
store i32 %128, i32* %9
switch i32 %128, label %132 [
i32 -1, label %129
i32 0, label %131
]
129: ; preds = %125
%130 = call i32 @exit(i32 1)
unreachable
131: ; preds = %125
br label %134
132: ; preds = %125
%133 = call i32 @exit(i32 0)
unreachable
134: ; preds = %131
%135 = load i32, i32* %10
%136 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%137 = call i32 @antp_handleRequest(i32 %135, i8* %136)
%138 = load i32, i32* %10
%139 = call i32 @close(i32 %138)
%140 = call i32 @exit(i32 0)
unreachable
141: ; preds = %114
%142 = load i32, i32* %10
%143 = call i32 @close(i32 %142)
%144 = call i32 @wait(i32* null)
%145 = load i32, i32* %9
%146 = icmp ne i32 %144, %145
br i1 %146, label %147, label %149
147: ; preds = %141
%148 = call i32 @exit(i32 1)
unreachable
149: ; preds = %141
br label %150
150: ; preds = %149
br label %154
151: ; preds = %111
%152 = load i32, i32* %10
%153 = call i32 @close(i32 %152)
br label %154
154: ; preds = %151, %150
br label %103
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i32 }
%struct.TYPE_2__ = type { i8* }
%struct.sockaddr = type { i32 }
@stdout = global i32 0
@.str = [134 x i8] c"Usage: %s <Port> <BaseDir>\0A\09Starts server which listens to port <Port> and handles %s requests\0A\09for files in the directory <BaseDir>\0A\00"
@.str.1 = [9 x i8] c"ANTP/1.0\00"
@.str.2 = [67 x i8] c"Usage: %s <Port> <BaseDir>\0A\09<BaseDir> to long (%d characters max)\0A\00"
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [44 x i8] c"Usage: %s <Port> <BaseDir>\0A\09Invalid <Port>\0A\00"
@.str.5 = [27 x i8] c"server: starting %s %d %s\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
define void @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [256 x i8]
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%9 = load i32, i32* @stdout
%10 = tail call i32 @setlinebuf(i32 %9)
%11 = icmp eq i32 %0, 3
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = load i8*, i8** %1
%14 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i8* %13, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i32 @strlen(i8* %21)
%23 = icmp sgt i32 %22, 245
br i1 %23, label %24, label %28
24: ; preds = %16
%25 = load i8*, i8** %1
%26 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.2, i64 0, i64 0), i8* %25, i32 245)
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %16
%29 = load i8*, i8** %20
%30 = call i32 @strcpy(i8* %8, i8* %29)
%31 = call i32 @strlen(i8* %8)
%32 = add nsw i32 %31, -1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 47
br i1 %36, label %39, label %37
37: ; preds = %28
%38 = call i32 @strcat(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %39
39: ; preds = %37, %28
%40 = icmp slt i32 %19, 0
%41 = load i8*, i8** %1
br i1 %40, label %42, label %45
42: ; preds = %39
%43 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i8* %41)
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %39
%46 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %41, i32 %19, i8* %8)
%47 = call i32 @close(i32 0)
%48 = load i32, i32* @AF_INET
%49 = load i32, i32* @SOCK_STREAM
%50 = call i32 @socket(i32 %48, i32 %49, i32 0)
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %45
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %45
%55 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 24)
%56 = load i32, i32* @AF_INET
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %56, i32* %57
%58 = call i8* @htons(i32 %19)
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i8* %58, i8** %59
%60 = load i32, i32* @INADDR_ANY
%61 = call i8* @htons(i32 %60)
%62 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i8* %61, i8** %62
%63 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%64 = call i64 @bind(i32 %50, %struct.sockaddr* %63, i32 24)
%65 = icmp slt i64 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %54
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %54
%69 = call i64 @listen(i32 %50, i32 5)
%70 = icmp slt i64 %69, 0
br i1 %70, label %77, label %71
71: ; preds = %68
%72 = bitcast %struct.sockaddr_in* %5 to i8*
%73 = bitcast i32* %6 to i8*
%74 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%75 = call i32 @accept(i32 %50, %struct.sockaddr* %74, i32* %6)
%76 = icmp slt i32 %75, 0
br i1 %76, label %79, label %81
77: ; preds = %68
%78 = call i32 @exit(i32 1)
unreachable
79: ; preds = %115, %71
%80 = call i32 @exit(i32 1)
unreachable
81: ; preds = %71, %115
%82 = phi i32 [ %116, %115 ], [ %75, %71 ]
%83 = call i64 @antp_validateAddr(%struct.sockaddr_in* byval(%struct.sockaddr_in) align 8 %5)
%84 = icmp eq i64 %83, 0
br i1 %84, label %113, label %85
85: ; preds = %81
%86 = call i32 (...) @fork()
switch i32 %86, label %107 [
i32 -1, label %87
i32 0, label %89
]
87: ; preds = %85
%88 = call i32 @exit(i32 1)
unreachable
89: ; preds = %85
%90 = call i32 @close(i32 %50)
%91 = call i32 @setpgid(i32 0, i32 0)
%92 = icmp eq i32 %91, 0
br i1 %92, label %95, label %93
93: ; preds = %89
%94 = call i32 @exit(i32 1)
unreachable
95: ; preds = %89
%96 = call i32 @close(i32 1)
%97 = call i32 @close(i32 2)
%98 = call i32 (...) @fork()
switch i32 %98, label %101 [
i32 -1, label %99
i32 0, label %103
]
99: ; preds = %95
%100 = call i32 @exit(i32 1)
unreachable
101: ; preds = %95
%102 = call i32 @exit(i32 0)
unreachable
103: ; preds = %95
%104 = call i32 @antp_handleRequest(i32 %82, i8* %8)
%105 = call i32 @close(i32 %82)
%106 = call i32 @exit(i32 0)
unreachable
107: ; preds = %85
%108 = call i32 @close(i32 %82)
%109 = call i32 @wait(i32* null)
%110 = icmp eq i32 %109, %86
br i1 %110, label %115, label %111
111: ; preds = %107
%112 = call i32 @exit(i32 1)
unreachable
113: ; preds = %81
%114 = call i32 @close(i32 %82)
br label %115
115: ; preds = %107, %113
%116 = call i32 @accept(i32 %50, %struct.sockaddr* %74, i32* %6)
%117 = icmp slt i32 %116, 0
br i1 %117, label %79, label %81
}