#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 */

/* Type definitions */
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SHUT_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fatal(char *);
int /*<<< orphan*/ free(unsigned char *);
int get_file_size(int);
char *inet_ntoa(int /*<<< orphan*/);
scalar_t__ malloc(int);
int ntohs(int /*<<< orphan*/);
int open(unsigned char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, unsigned char *, int);
int recv_line(int, unsigned char *);
int /*<<< orphan*/ send(int, unsigned char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send_string(int, char *);
int /*<<< orphan*/ shutdown(int, int /*<<< orphan*/);
int /*<<< orphan*/ strcat(unsigned char *, ...);
int /*<<< orphan*/ strcpy(unsigned char *, char *);
int strlen(unsigned char *);
scalar_t__ strncmp(unsigned char *, char *, int);
unsigned char *strstr(unsigned char *, char *);
void handle_connection(int sockfd, struct sockaddr_in *client_addr_ptr) {
  unsigned char *ptr, request[500], resource[500];
  int fd, length;
  length = recv_line(sockfd, request);
  printf("Got request from %s:%d \"%s\"\n",
         inet_ntoa(client_addr_ptr->sin_addr), ntohs(client_addr_ptr->sin_port),
         request);
  ptr = strstr(request, " HTTP/");
  if (ptr == NULL) {
    printf(" NOT HTTP!\n");
  } else {
    *ptr = 0;
    ptr = NULL;
    if (strncmp(request, "GET ", 4) == 0)
      ptr = request + 4;
    if (strncmp(request, "HEAD ", 5) == 0)
      ptr = request + 5;
    if (ptr == NULL) {
      printf("\tUNKNOWN REQUEST!\n");
    } else {
      if (ptr[strlen(ptr) - 1] == '/')
        strcat(ptr, "index.html");
      strcpy(resource, "./webroot");
      strcat(resource, ptr);
      fd = open(resource, O_RDONLY, 0);
      printf("\tOpening \'%s\'\t", resource);
      if (fd == -1) {
        printf(" 404 Not Found\n");
        send_string(sockfd, "HTTP/1.0 404 NOT FOUND\r\n");
        send_string(sockfd, "Server: Tiny webserver\r\n\r\n");
        send_string(sockfd, "<html><head><title>404 Not Found</title></head>");
        send_string(sockfd, "<body><h1>URL not found</h1></body></html>\r\n");
      } else {
        printf(" 200 OK\n");
        send_string(sockfd, "HTTP/1.0 200 OK\r\n");
        send_string(sockfd, "Server: Tiny webserver\r\n\r\n");
        if (ptr == request + 4) {
          if ((length = get_file_size(fd)) == -1)
            fatal("getting resource file size");
          if ((ptr = (unsigned char *)malloc(length)) == NULL)
            fatal("allocating memory for reading resource");
          read(fd, ptr, length);
          send(sockfd, ptr, length, 0);
          free(ptr);
        }
        close(fd);
      }
    }
  }
  shutdown(sockfd, SHUT_RDWR);
}


x86 assembly (clang, -O0):
<handle_connection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x210(%rbp),%rsi
call   1120 <recv_line@plt>
mov    %eax,-0x418(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1070 <inet_ntoa@plt>
mov    %rax,-0x420(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   10f0 <ntohs@plt>
mov    -0x420(%rbp),%rsi
mov    %eax,%edx
lea    -0x210(%rbp),%rcx
lea    0xd74(%rip),%rdi
mov    $0x0,%al
call   10b0 <printf@plt>
lea    -0x210(%rbp),%rdi
lea    0xd7c(%rip),%rsi
call   1150 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12c8 <handle_connection+0x98>
lea    0xd68(%rip),%rdi
mov    $0x0,%al
call   10b0 <printf@plt>
jmp    1522 <handle_connection+0x2f2>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
movq   $0x0,-0x18(%rbp)
lea    -0x210(%rbp),%rdi
lea    0xd4b(%rip),%rsi
mov    $0x4,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
jne    1308 <handle_connection+0xd8>
lea    -0x210(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
lea    -0x210(%rbp),%rdi
lea    0xd1f(%rip),%rsi
mov    $0x5,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
jne    1339 <handle_connection+0x109>
lea    -0x210(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1357 <handle_connection+0x127>
lea    0xcf0(%rip),%rdi
mov    $0x0,%al
call   10b0 <printf@plt>
jmp    151d <handle_connection+0x2ed>
mov    -0x18(%rbp),%rax
mov    %rax,-0x428(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <strlen@plt>
mov    %eax,%ecx
mov    -0x428(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1399 <handle_connection+0x169>
mov    -0x18(%rbp),%rdi
lea    0xcbc(%rip),%rsi
mov    $0x0,%al
call   1130 <strcat@plt>
lea    -0x410(%rbp),%rdi
lea    0xcb2(%rip),%rsi
call   1060 <strcpy@plt>
lea    -0x410(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1130 <strcat@plt>
lea    -0x410(%rbp),%rdi
mov    0x2c14(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <open@plt>
mov    %eax,-0x414(%rbp)
lea    -0x410(%rbp),%rsi
lea    0xc7a(%rip),%rdi
mov    $0x0,%al
call   10b0 <printf@plt>
cmpl   $0xffffffff,-0x414(%rbp)
jne    144c <handle_connection+0x21c>
lea    0xc6e(%rip),%rdi
mov    $0x0,%al
call   10b0 <printf@plt>
mov    -0x4(%rbp),%edi
lea    0xc6d(%rip),%rsi
call   1040 <send_string@plt>
mov    -0x4(%rbp),%edi
lea    0xc77(%rip),%rsi
call   1040 <send_string@plt>
mov    -0x4(%rbp),%edi
lea    0xc83(%rip),%rsi
call   1040 <send_string@plt>
mov    -0x4(%rbp),%edi
lea    0xca4(%rip),%rsi
call   1040 <send_string@plt>
jmp    1518 <handle_connection+0x2e8>
lea    0xcc0(%rip),%rdi
mov    $0x0,%al
call   10b0 <printf@plt>
mov    -0x4(%rbp),%edi
lea    0xcb8(%rip),%rsi
call   1040 <send_string@plt>
mov    -0x4(%rbp),%edi
lea    0xc28(%rip),%rsi
call   1040 <send_string@plt>
mov    -0x18(%rbp),%rax
lea    -0x210(%rbp),%rcx
add    $0x4,%rcx
cmp    %rcx,%rax
jne    150d <handle_connection+0x2dd>
mov    -0x414(%rbp),%edi
call   1100 <get_file_size@plt>
mov    %eax,-0x418(%rbp)
cmp    $0xffffffff,%eax
jne    14b6 <handle_connection+0x286>
lea    0xc7d(%rip),%rdi
call   1140 <fatal@plt>
mov    -0x418(%rbp),%edi
call   10e0 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    14db <handle_connection+0x2ab>
lea    0xc73(%rip),%rdi
call   1140 <fatal@plt>
mov    -0x414(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x418(%rbp),%edx
call   10d0 <read@plt>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x418(%rbp),%edx
xor    %ecx,%ecx
call   10a0 <send@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x414(%rbp),%edi
call   10c0 <close@plt>
jmp    151d <handle_connection+0x2ed>
jmp    1522 <handle_connection+0x2f2>
mov    -0x4(%rbp),%edi
mov    0x2ac4(%rip),%rax
mov    (%rax),%esi
call   1080 <shutdown@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_connection>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%rbp
mov    %edi,%r12d
mov    %rsp,%r14
mov    %r14,%rsi
call   1130 <recv_line@plt>
mov    0x4(%rbp),%edi
call   1080 <inet_ntoa@plt>
mov    %rax,%rbx
mov    0x0(%rbp),%edi
call   1100 <ntohs@plt>
lea    0xd86(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
mov    %r14,%rcx
xor    %eax,%eax
call   10c0 <printf@plt>
lea    0xd8d(%rip),%rsi
mov    %r14,%rdi
call   1160 <strstr@plt>
test   %rax,%rax
je     1400 <handle_connection+0x1c0>
movb   $0x0,(%rax)
lea    0xd79(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x4,%edx
call   1050 <strncmp@plt>
xor    %ebx,%ebx
test   %rax,%rax
lea    0x4(%rsp),%r15
cmove  %r15,%rbx
lea    0xd59(%rip),%rsi
mov    %rbp,%rdi
mov    $0x5,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
lea    0x5(%rsp),%rbp
cmovne %rbx,%rbp
test   %rbp,%rbp
je     140e <handle_connection+0x1ce>
mov    %rbp,%rdi
call   10a0 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbp,1)
jne    1314 <handle_connection+0xd4>
lea    0xd25(%rip),%rsi
mov    %rbp,%rdi
xor    %eax,%eax
call   1140 <strcat@plt>
lea    0xd1f(%rip),%rsi
lea    0x200(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <strcpy@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1140 <strcat@plt>
mov    0x2ca1(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
xor    %edx,%edx
call   1120 <open@plt>
mov    %eax,%r14d
lea    0xcef(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10c0 <printf@plt>
cmp    $0xffffffff,%r14d
je     141c <handle_connection+0x1dc>
lea    0xdc8(%rip),%rdi
call   1070 <puts@plt>
lea    0xd68(%rip),%rsi
mov    %r12d,%edi
call   1040 <send_string@plt>
lea    0xce1(%rip),%rsi
mov    %r12d,%edi
call   1040 <send_string@plt>
cmp    %r15,%rbp
jne    13f6 <handle_connection+0x1b6>
mov    %r14d,%edi
call   1110 <get_file_size@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
jne    13b4 <handle_connection+0x174>
lea    0xd47(%rip),%rdi
call   1150 <fatal@plt>
mov    %r15d,%edi
call   10f0 <malloc@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    13d0 <handle_connection+0x190>
lea    0xd46(%rip),%rdi
call   1150 <fatal@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %r15d,%edx
call   10e0 <read@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    %r15d,%edx
xor    %ecx,%ecx
call   10b0 <send@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r14d,%edi
call   10d0 <close@plt>
jmp    1464 <handle_connection+0x224>
lea    0xd5a(%rip),%rdi
call   1070 <puts@plt>
jmp    1464 <handle_connection+0x224>
lea    0xd3a(%rip),%rdi
call   1070 <puts@plt>
jmp    1464 <handle_connection+0x224>
lea    0xd1d(%rip),%rdi
call   1070 <puts@plt>
lea    0xc24(%rip),%rsi
mov    %r12d,%edi
call   1040 <send_string@plt>
lea    0xc2e(%rip),%rsi
mov    %r12d,%edi
call   1040 <send_string@plt>
lea    0xc3a(%rip),%rsi
mov    %r12d,%edi
call   1040 <send_string@plt>
lea    0xc5b(%rip),%rsi
mov    %r12d,%edi
call   1040 <send_string@plt>
mov    0x2b85(%rip),%rax
mov    (%rax),%esi
mov    %r12d,%edi
call   1090 <shutdown@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32 }
@.str = [29 x i8] c"Got request from %s:%d \22%s\22\0A\00"
@.str.1 = [7 x i8] c" HTTP/\00"
@.str.2 = [12 x i8] c" NOT HTTP!\0A\00"
@.str.3 = [5 x i8] c"GET \00"
@.str.4 = [6 x i8] c"HEAD \00"
@.str.5 = [19 x i8] c"\09UNKNOWN REQUEST!\0A\00"
@.str.6 = [11 x i8] c"index.html\00"
@.str.7 = [10 x i8] c"./webroot\00"
@O_RDONLY = global i32 0
@.str.8 = [15 x i8] c"\09Opening '%s'\09\00"
@.str.9 = [16 x i8] c" 404 Not Found\0A\00"
@.str.10 = [25 x i8] c"HTTP/1.0 404 NOT FOUND\0D\0A\00"
@.str.11 = [27 x i8] c"Server: Tiny webserver\0D\0A\0D\0A\00"
@.str.12 = [48 x i8] c"<html><head><title>404 Not Found</title></head>\00"
@.str.13 = [45 x i8] c"<body><h1>URL not found</h1></body></html>\0D\0A\00"
@.str.14 = [9 x i8] c" 200 OK\0A\00"
@.str.15 = [18 x i8] c"HTTP/1.0 200 OK\0D\0A\00"
@.str.16 = [27 x i8] c"getting resource file size\00"
@.str.17 = [39 x i8] c"allocating memory for reading resource\00"
@SHUT_RDWR = global i32 0
define void @handle_connection(i32 %0, %struct.sockaddr_in* %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in*
%5 = alloca i8*
%6 = alloca [500 x i8]
%7 = alloca [500 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %3
store %struct.sockaddr_in* %1, %struct.sockaddr_in** %4
%10 = load i32, i32* %3
%11 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%12 = call i32 @recv_line(i32 %10, i8* %11)
store i32 %12, i32* %9
%13 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 1
%15 = load i32, i32* %14
%16 = call i8* @inet_ntoa(i32 %15)
%17 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @ntohs(i32 %19)
%21 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %16, i32 %20, i8* %21)
%23 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%24 = call i8* @strstr(i8* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i8* %24, i8** %5
%25 = load i8*, i8** %5
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %29
27: ; preds = %2
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %124
29: ; preds = %2
%30 = load i8*, i8** %5
store i8 0, i8* %30
store i8* null, i8** %5
%31 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%32 = call i64 @strncmp(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%36 = getelementptr inbounds i8, i8* %35, i64 4
store i8* %36, i8** %5
br label %37
37: ; preds = %34, %29
%38 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%39 = call i64 @strncmp(i8* %38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%43 = getelementptr inbounds i8, i8* %42, i64 5
store i8* %43, i8** %5
br label %44
44: ; preds = %41, %37
%45 = load i8*, i8** %5
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
br label %123
49: ; preds = %44
%50 = load i8*, i8** %5
%51 = load i8*, i8** %5
%52 = call i32 @strlen(i8* %51)
%53 = sub nsw i32 %52, 1
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %50, i64 %54
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
%58 = icmp eq i32 %57, 47
br i1 %58, label %59, label %62
59: ; preds = %49
%60 = load i8*, i8** %5
%61 = call i32 (i8*, ...) @strcat(i8* %60, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
br label %62
62: ; preds = %59, %49
%63 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%64 = call i32 @strcpy(i8* %63, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
%65 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%66 = load i8*, i8** %5
%67 = call i32 (i8*, ...) @strcat(i8* %65, i8* %66)
%68 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%69 = load i32, i32* @O_RDONLY
%70 = call i32 @open(i8* %68, i32 %69, i32 0)
store i32 %70, i32* %8
%71 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i8* %71)
%73 = load i32, i32* %8
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %85
75: ; preds = %62
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
%77 = load i32, i32* %3
%78 = call i32 @send_string(i32 %77, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.10, i64 0, i64 0))
%79 = load i32, i32* %3
%80 = call i32 @send_string(i32 %79, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
%81 = load i32, i32* %3
%82 = call i32 @send_string(i32 %81, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.12, i64 0, i64 0))
%83 = load i32, i32* %3
%84 = call i32 @send_string(i32 %83, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.13, i64 0, i64 0))
br label %122
85: ; preds = %62
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.14, i64 0, i64 0))
%87 = load i32, i32* %3
%88 = call i32 @send_string(i32 %87, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.15, i64 0, i64 0))
%89 = load i32, i32* %3
%90 = call i32 @send_string(i32 %89, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
%91 = load i8*, i8** %5
%92 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%93 = getelementptr inbounds i8, i8* %92, i64 4
%94 = icmp eq i8* %91, %93
br i1 %94, label %95, label %119
95: ; preds = %85
%96 = load i32, i32* %8
%97 = call i32 @get_file_size(i32 %96)
store i32 %97, i32* %9
%98 = icmp eq i32 %97, -1
br i1 %98, label %99, label %101
99: ; preds = %95
%100 = call i32 @fatal(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.16, i64 0, i64 0))
br label %101
101: ; preds = %99, %95
%102 = load i32, i32* %9
%103 = call i64 @malloc(i32 %102)
%104 = inttoptr i64 %103 to i8*
store i8* %104, i8** %5
%105 = icmp eq i8* %104, null
br i1 %105, label %106, label %108
106: ; preds = %101
%107 = call i32 @fatal(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.17, i64 0, i64 0))
br label %108
108: ; preds = %106, %101
%109 = load i32, i32* %8
%110 = load i8*, i8** %5
%111 = load i32, i32* %9
%112 = call i32 @read(i32 %109, i8* %110, i32 %111)
%113 = load i32, i32* %3
%114 = load i8*, i8** %5
%115 = load i32, i32* %9
%116 = call i32 @send(i32 %113, i8* %114, i32 %115, i32 0)
%117 = load i8*, i8** %5
%118 = call i32 @free(i8* %117)
br label %119
119: ; preds = %108, %85
%120 = load i32, i32* %8
%121 = call i32 @close(i32 %120)
br label %122
122: ; preds = %119, %75
br label %123
123: ; preds = %122, %47
br label %124
124: ; preds = %123, %27
%125 = load i32, i32* %3
%126 = load i32, i32* @SHUT_RDWR
%127 = call i32 @shutdown(i32 %125, i32 %126)
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32 }
@.str = [29 x i8] c"Got request from %s:%d \22%s\22\0A\00"
@.str.1 = [7 x i8] c" HTTP/\00"
@.str.3 = [5 x i8] c"GET \00"
@.str.4 = [6 x i8] c"HEAD \00"
@.str.6 = [11 x i8] c"index.html\00"
@.str.7 = [10 x i8] c"./webroot\00"
@O_RDONLY = global i32 0
@.str.8 = [15 x i8] c"\09Opening '%s'\09\00"
@.str.10 = [25 x i8] c"HTTP/1.0 404 NOT FOUND\0D\0A\00"
@.str.11 = [27 x i8] c"Server: Tiny webserver\0D\0A\0D\0A\00"
@.str.12 = [48 x i8] c"<html><head><title>404 Not Found</title></head>\00"
@.str.13 = [45 x i8] c"<body><h1>URL not found</h1></body></html>\0D\0A\00"
@.str.15 = [18 x i8] c"HTTP/1.0 200 OK\0D\0A\00"
@.str.16 = [27 x i8] c"getting resource file size\00"
@.str.17 = [39 x i8] c"allocating memory for reading resource\00"
@SHUT_RDWR = global i32 0
@str = [8 x i8] c" 200 OK\00"
@str.18 = [15 x i8] c" 404 Not Found\00"
@str.19 = [18 x i8] c"\09UNKNOWN REQUEST!\00"
@str.20 = [11 x i8] c" NOT HTTP!\00"
define void @handle_connection(i32 %0, %struct.sockaddr_in* nocapture %1) {
%3 = alloca [500 x i8]
%4 = alloca [500 x i8]
%5 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [500 x i8], [500 x i8]* %4, i64 0, i64 0
%7 = call i32 @recv_line(i32 %0, i8* %5)
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
%9 = load i32, i32* %8
%10 = call i8* @inet_ntoa(i32 %9)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%12 = load i32, i32* %11
%13 = call i32 @ntohs(i32 %12)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %10, i32 %13, i8* %5)
%15 = call i8* @strstr(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.20, i64 0, i64 0))
br label %75
19: ; preds = %2
store i8 0, i8* %15
%20 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%21 = icmp eq i64 %20, 0
%22 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 4
%23 = select i1 %21, i8* %22, i8* null
%24 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%25 = icmp eq i64 %24, 0
%26 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 5
%27 = select i1 %25, i8* %26, i8* %23
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %31
29: ; preds = %19
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.19, i64 0, i64 0))
br label %75
31: ; preds = %19
%32 = call i32 @strlen(i8* %27)
%33 = add nsw i32 %32, -1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %27, i64 %34
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 47
br i1 %37, label %38, label %40
38: ; preds = %31
%39 = call i32 (i8*, ...) @strcat(i8* %27, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
br label %40
40: ; preds = %38, %31
%41 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
%42 = call i32 (i8*, ...) @strcat(i8* %6, i8* %27)
%43 = load i32, i32* @O_RDONLY
%44 = call i32 @open(i8* %6, i32 %43, i32 0)
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i8* %6)
%46 = icmp eq i32 %44, -1
br i1 %46, label %47, label %53
47: ; preds = %40
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.18, i64 0, i64 0))
%49 = call i32 @send_string(i32 %0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.10, i64 0, i64 0))
%50 = call i32 @send_string(i32 %0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
%51 = call i32 @send_string(i32 %0, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.12, i64 0, i64 0))
%52 = call i32 @send_string(i32 %0, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.13, i64 0, i64 0))
br label %75
53: ; preds = %40
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
%55 = call i32 @send_string(i32 %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.15, i64 0, i64 0))
%56 = call i32 @send_string(i32 %0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
%57 = icmp eq i8* %27, %22
br i1 %57, label %58, label %73
58: ; preds = %53
%59 = call i32 @get_file_size(i32 %44)
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %63
61: ; preds = %58
%62 = call i32 @fatal(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.16, i64 0, i64 0))
br label %63
63: ; preds = %61, %58
%64 = call i64 @malloc(i32 %59)
%65 = inttoptr i64 %64 to i8*
%66 = icmp eq i64 %64, 0
br i1 %66, label %67, label %69
67: ; preds = %63
%68 = call i32 @fatal(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.17, i64 0, i64 0))
br label %69
69: ; preds = %67, %63
%70 = call i32 @read(i32 %44, i8* %65, i32 %59)
%71 = call i32 @send(i32 %0, i8* %65, i32 %59, i32 0)
%72 = call i32 @free(i8* %65)
br label %73
73: ; preds = %69, %53
%74 = call i32 @close(i32 %44)
br label %75
75: ; preds = %29, %73, %47, %17
%76 = load i32, i32* @SHUT_RDWR
%77 = call i32 @shutdown(i32 %0, i32 %76)
ret void
}