#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*/ svr_addr;
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*/ cli_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ genindex(char *);
char *getenv(char *);
char getopt(int, char **, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
char *malloc(size_t);
int /*<<< orphan*/ memset(void *, int, int);
int open(char *, int /*<<< orphan*/);
char *optarg;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *strtok(char *, char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int one = 1, client_fd;
  int rcvd, fd, bytes_read;
  char mesg[99999], data_to_send[1024], path[99999];
  char c, *field[3], *ROOT;
  struct sockaddr_in svr_addr, cli_addr;
  socklen_t sin_len = sizeof(cli_addr);
  ROOT = getenv("PWD");
  while ((c = getopt(argc, argv, "r:")) != -1)
    switch (c) {
    case 'r':
      ROOT = malloc(strlen(optarg));
      strcpy(ROOT, optarg);
      break;
    case '?':
      fprintf(stderr, "Wrong arguments given!!!\n");
      exit(1);
    default:
      exit(1);
    }
  printf("Argument %s\n", ROOT);
  int sock = socket(AF_INET, SOCK_STREAM, 0);
  if (sock < 0)
    err(1, "can't open socket");
  setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(int));
  int port = 8080;
  svr_addr.sin_family = AF_INET;
  svr_addr.sin_addr.s_addr = INADDR_ANY;
  svr_addr.sin_port = htons(port);
  if (bind(sock, (struct sockaddr *)&svr_addr, sizeof(svr_addr)) == -1) {
    close(sock);
    err(1, "Can't bind");
  }
  listen(sock, 5);
  while (1) {
    client_fd = accept(sock, (struct sockaddr *)&cli_addr, &sin_len);
    memset((void *)mesg, (int)'\0', 99999);
    rcvd = recv(client_fd, mesg, 99999, 0);
    printf("got connection\n");
    printf("%s\n", mesg);
    if (client_fd == -1) {
      perror("Can't accept");
      continue;
    }
    field[0] = strtok(mesg, " \t\n");
    printf("head %s\n", field[0]);
    field[1] = strtok(NULL, " \t");
    if (strncmp(field[1], "/\0", 2) == 0) {
      field[1] = "/index.html";
      genindex(ROOT);
    }
    strcpy(path, ROOT);
    strcpy(&path[strlen(ROOT)], field[1]);
    printf("newpath %s\n", path);
    if ((fd = open(path, O_RDONLY)) != -1) {
      send(client_fd, "HTTP/1.0 200 OK\n\n", 17, 0);
      while ((bytes_read = read(fd, data_to_send, 1024)) > 0)
        write(client_fd, data_to_send, bytes_read);
    } else
      write(client_fd, "HTTP/1.0 404 Not Found\n", 23);
    close(client_fd);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x311d0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0xc,-0x311bc(%rbp)
lea    0xd2f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x31198(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xd19(%rip),%rdx
call   1190 <getopt@plt>
mov    %al,-0x31171(%rbp)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     1398 <main+0xf8>
movsbl -0x31171(%rbp),%eax
mov    %eax,-0x311c8(%rbp)
sub    $0x3f,%eax
je     136a <main+0xca>
jmp    131d <main+0x7d>
mov    -0x311c8(%rbp),%eax
sub    $0x72,%eax
jne    1389 <main+0xe9>
jmp    1331 <main+0x91>
mov    0x2cc0(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strlen@plt>
mov    %rax,%rdi
call   1130 <malloc@plt>
mov    %rax,-0x31198(%rbp)
mov    -0x31198(%rbp),%rdi
mov    0x2c9b(%rip),%rax
mov    (%rax),%rsi
call   1070 <strcpy@plt>
jmp    1393 <main+0xf3>
mov    0x2c47(%rip),%rax
mov    (%rax),%edi
lea    0xc8d(%rip),%rsi
call   1110 <fprintf@plt>
mov    $0x1,%edi
call   11b0 <exit@plt>
mov    $0x1,%edi
call   11b0 <exit@plt>
jmp    12dd <main+0x3d>
mov    -0x31198(%rbp),%rsi
lea    0xc7b(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
mov    0x2c24(%rip),%rax
mov    (%rax),%edi
mov    0x2bf3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   11c0 <socket@plt>
mov    %eax,-0x311c0(%rbp)
cmpl   $0x0,-0x311c0(%rbp)
jge    13ea <main+0x14a>
mov    $0x1,%edi
lea    0xc49(%rip),%rsi
call   1120 <err@plt>
mov    -0x311c0(%rbp),%edi
mov    0x2be9(%rip),%rax
mov    (%rax),%esi
mov    0x2ba8(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rcx
mov    $0x4,%r8d
call   1080 <setsockopt@plt>
movl   $0x1f90,-0x311c4(%rbp)
mov    0x2bb6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x311a0(%rbp)
mov    0x2b97(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x311a4(%rbp)
mov    -0x311c4(%rbp),%edi
call   10b0 <htons@plt>
mov    %eax,-0x311a8(%rbp)
mov    -0x311c0(%rbp),%edi
lea    -0x311a8(%rbp),%rsi
mov    $0xc,%edx
call   1150 <bind@plt>
cmp    $0xffffffff,%eax
jne    1486 <main+0x1e6>
mov    -0x311c0(%rbp),%edi
call   10f0 <close@plt>
mov    $0x1,%edi
lea    0xbbf(%rip),%rsi
call   1120 <err@plt>
mov    -0x311c0(%rbp),%edi
mov    $0x5,%esi
call   1140 <listen@plt>
mov    -0x311c0(%rbp),%edi
lea    -0x311b8(%rbp),%rsi
lea    -0x311bc(%rbp),%rdx
call   11a0 <accept@plt>
mov    %eax,-0x18(%rbp)
lea    -0x186d0(%rbp),%rdi
xor    %esi,%esi
mov    $0x1869f,%edx
call   10e0 <memset@plt>
mov    -0x18(%rbp),%edi
lea    -0x186d0(%rbp),%rsi
mov    $0x1869f,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,-0x1c(%rbp)
lea    0xb66(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
lea    -0x186d0(%rbp),%rsi
lea    0xb77(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
cmpl   $0xffffffff,-0x18(%rbp)
jne    151c <main+0x27c>
lea    0xb49(%rip),%rdi
call   1170 <perror@plt>
jmp    1496 <main+0x1f6>
lea    -0x186d0(%rbp),%rdi
lea    0xb3e(%rip),%rsi
call   1180 <strtok@plt>
mov    %rax,-0x31190(%rbp)
mov    -0x31190(%rbp),%rsi
lea    0xb28(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xb1f(%rip),%rsi
call   1180 <strtok@plt>
mov    %rax,-0x31188(%rbp)
mov    -0x31188(%rbp),%rdi
lea    0xb4a(%rip),%rsi
mov    $0x2,%edx
call   1060 <strncmp@plt>
cmp    $0x0,%rax
jne    159e <main+0x2fe>
lea    0xaed(%rip),%rax
mov    %rax,-0x31188(%rbp)
mov    -0x31198(%rbp),%rdi
call   1050 <genindex@plt>
lea    -0x31170(%rbp),%rdi
mov    -0x31198(%rbp),%rsi
call   1070 <strcpy@plt>
mov    -0x31198(%rbp),%rdi
call   10a0 <strlen@plt>
lea    -0x31170(%rbp),%rdi
add    %rax,%rdi
mov    -0x31188(%rbp),%rsi
call   1070 <strcpy@plt>
lea    -0x31170(%rbp),%rsi
lea    0xaa3(%rip),%rdi
mov    $0x0,%al
call   10d0 <printf@plt>
lea    -0x31170(%rbp),%rdi
mov    0x29da(%rip),%rax
mov    (%rax),%esi
call   1160 <open@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
je     165b <main+0x3bb>
mov    -0x18(%rbp),%edi
lea    0xa7d(%rip),%rsi
mov    $0x11,%edx
xor    %ecx,%ecx
call   10c0 <send@plt>
mov    -0x20(%rbp),%edi
lea    -0x18ad0(%rbp),%rsi
mov    $0x400,%edx
call   1100 <read@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jle    1656 <main+0x3b6>
mov    -0x18(%rbp),%edi
lea    -0x18ad0(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1090 <write@plt>
jmp    161f <main+0x37f>
jmp    166f <main+0x3cf>
mov    -0x18(%rbp),%edi
lea    0xa3d(%rip),%rsi
mov    $0x17,%edx
call   1090 <write@plt>
mov    -0x18(%rbp),%edi
call   10f0 <close@plt>
jmp    1496 <main+0x1f6>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x31178,%rsp
mov    %rsi,%r14
mov    %edi,%r13d
movl   $0x1,0xc(%rsp)
movl   $0xc,0x8(%rsp)
lea    0xd22(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r12
lea    0xd17(%rip),%rdx
mov    %r13d,%edi
mov    %r14,%rsi
call   11a0 <getopt@plt>
cmp    $0xff,%al
je     1353 <main+0xa3>
mov    0x2cf5(%rip),%r12
lea    0xcfa(%rip),%r15
nopw   0x0(%rax,%rax,1)
movsbl %al,%eax
cmp    $0x72,%eax
jne    15ee <main+0x33e>
mov    (%r12),%rbx
mov    %rbx,%rdi
call   10b0 <strlen@plt>
mov    %rax,%rdi
call   1140 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
call   1070 <strcpy@plt>
mov    %r13d,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   11a0 <getopt@plt>
cmp    $0xff,%al
jne    1310 <main+0x60>
mov    %rbp,%r12
lea    0xcc7(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   10e0 <printf@plt>
mov    0x2c6d(%rip),%rbx
mov    (%rbx),%edi
mov    0x2c3c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   11d0 <socket@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    1395 <main+0xe5>
lea    0xca3(%rip),%rsi
mov    $0x1,%edi
call   1130 <err@plt>
mov    0x2c44(%rip),%rax
mov    (%rax),%esi
mov    0x2c03(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %r14d,%edi
mov    $0x4,%r8d
call   1090 <setsockopt@plt>
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    0x2c01(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    $0x1f90,%edi
call   10c0 <htons@plt>
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   1160 <bind@plt>
cmp    $0xffffffff,%eax
jne    140b <main+0x15b>
mov    %r14d,%edi
call   1100 <close@plt>
lea    0xc3f(%rip),%rsi
mov    $0x1,%edi
call   1130 <err@plt>
mov    %r14d,%edi
mov    $0x5,%esi
call   1150 <listen@plt>
lea    0x20(%rsp),%rbx
lea    0x18ad0(%rsp),%rbp
lea    0x30(%rsp),%r15
mov    %r14d,0x4(%rsp)
jmp    144c <main+0x19c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xc04(%rip),%rdi
call   1180 <perror@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
lea    0x8(%rsp),%rdx
call   11b0 <accept@plt>
mov    %eax,%r13d
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x1869f,%edx
call   10f0 <memset@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x1869f,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
lea    0xc23(%rip),%rdi
call   1080 <puts@plt>
mov    %rbp,%rdi
call   1080 <puts@plt>
cmp    $0xffffffff,%r13d
je     1440 <main+0x190>
mov    %rbp,%rdi
lea    0xbb4(%rip),%rsi
call   1190 <strtok@plt>
lea    0xbac(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   10e0 <printf@plt>
xor    %edi,%edi
lea    0xba2(%rip),%rsi
call   1190 <strtok@plt>
mov    %rax,%rbx
mov    %rax,%rdi
lea    0xbe4(%rip),%rsi
mov    $0x2,%edx
call   1060 <strncmp@plt>
test   %rax,%rax
jne    14f3 <main+0x243>
mov    %r12,%rdi
call   1050 <genindex@plt>
lea    0xb75(%rip),%rbx
lea    0x430(%rsp),%r14
mov    %r14,%rdi
mov    %r12,%rsi
call   1070 <strcpy@plt>
mov    %r12,%rbp
mov    %r12,%rdi
call   10b0 <strlen@plt>
lea    (%rsp,%rax,1),%rdi
add    $0x430,%rdi
mov    %rbx,%rsi
call   1070 <strcpy@plt>
lea    0xb49(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   10e0 <printf@plt>
mov    0x2a94(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1170 <open@plt>
cmp    $0xffffffff,%eax
jne    1570 <main+0x2c0>
mov    %r13d,%edi
lea    0xb3d(%rip),%rsi
mov    $0x17,%edx
call   10a0 <write@plt>
lea    0x20(%rsp),%rbx
jmp    15d1 <main+0x321>
cs nopw 0x0(%rax,%rax,1)
mov    %eax,%r12d
mov    %r13d,%edi
lea    0xb03(%rip),%rsi
mov    $0x11,%edx
xor    %ecx,%ecx
call   10d0 <send@plt>
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0x400,%edx
call   1110 <read@plt>
test   %eax,%eax
lea    0x20(%rsp),%rbx
jle    15d1 <main+0x321>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13d,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   10a0 <write@plt>
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0x400,%edx
call   1110 <read@plt>
test   %eax,%eax
jg     15b0 <main+0x300>
mov    %r13d,%edi
call   1100 <close@plt>
mov    %rbp,%r12
mov    0x4(%rsp),%r14d
lea    0x18ad0(%rsp),%rbp
jmp    144c <main+0x19c>
cmp    $0x3f,%eax
jne    1608 <main+0x358>
mov    0x29be(%rip),%rax
mov    (%rax),%edi
lea    0xa04(%rip),%rsi
call   1120 <fprintf@plt>
mov    $0x1,%edi
call   11c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [4 x i8] c"PWD\00"
@.str.1 = [3 x i8] c"r:\00"
@optarg = global i8* null
@stderr = global i32 0
@.str.2 = [26 x i8] c"Wrong arguments given!!!\0A\00"
@.str.3 = [13 x i8] c"Argument %s\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [18 x i8] c"can't open socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@INADDR_ANY = global i32 0
@.str.5 = [11 x i8] c"Can't bind\00"
@.str.6 = [16 x i8] c"got connection\0A\00"
@.str.7 = [4 x i8] c"%s\0A\00"
@.str.8 = [13 x i8] c"Can't accept\00"
@.str.9 = [4 x i8] c" \09\0A\00"
@.str.10 = [9 x i8] c"head %s\0A\00"
@.str.11 = [3 x i8] c" \09\00"
@.str.12 = [3 x i8] c"/\00\00"
@.str.13 = [12 x i8] c"/index.html\00"
@.str.14 = [12 x i8] c"newpath %s\0A\00"
@O_RDONLY = global i32 0
@.str.15 = [18 x i8] c"HTTP/1.0 200 OK\0A\0A\00"
@.str.16 = [24 x i8] c"HTTP/1.0 404 Not Found\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 i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [99999 x i8]
%12 = alloca [1024 x i8]
%13 = alloca [99999 x i8]
%14 = alloca i8
%15 = alloca [3 x i8*]
%16 = alloca i8*
%17 = alloca %struct.sockaddr_in
%18 = alloca %struct.sockaddr_in
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
store i32 12, i32* %19
%22 = call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %22, i8** %16
br label %23
23: ; preds = %45, %2
%24 = load i32, i32* %4
%25 = load i8**, i8*** %5
%26 = call signext i8 @getopt(i32 %24, i8** %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8 %26, i8* %14
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, -1
br i1 %28, label %29, label %46
29: ; preds = %23
%30 = load i8, i8* %14
%31 = sext i8 %30 to i32
switch i32 %31, label %43 [
i32 114, label %32
i32 63, label %39
]
32: ; preds = %29
%33 = load i8*, i8** @optarg
%34 = call i64 @strlen(i8* %33)
%35 = call i8* @malloc(i64 %34)
store i8* %35, i8** %16
%36 = load i8*, i8** %16
%37 = load i8*, i8** @optarg
%38 = call i32 @strcpy(i8* %36, i8* %37)
br label %45
39: ; preds = %29
%40 = load i32, i32* @stderr
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %29
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %32
br label %23
46: ; preds = %23
%47 = load i8*, i8** %16
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %47)
%49 = load i32, i32* @AF_INET
%50 = load i32, i32* @SOCK_STREAM
%51 = call i32 @socket(i32 %49, i32 %50, i32 0)
store i32 %51, i32* %20
%52 = load i32, i32* %20
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %46
%55 = call i32 @err(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %56
56: ; preds = %54, %46
%57 = load i32, i32* %20
%58 = load i32, i32* @SOL_SOCKET
%59 = load i32, i32* @SO_REUSEADDR
%60 = call i32 @setsockopt(i32 %57, i32 %58, i32 %59, i32* %6, i32 4)
store i32 8080, i32* %21
%61 = load i32, i32* @AF_INET
%62 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 2
store i32 %61, i32* %62
%63 = load i32, i32* @INADDR_ANY
%64 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 1
%65 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %64, i32 0, i32 0
store i32 %63, i32* %65
%66 = load i32, i32* %21
%67 = call i32 @htons(i32 %66)
%68 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 0
store i32 %67, i32* %68
%69 = load i32, i32* %20
%70 = bitcast %struct.sockaddr_in* %17 to %struct.sockaddr*
%71 = call i32 @bind(i32 %69, %struct.sockaddr* %70, i32 12)
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %77
73: ; preds = %56
%74 = load i32, i32* %20
%75 = call i32 @close(i32 %74)
%76 = call i32 @err(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %77
77: ; preds = %73, %56
%78 = load i32, i32* %20
%79 = call i32 @listen(i32 %78, i32 5)
br label %80
80: ; preds = %77, %94, %146
%81 = load i32, i32* %20
%82 = bitcast %struct.sockaddr_in* %18 to %struct.sockaddr*
%83 = call i32 @accept(i32 %81, %struct.sockaddr* %82, i32* %19)
store i32 %83, i32* %7
%84 = getelementptr inbounds [99999 x i8], [99999 x i8]* %11, i64 0, i64 0
%85 = call i32 @memset(i8* %84, i32 0, i32 99999)
%86 = load i32, i32* %7
%87 = getelementptr inbounds [99999 x i8], [99999 x i8]* %11, i64 0, i64 0
%88 = call i32 @recv(i32 %86, i8* %87, i32 99999, i32 0)
store i32 %88, i32* %8
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%90 = getelementptr inbounds [99999 x i8], [99999 x i8]* %11, i64 0, i64 0
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %90)
%92 = load i32, i32* %7
%93 = icmp eq i32 %92, -1
br i1 %93, label %94, label %96
94: ; preds = %80
%95 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
br label %80
96: ; preds = %80
%97 = getelementptr inbounds [99999 x i8], [99999 x i8]* %11, i64 0, i64 0
%98 = call i8* @strtok(i8* %97, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%99 = getelementptr inbounds [3 x i8*], [3 x i8*]* %15, i64 0, i64 0
store i8* %98, i8** %99
%100 = getelementptr inbounds [3 x i8*], [3 x i8*]* %15, i64 0, i64 0
%101 = load i8*, i8** %100
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i8* %101)
%103 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%104 = getelementptr inbounds [3 x i8*], [3 x i8*]* %15, i64 0, i64 1
store i8* %103, i8** %104
%105 = getelementptr inbounds [3 x i8*], [3 x i8*]* %15, i64 0, i64 1
%106 = load i8*, i8** %105
%107 = call i64 @strncmp(i8* %106, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i32 2)
%108 = icmp eq i64 %107, 0
br i1 %108, label %109, label %113
109: ; preds = %96
%110 = getelementptr inbounds [3 x i8*], [3 x i8*]* %15, i64 0, i64 1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.13, i64 0, i64 0), i8** %110
%111 = load i8*, i8** %16
%112 = call i32 @genindex(i8* %111)
br label %113
113: ; preds = %109, %96
%114 = getelementptr inbounds [99999 x i8], [99999 x i8]* %13, i64 0, i64 0
%115 = load i8*, i8** %16
%116 = call i32 @strcpy(i8* %114, i8* %115)
%117 = load i8*, i8** %16
%118 = call i64 @strlen(i8* %117)
%119 = getelementptr inbounds [99999 x i8], [99999 x i8]* %13, i64 0, i64 %118
%120 = getelementptr inbounds [3 x i8*], [3 x i8*]* %15, i64 0, i64 1
%121 = load i8*, i8** %120
%122 = call i32 @strcpy(i8* %119, i8* %121)
%123 = getelementptr inbounds [99999 x i8], [99999 x i8]* %13, i64 0, i64 0
%124 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.14, i64 0, i64 0), i8* %123)
%125 = getelementptr inbounds [99999 x i8], [99999 x i8]* %13, i64 0, i64 0
%126 = load i32, i32* @O_RDONLY
%127 = call i32 @open(i8* %125, i32 %126)
store i32 %127, i32* %9
%128 = icmp ne i32 %127, -1
br i1 %128, label %129, label %143
129: ; preds = %113
%130 = load i32, i32* %7
%131 = call i32 @send(i32 %130, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.15, i64 0, i64 0), i32 17, i32 0)
br label %132
132: ; preds = %137, %129
%133 = load i32, i32* %9
%134 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%135 = call i32 @read(i32 %133, i8* %134, i32 1024)
store i32 %135, i32* %10
%136 = icmp sgt i32 %135, 0
br i1 %136, label %137, label %142
137: ; preds = %132
%138 = load i32, i32* %7
%139 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%140 = load i32, i32* %10
%141 = call i32 @write(i32 %138, i8* %139, i32 %140)
br label %132
142: ; preds = %132
br label %146
143: ; preds = %113
%144 = load i32, i32* %7
%145 = call i32 @write(i32 %144, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.16, i64 0, i64 0), i32 23)
br label %146
146: ; preds = %143, %142
%147 = load i32, i32* %7
%148 = call i32 @close(i32 %147)
br label %80
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [4 x i8] c"PWD\00"
@.str.1 = [3 x i8] c"r:\00"
@optarg = global i8* null
@stderr = global i32 0
@.str.2 = [26 x i8] c"Wrong arguments given!!!\0A\00"
@.str.3 = [13 x i8] c"Argument %s\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [18 x i8] c"can't open socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@INADDR_ANY = global i32 0
@.str.5 = [11 x i8] c"Can't bind\00"
@.str.8 = [13 x i8] c"Can't accept\00"
@.str.9 = [4 x i8] c" \09\0A\00"
@.str.10 = [9 x i8] c"head %s\0A\00"
@.str.11 = [3 x i8] c" \09\00"
@.str.12 = [3 x i8] c"/\00\00"
@.str.13 = [12 x i8] c"/index.html\00"
@.str.14 = [12 x i8] c"newpath %s\0A\00"
@O_RDONLY = global i32 0
@.str.15 = [18 x i8] c"HTTP/1.0 200 OK\0A\0A\00"
@.str.16 = [24 x i8] c"HTTP/1.0 404 Not Found\0A\00"
@str = [15 x i8] c"got connection\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca [99999 x i8]
%5 = alloca [1024 x i8]
%6 = alloca [99999 x i8]
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%11 = getelementptr inbounds [99999 x i8], [99999 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%13 = getelementptr inbounds [99999 x i8], [99999 x i8]* %6, i64 0, i64 0
%14 = bitcast %struct.sockaddr_in* %7 to i8*
%15 = bitcast %struct.sockaddr_in* %8 to i8*
%16 = bitcast i32* %9 to i8*
store i32 12, i32* %9
%17 = tail call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%18 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i8 %18, -1
br i1 %19, label %36, label %20
20: ; preds = %2, %23
%21 = phi i8 [ %28, %23 ], [ %18, %2 ]
%22 = sext i8 %21 to i32
switch i32 %22, label %34 [
i32 114, label %23
i32 63, label %30
]
23: ; preds = %20
%24 = load i8*, i8** @optarg
%25 = tail call i64 @strlen(i8* dereferenceable(1) %24)
%26 = tail call i8* @malloc(i64 %25)
%27 = tail call i32 @strcpy(i8* %26, i8* %24)
%28 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp eq i8 %28, -1
br i1 %29, label %36, label %20
30: ; preds = %20
%31 = load i32, i32* @stderr
%32 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%33 = tail call i32 @exit(i32 1)
unreachable
34: ; preds = %20
%35 = tail call i32 @exit(i32 1)
unreachable
36: ; preds = %23, %2
%37 = phi i8* [ %17, %2 ], [ %26, %23 ]
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %37)
%39 = load i32, i32* @AF_INET
%40 = load i32, i32* @SOCK_STREAM
%41 = tail call i32 @socket(i32 %39, i32 %40, i32 0)
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %36
%44 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %45
45: ; preds = %43, %36
%46 = load i32, i32* @SOL_SOCKET
%47 = load i32, i32* @SO_REUSEADDR
%48 = call i32 @setsockopt(i32 %41, i32 %46, i32 %47, i32* %3, i32 4)
%49 = load i32, i32* @AF_INET
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 2
store i32 %49, i32* %50
%51 = load i32, i32* @INADDR_ANY
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 1, i32 0
store i32 %51, i32* %52
%53 = call i32 @htons(i32 8080)
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 0
store i32 %53, i32* %54
%55 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%56 = call i32 @bind(i32 %41, %struct.sockaddr* %55, i32 12)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %61
58: ; preds = %45
%59 = call i32 @close(i32 %41)
%60 = call i32 @err(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %61
61: ; preds = %58, %45
%62 = call i32 @listen(i32 %41, i32 5)
%63 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
br label %64
64: ; preds = %73, %61
%65 = call i32 @accept(i32 %41, %struct.sockaddr* %63, i32* %9)
%66 = call i32 @memset(i8* %11, i32 0, i32 99999)
%67 = call i32 @recv(i32 %65, i8* %11, i32 99999, i32 0)
%68 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%69 = call i32 @puts(i8* %11)
%70 = icmp eq i32 %65, -1
br i1 %70, label %71, label %74
71: ; preds = %64
%72 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
br label %73
73: ; preds = %71, %103
br label %64
74: ; preds = %64
%75 = call i8* @strtok(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%76 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i8* %75)
%77 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%78 = call i64 @strncmp(i8* %77, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i32 2)
%79 = icmp eq i64 %78, 0
br i1 %79, label %80, label %82
80: ; preds = %74
%81 = call i32 @genindex(i8* %37)
br label %82
82: ; preds = %80, %74
%83 = phi i8* [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.13, i64 0, i64 0), %80 ], [ %77, %74 ]
%84 = call i32 @strcpy(i8* %13, i8* %37)
%85 = call i64 @strlen(i8* dereferenceable(1) %37)
%86 = getelementptr inbounds [99999 x i8], [99999 x i8]* %6, i64 0, i64 %85
%87 = call i32 @strcpy(i8* %86, i8* %83)
%88 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.14, i64 0, i64 0), i8* %13)
%89 = load i32, i32* @O_RDONLY
%90 = call i32 @open(i8* %13, i32 %89)
%91 = icmp eq i32 %90, -1
br i1 %91, label %101, label %92
92: ; preds = %82
%93 = call i32 @send(i32 %65, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.15, i64 0, i64 0), i32 17, i32 0)
%94 = call i32 @read(i32 %90, i8* %12, i32 1024)
%95 = icmp sgt i32 %94, 0
br i1 %95, label %96, label %103
96: ; preds = %92, %96
%97 = phi i32 [ %99, %96 ], [ %94, %92 ]
%98 = call i32 @write(i32 %65, i8* %12, i32 %97)
%99 = call i32 @read(i32 %90, i8* %12, i32 1024)
%100 = icmp sgt i32 %99, 0
br i1 %100, label %96, label %103
101: ; preds = %82
%102 = call i32 @write(i32 %65, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.16, i64 0, i64 0), i32 23)
br label %103
103: ; preds = %96, %92, %101
%104 = call i32 @close(i32 %65)
br label %73
}