#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 */
typedef int ssize_t;

/* Variables and functions */
scalar_t__ EAGAIN;
scalar_t__ EINTR;
scalar_t__ EWOULDBLOCK;
char *calloc(int, int);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ free(char *);
char *getenv(char *);
int read(int, char *, int);
scalar_t__ snprintf(char *, int, char *, char *, char *);
int socket_connect(char *, char *);
char *strdup(char const *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strstr(char const *, char *);
int strtol(char *, char **, int /*<<< orphan*/);
scalar_t__ write_bytes(int, char *, int);
int http_open(const char *fn) {
  char *p, *proxy, *q, *http_host, *host, *port, *path, *buf;
  int fd, ret, l;
  ssize_t bytes = 0, bufsz = 0x10000;
  if (strstr(fn, "http://") != fn)
    return 0;
  for (p = (char *)fn + 7; *p && *p != '/'; ++p)
    ;
  l = p - fn - 7;
  http_host = calloc(l + 1, 1);
  strncpy(http_host, fn + 7, l);
  http_host[l] = 0;
  for (q = http_host; *q && *q != ':'; ++q)
    ;
  if (*q == ':')
    *q++ = 0;
  proxy = getenv("http_proxy");
  if (proxy == 0) {
    host = strdup(http_host);
    port = strdup(*q ? q : "80");
    path = strdup(*p ? p : "/");
  } else {
    host =
        (strstr(proxy, "http://") == proxy) ? strdup(proxy + 7) : strdup(proxy);
    for (q = host; *q && *q != ':'; ++q)
      ;
    if (*q == ':')
      *q++ = 0;
    port = strdup(*q ? q : "80");
    path = strdup(fn);
  }
  l = 0;
  fd = socket_connect(host, port);
  buf = calloc(bufsz, 1);
  l += snprintf(buf + l, bufsz, "GET %s HTTP/1.0\r\nHost: %s\r\n\r\n", path,
                http_host);
  if (write_bytes(fd, buf, l) != 0) {
    close(fd);
    fd = -1;
    goto out;
  }
  l = 0;
retry:
  while (l < bufsz && (bytes = read(fd, buf + l, 1)) > 0) {
    if (buf[l] == '\n' && l >= 3)
      if (strncmp(buf + l - 3, "\r\n\r\n", 4) == 0)
        break;
    ++l;
  }
  if (bytes < 0 && (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR))
    goto retry;
  buf[l] = 0;
  if (bytes < 0 || l < 14) {
    close(fd);
    fd = -1;
    goto out;
  }
  ret = strtol(buf + 8, &p, 0);
  if (ret != 200) {
    close(fd);
    fd = -1;
  }
out:
  free(buf);
  free(http_host);
  free(host);
  free(port);
  free(path);
  return fd;
}


x86 assembly (clang, -O0):
<http_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x60(%rbp)
movl   $0x10000,-0x64(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe08(%rip),%rsi
call   10f0 <strstr@plt>
cmp    -0x10(%rbp),%rax
je     1213 <http_open+0x43>
movl   $0x0,-0x4(%rbp)
jmp    1713 <http_open+0x543>
mov    -0x10(%rbp),%rax
add    $0x7,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x65(%rbp)
je     1244 <http_open+0x74>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x65(%rbp)
mov    -0x65(%rbp),%al
test   $0x1,%al
jne    1254 <http_open+0x84>
jmp    126a <http_open+0x9a>
jmp    1259 <http_open+0x89>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    121f <http_open+0x4f>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
sub    $0x7,%rax
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x7,%rsi
mov    -0x5c(%rbp),%edx
call   1050 <strncpy@plt>
mov    -0x30(%rbp),%rax
movslq -0x5c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x66(%rbp)
je     12dd <http_open+0x10d>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
setne  %al
mov    %al,-0x66(%rbp)
mov    -0x66(%rbp),%al
test   $0x1,%al
jne    12ed <http_open+0x11d>
jmp    1303 <http_open+0x133>
jmp    12f2 <http_open+0x122>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    12b8 <http_open+0xe8>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    1325 <http_open+0x155>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x0,(%rax)
lea    0xcdc(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    13c6 <http_open+0x1f6>
mov    -0x30(%rbp),%rdi
call   10e0 <strdup@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     136a <http_open+0x19a>
mov    -0x28(%rbp),%rax
mov    %rax,-0x70(%rbp)
jmp    137a <http_open+0x1aa>
lea    0xca2(%rip),%rax
mov    %rax,-0x70(%rbp)
jmp    137a <http_open+0x1aa>
mov    -0x70(%rbp),%rdi
call   10e0 <strdup@plt>
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     13a4 <http_open+0x1d4>
mov    -0x18(%rbp),%rax
mov    %rax,-0x78(%rbp)
jmp    13b4 <http_open+0x1e4>
lea    0xc5b(%rip),%rax
mov    %rax,-0x78(%rbp)
jmp    13b4 <http_open+0x1e4>
mov    -0x78(%rbp),%rdi
call   10e0 <strdup@plt>
mov    %rax,-0x48(%rbp)
jmp    14d9 <http_open+0x309>
mov    -0x20(%rbp),%rdi
lea    0xc2f(%rip),%rsi
call   10f0 <strstr@plt>
cmp    -0x20(%rbp),%rax
jne    13f6 <http_open+0x226>
mov    -0x20(%rbp),%rdi
add    $0x7,%rdi
call   10e0 <strdup@plt>
mov    %rax,-0x80(%rbp)
jmp    1403 <http_open+0x233>
mov    -0x20(%rbp),%rdi
call   10e0 <strdup@plt>
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x81(%rbp)
je     143e <http_open+0x26e>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
setne  %al
mov    %al,-0x81(%rbp)
mov    -0x81(%rbp),%al
test   $0x1,%al
jne    1451 <http_open+0x281>
jmp    1467 <http_open+0x297>
jmp    1456 <http_open+0x286>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1413 <http_open+0x243>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    1489 <http_open+0x2b9>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     14a9 <http_open+0x2d9>
mov    -0x28(%rbp),%rax
mov    %rax,-0x90(%rbp)
jmp    14bc <http_open+0x2ec>
lea    0xb63(%rip),%rax
mov    %rax,-0x90(%rbp)
jmp    14bc <http_open+0x2ec>
mov    -0x90(%rbp),%rdi
call   10e0 <strdup@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   10e0 <strdup@plt>
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x5c(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   10c0 <socket_connect@plt>
mov    %eax,-0x54(%rbp)
mov    -0x64(%rbp),%edi
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
movslq -0x5c(%rbp),%rax
add    %rax,%rdi
mov    -0x64(%rbp),%esi
mov    -0x48(%rbp),%rcx
mov    -0x30(%rbp),%r8
lea    0xaf8(%rip),%rdx
call   1070 <snprintf@plt>
mov    %rax,%rcx
movslq -0x5c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x5c(%rbp)
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    -0x5c(%rbp),%edx
call   10d0 <write_bytes@plt>
cmp    $0x0,%rax
je     155d <http_open+0x38d>
mov    -0x54(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x54(%rbp)
jmp    16e0 <http_open+0x510>
movl   $0x0,-0x5c(%rbp)
jmp    1569 <http_open+0x399>
mov    -0x5c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x64(%rbp),%ecx
mov    %al,-0x91(%rbp)
jge    15a4 <http_open+0x3d4>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rsi
movslq -0x5c(%rbp),%rax
add    %rax,%rsi
mov    $0x1,%edx
call   1090 <read@plt>
mov    %eax,-0x60(%rbp)
cmp    $0x0,%eax
setg   %al
mov    %al,-0x91(%rbp)
mov    -0x91(%rbp),%al
test   $0x1,%al
jne    15b7 <http_open+0x3e7>
jmp    1618 <http_open+0x448>
mov    -0x50(%rbp),%rax
movslq -0x5c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    160a <http_open+0x43a>
cmpl   $0x3,-0x5c(%rbp)
jl     160a <http_open+0x43a>
mov    -0x50(%rbp),%rdi
movslq -0x5c(%rbp),%rax
add    %rax,%rdi
add    $0xfffffffffffffffd,%rdi
lea    0xa43(%rip),%rsi
mov    $0x4,%edx
call   1060 <strncmp@plt>
cmp    $0x0,%rax
jne    1605 <http_open+0x435>
jmp    1618 <http_open+0x448>
jmp    160a <http_open+0x43a>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1569 <http_open+0x399>
cmpl   $0x0,-0x60(%rbp)
jge    1675 <http_open+0x4a5>
mov    0x29b7(%rip),%rax
mov    (%rax),%rax
mov    0x298d(%rip),%rcx
cmp    (%rcx),%rax
je     1670 <http_open+0x4a0>
mov    0x299d(%rip),%rax
mov    (%rax),%rax
mov    0x298b(%rip),%rcx
cmp    (%rcx),%rax
je     1670 <http_open+0x4a0>
mov    0x2983(%rip),%rax
mov    (%rax),%rax
mov    0x2969(%rip),%rcx
cmp    (%rcx),%rax
jne    1675 <http_open+0x4a5>
jmp    1564 <http_open+0x394>
mov    -0x50(%rbp),%rax
movslq -0x5c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x0,-0x60(%rbp)
jl     1695 <http_open+0x4c5>
cmpl   $0xe,-0x5c(%rbp)
jge    16a9 <http_open+0x4d9>
mov    -0x54(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x54(%rbp)
jmp    16e0 <http_open+0x510>
mov    -0x50(%rbp),%rdi
add    $0x8,%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   10b0 <strtol@plt>
mov    %eax,-0x58(%rbp)
cmpl   $0xc8,-0x58(%rbp)
je     16db <http_open+0x50b>
mov    -0x54(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x54(%rbp)
jmp    16e0 <http_open+0x510>
mov    -0x50(%rbp),%rdi
call   1040 <free@plt>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
mov    -0x40(%rbp),%rdi
call   1040 <free@plt>
mov    -0x48(%rbp),%rdi
call   1040 <free@plt>
mov    -0x54(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_open>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
lea    0xe28(%rip),%rsi
mov    $0x7,%edx
call   1060 <strncmp@plt>
xor    %ebp,%ebp
test   %eax,%eax
jne    139f <http_open+0x1df>
lea    0x7(%r14),%r15
mov    $0x1,%edi
mov    %r15,%rbp
nopl   0x0(%rax,%rax,1)
movzbl 0x0(%rbp),%eax
test   %al,%al
je     1215 <http_open+0x55>
cmp    $0x2f,%al
je     1215 <http_open+0x55>
add    $0x1,%rbp
add    $0x1,%edi
jmp    1200 <http_open+0x40>
mov    %rbp,0x20(%rsp)
lea    -0x1(%rdi),%ebx
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1050 <strncpy@plt>
movslq %ebx,%rax
movb   $0x0,(%r12,%rax,1)
mov    %r12,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rbx),%eax
test   %al,%al
je     1268 <http_open+0xa8>
cmp    $0x3a,%al
je     1261 <http_open+0xa1>
add    $0x1,%rbx
jmp    1250 <http_open+0x90>
movb   $0x0,(%rbx)
add    $0x1,%rbx
lea    0xd99(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     12d5 <http_open+0x115>
mov    %rax,%r15
lea    0xd7d(%rip),%rsi
mov    $0x7,%edx
mov    %rax,%rdi
call   1060 <strncmp@plt>
lea    0x7(%r15),%rdi
test   %eax,%eax
cmovne %r15,%rdi
call   10e0 <strdup@plt>
mov    %rax,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rax
movzbl -0x1(%rax),%ecx
test   %cl,%cl
je     1307 <http_open+0x147>
cmp    $0x3a,%cl
jne    12b0 <http_open+0xf0>
movb   $0x0,-0x1(%rax)
cmpb   $0x0,(%rax)
lea    0xd44(%rip),%rdi
cmovne %rax,%rdi
jmp    130e <http_open+0x14e>
mov    %r12,%rdi
call   10e0 <strdup@plt>
cmpb   $0x0,(%rbx)
mov    %rax,%r15
lea    0xd29(%rip),%rdi
cmovne %rbx,%rdi
call   10e0 <strdup@plt>
cmpb   $0x0,0x0(%rbp)
mov    %rax,%rbx
lea    0xd05(%rip),%r14
cmovne %rbp,%r14
jmp    1316 <http_open+0x156>
lea    0xd05(%rip),%rdi
call   10e0 <strdup@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   10e0 <strdup@plt>
mov    %rax,%r14
mov    %r15,%rdi
mov    %rbx,%rsi
call   10c0 <socket_connect@plt>
mov    %eax,%ebp
mov    $0x10000,%edi
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,%r13
lea    0xccf(%rip),%rdx
mov    %rax,%rdi
mov    $0x10000,%esi
mov    %r14,%rcx
mov    %r12,%r8
call   1070 <snprintf@plt>
mov    %ebp,%edi
mov    %r13,%rsi
mov    %eax,%edx
call   10d0 <write_bytes@plt>
test   %rax,%rax
je     13b0 <http_open+0x1f0>
mov    %ebp,%edi
call   1080 <close@plt>
mov    $0xffffffff,%ebp
mov    %r13,%rdi
call   1040 <free@plt>
mov    %r12,%rdi
call   1040 <free@plt>
mov    %r15,%rdi
call   1040 <free@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %r14,%rdi
call   1040 <free@plt>
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12,0x8(%rsp)
mov    %rbx,(%rsp)
mov    %r15,0x10(%rsp)
xor    %r12d,%r12d
lea    0xc67(%rip),%r15
mov    0x2c11(%rip),%rbx
mov    0x2bea(%rip),%rdx
mov    0x2bfb(%rip),%rsi
xor    %eax,%eax
mov    %r14,0x18(%rsp)
cmp    $0xffff,%r12d
jg     145f <http_open+0x29f>
movslq %r12d,%r12
lea    (%r12,%r13,1),%r14
jmp    1415 <http_open+0x255>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r12
add    $0x1,%r14
cmp    $0x10000,%r12
je     14a4 <http_open+0x2e4>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1090 <read@plt>
test   %eax,%eax
jle    144c <http_open+0x28c>
cmpb   $0xa,(%r14)
jne    1400 <http_open+0x240>
cmp    $0x3,%r12
jl     1400 <http_open+0x240>
lea    -0x3(%r14),%rdi
mov    %r15,%rsi
mov    $0x4,%edx
call   1060 <strncmp@plt>
test   %rax,%rax
jne    1400 <http_open+0x240>
jmp    14c1 <http_open+0x301>
mov    0x18(%rsp),%r14
mov    0x2b68(%rip),%rdx
mov    0x2b79(%rip),%rsi
test   %eax,%eax
jns    14c1 <http_open+0x301>
mov    (%rbx),%rcx
cmp    (%rdx),%rcx
je     13e4 <http_open+0x224>
cmp    (%rsi),%rcx
je     13e4 <http_open+0x224>
mov    0x2b51(%rip),%rdi
cmp    (%rdi),%rcx
je     13e4 <http_open+0x224>
movslq %r12d,%rax
movb   $0x0,0x0(%r13,%rax,1)
mov    0x10(%rsp),%r15
mov    (%rsp),%rbx
mov    0x8(%rsp),%r12
jmp    136b <http_open+0x1ab>
movb   $0x0,0x10000(%r13)
mov    0x10(%rsp),%r15
mov    (%rsp),%rbx
mov    0x8(%rsp),%r12
mov    0x18(%rsp),%r14
jmp    14e6 <http_open+0x326>
movslq %r12d,%rax
movb   $0x0,0x0(%r13,%rax,1)
cmp    $0xe,%eax
mov    0x10(%rsp),%r15
mov    (%rsp),%rbx
mov    0x8(%rsp),%r12
mov    0x18(%rsp),%r14
jl     136b <http_open+0x1ab>
mov    %r13,%rdi
add    $0x8,%rdi
lea    0x20(%rsp),%rsi
xor    %edx,%edx
call   10b0 <strtol@plt>
cmp    $0xc8,%eax
jne    136b <http_open+0x1ab>
jmp    1377 <http_open+0x1b7>

LLVM IR (-O0):
@.str = [8 x i8] c"http://\00"
@.str.1 = [11 x i8] c"http_proxy\00"
@.str.2 = [3 x i8] c"80\00"
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [30 x i8] c"GET %s HTTP/1.0\0D\0AHost: %s\0D\0A\0D\0A\00"
@.str.5 = [5 x i8] c"\0D\0A\0D\0A\00"
@errno = global i64 0
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
@EINTR = global i64 0
define i32 @http_open(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %15
store i32 65536, i32* %16
%17 = load i8*, i8** %3
%18 = call i8* @strstr(i8* %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%19 = load i8*, i8** %3
%20 = icmp ne i8* %18, %19
br i1 %20, label %21, label %22
21: ; preds = %1
store i32 0, i32* %2
br label %282
22: ; preds = %1
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 7
store i8* %24, i8** %4
br label %25
25: ; preds = %38, %22
%26 = load i8*, i8** %4
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = load i8*, i8** %4
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 47
br label %35
35: ; preds = %30, %25
%36 = phi i1 [ false, %25 ], [ %34, %30 ]
br i1 %36, label %37, label %41
37: ; preds = %35
br label %38
38: ; preds = %37
%39 = load i8*, i8** %4
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %4
br label %25
41: ; preds = %35
%42 = load i8*, i8** %4
%43 = load i8*, i8** %3
%44 = ptrtoint i8* %42 to i64
%45 = ptrtoint i8* %43 to i64
%46 = sub i64 %44, %45
%47 = sub nsw i64 %46, 7
%48 = trunc i64 %47 to i32
store i32 %48, i32* %14
%49 = load i32, i32* %14
%50 = add nsw i32 %49, 1
%51 = call i8* @calloc(i32 %50, i32 1)
store i8* %51, i8** %7
%52 = load i8*, i8** %7
%53 = load i8*, i8** %3
%54 = getelementptr inbounds i8, i8* %53, i64 7
%55 = load i32, i32* %14
%56 = call i32 @strncpy(i8* %52, i8* %54, i32 %55)
%57 = load i8*, i8** %7
%58 = load i32, i32* %14
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
store i8 0, i8* %60
%61 = load i8*, i8** %7
store i8* %61, i8** %6
br label %62
62: ; preds = %75, %41
%63 = load i8*, i8** %6
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %72
67: ; preds = %62
%68 = load i8*, i8** %6
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = icmp ne i32 %70, 58
br label %72
72: ; preds = %67, %62
%73 = phi i1 [ false, %62 ], [ %71, %67 ]
br i1 %73, label %74, label %78
74: ; preds = %72
br label %75
75: ; preds = %74
%76 = load i8*, i8** %6
%77 = getelementptr inbounds i8, i8* %76, i32 1
store i8* %77, i8** %6
br label %62
78: ; preds = %72
%79 = load i8*, i8** %6
%80 = load i8, i8* %79
%81 = sext i8 %80 to i32
%82 = icmp eq i32 %81, 58
br i1 %82, label %83, label %86
83: ; preds = %78
%84 = load i8*, i8** %6
%85 = getelementptr inbounds i8, i8* %84, i32 1
store i8* %85, i8** %6
store i8 0, i8* %84
br label %86
86: ; preds = %83, %78
%87 = call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i8* %87, i8** %5
%88 = load i8*, i8** %5
%89 = icmp eq i8* %88, null
br i1 %89, label %90, label %113
90: ; preds = %86
%91 = load i8*, i8** %7
%92 = call i8* @strdup(i8* %91)
store i8* %92, i8** %8
%93 = load i8*, i8** %6
%94 = load i8, i8* %93
%95 = sext i8 %94 to i32
%96 = icmp ne i32 %95, 0
br i1 %96, label %97, label %99
97: ; preds = %90
%98 = load i8*, i8** %6
br label %100
99: ; preds = %90
br label %100
100: ; preds = %99, %97
%101 = phi i8* [ %98, %97 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %99 ]
%102 = call i8* @strdup(i8* %101)
store i8* %102, i8** %9
%103 = load i8*, i8** %4
%104 = load i8, i8* %103
%105 = sext i8 %104 to i32
%106 = icmp ne i32 %105, 0
br i1 %106, label %107, label %109
107: ; preds = %100
%108 = load i8*, i8** %4
br label %110
109: ; preds = %100
br label %110
110: ; preds = %109, %107
%111 = phi i8* [ %108, %107 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), %109 ]
%112 = call i8* @strdup(i8* %111)
store i8* %112, i8** %10
br label %165
113: ; preds = %86
%114 = load i8*, i8** %5
%115 = call i8* @strstr(i8* %114, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%116 = load i8*, i8** %5
%117 = icmp eq i8* %115, %116
br i1 %117, label %118, label %122
118: ; preds = %113
%119 = load i8*, i8** %5
%120 = getelementptr inbounds i8, i8* %119, i64 7
%121 = call i8* @strdup(i8* %120)
br label %125
122: ; preds = %113
%123 = load i8*, i8** %5
%124 = call i8* @strdup(i8* %123)
br label %125
125: ; preds = %122, %118
%126 = phi i8* [ %121, %118 ], [ %124, %122 ]
store i8* %126, i8** %8
%127 = load i8*, i8** %8
store i8* %127, i8** %6
br label %128
128: ; preds = %141, %125
%129 = load i8*, i8** %6
%130 = load i8, i8* %129
%131 = sext i8 %130 to i32
%132 = icmp ne i32 %131, 0
br i1 %132, label %133, label %138
133: ; preds = %128
%134 = load i8*, i8** %6
%135 = load i8, i8* %134
%136 = sext i8 %135 to i32
%137 = icmp ne i32 %136, 58
br label %138
138: ; preds = %133, %128
%139 = phi i1 [ false, %128 ], [ %137, %133 ]
br i1 %139, label %140, label %144
140: ; preds = %138
br label %141
141: ; preds = %140
%142 = load i8*, i8** %6
%143 = getelementptr inbounds i8, i8* %142, i32 1
store i8* %143, i8** %6
br label %128
144: ; preds = %138
%145 = load i8*, i8** %6
%146 = load i8, i8* %145
%147 = sext i8 %146 to i32
%148 = icmp eq i32 %147, 58
br i1 %148, label %149, label %152
149: ; preds = %144
%150 = load i8*, i8** %6
%151 = getelementptr inbounds i8, i8* %150, i32 1
store i8* %151, i8** %6
store i8 0, i8* %150
br label %152
152: ; preds = %149, %144
%153 = load i8*, i8** %6
%154 = load i8, i8* %153
%155 = sext i8 %154 to i32
%156 = icmp ne i32 %155, 0
br i1 %156, label %157, label %159
157: ; preds = %152
%158 = load i8*, i8** %6
br label %160
159: ; preds = %152
br label %160
160: ; preds = %159, %157
%161 = phi i8* [ %158, %157 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %159 ]
%162 = call i8* @strdup(i8* %161)
store i8* %162, i8** %9
%163 = load i8*, i8** %3
%164 = call i8* @strdup(i8* %163)
store i8* %164, i8** %10
br label %165
165: ; preds = %160, %110
store i32 0, i32* %14
%166 = load i8*, i8** %8
%167 = load i8*, i8** %9
%168 = call i32 @socket_connect(i8* %166, i8* %167)
store i32 %168, i32* %12
%169 = load i32, i32* %16
%170 = call i8* @calloc(i32 %169, i32 1)
store i8* %170, i8** %11
%171 = load i8*, i8** %11
%172 = load i32, i32* %14
%173 = sext i32 %172 to i64
%174 = getelementptr inbounds i8, i8* %171, i64 %173
%175 = load i32, i32* %16
%176 = load i8*, i8** %10
%177 = load i8*, i8** %7
%178 = call i64 @snprintf(i8* %174, i32 %175, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %176, i8* %177)
%179 = load i32, i32* %14
%180 = sext i32 %179 to i64
%181 = add nsw i64 %180, %178
%182 = trunc i64 %181 to i32
store i32 %182, i32* %14
%183 = load i32, i32* %12
%184 = load i8*, i8** %11
%185 = load i32, i32* %14
%186 = call i64 @write_bytes(i32 %183, i8* %184, i32 %185)
%187 = icmp ne i64 %186, 0
br i1 %187, label %188, label %191
188: ; preds = %165
%189 = load i32, i32* %12
%190 = call i32 @close(i32 %189)
store i32 -1, i32* %12
br label %270
191: ; preds = %165
store i32 0, i32* %14
br label %192
192: ; preds = %246, %191
br label %193
193: ; preds = %228, %192
%194 = load i32, i32* %14
%195 = load i32, i32* %16
%196 = icmp slt i32 %194, %195
br i1 %196, label %197, label %205
197: ; preds = %193
%198 = load i32, i32* %12
%199 = load i8*, i8** %11
%200 = load i32, i32* %14
%201 = sext i32 %200 to i64
%202 = getelementptr inbounds i8, i8* %199, i64 %201
%203 = call i32 @read(i32 %198, i8* %202, i32 1)
store i32 %203, i32* %15
%204 = icmp sgt i32 %203, 0
br label %205
205: ; preds = %197, %193
%206 = phi i1 [ false, %193 ], [ %204, %197 ]
br i1 %206, label %207, label %231
207: ; preds = %205
%208 = load i8*, i8** %11
%209 = load i32, i32* %14
%210 = sext i32 %209 to i64
%211 = getelementptr inbounds i8, i8* %208, i64 %210
%212 = load i8, i8* %211
%213 = sext i8 %212 to i32
%214 = icmp eq i32 %213, 10
br i1 %214, label %215, label %228
215: ; preds = %207
%216 = load i32, i32* %14
%217 = icmp sge i32 %216, 3
br i1 %217, label %218, label %228
218: ; preds = %215
%219 = load i8*, i8** %11
%220 = load i32, i32* %14
%221 = sext i32 %220 to i64
%222 = getelementptr inbounds i8, i8* %219, i64 %221
%223 = getelementptr inbounds i8, i8* %222, i64 -3
%224 = call i64 @strncmp(i8* %223, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 4)
%225 = icmp eq i64 %224, 0
br i1 %225, label %226, label %227
226: ; preds = %218
br label %231
227: ; preds = %218
br label %228
228: ; preds = %227, %215, %207
%229 = load i32, i32* %14
%230 = add nsw i32 %229, 1
store i32 %230, i32* %14
br label %193
231: ; preds = %226, %205
%232 = load i32, i32* %15
%233 = icmp slt i32 %232, 0
br i1 %233, label %234, label %247
234: ; preds = %231
%235 = load i64, i64* @errno
%236 = load i64, i64* @EAGAIN
%237 = icmp eq i64 %235, %236
br i1 %237, label %246, label %238
238: ; preds = %234
%239 = load i64, i64* @errno
%240 = load i64, i64* @EWOULDBLOCK
%241 = icmp eq i64 %239, %240
br i1 %241, label %246, label %242
242: ; preds = %238
%243 = load i64, i64* @errno
%244 = load i64, i64* @EINTR
%245 = icmp eq i64 %243, %244
br i1 %245, label %246, label %247
246: ; preds = %242, %238, %234
br label %192
247: ; preds = %242, %231
%248 = load i8*, i8** %11
%249 = load i32, i32* %14
%250 = sext i32 %249 to i64
%251 = getelementptr inbounds i8, i8* %248, i64 %250
store i8 0, i8* %251
%252 = load i32, i32* %15
%253 = icmp slt i32 %252, 0
br i1 %253, label %257, label %254
254: ; preds = %247
%255 = load i32, i32* %14
%256 = icmp slt i32 %255, 14
br i1 %256, label %257, label %260
257: ; preds = %254, %247
%258 = load i32, i32* %12
%259 = call i32 @close(i32 %258)
store i32 -1, i32* %12
br label %270
260: ; preds = %254
%261 = load i8*, i8** %11
%262 = getelementptr inbounds i8, i8* %261, i64 8
%263 = call i32 @strtol(i8* %262, i8** %4, i32 0)
store i32 %263, i32* %13
%264 = load i32, i32* %13
%265 = icmp ne i32 %264, 200
br i1 %265, label %266, label %269
266: ; preds = %260
%267 = load i32, i32* %12
%268 = call i32 @close(i32 %267)
store i32 -1, i32* %12
br label %269
269: ; preds = %266, %260
br label %270
270: ; preds = %269, %257, %188
%271 = load i8*, i8** %11
%272 = call i32 @free(i8* %271)
%273 = load i8*, i8** %7
%274 = call i32 @free(i8* %273)
%275 = load i8*, i8** %8
%276 = call i32 @free(i8* %275)
%277 = load i8*, i8** %9
%278 = call i32 @free(i8* %277)
%279 = load i8*, i8** %10
%280 = call i32 @free(i8* %279)
%281 = load i32, i32* %12
store i32 %281, i32* %2
br label %282
282: ; preds = %270, %21
%283 = load i32, i32* %2
ret i32 %283
}

LLVM IR (-O2):
@.str = [8 x i8] c"http://\00"
@.str.1 = [11 x i8] c"http_proxy\00"
@.str.2 = [3 x i8] c"80\00"
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [30 x i8] c"GET %s HTTP/1.0\0D\0AHost: %s\0D\0A\0D\0A\00"
@.str.5 = [5 x i8] c"\0D\0A\0D\0A\00"
@errno = global i64 0
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
@EINTR = global i64 0
define i32 @http_open(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = tail call i32 bitcast (i64 (i8*, i8*, i32)* @strncmp to i32 (i8*, i8*, i64)*)(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 7)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %138
6: ; preds = %1
%7 = getelementptr inbounds i8, i8* %0, i64 7
br label %8
8: ; preds = %11, %6
%9 = phi i8* [ %7, %6 ], [ %12, %11 ]
%10 = load i8, i8* %9
switch i8 %10, label %11 [
i8 0, label %13
i8 47, label %13
]
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %9, i64 1
br label %8
13: ; preds = %8, %8
store i8* %9, i8** %2
%14 = ptrtoint i8* %9 to i64
%15 = ptrtoint i8* %0 to i64
%16 = sub i64 %14, %15
%17 = trunc i64 %16 to i32
%18 = add i32 %17, -7
%19 = add i32 %17, -6
%20 = tail call i8* @calloc(i32 %19, i32 1)
%21 = tail call i32 @strncpy(i8* %20, i8* %7, i32 %18)
%22 = sext i32 %18 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 0, i8* %23
br label %24
24: ; preds = %27, %13
%25 = phi i8* [ %20, %13 ], [ %28, %27 ]
%26 = load i8, i8* %25
switch i8 %26, label %27 [
i8 58, label %29
i8 0, label %31
]
27: ; preds = %24
%28 = getelementptr inbounds i8, i8* %25, i64 1
br label %24
29: ; preds = %24
%30 = getelementptr inbounds i8, i8* %25, i64 1
store i8 0, i8* %25
br label %31
31: ; preds = %24, %29
%32 = phi i8* [ %30, %29 ], [ %25, %24 ]
%33 = tail call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %44
35: ; preds = %31
%36 = tail call i8* @strdup(i8* %20)
%37 = load i8, i8* %32
%38 = icmp eq i8 %37, 0
%39 = select i1 %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %32
%40 = tail call i8* @strdup(i8* %39)
%41 = load i8, i8* %9
%42 = icmp eq i8 %41, 0
%43 = select i1 %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* %9
br label %63
44: ; preds = %31
%45 = tail call i32 bitcast (i64 (i8*, i8*, i32)* @strncmp to i32 (i8*, i8*, i64)*)(i8* %33, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 7)
%46 = icmp eq i32 %45, 0
%47 = select i1 %46, i64 7, i64 0
%48 = getelementptr i8, i8* %33, i64 %47
%49 = tail call i8* @strdup(i8* %48)
br label %50
50: ; preds = %53, %44
%51 = phi i8* [ %49, %44 ], [ %54, %53 ]
%52 = load i8, i8* %51
switch i8 %52, label %53 [
i8 58, label %55
i8 0, label %60
]
53: ; preds = %50
%54 = getelementptr inbounds i8, i8* %51, i64 1
br label %50
55: ; preds = %50
%56 = getelementptr inbounds i8, i8* %51, i64 1
store i8 0, i8* %51
%57 = load i8, i8* %56
%58 = icmp eq i8 %57, 0
%59 = select i1 %58, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %56
br label %60
60: ; preds = %50, %55
%61 = phi i8* [ %59, %55 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %50 ]
%62 = tail call i8* @strdup(i8* %61)
br label %63
63: ; preds = %60, %35
%64 = phi i8* [ %0, %60 ], [ %43, %35 ]
%65 = phi i8* [ %62, %60 ], [ %40, %35 ]
%66 = phi i8* [ %49, %60 ], [ %36, %35 ]
%67 = tail call i8* @strdup(i8* %64)
%68 = tail call i32 @socket_connect(i8* %66, i8* %65)
%69 = tail call dereferenceable_or_null(65536) i8* @calloc(i32 65536, i32 1)
%70 = tail call i64 @snprintf(i8* %69, i32 65536, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %67, i8* %20)
%71 = trunc i64 %70 to i32
%72 = tail call i64 @write_bytes(i32 %68, i8* %69, i32 %71)
%73 = icmp eq i64 %72, 0
br i1 %73, label %74, label %129
74: ; preds = %63, %105
%75 = phi i32 [ %102, %105 ], [ 0, %63 ]
%76 = phi i32 [ %103, %105 ], [ 0, %63 ]
%77 = icmp slt i32 %75, 65536
br i1 %77, label %78, label %101
78: ; preds = %74
%79 = sext i32 %75 to i64
br label %80
80: ; preds = %78, %94
%81 = phi i64 [ %79, %78 ], [ %95, %94 ]
%82 = getelementptr inbounds i8, i8* %69, i64 %81
%83 = tail call i32 @read(i32 %68, i8* %82, i32 1)
%84 = icmp sgt i32 %83, 0
br i1 %84, label %85, label %99
85: ; preds = %80
%86 = load i8, i8* %82
%87 = icmp eq i8 %86, 10
%88 = icmp sgt i64 %81, 2
%89 = select i1 %87, i1 %88, i1 false
br i1 %89, label %90, label %94
90: ; preds = %85
%91 = getelementptr inbounds i8, i8* %82, i64 -3
%92 = tail call i64 @strncmp(i8* %91, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 4)
%93 = icmp eq i64 %92, 0
br i1 %93, label %118, label %94
94: ; preds = %90, %85
%95 = add nsw i64 %81, 1
%96 = icmp eq i64 %95, 65536
br i1 %96, label %97, label %80
97: ; preds = %94
%98 = getelementptr inbounds i8, i8* %69, i64 65536
store i8 0, i8* %98
br label %125
99: ; preds = %80
%100 = trunc i64 %81 to i32
br label %101
101: ; preds = %99, %74
%102 = phi i32 [ %75, %74 ], [ %100, %99 ]
%103 = phi i32 [ %76, %74 ], [ %83, %99 ]
%104 = icmp slt i32 %103, 0
br i1 %104, label %105, label %120
105: ; preds = %101
%106 = load i64, i64* @errno
%107 = load i64, i64* @EAGAIN
%108 = icmp eq i64 %106, %107
%109 = load i64, i64* @EWOULDBLOCK
%110 = icmp eq i64 %106, %109
%111 = select i1 %108, i1 true, i1 %110
%112 = load i64, i64* @EINTR
%113 = icmp eq i64 %106, %112
%114 = select i1 %111, i1 true, i1 %113
br i1 %114, label %74, label %115
115: ; preds = %105
%116 = sext i32 %102 to i64
%117 = getelementptr inbounds i8, i8* %69, i64 %116
store i8 0, i8* %117
br label %129
118: ; preds = %90
%119 = trunc i64 %81 to i32
br label %120
120: ; preds = %101, %118
%121 = phi i32 [ %119, %118 ], [ %102, %101 ]
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds i8, i8* %69, i64 %122
store i8 0, i8* %123
%124 = icmp slt i32 %121, 14
br i1 %124, label %129, label %125
125: ; preds = %97, %120
%126 = getelementptr inbounds i8, i8* %69, i64 8
%127 = call i32 @strtol(i8* %126, i8** %2, i32 0)
%128 = icmp eq i32 %127, 200
br i1 %128, label %131, label %129
129: ; preds = %125, %120, %115, %63
%130 = tail call i32 @close(i32 %68)
br label %131
131: ; preds = %129, %125
%132 = phi i32 [ %68, %125 ], [ -1, %129 ]
%133 = tail call i32 @free(i8* %69)
%134 = tail call i32 @free(i8* %20)
%135 = tail call i32 @free(i8* %66)
%136 = tail call i32 @free(i8* %65)
%137 = tail call i32 @free(i8* %67)
br label %138
138: ; preds = %1, %131
%139 = phi i32 [ %132, %131 ], [ 0, %1 ]
ret i32 %139
}