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

/* Variables and functions */
int /*<<< orphan*/ add_cache_header(char *, int *, int, int /*<<< orphan*/);
int /*<<< orphan*/ add_close_header(char *, int *, int);
char *cache_filename(char *, char *);
int /*<<< orphan*/ close(int);
int conn_socket(char *, int);
scalar_t__ extract_first_request(char *, int *, char *, int *);
char *extract_host(char *, int);
int extract_http_code(char *, int);
char *extract_uri(char *, int);
int file_get_contents(char *, char *, int);
int /*<<< orphan*/ file_put_contents(char *, char *, int);
int /*<<< orphan*/ free(char *);
int http_header(int, char *, int);
int /*<<< orphan*/ http_time(char *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int mempos(char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ remove_header(char *, int *, char *);
int send(int, char *, int, int /*<<< orphan*/);
int connection_handler(void *socket) {
  int close_client = 0, client = *(int *)socket;
  int server = -1;
  char request[1024 * 1024], response[1024 * 1024], requests[1024 * 1024],
      buffer[1024 * 1024];
  int request_size = 0, response_size = 0, requests_size = 0, buffer_size = 0;
  char *host = 0, *uri = 0, *cache_file = 0;
  buffer_size = recv(client, buffer, 1024 * 1024, 0);
  while (buffer_size > 0) {
    if (requests_size + buffer_size > 1024 * 1024) {
      return http_header(client, "413 Request Entity Too Large", 1);
    }
    memcpy(&requests[requests_size], buffer, buffer_size);
    requests_size += buffer_size;
    while (extract_first_request(requests, &requests_size, request,
                                 &request_size) == 0) {
      host = extract_host(request, request_size);
      uri = extract_uri(request, request_size);
      close_client = mempos(request, "Connection: close\r\n", request_size) + 1;
      if (host && uri) {
        server = conn_socket(host, 80);
        if (server < 0) {
          http_header(client, "502 Bad Gateway (1)", close_client);
        } else {
          printf("Connected to %s successfully to get %s.\n", host, uri);
          cache_file = cache_filename(host, uri);
          remove_header(request, &request_size, "If-None-Match");
          remove_header(request, &request_size, "If-Modified-Since");
          remove_header(request, &request_size, "Connection");
          add_cache_header(request, &request_size, 1024 * 1024,
                           http_time(cache_file));
          add_close_header(request, &request_size, 1024 * 1024);
          if (send(server, request, request_size, 0) != request_size) {
            http_header(client, "502 Bad Gateway (2)", close_client);
          } else {
            response_size = 0;
            while ((buffer_size = recv(server, buffer, 1024 * 1024, 0)) > 0) {
              if (response_size + buffer_size > 1024 * 1024) {
                printf("Buffer is full ! (should be %d)\n",
                       response_size + buffer_size);
                response_size = buffer_size = 0;
                break;
              }
              memcpy(&response[response_size], buffer, buffer_size);
              response_size += buffer_size;
            }
            if (buffer_size < 0) {
              printf("Error receiving data from server.\n");
              http_header(client, "502 Bad Gateway (3)", close_client);
            } else {
              printf("Connection closed by server.\n");
              if (response_size > 0) {
                switch (extract_http_code(response, response_size)) {
                case 304:
                  buffer_size =
                      file_get_contents(cache_file, buffer, 1024 * 1024);
                  if (buffer_size > 0) {
                    printf("Got 304, sending data from cache file %s.\n",
                           cache_file);
                    memcpy(response, buffer, buffer_size);
                    response_size = buffer_size;
                  } else {
                    printf("Got 304 but no cache file %s.\n", cache_file);
                  }
                  break;
                case 200:
                  printf("Got 200, saving data to cache file %s.\n",
                         cache_file);
                  file_put_contents(cache_file, response, response_size);
                  break;
                }
                if (send(client, response, response_size, 0) != response_size) {
                  printf("Error sending data back to the client.\n");
                  close(client);
                } else {
                  printf("Data sent back to the client.\n");
                  if (close_client) {
                    printf("Closing client connection.\n");
                    close(client);
                  }
                }
              } else {
                http_header(client, "502 Bad Gateway (4)", close_client);
              }
            }
          }
          close(server);
        }
        free(host);
        free(uri);
      } else {
        return http_header(client, "400 Bad Request", 1);
      }
    }
    buffer_size = recv(client, buffer, 1024 * 1024, 0);
  }
  printf("Connection with client closed\n");
  close(client);
}


x86 assembly (clang, -O0):
<connection_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400060,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movl   $0x0,-0x400024(%rbp)
movl   $0x0,-0x400028(%rbp)
movl   $0x0,-0x40002c(%rbp)
movl   $0x0,-0x400030(%rbp)
movq   $0x0,-0x400038(%rbp)
movq   $0x0,-0x400040(%rbp)
movq   $0x0,-0x400048(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x400020(%rbp),%rsi
mov    $0x100000,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,-0x400030(%rbp)
cmpl   $0x0,-0x400030(%rbp)
jle    1802 <connection_handler+0x5c2>
mov    -0x40002c(%rbp),%eax
add    -0x400030(%rbp),%eax
cmp    $0x100000,%eax
jle    130b <connection_handler+0xcb>
mov    -0x18(%rbp),%edi
lea    0xd07(%rip),%rsi
mov    $0x1,%edx
call   1100 <http_header@plt>
mov    %eax,-0x4(%rbp)
jmp    1818 <connection_handler+0x5d8>
movslq -0x40002c(%rbp),%rax
lea    -0x300020(%rbp),%rdi
add    %rax,%rdi
lea    -0x400020(%rbp),%rsi
mov    -0x400030(%rbp),%edx
call   1120 <memcpy@plt>
mov    -0x400030(%rbp),%eax
add    -0x40002c(%rbp),%eax
mov    %eax,-0x40002c(%rbp)
lea    -0x300020(%rbp),%rdi
lea    -0x100020(%rbp),%rdx
lea    -0x40002c(%rbp),%rsi
lea    -0x400024(%rbp),%rcx
call   1150 <extract_first_request@plt>
cmp    $0x0,%rax
jne    17e1 <connection_handler+0x5a1>
lea    -0x100020(%rbp),%rdi
mov    -0x400024(%rbp),%esi
call   1160 <extract_host@plt>
mov    %rax,-0x400038(%rbp)
lea    -0x100020(%rbp),%rdi
mov    -0x400024(%rbp),%esi
call   1080 <extract_uri@plt>
mov    %rax,-0x400040(%rbp)
lea    -0x100020(%rbp),%rdi
mov    -0x400024(%rbp),%edx
lea    0xc6c(%rip),%rsi
call   1070 <mempos@plt>
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpq   $0x0,-0x400038(%rbp)
je     17c0 <connection_handler+0x580>
cmpq   $0x0,-0x400040(%rbp)
je     17c0 <connection_handler+0x580>
mov    -0x400038(%rbp),%rdi
mov    $0x50,%esi
call   1130 <conn_socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    140d <connection_handler+0x1cd>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%edx
lea    0xc2e(%rip),%rsi
call   1100 <http_header@plt>
jmp    17a3 <connection_handler+0x563>
mov    -0x400038(%rbp),%rsi
mov    -0x400040(%rbp),%rdx
lea    0xc23(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x400038(%rbp),%rdi
mov    -0x400040(%rbp),%rsi
call   1140 <cache_filename@plt>
mov    %rax,-0x400048(%rbp)
lea    -0x100020(%rbp),%rdi
lea    -0x400024(%rbp),%rsi
lea    0xc16(%rip),%rdx
call   10b0 <remove_header@plt>
lea    -0x100020(%rbp),%rdi
lea    -0x400024(%rbp),%rsi
lea    0xc0a(%rip),%rdx
call   10b0 <remove_header@plt>
lea    -0x100020(%rbp),%rdi
lea    -0x400024(%rbp),%rsi
lea    0xc02(%rip),%rdx
call   10b0 <remove_header@plt>
lea    -0x100020(%rbp),%rax
mov    %rax,-0x400050(%rbp)
mov    -0x400048(%rbp),%rdi
call   10c0 <http_time@plt>
mov    -0x400050(%rbp),%rdi
mov    %eax,%ecx
lea    -0x400024(%rbp),%rsi
mov    $0x100000,%edx
call   1110 <add_cache_header@plt>
lea    -0x100020(%rbp),%rdi
lea    -0x400024(%rbp),%rsi
mov    $0x100000,%edx
call   10d0 <add_close_header@plt>
mov    -0x1c(%rbp),%edi
lea    -0x100020(%rbp),%rsi
mov    -0x400024(%rbp),%edx
xor    %ecx,%ecx
call   1090 <send@plt>
cmp    -0x400024(%rbp),%eax
je     1517 <connection_handler+0x2d7>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%edx
lea    0xb8c(%rip),%rsi
call   1100 <http_header@plt>
jmp    179b <connection_handler+0x55b>
movl   $0x0,-0x400028(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x400020(%rbp),%rsi
mov    $0x100000,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,-0x400030(%rbp)
cmp    $0x0,%eax
jle    15ca <connection_handler+0x38a>
mov    -0x400028(%rbp),%eax
add    -0x400030(%rbp),%eax
cmp    $0x100000,%eax
jle    1590 <connection_handler+0x350>
mov    -0x400028(%rbp),%esi
add    -0x400030(%rbp),%esi
lea    0xb3d(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
movl   $0x0,-0x400030(%rbp)
movl   $0x0,-0x400028(%rbp)
jmp    15ca <connection_handler+0x38a>
movslq -0x400028(%rbp),%rax
lea    -0x200020(%rbp),%rdi
add    %rax,%rdi
lea    -0x400020(%rbp),%rsi
mov    -0x400030(%rbp),%edx
call   1120 <memcpy@plt>
mov    -0x400030(%rbp),%eax
add    -0x400028(%rbp),%eax
mov    %eax,-0x400028(%rbp)
jmp    1521 <connection_handler+0x2e1>
cmpl   $0x0,-0x400030(%rbp)
jge    15fc <connection_handler+0x3bc>
lea    0xaf0(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%edx
lea    0xaff(%rip),%rsi
call   1100 <http_header@plt>
jmp    1796 <connection_handler+0x556>
lea    0xb02(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
cmpl   $0x0,-0x400028(%rbp)
jle    177f <connection_handler+0x53f>
mov    -0x400028(%rbp),%esi
lea    -0x200020(%rbp),%rdi
call   1050 <extract_http_code@plt>
mov    %eax,%ecx
mov    %ecx,-0x400054(%rbp)
sub    $0xc8,%eax
je     16db <connection_handler+0x49b>
jmp    1641 <connection_handler+0x401>
mov    -0x400054(%rbp),%eax
sub    $0x130,%eax
jne    1709 <connection_handler+0x4c9>
jmp    1657 <connection_handler+0x417>
mov    -0x400048(%rbp),%rdi
lea    -0x400020(%rbp),%rsi
mov    $0x100000,%edx
call   10f0 <file_get_contents@plt>
mov    %eax,-0x400030(%rbp)
cmpl   $0x0,-0x400030(%rbp)
jle    16c1 <connection_handler+0x481>
mov    -0x400048(%rbp),%rsi
lea    0xa93(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
lea    -0x200020(%rbp),%rdi
lea    -0x400020(%rbp),%rsi
mov    -0x400030(%rbp),%edx
call   1120 <memcpy@plt>
mov    -0x400030(%rbp),%eax
mov    %eax,-0x400028(%rbp)
jmp    16d6 <connection_handler+0x496>
mov    -0x400048(%rbp),%rsi
lea    0xa7f(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
jmp    1709 <connection_handler+0x4c9>
mov    -0x400048(%rbp),%rsi
lea    0xa84(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x400048(%rbp),%rdi
lea    -0x200020(%rbp),%rsi
mov    -0x400028(%rbp),%edx
call   1060 <file_put_contents@plt>
mov    -0x18(%rbp),%edi
lea    -0x200020(%rbp),%rsi
mov    -0x400028(%rbp),%edx
xor    %ecx,%ecx
call   1090 <send@plt>
cmp    -0x400028(%rbp),%eax
je     1747 <connection_handler+0x507>
lea    0xa62(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x18(%rbp),%edi
call   10e0 <close@plt>
jmp    177a <connection_handler+0x53a>
lea    0xa6f(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
je     1775 <connection_handler+0x535>
lea    0xa76(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x18(%rbp),%edi
call   10e0 <close@plt>
jmp    177a <connection_handler+0x53a>
jmp    1791 <connection_handler+0x551>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%edx
lea    0xa6c(%rip),%rsi
call   1100 <http_header@plt>
jmp    1796 <connection_handler+0x556>
jmp    179b <connection_handler+0x55b>
mov    -0x1c(%rbp),%edi
call   10e0 <close@plt>
mov    -0x400038(%rbp),%rdi
call   1030 <free@plt>
mov    -0x400040(%rbp),%rdi
call   1030 <free@plt>
jmp    17dc <connection_handler+0x59c>
mov    -0x18(%rbp),%edi
lea    0xa42(%rip),%rsi
mov    $0x1,%edx
call   1100 <http_header@plt>
mov    %eax,-0x4(%rbp)
jmp    1818 <connection_handler+0x5d8>
jmp    1340 <connection_handler+0x100>
mov    -0x18(%rbp),%edi
lea    -0x400020(%rbp),%rsi
mov    $0x100000,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,-0x400030(%rbp)
jmp    12cb <connection_handler+0x8b>
lea    0xa13(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x18(%rbp),%edi
call   10e0 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x400060,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<connection_handler>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x400028,%rsp
mov    (%rdi),%edi
movl   $0x0,0xc(%rsp)
movl   $0x0,0x14(%rsp)
lea    0x20(%rsp),%rsi
mov    %edi,0x10(%rsp)
mov    $0x100000,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
test   %eax,%eax
jle    169a <connection_handler+0x44a>
mov    %eax,%ebx
cmp    $0x100000,%eax
jle    12a9 <connection_handler+0x59>
lea    0xd60(%rip),%rsi
mov    0x10(%rsp),%edi
jmp    16bb <connection_handler+0x46b>
lea    0x20(%rsp),%r14
lea    0x200020(%rsp),%rbp
xor    %eax,%eax
cltq
lea    (%rsp,%rax,1),%rdi
add    $0x300020,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1130 <memcpy@plt>
add    %ebx,0x14(%rsp)
lea    0x300020(%rsp),%rdi
lea    0x14(%rsp),%rsi
mov    %rbp,%rdx
lea    0xc(%rsp),%rcx
call   1160 <extract_first_request@plt>
test   %rax,%rax
mov    0x10(%rsp),%r15d
je     1371 <connection_handler+0x121>
mov    %r15d,%edi
lea    0x20(%rsp),%r14
mov    %r14,%rsi
mov    $0x100000,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
test   %eax,%eax
jle    169a <connection_handler+0x44a>
mov    %eax,%ebx
mov    0x14(%rsp),%eax
mov    %ebx,%ecx
add    %eax,%ecx
cmp    $0x100000,%ecx
jle    12b8 <connection_handler+0x68>
jmp    1299 <connection_handler+0x49>
nopl   (%rax)
mov    %r15d,%edi
lea    0xcf7(%rip),%rsi
mov    %r13d,%edx
call   1110 <http_header@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0x300020(%rsp),%rdi
lea    0x14(%rsp),%rsi
mov    %rbp,%rdx
lea    0xc(%rsp),%rcx
call   1160 <extract_first_request@plt>
test   %rax,%rax
jne    12f7 <connection_handler+0xa7>
mov    0xc(%rsp),%esi
mov    %rbp,%rdi
call   1170 <extract_host@plt>
mov    %rax,%r14
mov    0xc(%rsp),%esi
mov    %rbp,%rdi
call   1090 <extract_uri@plt>
mov    %rax,%rbx
mov    0xc(%rsp),%edx
mov    %rbp,%rdi
lea    0xc80(%rip),%rsi
call   1080 <mempos@plt>
test   %r14,%r14
je     16b1 <connection_handler+0x461>
test   %rbx,%rbx
je     16b1 <connection_handler+0x461>
mov    %eax,%r13d
add    $0x1,%r13d
mov    %r14,%rdi
mov    $0x50,%esi
call   1140 <conn_socket@plt>
test   %eax,%eax
js     1330 <connection_handler+0xe0>
mov    %eax,%r12d
lea    0xc6b(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   10b0 <printf@plt>
mov    %r14,%rdi
mov    %rbx,0x18(%rsp)
mov    %rbx,%rsi
call   1150 <cache_filename@plt>
mov    %rax,%r15
mov    %rbp,%rdi
lea    0xc(%rsp),%rbx
mov    %rbx,%rsi
lea    0xc62(%rip),%rdx
call   10c0 <remove_header@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
lea    0xc5e(%rip),%rdx
call   10c0 <remove_header@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
lea    0xc5e(%rip),%rdx
call   10c0 <remove_header@plt>
mov    %r15,%rdi
call   10d0 <http_time@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x100000,%edx
mov    %eax,%ecx
call   1120 <add_cache_header@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x100000,%edx
call   10e0 <add_close_header@plt>
mov    0xc(%rsp),%edx
mov    %r12d,%edi
mov    %rbp,%rsi
xor    %ecx,%ecx
call   10a0 <send@plt>
cmp    0xc(%rsp),%eax
jne    1580 <connection_handler+0x330>
mov    %r12d,%edi
lea    0x20(%rsp),%rsi
mov    $0x100000,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
test   %eax,%eax
jle    1591 <connection_handler+0x341>
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
lea    (%rax,%rcx,1),%ebx
cmp    $0x100001,%ebx
jge    15b0 <connection_handler+0x360>
movslq %ecx,%rcx
lea    (%rsp,%rcx,1),%rdi
add    $0x100020,%rdi
lea    0x20(%rsp),%rbp
mov    %rbp,%rsi
mov    %eax,%edx
call   1130 <memcpy@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x100000,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %ebx,%ecx
test   %eax,%eax
jg     14a0 <connection_handler+0x250>
lea    0x200020(%rsp),%rbp
js     1593 <connection_handler+0x343>
lea    0xc9d(%rip),%rdi
call   1050 <puts@plt>
test   %ebx,%ebx
jle    15d4 <connection_handler+0x384>
lea    0x100020(%rsp),%rdi
mov    %ebx,%esi
call   1060 <extract_http_code@plt>
cmp    $0xc8,%eax
je     15fd <connection_handler+0x3ad>
cmp    $0x130,%eax
jne    1641 <connection_handler+0x3f1>
mov    %r15,%rdi
lea    0x20(%rsp),%rbp
mov    %rbp,%rsi
mov    $0x100000,%edx
call   1100 <file_get_contents@plt>
test   %eax,%eax
jle    1628 <connection_handler+0x3d8>
lea    0xb93(%rip),%rdi
mov    %r15,%rsi
mov    %eax,%ebx
xor    %eax,%eax
call   10b0 <printf@plt>
lea    0x100020(%rsp),%r15
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1130 <memcpy@plt>
mov    %r15,%rsi
lea    0x200020(%rsp),%rbp
jmp    1649 <connection_handler+0x3f9>
mov    0x10(%rsp),%r15d
mov    %r15d,%edi
lea    0xb0a(%rip),%rsi
jmp    15e3 <connection_handler+0x393>
jns    15c8 <connection_handler+0x378>
lea    0xc79(%rip),%rdi
call   1050 <puts@plt>
mov    0x10(%rsp),%r15d
mov    %r15d,%edi
lea    0xb20(%rip),%rsi
jmp    15e3 <connection_handler+0x393>
lea    0xaf6(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   10b0 <printf@plt>
lea    0x200020(%rsp),%rbp
lea    0xbc7(%rip),%rdi
call   1050 <puts@plt>
mov    0x10(%rsp),%r15d
mov    %r15d,%edi
lea    0xb71(%rip),%rsi
mov    %r13d,%edx
call   1110 <http_header@plt>
mov    0x18(%rsp),%rbx
mov    %r12d,%edi
call   10f0 <close@plt>
jmp    1342 <connection_handler+0xf2>
lea    0xb28(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   10b0 <printf@plt>
mov    %r15,%rdi
lea    0x100020(%rsp),%r15
mov    %r15,%rsi
mov    %ebx,%edx
call   1070 <file_put_contents@plt>
mov    %r15,%rsi
jmp    1649 <connection_handler+0x3f9>
lea    0xade(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   10b0 <printf@plt>
lea    0x200020(%rsp),%rbp
lea    0x100020(%rsp),%rsi
mov    0x10(%rsp),%r15d
mov    %r15d,%edi
mov    %ebx,%edx
xor    %ecx,%ecx
call   10a0 <send@plt>
cmp    %ebx,%eax
mov    0x18(%rsp),%rbx
jne    1681 <connection_handler+0x431>
lea    0xb49(%rip),%rdi
call   1050 <puts@plt>
test   %r13d,%r13d
je     15f0 <connection_handler+0x3a0>
lea    0xb52(%rip),%rdi
jmp    1688 <connection_handler+0x438>
lea    0xb64(%rip),%rdi
call   1050 <puts@plt>
mov    %r15d,%edi
call   10f0 <close@plt>
jmp    15f0 <connection_handler+0x3a0>
lea    0xad7(%rip),%rdi
call   1050 <puts@plt>
mov    0x10(%rsp),%edi
call   10f0 <close@plt>
jmp    16c5 <connection_handler+0x475>
lea    0xab0(%rip),%rsi
mov    %r15d,%edi
mov    $0x1,%edx
call   1110 <http_header@plt>
add    $0x400028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"413 Request Entity Too Large\00"
@.str.1 = [20 x i8] c"Connection: close\0D\0A\00"
@.str.2 = [20 x i8] c"502 Bad Gateway (1)\00"
@.str.3 = [41 x i8] c"Connected to %s successfully to get %s.\0A\00"
@.str.4 = [14 x i8] c"If-None-Match\00"
@.str.5 = [18 x i8] c"If-Modified-Since\00"
@.str.6 = [11 x i8] c"Connection\00"
@.str.7 = [20 x i8] c"502 Bad Gateway (2)\00"
@.str.8 = [33 x i8] c"Buffer is full ! (should be %d)\0A\00"
@.str.9 = [35 x i8] c"Error receiving data from server.\0A\00"
@.str.10 = [20 x i8] c"502 Bad Gateway (3)\00"
@.str.11 = [30 x i8] c"Connection closed by server.\0A\00"
@.str.12 = [43 x i8] c"Got 304, sending data from cache file %s.\0A\00"
@.str.13 = [31 x i8] c"Got 304 but no cache file %s.\0A\00"
@.str.14 = [40 x i8] c"Got 200, saving data to cache file %s.\0A\00"
@.str.15 = [40 x i8] c"Error sending data back to the client.\0A\00"
@.str.16 = [31 x i8] c"Data sent back to the client.\0A\00"
@.str.17 = [28 x i8] c"Closing client connection.\0A\00"
@.str.18 = [20 x i8] c"502 Bad Gateway (4)\00"
@.str.19 = [16 x i8] c"400 Bad Request\00"
@.str.20 = [31 x i8] c"Connection with client closed\0A\00"
define i32 @connection_handler(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [1048576 x i8]
%8 = alloca [1048576 x i8]
%9 = alloca [1048576 x i8]
%10 = alloca [1048576 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i8*
store i8* %0, i8** %3
store i32 0, i32* %4
%18 = load i8*, i8** %3
%19 = bitcast i8* %18 to i32*
%20 = load i32, i32* %19
store i32 %20, i32* %5
store i32 -1, i32* %6
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
store i8* null, i8** %15
store i8* null, i8** %16
store i8* null, i8** %17
%21 = load i32, i32* %5
%22 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %10, i64 0, i64 0
%23 = call i32 @recv(i32 %21, i8* %22, i32 1048576, i32 0)
store i32 %23, i32* %14
br label %24
24: ; preds = %210, %1
%25 = load i32, i32* %14
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %214
27: ; preds = %24
%28 = load i32, i32* %13
%29 = load i32, i32* %14
%30 = add nsw i32 %28, %29
%31 = icmp sgt i32 %30, 1048576
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i32, i32* %5
%34 = call i32 @http_header(i32 %33, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 1)
store i32 %34, i32* %2
br label %218
35: ; preds = %27
%36 = load i32, i32* %13
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %9, i64 0, i64 %37
%39 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %10, i64 0, i64 0
%40 = load i32, i32* %14
%41 = call i32 @memcpy(i8* %38, i8* %39, i32 %40)
%42 = load i32, i32* %14
%43 = load i32, i32* %13
%44 = add nsw i32 %43, %42
store i32 %44, i32* %13
br label %45
45: ; preds = %209, %35
%46 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %9, i64 0, i64 0
%47 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %7, i64 0, i64 0
%48 = call i64 @extract_first_request(i8* %46, i32* %13, i8* %47, i32* %11)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %210
50: ; preds = %45
%51 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %7, i64 0, i64 0
%52 = load i32, i32* %11
%53 = call i8* @extract_host(i8* %51, i32 %52)
store i8* %53, i8** %15
%54 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %7, i64 0, i64 0
%55 = load i32, i32* %11
%56 = call i8* @extract_uri(i8* %54, i32 %55)
store i8* %56, i8** %16
%57 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %7, i64 0, i64 0
%58 = load i32, i32* %11
%59 = call i32 @mempos(i8* %57, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %58)
%60 = add nsw i32 %59, 1
store i32 %60, i32* %4
%61 = load i8*, i8** %15
%62 = icmp ne i8* %61, null
br i1 %62, label %63, label %206
63: ; preds = %50
%64 = load i8*, i8** %16
%65 = icmp ne i8* %64, null
br i1 %65, label %66, label %206
66: ; preds = %63
%67 = load i8*, i8** %15
%68 = call i32 @conn_socket(i8* %67, i32 80)
store i32 %68, i32* %6
%69 = load i32, i32* %6
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %75
71: ; preds = %66
%72 = load i32, i32* %5
%73 = load i32, i32* %4
%74 = call i32 @http_header(i32 %72, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %73)
br label %201
75: ; preds = %66
%76 = load i8*, i8** %15
%77 = load i8*, i8** %16
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* %76, i8* %77)
%79 = load i8*, i8** %15
%80 = load i8*, i8** %16
%81 = call i8* @cache_filename(i8* %79, i8* %80)
store i8* %81, i8** %17
%82 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %7, i64 0, i64 0
%83 = call i32 @remove_header(i8* %82, i32* %11, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%84 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %7, i64 0, i64 0
%85 = call i32 @remove_header(i8* %84, i32* %11, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%86 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %7, i64 0, i64 0
%87 = call i32 @remove_header(i8* %86, i32* %11, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%88 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %7, i64 0, i64 0
%89 = load i8*, i8** %17
%90 = call i32 @http_time(i8* %89)
%91 = call i32 @add_cache_header(i8* %88, i32* %11, i32 1048576, i32 %90)
%92 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %7, i64 0, i64 0
%93 = call i32 @add_close_header(i8* %92, i32* %11, i32 1048576)
%94 = load i32, i32* %6
%95 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %7, i64 0, i64 0
%96 = load i32, i32* %11
%97 = call i32 @send(i32 %94, i8* %95, i32 %96, i32 0)
%98 = load i32, i32* %11
%99 = icmp ne i32 %97, %98
br i1 %99, label %100, label %104
100: ; preds = %75
%101 = load i32, i32* %5
%102 = load i32, i32* %4
%103 = call i32 @http_header(i32 %101, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i32 %102)
br label %198
104: ; preds = %75
store i32 0, i32* %12
br label %105
105: ; preds = %120, %104
%106 = load i32, i32* %6
%107 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %10, i64 0, i64 0
%108 = call i32 @recv(i32 %106, i8* %107, i32 1048576, i32 0)
store i32 %108, i32* %14
%109 = icmp sgt i32 %108, 0
br i1 %109, label %110, label %130
110: ; preds = %105
%111 = load i32, i32* %12
%112 = load i32, i32* %14
%113 = add nsw i32 %111, %112
%114 = icmp sgt i32 %113, 1048576
br i1 %114, label %115, label %120
115: ; preds = %110
%116 = load i32, i32* %12
%117 = load i32, i32* %14
%118 = add nsw i32 %116, %117
%119 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i32 %118)
store i32 0, i32* %14
store i32 0, i32* %12
br label %130
120: ; preds = %110
%121 = load i32, i32* %12
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %8, i64 0, i64 %122
%124 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %10, i64 0, i64 0
%125 = load i32, i32* %14
%126 = call i32 @memcpy(i8* %123, i8* %124, i32 %125)
%127 = load i32, i32* %14
%128 = load i32, i32* %12
%129 = add nsw i32 %128, %127
store i32 %129, i32* %12
br label %105
130: ; preds = %115, %105
%131 = load i32, i32* %14
%132 = icmp slt i32 %131, 0
br i1 %132, label %133, label %138
133: ; preds = %130
%134 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0))
%135 = load i32, i32* %5
%136 = load i32, i32* %4
%137 = call i32 @http_header(i32 %135, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0), i32 %136)
br label %197
138: ; preds = %130
%139 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.11, i64 0, i64 0))
%140 = load i32, i32* %12
%141 = icmp sgt i32 %140, 0
br i1 %141, label %142, label %192
142: ; preds = %138
%143 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %8, i64 0, i64 0
%144 = load i32, i32* %12
%145 = call i32 @extract_http_code(i8* %143, i32 %144)
switch i32 %145, label %171 [
i32 304, label %146
i32 200, label %164
]
146: ; preds = %142
%147 = load i8*, i8** %17
%148 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %10, i64 0, i64 0
%149 = call i32 @file_get_contents(i8* %147, i8* %148, i32 1048576)
store i32 %149, i32* %14
%150 = load i32, i32* %14
%151 = icmp sgt i32 %150, 0
br i1 %151, label %152, label %160
152: ; preds = %146
%153 = load i8*, i8** %17
%154 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.12, i64 0, i64 0), i8* %153)
%155 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %8, i64 0, i64 0
%156 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %10, i64 0, i64 0
%157 = load i32, i32* %14
%158 = call i32 @memcpy(i8* %155, i8* %156, i32 %157)
%159 = load i32, i32* %14
store i32 %159, i32* %12
br label %163
160: ; preds = %146
%161 = load i8*, i8** %17
%162 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.13, i64 0, i64 0), i8* %161)
br label %163
163: ; preds = %160, %152
br label %171
164: ; preds = %142
%165 = load i8*, i8** %17
%166 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.14, i64 0, i64 0), i8* %165)
%167 = load i8*, i8** %17
%168 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %8, i64 0, i64 0
%169 = load i32, i32* %12
%170 = call i32 @file_put_contents(i8* %167, i8* %168, i32 %169)
br label %171
171: ; preds = %142, %164, %163
%172 = load i32, i32* %5
%173 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %8, i64 0, i64 0
%174 = load i32, i32* %12
%175 = call i32 @send(i32 %172, i8* %173, i32 %174, i32 0)
%176 = load i32, i32* %12
%177 = icmp ne i32 %175, %176
br i1 %177, label %178, label %182
178: ; preds = %171
%179 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.15, i64 0, i64 0))
%180 = load i32, i32* %5
%181 = call i32 @close(i32 %180)
br label %191
182: ; preds = %171
%183 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.16, i64 0, i64 0))
%184 = load i32, i32* %4
%185 = icmp ne i32 %184, 0
br i1 %185, label %186, label %190
186: ; preds = %182
%187 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.17, i64 0, i64 0))
%188 = load i32, i32* %5
%189 = call i32 @close(i32 %188)
br label %190
190: ; preds = %186, %182
br label %191
191: ; preds = %190, %178
br label %196
192: ; preds = %138
%193 = load i32, i32* %5
%194 = load i32, i32* %4
%195 = call i32 @http_header(i32 %193, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.18, i64 0, i64 0), i32 %194)
br label %196
196: ; preds = %192, %191
br label %197
197: ; preds = %196, %133
br label %198
198: ; preds = %197, %100
%199 = load i32, i32* %6
%200 = call i32 @close(i32 %199)
br label %201
201: ; preds = %198, %71
%202 = load i8*, i8** %15
%203 = call i32 @free(i8* %202)
%204 = load i8*, i8** %16
%205 = call i32 @free(i8* %204)
br label %209
206: ; preds = %63, %50
%207 = load i32, i32* %5
%208 = call i32 @http_header(i32 %207, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.19, i64 0, i64 0), i32 1)
store i32 %208, i32* %2
br label %218
209: ; preds = %201
br label %45
210: ; preds = %45
%211 = load i32, i32* %5
%212 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %10, i64 0, i64 0
%213 = call i32 @recv(i32 %211, i8* %212, i32 1048576, i32 0)
store i32 %213, i32* %14
br label %24
214: ; preds = %24
%215 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.20, i64 0, i64 0))
%216 = load i32, i32* %5
%217 = call i32 @close(i32 %216)
br label %218
218: ; preds = %214, %206, %32
%219 = load i32, i32* %2
ret i32 %219
}

LLVM IR (-O2):
@.str = [29 x i8] c"413 Request Entity Too Large\00"
@.str.1 = [20 x i8] c"Connection: close\0D\0A\00"
@.str.2 = [20 x i8] c"502 Bad Gateway (1)\00"
@.str.3 = [41 x i8] c"Connected to %s successfully to get %s.\0A\00"
@.str.4 = [14 x i8] c"If-None-Match\00"
@.str.5 = [18 x i8] c"If-Modified-Since\00"
@.str.6 = [11 x i8] c"Connection\00"
@.str.7 = [20 x i8] c"502 Bad Gateway (2)\00"
@.str.8 = [33 x i8] c"Buffer is full ! (should be %d)\0A\00"
@.str.10 = [20 x i8] c"502 Bad Gateway (3)\00"
@.str.12 = [43 x i8] c"Got 304, sending data from cache file %s.\0A\00"
@.str.13 = [31 x i8] c"Got 304 but no cache file %s.\0A\00"
@.str.14 = [40 x i8] c"Got 200, saving data to cache file %s.\0A\00"
@.str.18 = [20 x i8] c"502 Bad Gateway (4)\00"
@.str.19 = [16 x i8] c"400 Bad Request\00"
@str = [30 x i8] c"Connection with client closed\00"
@str.21 = [29 x i8] c"Connection closed by server.\00"
@str.22 = [30 x i8] c"Data sent back to the client.\00"
@str.23 = [27 x i8] c"Closing client connection.\00"
@str.24 = [39 x i8] c"Error sending data back to the client.\00"
@str.25 = [34 x i8] c"Error receiving data from server.\00"
define i32 @connection_handler(i8* nocapture %0) {
%2 = alloca [1048576 x i8]
%3 = alloca [1048576 x i8]
%4 = alloca [1048576 x i8]
%5 = alloca [1048576 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i8* %0 to i32*
%9 = load i32, i32* %8
%10 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %2, i64 0, i64 0
%11 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %3, i64 0, i64 0
%12 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %4, i64 0, i64 0
%13 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %5, i64 0, i64 0
%14 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%15 = bitcast i32* %7 to i8*
store i32 0, i32* %7
%16 = call i32 @recv(i32 %9, i8* %13, i32 1048576, i32 0)
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %135
18: ; preds = %1
%19 = icmp sgt i32 %16, 1048576
br i1 %19, label %20, label %22
20: ; preds = %131, %18
%21 = call i32 @http_header(i32 %9, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 1)
br label %138
22: ; preds = %18, %131
%23 = phi i32 [ %129, %131 ], [ %16, %18 ]
%24 = phi i32 [ %132, %131 ], [ 0, %18 ]
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %4, i64 0, i64 %25
%27 = call i32 @memcpy(i8* %26, i8* %13, i32 %23)
%28 = load i32, i32* %7
%29 = add nsw i32 %28, %23
store i32 %29, i32* %7
%30 = call i64 @extract_first_request(i8* %12, i32* %7, i8* %10, i32* %6)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %128
32: ; preds = %22, %121
%33 = load i32, i32* %6
%34 = call i8* @extract_host(i8* %10, i32 %33)
%35 = load i32, i32* %6
%36 = call i8* @extract_uri(i8* %10, i32 %35)
%37 = load i32, i32* %6
%38 = call i32 @mempos(i8* %10, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %37)
%39 = add nsw i32 %38, 1
%40 = icmp ne i8* %34, null
%41 = icmp ne i8* %36, null
%42 = select i1 %40, i1 %41, i1 false
br i1 %42, label %43, label %126
43: ; preds = %32
%44 = call i32 @conn_socket(i8* %34, i32 80)
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = call i32 @http_header(i32 %9, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %39)
br label %121
48: ; preds = %43
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* %34, i8* %36)
%50 = call i8* @cache_filename(i8* %34, i8* %36)
%51 = call i32 @remove_header(i8* %10, i32* %6, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%52 = call i32 @remove_header(i8* %10, i32* %6, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%53 = call i32 @remove_header(i8* %10, i32* %6, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%54 = call i32 @http_time(i8* %50)
%55 = call i32 @add_cache_header(i8* %10, i32* %6, i32 1048576, i32 %54)
%56 = call i32 @add_close_header(i8* %10, i32* %6, i32 1048576)
%57 = load i32, i32* %6
%58 = call i32 @send(i32 %44, i8* %10, i32 %57, i32 0)
%59 = load i32, i32* %6
%60 = icmp eq i32 %58, %59
br i1 %60, label %61, label %64
61: ; preds = %48
%62 = call i32 @recv(i32 %44, i8* %13, i32 1048576, i32 0)
%63 = icmp sgt i32 %62, 0
br i1 %63, label %66, label %81
64: ; preds = %48
%65 = call i32 @http_header(i32 %9, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i32 %39)
br label %119
66: ; preds = %61, %73
%67 = phi i32 [ %77, %73 ], [ %62, %61 ]
%68 = phi i32 [ %69, %73 ], [ 0, %61 ]
%69 = add nsw i32 %67, %68
%70 = icmp sgt i32 %69, 1048576
br i1 %70, label %71, label %73
71: ; preds = %66
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i32 %69)
br label %115
73: ; preds = %66
%74 = sext i32 %68 to i64
%75 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %3, i64 0, i64 %74
%76 = call i32 @memcpy(i8* %75, i8* %13, i32 %67)
%77 = call i32 @recv(i32 %44, i8* %13, i32 1048576, i32 0)
%78 = icmp sgt i32 %77, 0
br i1 %78, label %66, label %79
79: ; preds = %73
%80 = icmp slt i32 %77, 0
br i1 %80, label %83, label %86
81: ; preds = %61
%82 = icmp slt i32 %62, 0
br i1 %82, label %83, label %115
83: ; preds = %81, %79
%84 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.25, i64 0, i64 0))
%85 = call i32 @http_header(i32 %9, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0), i32 %39)
br label %119
86: ; preds = %79
%87 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.21, i64 0, i64 0))
%88 = icmp sgt i32 %69, 0
br i1 %88, label %89, label %117
89: ; preds = %86
%90 = call i32 @extract_http_code(i8* %11, i32 %69)
switch i32 %90, label %102 [
i32 304, label %91
i32 200, label %99
]
91: ; preds = %89
%92 = call i32 @file_get_contents(i8* %50, i8* %13, i32 1048576)
%93 = icmp sgt i32 %92, 0
br i1 %93, label %94, label %97
94: ; preds = %91
%95 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.12, i64 0, i64 0), i8* %50)
%96 = call i32 @memcpy(i8* %11, i8* %13, i32 %92)
br label %102
97: ; preds = %91
%98 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.13, i64 0, i64 0), i8* %50)
br label %102
99: ; preds = %89
%100 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.14, i64 0, i64 0), i8* %50)
%101 = call i32 @file_put_contents(i8* %50, i8* %11, i32 %69)
br label %102
102: ; preds = %94, %97, %89, %99
%103 = phi i32 [ %69, %89 ], [ %69, %99 ], [ %92, %94 ], [ %69, %97 ]
%104 = call i32 @send(i32 %9, i8* %11, i32 %103, i32 0)
%105 = icmp eq i32 %104, %103
br i1 %105, label %109, label %106
106: ; preds = %102
%107 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.24, i64 0, i64 0))
%108 = call i32 @close(i32 %9)
br label %119
109: ; preds = %102
%110 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.22, i64 0, i64 0))
%111 = icmp eq i32 %39, 0
br i1 %111, label %119, label %112
112: ; preds = %109
%113 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.23, i64 0, i64 0))
%114 = call i32 @close(i32 %9)
br label %119
115: ; preds = %81, %71
%116 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.21, i64 0, i64 0))
br label %117
117: ; preds = %115, %86
%118 = call i32 @http_header(i32 %9, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.18, i64 0, i64 0), i32 %39)
br label %119
119: ; preds = %83, %106, %112, %109, %117, %64
%120 = call i32 @close(i32 %44)
br label %121
121: ; preds = %119, %46
%122 = call i32 @free(i8* %34)
%123 = call i32 @free(i8* %36)
%124 = call i64 @extract_first_request(i8* %12, i32* %7, i8* %10, i32* %6)
%125 = icmp eq i64 %124, 0
br i1 %125, label %32, label %128
126: ; preds = %32
%127 = call i32 @http_header(i32 %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.19, i64 0, i64 0), i32 1)
br label %138
128: ; preds = %121, %22
%129 = call i32 @recv(i32 %9, i8* %13, i32 1048576, i32 0)
%130 = icmp sgt i32 %129, 0
br i1 %130, label %131, label %135
131: ; preds = %128
%132 = load i32, i32* %7
%133 = add nsw i32 %132, %129
%134 = icmp sgt i32 %133, 1048576
br i1 %134, label %20, label %22
135: ; preds = %128, %1
%136 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%137 = call i32 @close(i32 %9)
br label %138
138: ; preds = %135, %126, %20
%139 = phi i32 [ %21, %20 ], [ %127, %126 ], [ undef, %135 ]
ret i32 %139
}