#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 socklen_t;
typedef int /*<<< orphan*/ serverDetail;
typedef int /*<<< orphan*/ pthread_t;
typedef int /*<<< orphan*/ clientDetail;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ ErrorHandling(char *);
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
int listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
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 socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strtok(char *, char *);
int main(int argc, char *argv[]) {
  int serverSock, clientSock;
  struct sockaddr_in serverDetail, clientDetail;
  socklen_t clientAddrSize;
  int fd, errfd, strLength;
  char buf[4096];
  pthread_t tid;
  char header[] =
      "HTTP/1.1 200 OK\r\nDate: Wed, 12 Mar 2014 00:00:00 GMT\r\n\r\n";
  char method[10];
  char fileName[30];
  char protocol[100];
  if (argc != 1) {
    printf("Usage : %s\n", argv[0]);
    exit(1);
  }
  serverSock = socket(PF_INET, SOCK_STREAM, 0);
  if (serverSock == -1) {
    ErrorHandling("socket() error");
  }
  memset(&serverDetail, 0, sizeof(serverDetail));
  serverDetail.sin_family = AF_INET;
  serverDetail.sin_addr.s_addr = htonl(INADDR_ANY);
  serverDetail.sin_port = htons(32000);
  if (bind(serverSock, (struct sockaddr *)&serverDetail,
           sizeof(serverDetail)) == -1) {
    ErrorHandling("bind() error");
  }
  if (listen(serverSock, 10) == -1) {
    ErrorHandling("listen() error");
  }
  printf("Server Activated\n");
  while (1) {
    clientAddrSize = sizeof(clientDetail);
    clientSock =
        accept(serverSock, (struct sockaddr *)&clientDetail, &clientAddrSize);
    if (clientSock == -1) {
      perror("accept() error");
    }
    printf("Connection Request: %s\n", inet_ntoa(clientDetail.sin_addr));
    strLength = recv(clientSock, buf, 4096, 0);
    buf[strLength] = 0;
    strcpy(fileName, ".");
    strcpy(method, strtok(buf, " "));
    strcat(fileName, strtok(NULL, " "));
    if (fileName[strlen(fileName) - 1] == '/') {
      strcat(fileName, "index.html");
    }
    fd = open(fileName, O_RDONLY);
    if (fd == -1) {
      strcpy(protocol, "HTTP/1.1 404 Not Found\r\n\r\n");
      send(clientSock, protocol, strlen(protocol), 0);
      errfd = open("error404.html", O_RDONLY);
      while ((strLength = read(errfd, buf, 4096)) > 0) {
        send(clientSock, buf, strLength, 0);
      }
      close(errfd);
    } else {
      while ((strLength = read(fd, buf, 4096)) > 0) {
        send(clientSock, buf, strLength, 0);
      }
    }
    close(fd);
    close(clientSock);
  }
  close(serverSock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1150,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x1090(%rbp),%rdi
lea    0xd79(%rip),%rsi
mov    $0x39,%edx
call   10e0 <memcpy@plt>
cmpl   $0x1,-0x8(%rbp)
je     12ba <main+0x5a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
mov    0x2cfe(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1180 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    12ec <main+0x8c>
lea    0xd5e(%rip),%rdi
call   1150 <ErrorHandling@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10b0 <memset@plt>
mov    0x2ce5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
call   10a0 <htonl@plt>
mov    %eax,-0x28(%rbp)
mov    $0x7d00,%edi
call   1070 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   1100 <bind@plt>
cmp    $0xffffffff,%eax
jne    134c <main+0xec>
lea    0xd0d(%rip),%rdi
call   1150 <ErrorHandling@plt>
mov    -0x14(%rbp),%edi
mov    $0xa,%esi
call   10f0 <listen@plt>
cmp    $0xffffffff,%eax
jne    136e <main+0x10e>
lea    0xcf8(%rip),%rdi
call   1150 <ErrorHandling@plt>
lea    0xcfb(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
movl   $0xc,-0x3c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
call   1140 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    13ac <main+0x14c>
lea    0xcdb(%rip),%rdi
call   1120 <perror@plt>
mov    -0x38(%rbp),%edi
call   1050 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xcd3(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x18(%rbp),%edi
lea    -0x1050(%rbp),%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x48(%rbp)
movslq -0x48(%rbp),%rax
movb   $0x0,-0x1050(%rbp,%rax,1)
lea    -0x10c0(%rbp),%rdi
lea    0xcb1(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x109a(%rbp),%rax
mov    %rax,-0x1140(%rbp)
lea    -0x1050(%rbp),%rdi
lea    0xc92(%rip),%rsi
call   1130 <strtok@plt>
mov    -0x1140(%rbp),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
lea    -0x10c0(%rbp),%rax
mov    %rax,-0x1138(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xc65(%rip),%rsi
call   1130 <strtok@plt>
mov    -0x1138(%rbp),%rdi
mov    %rax,%rsi
call   1160 <strcat@plt>
lea    -0x10c0(%rbp),%rdi
call   1060 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x10c0(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
jne    148f <main+0x22f>
lea    -0x10c0(%rbp),%rdi
lea    0xc23(%rip),%rsi
call   1160 <strcat@plt>
lea    -0x10c0(%rbp),%rdi
mov    0x2b43(%rip),%rax
mov    (%rax),%esi
call   1110 <open@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0xffffffff,-0x40(%rbp)
jne    155b <main+0x2fb>
lea    -0x1130(%rbp),%rdi
lea    0xbf9(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x114c(%rbp)
lea    -0x1130(%rbp),%rax
mov    %rax,-0x1148(%rbp)
lea    -0x1130(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x114c(%rbp),%edi
mov    -0x1148(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
mov    0x2adc(%rip),%rax
mov    (%rax),%esi
lea    0xbc6(%rip),%rdi
call   1110 <open@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%edi
lea    -0x1050(%rbp),%rsi
mov    $0x1000,%edx
call   10d0 <read@plt>
mov    %eax,-0x48(%rbp)
cmp    $0x0,%eax
jle    154e <main+0x2ee>
mov    -0x18(%rbp),%edi
lea    -0x1050(%rbp),%rsi
mov    -0x48(%rbp),%edx
xor    %ecx,%ecx
call   1080 <send@plt>
jmp    1515 <main+0x2b5>
mov    -0x44(%rbp),%edi
call   10c0 <close@plt>
jmp    159e <main+0x33e>
jmp    1560 <main+0x300>
mov    -0x40(%rbp),%edi
lea    -0x1050(%rbp),%rsi
mov    $0x1000,%edx
call   10d0 <read@plt>
mov    %eax,-0x48(%rbp)
cmp    $0x0,%eax
jle    1599 <main+0x339>
mov    -0x18(%rbp),%edi
lea    -0x1050(%rbp),%rsi
mov    -0x48(%rbp),%edx
xor    %ecx,%ecx
call   1080 <send@plt>
jmp    1560 <main+0x300>
jmp    159e <main+0x33e>
mov    -0x40(%rbp),%edi
call   10c0 <close@plt>
mov    -0x18(%rbp),%edi
call   10c0 <close@plt>
jmp    137c <main+0x11c>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10c8,%rsp
cmp    $0x1,%edi
jne    1517 <main+0x2b7>
mov    0x2d3f(%rip),%rax
mov    (%rax),%edi
mov    0x2d3e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1180 <socket@plt>
mov    %eax,%r12d
cmp    $0xffffffff,%eax
jne    12a7 <main+0x47>
lea    0xd6a(%rip),%rdi
call   1150 <ErrorHandling@plt>
lea    0x18(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10c0 <memset@plt>
mov    0x2d26(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
mov    0x2d09(%rip),%rax
mov    (%rax),%edi
call   10b0 <htonl@plt>
mov    %eax,0x18(%rsp)
mov    $0x7d00,%edi
call   1080 <htons@plt>
mov    %eax,0x1c(%rsp)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1100 <bind@plt>
cmp    $0xffffffff,%eax
jne    1309 <main+0xa9>
lea    0xd17(%rip),%rdi
call   1150 <ErrorHandling@plt>
mov    %r12d,%edi
mov    $0xa,%esi
call   10f0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1327 <main+0xc7>
lea    0xd06(%rip),%rdi
call   1150 <ErrorHandling@plt>
lea    0xd68(%rip),%rdi
call   1050 <puts@plt>
lea    0x8(%rsp),%r15
lea    0xc0(%rsp),%rbp
lea    0x30(%rsp),%r14
mov    %r12d,(%rsp)
jmp    1370 <main+0x110>
nopl   0x0(%rax,%rax,1)
mov    %r12d,%edi
call   10d0 <close@plt>
mov    (%rsp),%r12d
lea    0x8(%rsp),%r15
mov    %ebx,%edi
call   10d0 <close@plt>
mov    %r13d,%edi
call   10d0 <close@plt>
movl   $0xc,0x4(%rsp)
mov    %r12d,%edi
mov    %r15,%rsi
lea    0x4(%rsp),%rdx
call   1140 <accept@plt>
mov    %eax,%r13d
cmp    $0xffffffff,%eax
jne    139c <main+0x13c>
lea    0xca0(%rip),%rdi
call   1120 <perror@plt>
mov    %r12d,%r15d
mov    0x8(%rsp),%edi
call   1060 <inet_ntoa@plt>
lea    0xc97(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cltq
movb   $0x0,0xc0(%rsp,%rax,1)
mov    %r14,%rdi
lea    0xc7f(%rip),%rsi
call   1040 <strcpy@plt>
mov    %rbp,%rdi
lea    0xc72(%rip),%rbx
mov    %rbx,%rsi
call   1130 <strtok@plt>
lea    0x26(%rsp),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    %r14,%rbx
call   1130 <strtok@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1160 <strcat@plt>
mov    %r14,%rdi
call   1070 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%r14,1)
jne    143c <main+0x1dc>
mov    %rbx,%rdi
lea    0xc2b(%rip),%rsi
call   1160 <strcat@plt>
mov    0x2b9d(%rip),%r12
mov    (%r12),%esi
mov    %rbx,%rdi
call   1110 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    14d0 <main+0x270>
lea    0x50(%rsp),%r15
mov    %r15,%rdi
lea    0xc08(%rip),%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
call   1070 <strlen@plt>
mov    %r13d,%edi
mov    %r15,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
mov    (%r12),%esi
lea    0xbfc(%rip),%rdi
call   1110 <open@plt>
mov    %eax,%r12d
mov    %eax,%edi
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%rsi
mov    $0x1000,%edx
call   10e0 <read@plt>
test   %eax,%eax
jle    1350 <main+0xf0>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
mov    %r12d,%edi
jmp    14a0 <main+0x240>
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x1000,%edx
call   10e0 <read@plt>
test   %eax,%eax
mov    %r15d,%r12d
lea    0x8(%rsp),%r15
jle    1361 <main+0x101>
nop
mov    %r13d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x1000,%edx
call   10e0 <read@plt>
test   %eax,%eax
jg     14f0 <main+0x290>
jmp    1361 <main+0x101>
mov    (%rsi),%rsi
lea    0xadf(%rip),%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    $0x1,%edi
call   1170 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.header = [57 x i8] c"HTTP/1.1 200 OK\0D\0ADate: Wed, 12 Mar 2014 00:00:00 GMT\0D\0A\0D\0A\00"
@.str = [12 x i8] c"Usage : %s\0A\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [15 x i8] c"socket() error\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [13 x i8] c"bind() error\00"
@.str.3 = [15 x i8] c"listen() error\00"
@.str.4 = [18 x i8] c"Server Activated\0A\00"
@.str.5 = [15 x i8] c"accept() error\00"
@.str.6 = [24 x i8] c"Connection Request: %s\0A\00"
@.str.7 = [2 x i8] c".\00"
@.str.8 = [2 x i8] c" \00"
@.str.9 = [11 x i8] c"index.html\00"
@O_RDONLY = global i32 0
@.str.10 = [27 x i8] c"HTTP/1.1 404 Not Found\0D\0A\0D\0A\00"
@.str.11 = [14 x i8] c"error404.html\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 %struct.sockaddr_in
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca [4096 x i8]
%15 = alloca i32
%16 = alloca [57 x i8]
%17 = alloca [10 x i8]
%18 = alloca [30 x i8]
%19 = alloca [100 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%20 = bitcast [57 x i8]* %16 to i8*
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 1
br i1 %22, label %23, label %29
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %26)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %2
%30 = load i32, i32* @PF_INET
%31 = load i32, i32* @SOCK_STREAM
%32 = call i32 @socket(i32 %30, i32 %31, i32 0)
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %29
%36 = call i32 @ErrorHandling(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %37
37: ; preds = %35, %29
%38 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 12)
%39 = load i32, i32* @AF_INET
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %39, i32* %40
%41 = load i32, i32* @INADDR_ANY
%42 = call i32 @htonl(i32 %41)
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%44 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %43, i32 0, i32 0
store i32 %42, i32* %44
%45 = call i32 @htons(i32 32000)
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %45, i32* %46
%47 = load i32, i32* %6
%48 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%49 = call i32 @bind(i32 %47, %struct.sockaddr* %48, i32 12)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %53
51: ; preds = %37
%52 = call i32 @ErrorHandling(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %53
53: ; preds = %51, %37
%54 = load i32, i32* %6
%55 = call i32 @listen(i32 %54, i32 10)
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %59
57: ; preds = %53
%58 = call i32 @ErrorHandling(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %59
59: ; preds = %57, %53
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %61
61: ; preds = %59, %142
store i32 12, i32* %10
%62 = load i32, i32* %6
%63 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%64 = call i32 @accept(i32 %62, %struct.sockaddr* %63, i32* %10)
store i32 %64, i32* %7
%65 = load i32, i32* %7
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %69
67: ; preds = %61
%68 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
br label %69
69: ; preds = %67, %61
%70 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%71 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %70, i32 0, i32 0
%72 = load i32, i32* %71
%73 = call i8* @inet_ntoa(i32 %72)
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %73)
%75 = load i32, i32* %7
%76 = getelementptr inbounds [4096 x i8], [4096 x i8]* %14, i64 0, i64 0
%77 = call i32 @recv(i32 %75, i8* %76, i32 4096, i32 0)
store i32 %77, i32* %13
%78 = load i32, i32* %13
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds [4096 x i8], [4096 x i8]* %14, i64 0, i64 %79
store i8 0, i8* %80
%81 = getelementptr inbounds [30 x i8], [30 x i8]* %18, i64 0, i64 0
%82 = call i32 @strcpy(i8* %81, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%83 = getelementptr inbounds [10 x i8], [10 x i8]* %17, i64 0, i64 0
%84 = getelementptr inbounds [4096 x i8], [4096 x i8]* %14, i64 0, i64 0
%85 = call i8* @strtok(i8* %84, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%86 = call i32 @strcpy(i8* %83, i8* %85)
%87 = getelementptr inbounds [30 x i8], [30 x i8]* %18, i64 0, i64 0
%88 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%89 = call i32 @strcat(i8* %87, i8* %88)
%90 = getelementptr inbounds [30 x i8], [30 x i8]* %18, i64 0, i64 0
%91 = call i32 @strlen(i8* %90)
%92 = sub nsw i32 %91, 1
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds [30 x i8], [30 x i8]* %18, i64 0, i64 %93
%95 = load i8, i8* %94
%96 = sext i8 %95 to i32
%97 = icmp eq i32 %96, 47
br i1 %97, label %98, label %101
98: ; preds = %69
%99 = getelementptr inbounds [30 x i8], [30 x i8]* %18, i64 0, i64 0
%100 = call i32 @strcat(i8* %99, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
br label %101
101: ; preds = %98, %69
%102 = getelementptr inbounds [30 x i8], [30 x i8]* %18, i64 0, i64 0
%103 = load i32, i32* @O_RDONLY
%104 = call i32 @open(i8* %102, i32 %103)
store i32 %104, i32* %11
%105 = load i32, i32* %11
%106 = icmp eq i32 %105, -1
br i1 %106, label %107, label %130
107: ; preds = %101
%108 = getelementptr inbounds [100 x i8], [100 x i8]* %19, i64 0, i64 0
%109 = call i32 @strcpy(i8* %108, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
%110 = load i32, i32* %7
%111 = getelementptr inbounds [100 x i8], [100 x i8]* %19, i64 0, i64 0
%112 = getelementptr inbounds [100 x i8], [100 x i8]* %19, i64 0, i64 0
%113 = call i32 @strlen(i8* %112)
%114 = call i32 @send(i32 %110, i8* %111, i32 %113, i32 0)
%115 = load i32, i32* @O_RDONLY
%116 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0), i32 %115)
store i32 %116, i32* %12
br label %117
117: ; preds = %122, %107
%118 = load i32, i32* %12
%119 = getelementptr inbounds [4096 x i8], [4096 x i8]* %14, i64 0, i64 0
%120 = call i32 @read(i32 %118, i8* %119, i32 4096)
store i32 %120, i32* %13
%121 = icmp sgt i32 %120, 0
br i1 %121, label %122, label %127
122: ; preds = %117
%123 = load i32, i32* %7
%124 = getelementptr inbounds [4096 x i8], [4096 x i8]* %14, i64 0, i64 0
%125 = load i32, i32* %13
%126 = call i32 @send(i32 %123, i8* %124, i32 %125, i32 0)
br label %117
127: ; preds = %117
%128 = load i32, i32* %12
%129 = call i32 @close(i32 %128)
br label %142
130: ; preds = %101
br label %131
131: ; preds = %136, %130
%132 = load i32, i32* %11
%133 = getelementptr inbounds [4096 x i8], [4096 x i8]* %14, i64 0, i64 0
%134 = call i32 @read(i32 %132, i8* %133, i32 4096)
store i32 %134, i32* %13
%135 = icmp sgt i32 %134, 0
br i1 %135, label %136, label %141
136: ; preds = %131
%137 = load i32, i32* %7
%138 = getelementptr inbounds [4096 x i8], [4096 x i8]* %14, i64 0, i64 0
%139 = load i32, i32* %13
%140 = call i32 @send(i32 %137, i8* %138, i32 %139, i32 0)
br label %131
141: ; preds = %131
br label %142
142: ; preds = %141, %127
%143 = load i32, i32* %11
%144 = call i32 @close(i32 %143)
%145 = load i32, i32* %7
%146 = call i32 @close(i32 %145)
br label %61
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [12 x i8] c"Usage : %s\0A\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [15 x i8] c"socket() error\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [13 x i8] c"bind() error\00"
@.str.3 = [15 x i8] c"listen() error\00"
@.str.5 = [15 x i8] c"accept() error\00"
@.str.6 = [24 x i8] c"Connection Request: %s\0A\00"
@.str.7 = [2 x i8] c".\00"
@.str.8 = [2 x i8] c" \00"
@.str.9 = [11 x i8] c"index.html\00"
@O_RDONLY = global i32 0
@.str.10 = [27 x i8] c"HTTP/1.1 404 Not Found\0D\0A\0D\0A\00"
@.str.11 = [14 x i8] c"error404.html\00"
@str = [17 x i8] c"Server Activated\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [4096 x i8]
%7 = alloca [10 x i8]
%8 = alloca [30 x i8]
%9 = alloca [100 x i8]
%10 = bitcast %struct.sockaddr_in* %3 to i8*
%11 = bitcast %struct.sockaddr_in* %4 to i8*
%12 = bitcast i32* %5 to i8*
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%15 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 0
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%17 = icmp eq i32 %0, 1
br i1 %17, label %22, label %18
18: ; preds = %2
%19 = load i8*, i8** %1
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %2
%23 = load i32, i32* @PF_INET
%24 = load i32, i32* @SOCK_STREAM
%25 = tail call i32 @socket(i32 %23, i32 %24, i32 0)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = tail call i32 @ErrorHandling(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %27, %22
%30 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%31 = load i32, i32* @AF_INET
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %31, i32* %32
%33 = load i32, i32* @INADDR_ANY
%34 = call i32 @htonl(i32 %33)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %34, i32* %35
%36 = call i32 @htons(i32 32000)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %36, i32* %37
%38 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%39 = call i32 @bind(i32 %25, %struct.sockaddr* %38, i32 12)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %29
%42 = call i32 @ErrorHandling(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %43
43: ; preds = %41, %29
%44 = call i32 @listen(i32 %25, i32 10)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = call i32 @ErrorHandling(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %48
48: ; preds = %46, %43
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%50 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
br label %52
52: ; preds = %104, %48
store i32 12, i32* %5
%53 = call i32 @accept(i32 %25, %struct.sockaddr* %50, i32* %5)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
br label %57
57: ; preds = %55, %52
%58 = load i32, i32* %51
%59 = call i8* @inet_ntoa(i32 %58)
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %59)
%61 = call i32 @recv(i32 %53, i8* %13, i32 4096, i32 0)
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 %62
store i8 0, i8* %63
%64 = call i32 @strcpy(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%65 = call i8* @strtok(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%66 = call i32 @strcpy(i8* %14, i8* %65)
%67 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%68 = call i32 @strcat(i8* %15, i8* %67)
%69 = call i32 @strlen(i8* %15)
%70 = add nsw i32 %69, -1
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 %71
%73 = load i8, i8* %72
%74 = icmp eq i8 %73, 47
br i1 %74, label %75, label %77
75: ; preds = %57
%76 = call i32 @strcat(i8* %15, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
br label %77
77: ; preds = %75, %57
%78 = load i32, i32* @O_RDONLY
%79 = call i32 @open(i8* %15, i32 %78)
%80 = icmp eq i32 %79, -1
br i1 %80, label %84, label %81
81: ; preds = %77
%82 = call i32 @read(i32 %79, i8* %13, i32 4096)
%83 = icmp sgt i32 %82, 0
br i1 %83, label %99, label %104
84: ; preds = %77
%85 = call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
%86 = call i32 @strlen(i8* %16)
%87 = call i32 @send(i32 %53, i8* %16, i32 %86, i32 0)
%88 = load i32, i32* @O_RDONLY
%89 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0), i32 %88)
%90 = call i32 @read(i32 %89, i8* %13, i32 4096)
%91 = icmp sgt i32 %90, 0
br i1 %91, label %92, label %97
92: ; preds = %84, %92
%93 = phi i32 [ %95, %92 ], [ %90, %84 ]
%94 = call i32 @send(i32 %53, i8* %13, i32 %93, i32 0)
%95 = call i32 @read(i32 %89, i8* %13, i32 4096)
%96 = icmp sgt i32 %95, 0
br i1 %96, label %92, label %97
97: ; preds = %92, %84
%98 = call i32 @close(i32 %89)
br label %104
99: ; preds = %81, %99
%100 = phi i32 [ %102, %99 ], [ %82, %81 ]
%101 = call i32 @send(i32 %53, i8* %13, i32 %100, i32 0)
%102 = call i32 @read(i32 %79, i8* %13, i32 4096)
%103 = icmp sgt i32 %102, 0
br i1 %103, label %99, label %104
104: ; preds = %99, %81, %97
%105 = call i32 @close(i32 %79)
%106 = call i32 @close(i32 %53)
br label %52
}