#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 */
char *calloc(int, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
scalar_t__ read(int, char *, int);
int socket_connect(char *, char *);
scalar_t__ sprintf(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*/);
int /*<<< orphan*/ write(int, char *, int);
int http_open(const char *fn) {
  char *p, *proxy, *q, *http_host, *host, *port, *path, *buf;
  int fd, ret, l;
  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(0x10000, 1);
  l += sprintf(buf + l, "GET %s HTTP/1.0\r\nHost: %s\r\n", path, http_host);
  l += sprintf(buf + l, "\r\n");
  write(fd, buf, l);
  l = 0;
  while (read(fd, buf + l, 1)) {
    if (buf[l] == '\n' && l >= 3)
      if (strncmp(buf + l - 3, "\r\n\r\n", 4) == 0)
        break;
    ++l;
  }
  buf[l] = 0;
  if (l < 14) {
    close(fd);
    fd = -1;
  }
  ret = strtol(buf + 8, &p, 0);
  if (ret != 200) {
    close(fd);
    fd = -1;
  }
  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    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe16(%rip),%rsi
call   10f0 <strstr@plt>
cmp    -0x10(%rbp),%rax
je     1205 <http_open+0x35>
movl   $0x0,-0x4(%rbp)
jmp    1663 <http_open+0x493>
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,-0x5d(%rbp)
je     1236 <http_open+0x66>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x5d(%rbp)
mov    -0x5d(%rbp),%al
test   $0x1,%al
jne    1246 <http_open+0x76>
jmp    125c <http_open+0x8c>
jmp    124b <http_open+0x7b>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1211 <http_open+0x41>
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,-0x5e(%rbp)
je     12cf <http_open+0xff>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
setne  %al
mov    %al,-0x5e(%rbp)
mov    -0x5e(%rbp),%al
test   $0x1,%al
jne    12df <http_open+0x10f>
jmp    12f5 <http_open+0x125>
jmp    12e4 <http_open+0x114>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    12aa <http_open+0xda>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    1317 <http_open+0x147>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x0,(%rax)
lea    0xcea(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    13b8 <http_open+0x1e8>
mov    -0x30(%rbp),%rdi
call   10e0 <strdup@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     135c <http_open+0x18c>
mov    -0x28(%rbp),%rax
mov    %rax,-0x68(%rbp)
jmp    136c <http_open+0x19c>
lea    0xcb0(%rip),%rax
mov    %rax,-0x68(%rbp)
jmp    136c <http_open+0x19c>
mov    -0x68(%rbp),%rdi
call   10e0 <strdup@plt>
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1396 <http_open+0x1c6>
mov    -0x18(%rbp),%rax
mov    %rax,-0x70(%rbp)
jmp    13a6 <http_open+0x1d6>
lea    0xc69(%rip),%rax
mov    %rax,-0x70(%rbp)
jmp    13a6 <http_open+0x1d6>
mov    -0x70(%rbp),%rdi
call   10e0 <strdup@plt>
mov    %rax,-0x48(%rbp)
jmp    14c2 <http_open+0x2f2>
mov    -0x20(%rbp),%rdi
lea    0xc3d(%rip),%rsi
call   10f0 <strstr@plt>
cmp    -0x20(%rbp),%rax
jne    13e8 <http_open+0x218>
mov    -0x20(%rbp),%rdi
add    $0x7,%rdi
call   10e0 <strdup@plt>
mov    %rax,-0x78(%rbp)
jmp    13f5 <http_open+0x225>
mov    -0x20(%rbp),%rdi
call   10e0 <strdup@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%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,-0x79(%rbp)
je     142a <http_open+0x25a>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
setne  %al
mov    %al,-0x79(%rbp)
mov    -0x79(%rbp),%al
test   $0x1,%al
jne    143a <http_open+0x26a>
jmp    1450 <http_open+0x280>
jmp    143f <http_open+0x26f>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1405 <http_open+0x235>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    1472 <http_open+0x2a2>
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     1492 <http_open+0x2c2>
mov    -0x28(%rbp),%rax
mov    %rax,-0x88(%rbp)
jmp    14a5 <http_open+0x2d5>
lea    0xb7a(%rip),%rax
mov    %rax,-0x88(%rbp)
jmp    14a5 <http_open+0x2d5>
mov    -0x88(%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    $0x10000,%edi
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
movslq -0x5c(%rbp),%rax
add    %rax,%rdi
mov    -0x48(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    0xb10(%rip),%rsi
mov    $0x0,%al
call   10d0 <sprintf@plt>
mov    %rax,%rcx
movslq -0x5c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x5c(%rbp)
mov    -0x50(%rbp),%rdi
movslq -0x5c(%rbp),%rax
add    %rax,%rdi
lea    0xb08(%rip),%rsi
mov    $0x0,%al
call   10d0 <sprintf@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   1070 <write@plt>
movl   $0x0,-0x5c(%rbp)
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rsi
movslq -0x5c(%rbp),%rax
add    %rax,%rsi
mov    $0x1,%edx
call   1090 <read@plt>
cmp    $0x0,%rax
je     15d9 <http_open+0x409>
mov    -0x50(%rbp),%rax
movslq -0x5c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    15cb <http_open+0x3fb>
cmpl   $0x3,-0x5c(%rbp)
jl     15cb <http_open+0x3fb>
mov    -0x50(%rbp),%rdi
movslq -0x5c(%rbp),%rax
add    %rax,%rdi
add    $0xfffffffffffffffd,%rdi
lea    0xa85(%rip),%rsi
mov    $0x4,%edx
call   1060 <strncmp@plt>
cmp    $0x0,%rax
jne    15c6 <http_open+0x3f6>
jmp    15d9 <http_open+0x409>
jmp    15cb <http_open+0x3fb>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1556 <http_open+0x386>
mov    -0x50(%rbp),%rax
movslq -0x5c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0xe,-0x5c(%rbp)
jge    15fe <http_open+0x42e>
mov    -0x54(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x54(%rbp)
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     1630 <http_open+0x460>
mov    -0x54(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x54(%rbp)
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    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_open>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r15
lea    0xe28(%rip),%rsi
mov    $0x7,%edx
call   1060 <strncmp@plt>
xor    %r14d,%r14d
test   %eax,%eax
jne    1466 <http_open+0x2a6>
lea    0x7(%r15),%r14
mov    $0x1,%edi
mov    %r14,%rbp
nopl   0x0(%rax)
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,0x10(%rsp)
lea    -0x1(%rdi),%ebx
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1050 <strncpy@plt>
movslq %ebx,%rax
movb   $0x0,0x0(%r13,%rax,1)
mov    %r13,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%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,%r14
lea    0xd7d(%rip),%rsi
mov    $0x7,%edx
mov    %rax,%rdi
call   1060 <strncmp@plt>
lea    0x7(%r14),%rdi
test   %eax,%eax
cmovne %r14,%rdi
call   10e0 <strdup@plt>
mov    %rax,%r14
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    %r13,%rdi
call   10e0 <strdup@plt>
cmpb   $0x0,(%rbx)
mov    %rax,%r14
lea    0xd29(%rip),%rdi
cmovne %rbx,%rdi
call   10e0 <strdup@plt>
cmpb   $0x0,0x0(%rbp)
mov    %rax,%rbx
lea    0xd05(%rip),%r15
cmovne %rbp,%r15
jmp    1316 <http_open+0x156>
lea    0xd05(%rip),%rdi
call   10e0 <strdup@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   10e0 <strdup@plt>
mov    %rax,%r12
mov    %r14,0x8(%rsp)
mov    %r14,%rdi
mov    %rbx,(%rsp)
mov    %rbx,%rsi
call   10c0 <socket_connect@plt>
mov    %eax,%r14d
mov    $0x10000,%edi
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,%rbx
lea    0xcc5(%rip),%rsi
mov    %rax,%rdi
mov    %r12,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   10d0 <sprintf@plt>
movslq %eax,%rbp
lea    (%rbx,%rbp,1),%rdi
lea    0xcc5(%rip),%rsi
xor    %eax,%eax
call   10d0 <sprintf@plt>
add    %eax,%ebp
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1070 <write@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1090 <read@plt>
test   %rax,%rax
je     1402 <http_open+0x242>
xor    %ebp,%ebp
lea    0xc8f(%rip),%r15
jmp    13ce <http_open+0x20e>
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%rbx,%rbp,1),%rsi
add    $0x1,%rsi
add    $0x1,%rbp
mov    %r14d,%edi
mov    $0x1,%edx
call   1090 <read@plt>
test   %rax,%rax
je     13f4 <http_open+0x234>
cmpb   $0xa,(%rbx,%rbp,1)
jne    13b0 <http_open+0x1f0>
cmp    $0x3,%rbp
jb     13b0 <http_open+0x1f0>
lea    (%rbx,%rbp,1),%rdi
add    $0xfffffffffffffffd,%rdi
mov    %r15,%rsi
mov    $0x4,%edx
call   1060 <strncmp@plt>
test   %rax,%rax
jne    13b0 <http_open+0x1f0>
lea    (%rbx,%rbp,1),%rax
movb   $0x0,(%rax)
cmp    $0xd,%ebp
jbe    1405 <http_open+0x245>
jmp    1413 <http_open+0x253>
movb   $0x0,(%rbx)
mov    %r14d,%edi
call   1080 <close@plt>
mov    $0xffffffff,%r14d
mov    %rbx,%rdi
add    $0x8,%rdi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
call   10b0 <strtol@plt>
cmp    $0xc8,%eax
je     143b <http_open+0x27b>
mov    %r14d,%edi
call   1080 <close@plt>
mov    $0xffffffff,%r14d
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %r13,%rdi
call   1040 <free@plt>
mov    0x8(%rsp),%rdi
call   1040 <free@plt>
mov    (%rsp),%rdi
call   1040 <free@plt>
mov    %r12,%rdi
call   1040 <free@plt>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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 = [28 x i8] c"GET %s HTTP/1.0\0D\0AHost: %s\0D\0A\00"
@.str.5 = [3 x i8] c"\0D\0A\00"
@.str.6 = [5 x i8] c"\0D\0A\0D\0A\00"
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 %118
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* [ %49, %60 ], [ %36, %35 ]
%66 = phi i8* [ %62, %60 ], [ %40, %35 ]
%67 = tail call i8* @strdup(i8* %64)
%68 = tail call i32 @socket_connect(i8* %65, i8* %66)
%69 = tail call dereferenceable_or_null(65536) i8* @calloc(i32 65536, i32 1)
%70 = tail call i64 (i8*, i8*, ...) @sprintf(i8* %69, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %67, i8* %20)
%71 = shl i64 %70, 32
%72 = ashr exact i64 %71, 32
%73 = getelementptr inbounds i8, i8* %69, i64 %72
%74 = tail call i64 (i8*, i8*, ...) @sprintf(i8* %73, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%75 = add i64 %74, %70
%76 = trunc i64 %75 to i32
%77 = tail call i32 @write(i32 %68, i8* %69, i32 %76)
%78 = tail call i64 @read(i32 %68, i8* %69, i32 1)
%79 = icmp eq i64 %78, 0
br i1 %79, label %80, label %81
80: ; preds = %63
store i8 0, i8* %69
br label %102
81: ; preds = %63, %92
%82 = phi i64 [ %93, %92 ], [ 0, %63 ]
%83 = phi i8* [ %94, %92 ], [ %69, %63 ]
%84 = load i8, i8* %83
%85 = icmp eq i8 %84, 10
%86 = icmp ugt i64 %82, 2
%87 = select i1 %85, i1 %86, i1 false
br i1 %87, label %88, label %92
88: ; preds = %81
%89 = getelementptr inbounds i8, i8* %83, i64 -3
%90 = tail call i64 @strncmp(i8* %89, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 4)
%91 = icmp eq i64 %90, 0
br i1 %91, label %97, label %92
92: ; preds = %88, %81
%93 = add nuw i64 %82, 1
%94 = getelementptr inbounds i8, i8* %69, i64 %93
%95 = tail call i64 @read(i32 %68, i8* %94, i32 1)
%96 = icmp eq i64 %95, 0
br i1 %96, label %97, label %81
97: ; preds = %92, %88
%98 = phi i64 [ %93, %92 ], [ %82, %88 ]
%99 = phi i8* [ %94, %92 ], [ %83, %88 ]
%100 = trunc i64 %98 to i32
%101 = icmp ult i32 %100, 14
store i8 0, i8* %99
br i1 %101, label %102, label %104
102: ; preds = %80, %97
%103 = tail call i32 @close(i32 %68)
br label %104
104: ; preds = %102, %97
%105 = phi i32 [ -1, %102 ], [ %68, %97 ]
%106 = getelementptr inbounds i8, i8* %69, i64 8
%107 = call i32 @strtol(i8* %106, i8** %2, i32 0)
%108 = icmp eq i32 %107, 200
br i1 %108, label %111, label %109
109: ; preds = %104
%110 = tail call i32 @close(i32 %105)
br label %111
111: ; preds = %109, %104
%112 = phi i32 [ -1, %109 ], [ %105, %104 ]
%113 = tail call i32 @free(i8* %69)
%114 = tail call i32 @free(i8* %20)
%115 = tail call i32 @free(i8* %65)
%116 = tail call i32 @free(i8* %66)
%117 = tail call i32 @free(i8* %67)
br label %118
118: ; preds = %1, %111
%119 = phi i32 [ %112, %111 ], [ 0, %1 ]
ret i32 %119
}