#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_close_header(char *, int *, int);
int /*<<< orphan*/ close(int);
int conn_socket(char *, int);
int get_int(char *, scalar_t__);
char *make_request(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, int, int /*<<< orphan*/);
int strlen(char *);
int main(int argc, char *argv[]) {
  char *request, buffer[1024 * 1024 + 1];
  int server, port, request_size = 0, buffer_size = 0, persistance = 0,
                    pipelining = 0, i = 0;
  if (argc < 6) {
    printf("Not enough arguments. Usage : %s server port persistance "
           "pipelining uri1 [uri2 [...]]\n",
           argv[0]);
    return -1;
  } else {
    port = get_int(argv[2], 0 - 1);
    if (port < 0 || port > 65535) {
      printf("Invalid port number. Port must range from %d to %d.\n", 0, 65535);
      return -2;
    }
    if (argv[3][0] == '1') {
      persistance = 1;
    }
    if (persistance && argv[4][0] == '1') {
      pipelining = 1;
    }
  }
  printf("pers=%d, pipe=%d\n", persistance, pipelining);
  if (persistance) {
    server = conn_socket("127.0.0.1", port);
    if (server < 0) {
      printf("Error connecting to proxy server.\n");
      return -3;
    } else {
      printf("Connected to proxy server successfully.\n");
    }
  }
  for (i = 5; i < argc; ++i) {
    if (!persistance) {
      server = conn_socket("127.0.0.1", port);
      if (server < 0) {
        printf("Error connecting to proxy server.\n");
        return -3;
      } else {
        printf("Connected to proxy server successfully.\n");
      }
    }
    request = make_request(argv[1], argv[i]);
    request_size = strlen(request);
    if (!persistance || i == argc - 1) {
      add_close_header(request, &request_size, 1024 * 1024);
      request[request_size] = '\0';
    }
    printf("\n--- REQUEST ---\n\n%s", request);
    if (send(server, request, request_size, 0) != request_size) {
      printf("Error sending data to server.\n");
      return -4;
    }
    if (!pipelining) {
      buffer_size = recv(server, buffer, 1024 * 1024, 0);
      if (buffer_size < 0) {
        printf("Error receiving data from server.\n");
      } else if (buffer_size == 0) {
        printf("Connection closed by server.\n");
      } else {
        buffer[buffer_size] = '\0';
        printf("\n--- RESPONSE ---\n\n%s", buffer);
      }
    }
    if (!persistance) {
      close(server);
      printf("Closed proxy connection.\n");
    }
  }
  if (pipelining) {
    do {
      buffer_size = recv(server, buffer, 1024 * 1024, 0);
      if (buffer_size < 0) {
        printf("Error receiving data from server.\n");
      } else if (buffer_size == 0) {
        printf("Connection closed by server.\n");
      } else {
        buffer[buffer_size] = '\0';
        printf("\n--- RESPONSE ---\n\n%s", buffer);
      }
    } while (buffer_size > 0);
  }
  if (persistance) {
    close(server);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x10002c(%rbp)
movl   $0x0,-0x100030(%rbp)
movl   $0x0,-0x100034(%rbp)
movl   $0x0,-0x100038(%rbp)
movl   $0x0,-0x10003c(%rbp)
cmpl   $0x6,-0x8(%rbp)
jge    1206 <main+0x76>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1609 <main+0x479>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    $0xffffffffffffffff,%rsi
call   10b0 <get_int@plt>
mov    %eax,-0x100028(%rbp)
cmpl   $0x0,-0x100028(%rbp)
jl     123d <main+0xad>
cmpl   $0xffff,-0x100028(%rbp)
jle    125e <main+0xce>
lea    0xe13(%rip),%rdi
xor    %esi,%esi
mov    $0xffff,%edx
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1609 <main+0x479>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
movsbl (%rax),%eax
cmp    $0x31,%eax
jne    127c <main+0xec>
movl   $0x1,-0x100034(%rbp)
cmpl   $0x0,-0x100034(%rbp)
je     12a7 <main+0x117>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
movsbl (%rax),%eax
cmp    $0x31,%eax
jne    12a7 <main+0x117>
movl   $0x1,-0x100038(%rbp)
jmp    12ac <main+0x11c>
mov    -0x100034(%rbp),%esi
mov    -0x100038(%rbp),%edx
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x0,-0x100034(%rbp)
je     1325 <main+0x195>
mov    -0x100028(%rbp),%esi
lea    0xdbe(%rip),%rdi
call   10a0 <conn_socket@plt>
mov    %eax,-0x100024(%rbp)
cmpl   $0x0,-0x100024(%rbp)
jge    1312 <main+0x182>
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1609 <main+0x479>
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1325 <main+0x195>
movl   $0x5,-0x10003c(%rbp)
mov    -0x10003c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1539 <main+0x3a9>
cmpl   $0x0,-0x100034(%rbp)
jne    139d <main+0x20d>
mov    -0x100028(%rbp),%esi
lea    0xd46(%rip),%rdi
call   10a0 <conn_socket@plt>
mov    %eax,-0x100024(%rbp)
cmpl   $0x0,-0x100024(%rbp)
jge    138a <main+0x1fa>
lea    0xd31(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1609 <main+0x479>
lea    0xd3a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    139d <main+0x20d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
movslq -0x10003c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <make_request@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x10002c(%rbp)
cmpl   $0x0,-0x100034(%rbp)
je     13ed <main+0x25d>
mov    -0x10003c(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1411 <main+0x281>
mov    -0x18(%rbp),%rdi
lea    -0x10002c(%rbp),%rsi
mov    $0x100000,%edx
call   1080 <add_close_header@plt>
mov    -0x18(%rbp),%rax
movslq -0x10002c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rsi
lea    0xcd8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x100024(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10002c(%rbp),%edx
xor    %ecx,%ecx
call   1060 <send@plt>
cmp    -0x10002c(%rbp),%eax
je     1460 <main+0x2d0>
lea    0xcbc(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xfffffffc,-0x4(%rbp)
jmp    1609 <main+0x479>
cmpl   $0x0,-0x100038(%rbp)
jne    14fa <main+0x36a>
mov    -0x100024(%rbp),%edi
lea    -0x100020(%rbp),%rsi
mov    $0x100000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x100030(%rbp)
cmpl   $0x0,-0x100030(%rbp)
jge    14ac <main+0x31c>
lea    0xc88(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    14f5 <main+0x365>
cmpl   $0x0,-0x100030(%rbp)
jne    14cc <main+0x33c>
lea    0xc8b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    14f0 <main+0x360>
movslq -0x100030(%rbp),%rax
movb   $0x0,-0x100020(%rbp,%rax,1)
lea    -0x100020(%rbp),%rsi
lea    0xc80(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    14f5 <main+0x365>
jmp    14fa <main+0x36a>
cmpl   $0x0,-0x100034(%rbp)
jne    1520 <main+0x390>
mov    -0x100024(%rbp),%edi
call   1090 <close@plt>
lea    0xc66(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1525 <main+0x395>
mov    -0x10003c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10003c(%rbp)
jmp    132f <main+0x19f>
cmpl   $0x0,-0x100038(%rbp)
je     15ea <main+0x45a>
jmp    154b <main+0x3bb>
mov    -0x100024(%rbp),%edi
lea    -0x100020(%rbp),%rsi
mov    $0x100000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x100030(%rbp)
cmpl   $0x0,-0x100030(%rbp)
jge    158a <main+0x3fa>
lea    0xbaa(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    15d3 <main+0x443>
cmpl   $0x0,-0x100030(%rbp)
jne    15aa <main+0x41a>
lea    0xbad(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    15ce <main+0x43e>
movslq -0x100030(%rbp),%rax
movb   $0x0,-0x100020(%rbp,%rax,1)
lea    -0x100020(%rbp),%rsi
lea    0xba2(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    15d3 <main+0x443>
jmp    15d8 <main+0x448>
cmpl   $0x0,-0x100030(%rbp)
jg     154b <main+0x3bb>
jmp    15ea <main+0x45a>
cmpl   $0x0,-0x100034(%rbp)
je     1602 <main+0x472>
mov    -0x100024(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x100040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x100028,%rsp
mov    %rsi,%rbx
movl   $0x0,0x8(%rsp)
cmp    $0x5,%edi
jg     11dc <main+0x3c>
mov    (%rbx),%rsi
lea    0xe35(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0xffffffff,%ebx
jmp    14a4 <main+0x304>
mov    %edi,%r15d
mov    0x10(%rbx),%rdi
mov    $0xffffffffffffffff,%rsi
call   10c0 <get_int@plt>
cmp    $0x10000,%eax
jb     1215 <main+0x75>
lea    0xe5a(%rip),%rdi
xor    %esi,%esi
mov    $0xffff,%edx
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0xfffffffe,%ebx
jmp    14a4 <main+0x304>
mov    %eax,%ebp
mov    0x18(%rbx),%rax
mov    (%rax),%r12b
xor    %esi,%esi
cmp    $0x31,%r12b
sete   %sil
mov    %ebp,0xc(%rsp)
jne    127b <main+0xdb>
mov    0x20(%rbx),%rax
mov    (%rax),%r14b
xor    %edx,%edx
cmp    $0x31,%r14b
sete   %dl
lea    0xe47(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xe4b(%rip),%rdi
mov    %ebp,%esi
call   10b0 <conn_socket@plt>
test   %eax,%eax
js     13fa <main+0x25a>
mov    %eax,%ebp
cmp    $0x31,%r14b
setne  0x6(%rsp)
lea    0xed5(%rip),%rdi
call   1050 <puts@plt>
jmp    1290 <main+0xf0>
lea    0xe0a(%rip),%rdi
xor    %edx,%edx
xor    %eax,%eax
call   1080 <printf@plt>
movb   $0x1,0x6(%rsp)
cmp    $0x31,%r12b
setne  0x7(%rsp)
lea    -0x1(%r15),%r14d
mov    %r15d,%eax
mov    %rax,0x18(%rsp)
mov    $0x5,%r15d
lea    0xe57(%rip),%rax
mov    %rax,0x10(%rsp)
jmp    12cf <main+0x12f>
nopl   0x0(%rax)
add    $0x1,%r15
cmp    %r15,0x18(%rsp)
je     1426 <main+0x286>
cmp    $0x31,%r12b
je     12fb <main+0x15b>
lea    0xdc2(%rip),%rdi
mov    0xc(%rsp),%esi
call   10b0 <conn_socket@plt>
test   %eax,%eax
js     13fa <main+0x25a>
mov    %eax,%ebp
lea    0xe53(%rip),%rdi
call   1050 <puts@plt>
mov    0x8(%rbx),%rdi
mov    (%rbx,%r15,8),%rsi
call   1040 <make_request@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   1060 <strlen@plt>
mov    %eax,0x8(%rsp)
cmp    %r15,%r14
sete   %al
or     0x7(%rsp),%al
cmp    $0x1,%al
jne    1342 <main+0x1a2>
mov    %r13,%rdi
lea    0x8(%rsp),%rsi
mov    $0x100000,%edx
call   1090 <add_close_header@plt>
movslq 0x8(%rsp),%rax
movb   $0x0,0x0(%r13,%rax,1)
lea    0xd5f(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x8(%rsp),%edx
mov    %ebp,%edi
mov    %r13,%rsi
xor    %ecx,%ecx
call   1070 <send@plt>
cmp    0x8(%rsp),%eax
jne    1410 <main+0x270>
cmpb   $0x0,0x6(%rsp)
je     13c0 <main+0x220>
mov    %ebp,%edi
lea    0x20(%rsp),%rsi
mov    $0x100000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
js     13b3 <main+0x213>
je     13e2 <main+0x242>
mov    %eax,%eax
movb   $0x0,0x20(%rsp,%rax,1)
lea    0xd22(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1080 <printf@plt>
cmp    $0x31,%r12b
je     12c0 <main+0x120>
jmp    13ca <main+0x22a>
lea    0xd4f(%rip),%rdi
call   1050 <puts@plt>
nop
cmp    $0x31,%r12b
je     12c0 <main+0x120>
mov    %ebp,%edi
call   10a0 <close@plt>
lea    0xcfb(%rip),%rdi
call   1050 <puts@plt>
jmp    12c0 <main+0x120>
lea    0xd03(%rip),%rdi
call   1050 <puts@plt>
cmp    $0x31,%r12b
je     12c0 <main+0x120>
jmp    13ca <main+0x22a>
lea    0xd70(%rip),%rdi
call   1050 <puts@plt>
mov    $0xfffffffd,%ebx
jmp    14a4 <main+0x304>
lea    0xd14(%rip),%rdi
call   1050 <puts@plt>
mov    $0xfffffffc,%ebx
jmp    14a4 <main+0x304>
cmpb   $0x0,0x6(%rsp)
jne    1495 <main+0x2f5>
lea    0x20(%rsp),%rsi
mov    %ebp,%edi
mov    $0x100000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
js     148b <main+0x2eb>
lea    0xc72(%rip),%r14
lea    0x20(%rsp),%rbx
test   %eax,%eax
je     147f <main+0x2df>
mov    %eax,%eax
movb   $0x0,0x20(%rsp,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x100000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jns    1450 <main+0x2b0>
jmp    148b <main+0x2eb>
lea    0xc66(%rip),%rax
mov    %rax,0x10(%rsp)
mov    0x10(%rsp),%rdi
call   1050 <puts@plt>
xor    %ebx,%ebx
cmp    $0x31,%r12b
jne    14a4 <main+0x304>
mov    %ebp,%edi
call   10a0 <close@plt>
mov    %ebx,%eax
add    $0x100028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [87 x i8] c"Not enough arguments. Usage : %s server port persistance pipelining uri1 [uri2 [...]]\0A\00"
@.str.1 = [53 x i8] c"Invalid port number. Port must range from %d to %d.\0A\00"
@.str.2 = [18 x i8] c"pers=%d, pipe=%d\0A\00"
@.str.3 = [10 x i8] c"127.0.0.1\00"
@.str.4 = [35 x i8] c"Error connecting to proxy server.\0A\00"
@.str.5 = [41 x i8] c"Connected to proxy server successfully.\0A\00"
@.str.6 = [21 x i8] c"\0A--- REQUEST ---\0A\0A%s\00"
@.str.7 = [31 x i8] c"Error sending data to server.\0A\00"
@.str.8 = [35 x i8] c"Error receiving data from server.\0A\00"
@.str.9 = [30 x i8] c"Connection closed by server.\0A\00"
@.str.10 = [22 x i8] c"\0A--- RESPONSE ---\0A\0A%s\00"
@.str.11 = [26 x i8] c"Closed proxy connection.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [1048577 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 6
br i1 %16, label %17, label %22
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str, i64 0, i64 0), i8* %20)
store i32 -1, i32* %3
br label %198
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @get_int(i8* %25, i64 -1)
store i32 %26, i32* %9
%27 = load i32, i32* %9
%28 = icmp slt i32 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %22
%30 = load i32, i32* %9
%31 = icmp sgt i32 %30, 65535
br i1 %31, label %32, label %34
32: ; preds = %29, %22
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 65535)
store i32 -2, i32* %3
br label %198
34: ; preds = %29
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 3
%37 = load i8*, i8** %36
%38 = getelementptr inbounds i8, i8* %37, i64 0
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 49
br i1 %41, label %42, label %43
42: ; preds = %34
store i32 1, i32* %12
br label %43
43: ; preds = %42, %34
%44 = load i32, i32* %12
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %55
46: ; preds = %43
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 4
%49 = load i8*, i8** %48
%50 = getelementptr inbounds i8, i8* %49, i64 0
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp eq i32 %52, 49
br i1 %53, label %54, label %55
54: ; preds = %46
store i32 1, i32* %13
br label %55
55: ; preds = %54, %46, %43
br label %56
56: ; preds = %55
%57 = load i32, i32* %12
%58 = load i32, i32* %13
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %57, i32 %58)
%60 = load i32, i32* %12
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %72
62: ; preds = %56
%63 = load i32, i32* %9
%64 = call i32 @conn_socket(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %63)
store i32 %64, i32* %8
%65 = load i32, i32* %8
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %62
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
store i32 -3, i32* %3
br label %198
69: ; preds = %62
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
br label %71
71: ; preds = %69
br label %72
72: ; preds = %71, %56
store i32 5, i32* %14
br label %73
73: ; preds = %159, %72
%74 = load i32, i32* %14
%75 = load i32, i32* %4
%76 = icmp slt i32 %74, %75
br i1 %76, label %77, label %162
77: ; preds = %73
%78 = load i32, i32* %12
%79 = icmp ne i32 %78, 0
br i1 %79, label %90, label %80
80: ; preds = %77
%81 = load i32, i32* %9
%82 = call i32 @conn_socket(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %81)
store i32 %82, i32* %8
%83 = load i32, i32* %8
%84 = icmp slt i32 %83, 0
br i1 %84, label %85, label %87
85: ; preds = %80
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
store i32 -3, i32* %3
br label %198
87: ; preds = %80
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
br label %89
89: ; preds = %87
br label %90
90: ; preds = %89, %77
%91 = load i8**, i8*** %5
%92 = getelementptr inbounds i8*, i8** %91, i64 1
%93 = load i8*, i8** %92
%94 = load i8**, i8*** %5
%95 = load i32, i32* %14
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i8*, i8** %94, i64 %96
%98 = load i8*, i8** %97
%99 = call i8* @make_request(i8* %93, i8* %98)
store i8* %99, i8** %6
%100 = load i8*, i8** %6
%101 = call i32 @strlen(i8* %100)
store i32 %101, i32* %10
%102 = load i32, i32* %12
%103 = icmp ne i32 %102, 0
br i1 %103, label %104, label %109
104: ; preds = %90
%105 = load i32, i32* %14
%106 = load i32, i32* %4
%107 = sub nsw i32 %106, 1
%108 = icmp eq i32 %105, %107
br i1 %108, label %109, label %116
109: ; preds = %104, %90
%110 = load i8*, i8** %6
%111 = call i32 @add_close_header(i8* %110, i32* %10, i32 1048576)
%112 = load i8*, i8** %6
%113 = load i32, i32* %10
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds i8, i8* %112, i64 %114
store i8 0, i8* %115
br label %116
116: ; preds = %109, %104
%117 = load i8*, i8** %6
%118 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %117)
%119 = load i32, i32* %8
%120 = load i8*, i8** %6
%121 = load i32, i32* %10
%122 = call i32 @send(i32 %119, i8* %120, i32 %121, i32 0)
%123 = load i32, i32* %10
%124 = icmp ne i32 %122, %123
br i1 %124, label %125, label %127
125: ; preds = %116
%126 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
store i32 -4, i32* %3
br label %198
127: ; preds = %116
%128 = load i32, i32* %13
%129 = icmp ne i32 %128, 0
br i1 %129, label %151, label %130
130: ; preds = %127
%131 = load i32, i32* %8
%132 = getelementptr inbounds [1048577 x i8], [1048577 x i8]* %7, i64 0, i64 0
%133 = call i32 @recv(i32 %131, i8* %132, i32 1048576, i32 0)
store i32 %133, i32* %11
%134 = load i32, i32* %11
%135 = icmp slt i32 %134, 0
br i1 %135, label %136, label %138
136: ; preds = %130
%137 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0))
br label %150
138: ; preds = %130
%139 = load i32, i32* %11
%140 = icmp eq i32 %139, 0
br i1 %140, label %141, label %143
141: ; preds = %138
%142 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0))
br label %149
143: ; preds = %138
%144 = load i32, i32* %11
%145 = sext i32 %144 to i64
%146 = getelementptr inbounds [1048577 x i8], [1048577 x i8]* %7, i64 0, i64 %145
store i8 0, i8* %146
%147 = getelementptr inbounds [1048577 x i8], [1048577 x i8]* %7, i64 0, i64 0
%148 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i8* %147)
br label %149
149: ; preds = %143, %141
br label %150
150: ; preds = %149, %136
br label %151
151: ; preds = %150, %127
%152 = load i32, i32* %12
%153 = icmp ne i32 %152, 0
br i1 %153, label %158, label %154
154: ; preds = %151
%155 = load i32, i32* %8
%156 = call i32 @close(i32 %155)
%157 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.11, i64 0, i64 0))
br label %158
158: ; preds = %154, %151
br label %159
159: ; preds = %158
%160 = load i32, i32* %14
%161 = add nsw i32 %160, 1
store i32 %161, i32* %14
br label %73
162: ; preds = %73
%163 = load i32, i32* %13
%164 = icmp ne i32 %163, 0
br i1 %164, label %165, label %191
165: ; preds = %162
br label %166
166: ; preds = %187, %165
%167 = load i32, i32* %8
%168 = getelementptr inbounds [1048577 x i8], [1048577 x i8]* %7, i64 0, i64 0
%169 = call i32 @recv(i32 %167, i8* %168, i32 1048576, i32 0)
store i32 %169, i32* %11
%170 = load i32, i32* %11
%171 = icmp slt i32 %170, 0
br i1 %171, label %172, label %174
172: ; preds = %166
%173 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0))
br label %186
174: ; preds = %166
%175 = load i32, i32* %11
%176 = icmp eq i32 %175, 0
br i1 %176, label %177, label %179
177: ; preds = %174
%178 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0))
br label %185
179: ; preds = %174
%180 = load i32, i32* %11
%181 = sext i32 %180 to i64
%182 = getelementptr inbounds [1048577 x i8], [1048577 x i8]* %7, i64 0, i64 %181
store i8 0, i8* %182
%183 = getelementptr inbounds [1048577 x i8], [1048577 x i8]* %7, i64 0, i64 0
%184 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i8* %183)
br label %185
185: ; preds = %179, %177
br label %186
186: ; preds = %185, %172
br label %187
187: ; preds = %186
%188 = load i32, i32* %11
%189 = icmp sgt i32 %188, 0
br i1 %189, label %166, label %190
190: ; preds = %187
br label %191
191: ; preds = %190, %162
%192 = load i32, i32* %12
%193 = icmp ne i32 %192, 0
br i1 %193, label %194, label %197
194: ; preds = %191
%195 = load i32, i32* %8
%196 = call i32 @close(i32 %195)
br label %197
197: ; preds = %194, %191
store i32 0, i32* %3
br label %198
198: ; preds = %197, %125, %85, %67, %32, %17
%199 = load i32, i32* %3
ret i32 %199
}

LLVM IR (-O2):
@.str = [87 x i8] c"Not enough arguments. Usage : %s server port persistance pipelining uri1 [uri2 [...]]\0A\00"
@.str.1 = [53 x i8] c"Invalid port number. Port must range from %d to %d.\0A\00"
@.str.2 = [18 x i8] c"pers=%d, pipe=%d\0A\00"
@.str.3 = [10 x i8] c"127.0.0.1\00"
@.str.6 = [21 x i8] c"\0A--- REQUEST ---\0A\0A%s\00"
@.str.10 = [22 x i8] c"\0A--- RESPONSE ---\0A\0A%s\00"
@str.14 = [25 x i8] c"Closed proxy connection.\00"
@str.15 = [29 x i8] c"Connection closed by server.\00"
@str.16 = [34 x i8] c"Error receiving data from server.\00"
@str.17 = [30 x i8] c"Error sending data to server.\00"
@str.19 = [40 x i8] c"Connected to proxy server successfully.\00"
@str.20 = [34 x i8] c"Error connecting to proxy server.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1048577 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [1048577 x i8], [1048577 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%7 = icmp slt i32 %0, 6
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([87 x i8], [87 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %120
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @get_int(i8* %13, i64 -1)
%15 = icmp ugt i32 %14, 65535
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 65535)
br label %120
18: ; preds = %11
%19 = getelementptr inbounds i8*, i8** %1, i64 3
%20 = load i8*, i8** %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 49
%23 = zext i1 %22 to i32
br i1 %22, label %26, label %24
24: ; preds = %18
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %23, i32 0)
br label %40
26: ; preds = %18
%27 = getelementptr inbounds i8*, i8** %1, i64 4
%28 = load i8*, i8** %27
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 49
%31 = zext i1 %30 to i32
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %23, i32 %31)
%33 = tail call i32 @conn_socket(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %26
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.20, i64 0, i64 0))
br label %120
37: ; preds = %26
%38 = xor i1 %30, true
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.19, i64 0, i64 0))
br label %40
40: ; preds = %37, %24
%41 = phi i1 [ %38, %37 ], [ true, %24 ]
%42 = phi i32 [ %33, %37 ], [ undef, %24 ]
%43 = getelementptr inbounds i8*, i8** %1, i64 1
%44 = xor i1 %22, true
%45 = add nsw i32 %0, -1
%46 = zext i32 %45 to i64
%47 = zext i32 %0 to i64
br label %48
48: ; preds = %40, %98
%49 = phi i64 [ 5, %40 ], [ %99, %98 ]
%50 = phi i32 [ %42, %40 ], [ %59, %98 ]
br i1 %22, label %58, label %51
51: ; preds = %48
%52 = call i32 @conn_socket(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %51
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.20, i64 0, i64 0))
br label %120
56: ; preds = %51
%57 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.19, i64 0, i64 0))
br label %58
58: ; preds = %56, %48
%59 = phi i32 [ %50, %48 ], [ %52, %56 ]
%60 = load i8*, i8** %43
%61 = getelementptr inbounds i8*, i8** %1, i64 %49
%62 = load i8*, i8** %61
%63 = call i8* @make_request(i8* %60, i8* %62)
%64 = call i32 @strlen(i8* %63)
store i32 %64, i32* %4
%65 = icmp eq i64 %49, %46
%66 = select i1 %44, i1 true, i1 %65
br i1 %66, label %67, label %72
67: ; preds = %58
%68 = call i32 @add_close_header(i8* %63, i32* %4, i32 1048576)
%69 = load i32, i32* %4
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %63, i64 %70
store i8 0, i8* %71
br label %72
72: ; preds = %58, %67
%73 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %63)
%74 = load i32, i32* %4
%75 = call i32 @send(i32 %59, i8* %63, i32 %74, i32 0)
%76 = load i32, i32* %4
%77 = icmp eq i32 %75, %76
br i1 %77, label %80, label %78
78: ; preds = %72
%79 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.17, i64 0, i64 0))
br label %120
80: ; preds = %72
br i1 %41, label %81, label %94
81: ; preds = %80
%82 = call i32 @recv(i32 %59, i8* %5, i32 1048576, i32 0)
%83 = icmp slt i32 %82, 0
br i1 %83, label %84, label %86
84: ; preds = %81
%85 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.16, i64 0, i64 0))
br label %94
86: ; preds = %81
%87 = icmp eq i32 %82, 0
br i1 %87, label %88, label %90
88: ; preds = %86
%89 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.15, i64 0, i64 0))
br label %94
90: ; preds = %86
%91 = zext i32 %82 to i64
%92 = getelementptr inbounds [1048577 x i8], [1048577 x i8]* %3, i64 0, i64 %91
store i8 0, i8* %92
%93 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i8* %5)
br label %94
94: ; preds = %84, %90, %88, %80
br i1 %22, label %98, label %95
95: ; preds = %94
%96 = call i32 @close(i32 %59)
%97 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.14, i64 0, i64 0))
br label %98
98: ; preds = %94, %95
%99 = add nuw nsw i64 %49, 1
%100 = icmp eq i64 %99, %47
br i1 %100, label %101, label %48
101: ; preds = %98
br i1 %41, label %117, label %102
102: ; preds = %101
%103 = call i32 @recv(i32 %59, i8* %5, i32 1048576, i32 0)
%104 = icmp slt i32 %103, 0
br i1 %104, label %114, label %105
105: ; preds = %102, %108
%106 = phi i32 [ %112, %108 ], [ %103, %102 ]
%107 = icmp eq i32 %106, 0
br i1 %107, label %114, label %108
108: ; preds = %105
%109 = zext i32 %106 to i64
%110 = getelementptr inbounds [1048577 x i8], [1048577 x i8]* %3, i64 0, i64 %109
store i8 0, i8* %110
%111 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i8* %5)
%112 = call i32 @recv(i32 %59, i8* %5, i32 1048576, i32 0)
%113 = icmp slt i32 %112, 0
br i1 %113, label %114, label %105
114: ; preds = %105, %108, %102
%115 = phi i8* [ getelementptr inbounds ([34 x i8], [34 x i8]* @str.16, i64 0, i64 0), %102 ], [ getelementptr inbounds ([34 x i8], [34 x i8]* @str.16, i64 0, i64 0), %108 ], [ getelementptr inbounds ([29 x i8], [29 x i8]* @str.15, i64 0, i64 0), %105 ]
%116 = call i32 @puts(i8* dereferenceable(1) %115)
br label %117
117: ; preds = %114, %101
br i1 %22, label %118, label %120
118: ; preds = %117
%119 = call i32 @close(i32 %59)
br label %120
120: ; preds = %117, %118, %78, %54, %35, %16, %8
%121 = phi i32 [ -1, %8 ], [ -2, %16 ], [ -3, %35 ], [ -4, %78 ], [ -3, %54 ], [ 0, %118 ], [ 0, %117 ]
ret i32 %121
}