#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 /*<<< orphan*/ urlport;
typedef int /*<<< orphan*/ urlip;
typedef int /*<<< orphan*/ urlfile;
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_family;
  int /*<<< orphan*/ sin_port;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ h_addr;
  int /*<<< orphan*/ h_addrtype;
};
typedef int /*<<< orphan*/ sin;
typedef int /*<<< orphan*/ relocurl;
typedef int /*<<< orphan*/ enc_authbuf;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ authbuf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int b64_ntop(unsigned char const *, int, char *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
scalar_t__ httpreadline(int, char *, int);
scalar_t__ inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int snprintf(char *, int, char *, char *, char *, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
char *strchr(char *, char);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
scalar_t__ write(int, char *, int /*<<< orphan*/);
int openhttp(char *url) {
  struct sockaddr_in sin;
  struct hostent *hp;
  char *up, *sp, *ap;
  char urlip[256];
  char urlport[32];
  char urlfile[256];
  char authbuf[256];
  char enc_authbuf[(((256) + 2) / 3 * 4 + 1)];
  char buf[256];
  char relocurl[512];
  int fd, portnr, relocated, auth;
  fd = -1;
  portnr = 80;
  up = url;
  auth = 0;
  do {
    if (strncmp(up, "http://", 7) == 0)
      up += 7;
    ap = up;
    while (ap && (*ap != '/')) {
      if (*ap == '@')
        auth = 1;
      ap++;
    }
    if (auth) {
      ap = up;
      for (sp = &authbuf[0]; (*ap != '@'); ap++) {
        *sp++ = *ap;
        if (sp >= &authbuf[sizeof(authbuf) - 1])
          return (-1);
      }
      up = ap + 1;
      if (b64_ntop((const unsigned char *)authbuf, (sp - authbuf), enc_authbuf,
                   sizeof(enc_authbuf) - 1) == -1)
        return (-1);
    }
    for (sp = &urlip[0]; ((*up != ':') && (*up != '/')); up++) {
      if (*up == 0)
        return (-1);
      *sp++ = *up;
      if (sp >= &urlip[sizeof(urlip) - 1])
        return (-1);
    }
    *sp = 0;
    if (*up == ':') {
      for (up++, sp = &urlport[0]; (*up != 0); up++) {
        if (*up == '/')
          break;
        *sp++ = *up;
        if (sp >= &urlport[sizeof(urlport) - 1])
          return (-1);
      }
      *sp = 0;
      portnr = atoi(urlport);
    }
    for (sp = &urlfile[0]; (*up != 0); up++) {
      *sp++ = *up;
      if (sp >= &urlfile[sizeof(urlfile) - 1])
        return (-1);
    }
    *sp = 0;
    bzero(&sin, sizeof(sin));
    sin.sin_family = AF_INET;
    sin.sin_port = htons(portnr);
    if (inet_aton(urlip, &sin.sin_addr) == 0) {
      if ((hp = gethostbyname(urlip))) {
        sin.sin_family = hp->h_addrtype;
        memcpy(&sin.sin_addr, hp->h_addr, hp->h_length);
      } else
        return (-1);
    }
    if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
      return (-1);
    if (connect(fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
      close(fd);
      return (-1);
    }
    if (!auth) {
      if (snprintf(buf, sizeof(buf),
                   "GET %s HTTP/1.0\r\n"
                   "User-Agent: netflash/100\r\n"
                   "Host: %s\r\n"
                   "\r\n",
                   urlfile, urlip) >= sizeof(buf)) {
        close(fd);
        return (-1);
      }
    } else {
      if (snprintf(buf, sizeof(buf),
                   "GET %s HTTP/1.0\r\n"
                   "User-Agent: netflash/100\r\n"
                   "Host: %s\r\n"
                   "Authorization: Basic %s\r\n"
                   "\r\n",
                   urlfile, urlip, enc_authbuf) >= sizeof(buf)) {
        close(fd);
        return (-1);
      }
    }
    if (write(fd, buf, strlen(buf)) < 0) {
      close(fd);
      return (-1);
    }
    if (httpreadline(fd, buf, sizeof(buf)) < 0) {
      close(fd);
      return (-1);
    }
    relocated = 0;
    if ((sp = strchr(buf, ' '))) {
      switch (sp[1]) {
      case '3':
        relocated++;
        break;
      case '2':
        break;
      default:
        close(fd);
        return (-1);
      }
    }
    for (;;) {
      if (httpreadline(fd, buf, sizeof(buf)) < 0) {
        close(fd);
        return (-1);
      }
      if ((buf[0] == '\n') || (buf[0] == '\r'))
        break;
      if (strncmp(buf, "Location:", 9) == 0) {
        strncpy(relocurl, buf + 10, sizeof(relocurl));
        up = relocurl;
      }
    }
  } while (relocated);
  return (fd);
}


x86 assembly (clang, -O0):
<openhttp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7f0,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0x7c4(%rbp)
ff ff ff
movl   $0x50,-0x7c8(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x7d0(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xdb0(%rip),%rsi
mov    $0x7,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1270 <openhttp+0x60>
mov    -0x30(%rbp),%rax
add    $0x7,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x40(%rbp)
mov    %al,-0x7d1(%rbp)
je     129e <openhttp+0x8e>
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x7d1(%rbp)
mov    -0x7d1(%rbp),%al
test   $0x1,%al
jne    12b1 <openhttp+0xa1>
jmp    12dc <openhttp+0xcc>
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x40,%eax
jne    12cb <openhttp+0xbb>
movl   $0x1,-0x7d0(%rbp)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1278 <openhttp+0x68>
cmpl   $0x0,-0x7d0(%rbp)
je     13ae <openhttp+0x19e>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x360(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x40,%eax
je     1360 <openhttp+0x150>
mov    -0x40(%rbp),%rax
mov    (%rax),%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x38(%rbp),%rax
lea    -0x360(%rbp),%rcx
add    $0xff,%rcx
cmp    %rcx,%rax
jb     134a <openhttp+0x13a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1939 <openhttp+0x729>
jmp    134f <openhttp+0x13f>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    12fc <openhttp+0xec>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
lea    -0x360(%rbp),%rdi
mov    -0x38(%rbp),%rax
lea    -0x360(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
lea    -0x4c0(%rbp),%rdx
mov    $0x158,%ecx
call   1110 <b64_ntop@plt>
cmp    $0xffffffff,%eax
jne    13a9 <openhttp+0x199>
movl   $0xffffffff,-0x4(%rbp)
jmp    1939 <openhttp+0x729>
jmp    13ae <openhttp+0x19e>
lea    -0x140(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x3a,%ecx
mov    %al,-0x7d2(%rbp)
je     13e4 <openhttp+0x1d4>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x7d2(%rbp)
mov    -0x7d2(%rbp),%al
test   $0x1,%al
jne    13f7 <openhttp+0x1e7>
jmp    1467 <openhttp+0x257>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1413 <openhttp+0x203>
movl   $0xffffffff,-0x4(%rbp)
jmp    1939 <openhttp+0x729>
mov    -0x30(%rbp),%rax
mov    (%rax),%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x38(%rbp),%rax
lea    -0x140(%rbp),%rcx
add    $0xff,%rcx
cmp    %rcx,%rax
jb     1451 <openhttp+0x241>
movl   $0xffffffff,-0x4(%rbp)
jmp    1939 <openhttp+0x729>
jmp    1456 <openhttp+0x246>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    13b9 <openhttp+0x1a9>
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    1524 <openhttp+0x314>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
lea    -0x160(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     150b <openhttp+0x2fb>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    14ba <openhttp+0x2aa>
jmp    150b <openhttp+0x2fb>
mov    -0x30(%rbp),%rax
mov    (%rax),%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x38(%rbp),%rax
lea    -0x160(%rbp),%rcx
add    $0x1f,%rcx
cmp    %rcx,%rax
jb     14f5 <openhttp+0x2e5>
movl   $0xffffffff,-0x4(%rbp)
jmp    1939 <openhttp+0x729>
jmp    14fa <openhttp+0x2ea>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1495 <openhttp+0x285>
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x160(%rbp),%rdi
call   1100 <atoi@plt>
mov    %eax,-0x7c8(%rbp)
lea    -0x260(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1593 <openhttp+0x383>
mov    -0x30(%rbp),%rax
mov    (%rax),%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x38(%rbp),%rax
lea    -0x260(%rbp),%rcx
add    $0xff,%rcx
cmp    %rcx,%rax
jb     157d <openhttp+0x36d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1939 <openhttp+0x729>
jmp    1582 <openhttp+0x372>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    152f <openhttp+0x31f>
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   10f0 <bzero@plt>
mov    0x2a39(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x7c8(%rbp),%edi
call   1070 <htons@plt>
mov    %eax,-0x18(%rbp)
lea    -0x140(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   10d0 <inet_aton@plt>
cmp    $0x0,%rax
jne    162c <openhttp+0x41c>
lea    -0x140(%rbp),%rdi
call   10b0 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     161b <openhttp+0x40b>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
call   10c0 <memcpy@plt>
jmp    1627 <openhttp+0x417>
movl   $0xffffffff,-0x4(%rbp)
jmp    1939 <openhttp+0x729>
jmp    162c <openhttp+0x41c>
mov    0x29b5(%rip),%rax
mov    (%rax),%edi
mov    0x299c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,-0x7c4(%rbp)
cmp    $0x0,%eax
jge    1660 <openhttp+0x450>
movl   $0xffffffff,-0x4(%rbp)
jmp    1939 <openhttp+0x729>
mov    -0x7c4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1120 <connect@plt>
cmp    $0x0,%rax
jge    1695 <openhttp+0x485>
mov    -0x7c4(%rbp),%edi
call   10a0 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1939 <openhttp+0x729>
cmpl   $0x0,-0x7d0(%rbp)
jne    16f4 <openhttp+0x4e4>
lea    -0x5c0(%rbp),%rdi
lea    -0x260(%rbp),%rcx
lea    -0x140(%rbp),%r8
mov    $0x100,%esi
lea    0x945(%rip),%rdx
mov    $0x0,%al
call   1090 <snprintf@plt>
cltq
cmp    $0x100,%rax
jb     16ef <openhttp+0x4df>
mov    -0x7c4(%rbp),%edi
call   10a0 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1939 <openhttp+0x729>
jmp    174d <openhttp+0x53d>
lea    -0x5c0(%rbp),%rdi
lea    -0x260(%rbp),%rcx
lea    -0x140(%rbp),%r8
lea    -0x4c0(%rbp),%r9
mov    $0x100,%esi
lea    0x924(%rip),%rdx
mov    $0x0,%al
call   1090 <snprintf@plt>
cltq
cmp    $0x100,%rax
jb     1748 <openhttp+0x538>
mov    -0x7c4(%rbp),%edi
call   10a0 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1939 <openhttp+0x729>
jmp    174d <openhttp+0x53d>
mov    -0x7c4(%rbp),%eax
mov    %eax,-0x7e4(%rbp)
lea    -0x5c0(%rbp),%rax
mov    %rax,-0x7e0(%rbp)
lea    -0x5c0(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x7e4(%rbp),%edi
mov    -0x7e0(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
cmp    $0x0,%rax
jge    17a8 <openhttp+0x598>
mov    -0x7c4(%rbp),%edi
call   10a0 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1939 <openhttp+0x729>
mov    -0x7c4(%rbp),%edi
lea    -0x5c0(%rbp),%rsi
mov    $0x100,%edx
call   10e0 <httpreadline@plt>
cmp    $0x0,%rax
jge    17e0 <openhttp+0x5d0>
mov    -0x7c4(%rbp),%edi
call   10a0 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1939 <openhttp+0x729>
movl   $0x0,-0x7cc(%rbp)
lea    -0x5c0(%rbp),%rdi
mov    $0x20,%esi
call   1080 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     186e <openhttp+0x65e>
mov    -0x38(%rbp),%rax
movsbl 0x1(%rax),%eax
mov    %eax,-0x7e8(%rbp)
sub    $0x32,%eax
je     184d <openhttp+0x63d>
jmp    1825 <openhttp+0x615>
mov    -0x7e8(%rbp),%eax
sub    $0x33,%eax
jne    1852 <openhttp+0x642>
jmp    1839 <openhttp+0x629>
mov    -0x7cc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7cc(%rbp)
jmp    1869 <openhttp+0x659>
jmp    1869 <openhttp+0x659>
mov    -0x7c4(%rbp),%edi
call   10a0 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1939 <openhttp+0x729>
jmp    186e <openhttp+0x65e>
jmp    1873 <openhttp+0x663>
mov    -0x7c4(%rbp),%edi
lea    -0x5c0(%rbp),%rsi
mov    $0x100,%edx
call   10e0 <httpreadline@plt>
cmp    $0x0,%rax
jge    18ab <openhttp+0x69b>
mov    -0x7c4(%rbp),%edi
call   10a0 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1939 <openhttp+0x729>
movsbl -0x5c0(%rbp),%eax
cmp    $0xa,%eax
je     18cb <openhttp+0x6bb>
movsbl -0x5c0(%rbp),%eax
cmp    $0xd,%eax
jne    18d0 <openhttp+0x6c0>
jmp    191e <openhttp+0x70e>
lea    -0x5c0(%rbp),%rdi
lea    0x7b3(%rip),%rsi
mov    $0x9,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1919 <openhttp+0x709>
lea    -0x7c0(%rbp),%rdi
lea    -0x5c0(%rbp),%rsi
add    $0xa,%rsi
mov    $0x200,%edx
call   1030 <strncpy@plt>
lea    -0x7c0(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1873 <openhttp+0x663>
jmp    1923 <openhttp+0x713>
cmpl   $0x0,-0x7cc(%rbp)
jne    1245 <openhttp+0x35>
mov    -0x7c4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x7f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openhttp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x7a8,%rsp
mov    %rdi,%r12
lea    0x43f(%rsp),%rbp
lea    0x23f(%rsp),%r14
movl   $0x50,0xc(%rsp)
lea    0x340(%rsp),%r15
xor    %r13d,%r13d
mov    %r12,%rdi
lea    0xdaf(%rip),%rsi
mov    $0x7,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
mov    $0x0,%ebx
mov    $0x7,%eax
cmove  %rax,%rbx
add    %r12,%rbx
je     12a0 <openhttp+0x90>
mov    %rbx,%rax
mov    0x2d6d(%rip),%rsi
mov    %r14,%rdi
jmp    128a <openhttp+0x7a>
mov    $0x1,%r13d
add    $0x1,%rax
movzbl (%rax),%ecx
cmp    $0x40,%cl
je     1280 <openhttp+0x70>
cmp    $0x2f,%cl
jne    1286 <openhttp+0x76>
test   %r13d,%r13d
jne    12af <openhttp+0x9f>
jmp    130a <openhttp+0xfa>
xchg   %ax,%ax
mov    0x2d41(%rip),%rsi
mov    %r14,%rdi
test   %r13d,%r13d
je     130a <openhttp+0xfa>
mov    (%rbx),%al
mov    %r15,%rsi
cmp    $0x40,%al
je     12db <openhttp+0xcb>
nopl   0x0(%rax,%rax,1)
mov    %al,(%rsi)
add    $0x1,%rsi
cmp    %rbp,%rsi
jae    1612 <openhttp+0x402>
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
cmp    $0x40,%al
jne    12c0 <openhttp+0xb0>
sub    %r15d,%esi
mov    %r15,%rdi
lea    0x440(%rsp),%rdx
mov    $0x158,%ecx
call   1110 <b64_ntop@plt>
cmp    $0xffffffff,%eax
je     1612 <openhttp+0x402>
add    $0x1,%rbx
mov    0x2ce1(%rip),%rsi
mov    %r14,%rdi
lea    0x1(%rbx),%rax
lea    0x141(%rsp),%rcx
mov    %rbx,%r12
nopl   0x0(%rax)
movzbl (%r12),%edx
mov    $0xffffffff,%ebx
test   %dl,%dl
je     1621 <openhttp+0x411>
cmp    $0x2f,%dl
je     1360 <openhttp+0x150>
cmp    $0x3a,%dl
je     1360 <openhttp+0x150>
mov    %dl,-0x1(%rcx)
cmp    %rdi,%rcx
jae    1621 <openhttp+0x411>
add    $0x1,%r12
add    $0x1,%rcx
add    $0x1,%rax
jmp    1320 <openhttp+0x110>
cs nopw 0x0(%rax,%rax,1)
movb   $0x0,-0x1(%rcx)
mov    (%r12),%cl
cmp    $0x3a,%cl
jne    13be <openhttp+0x1ae>
mov    %rax,%r12
lea    0x20(%rsp),%rax
lea    0x3f(%rsp),%rdx
nopw   0x0(%rax,%rax,1)
movzbl (%r12),%ecx
test   %cl,%cl
je     13a2 <openhttp+0x192>
cmp    $0x2f,%cl
je     13a2 <openhttp+0x192>
mov    %cl,(%rax)
add    $0x1,%rax
add    $0x1,%r12
cmp    %rdx,%rax
jb     1380 <openhttp+0x170>
jmp    1621 <openhttp+0x411>
movb   $0x0,(%rax)
lea    0x20(%rsp),%rdi
call   1100 <atoi@plt>
mov    0x2c32(%rip),%rsi
mov    %eax,0xc(%rsp)
mov    (%r12),%cl
lea    0x240(%rsp),%rax
test   %cl,%cl
je     13fd <openhttp+0x1ed>
lea    0x33f(%rsp),%rdx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %cl,(%rax)
add    $0x1,%rax
cmp    %rdx,%rax
jae    1621 <openhttp+0x411>
movzbl 0x1(%r12),%ecx
add    $0x1,%r12
test   %cl,%cl
jne    13e0 <openhttp+0x1d0>
movb   $0x0,(%rax)
lea    0x10(%rsp),%r14
mov    %rsi,%r15
mov    %r14,%rdi
mov    $0xc,%esi
call   10f0 <bzero@plt>
mov    (%r15),%eax
mov    %eax,0x14(%rsp)
mov    0xc(%rsp),%edi
call   1070 <htons@plt>
mov    %eax,0x18(%rsp)
lea    0x140(%rsp),%rdi
mov    %r14,%rsi
call   10d0 <inet_aton@plt>
test   %rax,%rax
jne    1471 <openhttp+0x261>
lea    0x140(%rsp),%rdi
call   10b0 <gethostbyname@plt>
test   %rax,%rax
je     1621 <openhttp+0x411>
mov    0x8(%rax),%ecx
mov    %ecx,0x14(%rsp)
mov    (%rax),%edx
mov    0x4(%rax),%esi
lea    0x10(%rsp),%rdi
call   10c0 <memcpy@plt>
mov    0x2b77(%rip),%r15
mov    (%r15),%edi
mov    0x2b5d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
test   %eax,%eax
js     1621 <openhttp+0x411>
mov    %eax,%r14d
mov    %eax,%edi
lea    0x10(%rsp),%rsi
mov    $0xc,%edx
call   1120 <connect@plt>
test   %rax,%rax
js     1619 <openhttp+0x409>
lea    0x40(%rsp),%rdi
mov    $0x100,%esi
test   %r13d,%r13d
je     14ea <openhttp+0x2da>
lea    0xb81(%rip),%rdx
lea    0x240(%rsp),%rcx
lea    0x140(%rsp),%r8
lea    0x440(%rsp),%r9
xor    %eax,%eax
call   1090 <snprintf@plt>
cmp    $0xff,%eax
jbe    1513 <openhttp+0x303>
jmp    1619 <openhttp+0x409>
lea    0xb17(%rip),%rdx
lea    0x240(%rsp),%rcx
lea    0x140(%rsp),%r8
xor    %eax,%eax
call   1090 <snprintf@plt>
cmp    $0xff,%eax
ja     1619 <openhttp+0x409>
lea    0x40(%rsp),%r15
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %r14d,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1050 <write@plt>
test   %rax,%rax
js     1619 <openhttp+0x409>
mov    %r14d,%edi
lea    0x40(%rsp),%rsi
mov    $0x100,%edx
call   10e0 <httpreadline@plt>
test   %rax,%rax
js     1619 <openhttp+0x409>
lea    0x40(%rsp),%rdi
mov    $0x20,%esi
call   1080 <strchr@plt>
mov    $0x1,%bpl
test   %rax,%rax
je     157c <openhttp+0x36c>
movsbl 0x1(%rax),%eax
cmp    $0x32,%eax
je     157c <openhttp+0x36c>
cmp    $0x33,%eax
jne    1619 <openhttp+0x409>
xor    %ebp,%ebp
mov    %r14d,%edi
lea    0x40(%rsp),%rsi
jmp    1596 <openhttp+0x386>
cs nopw 0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x100,%edx
call   10e0 <httpreadline@plt>
test   %rax,%rax
js     1619 <openhttp+0x409>
movzbl 0x40(%rsp),%eax
cmp    $0xa,%al
je     15ec <openhttp+0x3dc>
cmp    $0xd,%al
je     15ec <openhttp+0x3dc>
lea    0x40(%rsp),%r15
mov    %r15,%rdi
lea    0xad0(%rip),%rsi
mov    $0x9,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1590 <openhttp+0x380>
lea    0x5a0(%rsp),%r12
mov    %r12,%rdi
lea    0x4a(%rsp),%rsi
mov    $0x200,%edx
call   1030 <strncpy@plt>
jmp    1590 <openhttp+0x380>
mov    %r14d,%ebx
test   %bpl,%bpl
lea    0x43f(%rsp),%rbp
lea    0x340(%rsp),%r15
lea    0x23f(%rsp),%r14
je     1247 <openhttp+0x37>
jmp    1621 <openhttp+0x411>
mov    $0xffffffff,%ebx
jmp    1621 <openhttp+0x411>
mov    %r14d,%edi
call   10a0 <close@plt>
mov    %ebx,%eax
add    $0x7a8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [8 x i8] c"http://\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [56 x i8] c"GET %s HTTP/1.0\0D\0AUser-Agent: netflash/100\0D\0AHost: %s\0D\0A\0D\0A\00"
@.str.2 = [81 x i8] c"GET %s HTTP/1.0\0D\0AUser-Agent: netflash/100\0D\0AHost: %s\0D\0AAuthorization: Basic %s\0D\0A\0D\0A\00"
@.str.3 = [10 x i8] c"Location:\00"
define i32 @openhttp(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.hostent*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [256 x i8]
%10 = alloca [32 x i8]
%11 = alloca [256 x i8]
%12 = alloca [256 x i8]
%13 = alloca [345 x i8]
%14 = alloca [256 x i8]
%15 = alloca [512 x i8]
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
store i8* %0, i8** %3
store i32 -1, i32* %16
store i32 80, i32* %17
%20 = load i8*, i8** %3
store i8* %20, i8** %6
store i32 0, i32* %19
br label %21
21: ; preds = %317, %1
%22 = load i8*, i8** %6
%23 = call i64 @strncmp(i8* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i8*, i8** %6
%27 = getelementptr inbounds i8, i8* %26, i64 7
store i8* %27, i8** %6
br label %28
28: ; preds = %25, %21
%29 = load i8*, i8** %6
store i8* %29, i8** %8
br label %30
30: ; preds = %46, %28
%31 = load i8*, i8** %8
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %38
33: ; preds = %30
%34 = load i8*, i8** %8
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 47
br label %38
38: ; preds = %33, %30
%39 = phi i1 [ false, %30 ], [ %37, %33 ]
br i1 %39, label %40, label %49
40: ; preds = %38
%41 = load i8*, i8** %8
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 64
br i1 %44, label %45, label %46
45: ; preds = %40
store i32 1, i32* %19
br label %46
46: ; preds = %45, %40
%47 = load i8*, i8** %8
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %8
br label %30
49: ; preds = %38
%50 = load i32, i32* %19
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %88
52: ; preds = %49
%53 = load i8*, i8** %6
store i8* %53, i8** %8
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
store i8* %54, i8** %7
br label %55
55: ; preds = %70, %52
%56 = load i8*, i8** %8
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp ne i32 %58, 64
br i1 %59, label %60, label %73
60: ; preds = %55
%61 = load i8*, i8** %8
%62 = load i8, i8* %61
%63 = load i8*, i8** %7
%64 = getelementptr inbounds i8, i8* %63, i32 1
store i8* %64, i8** %7
store i8 %62, i8* %63
%65 = load i8*, i8** %7
%66 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 255
%67 = icmp uge i8* %65, %66
br i1 %67, label %68, label %69
68: ; preds = %60
store i32 -1, i32* %2
br label %322
69: ; preds = %60
br label %70
70: ; preds = %69
%71 = load i8*, i8** %8
%72 = getelementptr inbounds i8, i8* %71, i32 1
store i8* %72, i8** %8
br label %55
73: ; preds = %55
%74 = load i8*, i8** %8
%75 = getelementptr inbounds i8, i8* %74, i64 1
store i8* %75, i8** %6
%76 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%77 = load i8*, i8** %7
%78 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%79 = ptrtoint i8* %77 to i64
%80 = ptrtoint i8* %78 to i64
%81 = sub i64 %79, %80
%82 = trunc i64 %81 to i32
%83 = getelementptr inbounds [345 x i8], [345 x i8]* %13, i64 0, i64 0
%84 = call i32 @b64_ntop(i8* %76, i32 %82, i8* %83, i32 344)
%85 = icmp eq i32 %84, -1
br i1 %85, label %86, label %87
86: ; preds = %73
store i32 -1, i32* %2
br label %322
87: ; preds = %73
br label %88
88: ; preds = %87, %49
%89 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
store i8* %89, i8** %7
br label %90
90: ; preds = %118, %88
%91 = load i8*, i8** %6
%92 = load i8, i8* %91
%93 = sext i8 %92 to i32
%94 = icmp ne i32 %93, 58
br i1 %94, label %95, label %100
95: ; preds = %90
%96 = load i8*, i8** %6
%97 = load i8, i8* %96
%98 = sext i8 %97 to i32
%99 = icmp ne i32 %98, 47
br label %100
100: ; preds = %95, %90
%101 = phi i1 [ false, %90 ], [ %99, %95 ]
br i1 %101, label %102, label %121
102: ; preds = %100
%103 = load i8*, i8** %6
%104 = load i8, i8* %103
%105 = sext i8 %104 to i32
%106 = icmp eq i32 %105, 0
br i1 %106, label %107, label %108
107: ; preds = %102
store i32 -1, i32* %2
br label %322
108: ; preds = %102
%109 = load i8*, i8** %6
%110 = load i8, i8* %109
%111 = load i8*, i8** %7
%112 = getelementptr inbounds i8, i8* %111, i32 1
store i8* %112, i8** %7
store i8 %110, i8* %111
%113 = load i8*, i8** %7
%114 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 255
%115 = icmp uge i8* %113, %114
br i1 %115, label %116, label %117
116: ; preds = %108
store i32 -1, i32* %2
br label %322
117: ; preds = %108
br label %118
118: ; preds = %117
%119 = load i8*, i8** %6
%120 = getelementptr inbounds i8, i8* %119, i32 1
store i8* %120, i8** %6
br label %90
121: ; preds = %100
%122 = load i8*, i8** %7
store i8 0, i8* %122
%123 = load i8*, i8** %6
%124 = load i8, i8* %123
%125 = sext i8 %124 to i32
%126 = icmp eq i32 %125, 58
br i1 %126, label %127, label %159
127: ; preds = %121
%128 = load i8*, i8** %6
%129 = getelementptr inbounds i8, i8* %128, i32 1
store i8* %129, i8** %6
%130 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
store i8* %130, i8** %7
br label %131
131: ; preds = %152, %127
%132 = load i8*, i8** %6
%133 = load i8, i8* %132
%134 = sext i8 %133 to i32
%135 = icmp ne i32 %134, 0
br i1 %135, label %136, label %155
136: ; preds = %131
%137 = load i8*, i8** %6
%138 = load i8, i8* %137
%139 = sext i8 %138 to i32
%140 = icmp eq i32 %139, 47
br i1 %140, label %141, label %142
141: ; preds = %136
br label %155
142: ; preds = %136
%143 = load i8*, i8** %6
%144 = load i8, i8* %143
%145 = load i8*, i8** %7
%146 = getelementptr inbounds i8, i8* %145, i32 1
store i8* %146, i8** %7
store i8 %144, i8* %145
%147 = load i8*, i8** %7
%148 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 31
%149 = icmp uge i8* %147, %148
br i1 %149, label %150, label %151
150: ; preds = %142
store i32 -1, i32* %2
br label %322
151: ; preds = %142
br label %152
152: ; preds = %151
%153 = load i8*, i8** %6
%154 = getelementptr inbounds i8, i8* %153, i32 1
store i8* %154, i8** %6
br label %131
155: ; preds = %141, %131
%156 = load i8*, i8** %7
store i8 0, i8* %156
%157 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%158 = call i32 @atoi(i8* %157)
store i32 %158, i32* %17
br label %159
159: ; preds = %155, %121
%160 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
store i8* %160, i8** %7
br label %161
161: ; preds = %176, %159
%162 = load i8*, i8** %6
%163 = load i8, i8* %162
%164 = sext i8 %163 to i32
%165 = icmp ne i32 %164, 0
br i1 %165, label %166, label %179
166: ; preds = %161
%167 = load i8*, i8** %6
%168 = load i8, i8* %167
%169 = load i8*, i8** %7
%170 = getelementptr inbounds i8, i8* %169, i32 1
store i8* %170, i8** %7
store i8 %168, i8* %169
%171 = load i8*, i8** %7
%172 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 255
%173 = icmp uge i8* %171, %172
br i1 %173, label %174, label %175
174: ; preds = %166
store i32 -1, i32* %2
br label %322
175: ; preds = %166
br label %176
176: ; preds = %175
%177 = load i8*, i8** %6
%178 = getelementptr inbounds i8, i8* %177, i32 1
store i8* %178, i8** %6
br label %161
179: ; preds = %161
%180 = load i8*, i8** %7
store i8 0, i8* %180
%181 = call i32 @bzero(%struct.sockaddr_in* %4, i32 12)
%182 = load i32, i32* @AF_INET
%183 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
store i32 %182, i32* %183
%184 = load i32, i32* %17
%185 = call i32 @htons(i32 %184)
%186 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %185, i32* %186
%187 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%188 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%189 = call i64 @inet_aton(i8* %187, i32* %188)
%190 = icmp eq i64 %189, 0
br i1 %190, label %191, label %210
191: ; preds = %179
%192 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%193 = call %struct.hostent* @gethostbyname(i8* %192)
store %struct.hostent* %193, %struct.hostent** %5
%194 = icmp ne %struct.hostent* %193, null
br i1 %194, label %195, label %208
195: ; preds = %191
%196 = load %struct.hostent*, %struct.hostent** %5
%197 = getelementptr inbounds %struct.hostent, %struct.hostent* %196, i32 0, i32 2
%198 = load i32, i32* %197
%199 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
store i32 %198, i32* %199
%200 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%201 = load %struct.hostent*, %struct.hostent** %5
%202 = getelementptr inbounds %struct.hostent, %struct.hostent* %201, i32 0, i32 1
%203 = load i32, i32* %202
%204 = load %struct.hostent*, %struct.hostent** %5
%205 = getelementptr inbounds %struct.hostent, %struct.hostent* %204, i32 0, i32 0
%206 = load i32, i32* %205
%207 = call i32 @memcpy(i32* %200, i32 %203, i32 %206)
br label %209
208: ; preds = %191
store i32 -1, i32* %2
br label %322
209: ; preds = %195
br label %210
210: ; preds = %209, %179
%211 = load i32, i32* @AF_INET
%212 = load i32, i32* @SOCK_STREAM
%213 = call i32 @socket(i32 %211, i32 %212, i32 0)
store i32 %213, i32* %16
%214 = icmp slt i32 %213, 0
br i1 %214, label %215, label %216
215: ; preds = %210
store i32 -1, i32* %2
br label %322
216: ; preds = %210
%217 = load i32, i32* %16
%218 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%219 = call i64 @connect(i32 %217, %struct.sockaddr* %218, i32 12)
%220 = icmp slt i64 %219, 0
br i1 %220, label %221, label %224
221: ; preds = %216
%222 = load i32, i32* %16
%223 = call i32 @close(i32 %222)
store i32 -1, i32* %2
br label %322
224: ; preds = %216
%225 = load i32, i32* %19
%226 = icmp ne i32 %225, 0
br i1 %226, label %238, label %227
227: ; preds = %224
%228 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%229 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%230 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%231 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %228, i32 256, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i8* %229, i8* %230)
%232 = sext i32 %231 to i64
%233 = icmp uge i64 %232, 256
br i1 %233, label %234, label %237
234: ; preds = %227
%235 = load i32, i32* %16
%236 = call i32 @close(i32 %235)
store i32 -1, i32* %2
br label %322
237: ; preds = %227
br label %250
238: ; preds = %224
%239 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%240 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%241 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%242 = getelementptr inbounds [345 x i8], [345 x i8]* %13, i64 0, i64 0
%243 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %239, i32 256, i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.2, i64 0, i64 0), i8* %240, i8* %241, i8* %242)
%244 = sext i32 %243 to i64
%245 = icmp uge i64 %244, 256
br i1 %245, label %246, label %249
246: ; preds = %238
%247 = load i32, i32* %16
%248 = call i32 @close(i32 %247)
store i32 -1, i32* %2
br label %322
249: ; preds = %238
br label %250
250: ; preds = %249, %237
%251 = load i32, i32* %16
%252 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%253 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%254 = call i32 @strlen(i8* %253)
%255 = call i64 @write(i32 %251, i8* %252, i32 %254)
%256 = icmp slt i64 %255, 0
br i1 %256, label %257, label %260
257: ; preds = %250
%258 = load i32, i32* %16
%259 = call i32 @close(i32 %258)
store i32 -1, i32* %2
br label %322
260: ; preds = %250
%261 = load i32, i32* %16
%262 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%263 = call i64 @httpreadline(i32 %261, i8* %262, i32 256)
%264 = icmp slt i64 %263, 0
br i1 %264, label %265, label %268
265: ; preds = %260
%266 = load i32, i32* %16
%267 = call i32 @close(i32 %266)
store i32 -1, i32* %2
br label %322
268: ; preds = %260
store i32 0, i32* %18
%269 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%270 = call i8* @strchr(i8* %269, i8 signext 32)
store i8* %270, i8** %7
%271 = icmp ne i8* %270, null
br i1 %271, label %272, label %285
272: ; preds = %268
%273 = load i8*, i8** %7
%274 = getelementptr inbounds i8, i8* %273, i64 1
%275 = load i8, i8* %274
%276 = sext i8 %275 to i32
switch i32 %276, label %281 [
i32 51, label %277
i32 50, label %280
]
277: ; preds = %272
%278 = load i32, i32* %18
%279 = add nsw i32 %278, 1
store i32 %279, i32* %18
br label %284
280: ; preds = %272
br label %284
281: ; preds = %272
%282 = load i32, i32* %16
%283 = call i32 @close(i32 %282)
store i32 -1, i32* %2
br label %322
284: ; preds = %280, %277
br label %285
285: ; preds = %284, %268
br label %286
286: ; preds = %315, %285
%287 = load i32, i32* %16
%288 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%289 = call i64 @httpreadline(i32 %287, i8* %288, i32 256)
%290 = icmp slt i64 %289, 0
br i1 %290, label %291, label %294
291: ; preds = %286
%292 = load i32, i32* %16
%293 = call i32 @close(i32 %292)
store i32 -1, i32* %2
br label %322
294: ; preds = %286
%295 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%296 = load i8, i8* %295
%297 = sext i8 %296 to i32
%298 = icmp eq i32 %297, 10
br i1 %298, label %304, label %299
299: ; preds = %294
%300 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%301 = load i8, i8* %300
%302 = sext i8 %301 to i32
%303 = icmp eq i32 %302, 13
br i1 %303, label %304, label %305
304: ; preds = %299, %294
br label %316
305: ; preds = %299
%306 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%307 = call i64 @strncmp(i8* %306, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 9)
%308 = icmp eq i64 %307, 0
br i1 %308, label %309, label %315
309: ; preds = %305
%310 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%311 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%312 = getelementptr inbounds i8, i8* %311, i64 10
%313 = call i32 @strncpy(i8* %310, i8* %312, i32 512)
%314 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
store i8* %314, i8** %6
br label %315
315: ; preds = %309, %305
br label %286
316: ; preds = %304
br label %317
317: ; preds = %316
%318 = load i32, i32* %18
%319 = icmp ne i32 %318, 0
br i1 %319, label %21, label %320
320: ; preds = %317
%321 = load i32, i32* %16
store i32 %321, i32* %2
br label %322
322: ; preds = %320, %291, %281, %265, %257, %246, %234, %221, %215, %208, %174, %150, %116, %107, %86, %68
%323 = load i32, i32* %2
ret i32 %323
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
%struct.hostent = type { i32, i32, i32 }
@.str = [8 x i8] c"http://\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [56 x i8] c"GET %s HTTP/1.0\0D\0AUser-Agent: netflash/100\0D\0AHost: %s\0D\0A\0D\0A\00"
@.str.2 = [81 x i8] c"GET %s HTTP/1.0\0D\0AUser-Agent: netflash/100\0D\0AHost: %s\0D\0AAuthorization: Basic %s\0D\0A\0D\0A\00"
@.str.3 = [10 x i8] c"Location:\00"
define i32 @openhttp(i8* %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca [256 x i8]
%4 = alloca [32 x i8]
%5 = alloca [256 x i8]
%6 = alloca [256 x i8]
%7 = alloca [345 x i8]
%8 = alloca [256 x i8]
%9 = alloca [512 x i8]
%10 = bitcast %struct.sockaddr_in* %2 to i8*
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%15 = getelementptr inbounds [345 x i8], [345 x i8]* %7, i64 0, i64 0
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 255
%19 = ptrtoint [256 x i8]* %6 to i64
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 255
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 31
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 255
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
%26 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 10
br label %28
28: ; preds = %175, %1
%29 = phi i8* [ %0, %1 ], [ %164, %175 ]
%30 = phi i32 [ 80, %1 ], [ %98, %175 ]
%31 = phi i32 [ 0, %1 ], [ %46, %175 ]
%32 = call i64 @strncmp(i8* %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%33 = icmp eq i64 %32, 0
%34 = select i1 %33, i64 7, i64 0
%35 = getelementptr i8, i8* %29, i64 %34
%36 = icmp eq i8* %35, null
br i1 %36, label %45, label %37
37: ; preds = %28, %42
%38 = phi i32 [ %43, %42 ], [ %31, %28 ]
%39 = phi i8* [ %44, %42 ], [ %35, %28 ]
%40 = load i8, i8* %39
switch i8 %40, label %42 [
i8 47, label %45
i8 64, label %41
]
41: ; preds = %37
br label %42
42: ; preds = %37, %41
%43 = phi i32 [ 1, %41 ], [ %38, %37 ]
%44 = getelementptr inbounds i8, i8* %39, i64 1
br label %37
45: ; preds = %37, %28
%46 = phi i32 [ %31, %28 ], [ %38, %37 ]
%47 = icmp eq i32 %46, 0
br i1 %47, label %70, label %48
48: ; preds = %45
%49 = load i8, i8* %35
%50 = icmp eq i8 %49, 64
br i1 %50, label %61, label %51
51: ; preds = %48, %57
%52 = phi i8 [ %59, %57 ], [ %49, %48 ]
%53 = phi i8* [ %58, %57 ], [ %35, %48 ]
%54 = phi i8* [ %55, %57 ], [ %14, %48 ]
%55 = getelementptr inbounds i8, i8* %54, i64 1
store i8 %52, i8* %54
%56 = icmp ult i8* %55, %18
br i1 %56, label %57, label %178
57: ; preds = %51
%58 = getelementptr inbounds i8, i8* %53, i64 1
%59 = load i8, i8* %58
%60 = icmp eq i8 %59, 64
br i1 %60, label %61, label %51
61: ; preds = %57, %48
%62 = phi i8* [ %14, %48 ], [ %55, %57 ]
%63 = phi i8* [ %35, %48 ], [ %58, %57 ]
%64 = getelementptr inbounds i8, i8* %63, i64 1
%65 = ptrtoint i8* %62 to i64
%66 = sub i64 %65, %19
%67 = trunc i64 %66 to i32
%68 = call i32 @b64_ntop(i8* %14, i32 %67, i8* %15, i32 344)
%69 = icmp eq i32 %68, -1
br i1 %69, label %178, label %70
70: ; preds = %61, %45
%71 = phi i8* [ %35, %45 ], [ %64, %61 ]
br label %72
72: ; preds = %70, %79
%73 = phi i8* [ %80, %79 ], [ %71, %70 ]
%74 = phi i8* [ %77, %79 ], [ %11, %70 ]
%75 = load i8, i8* %73
switch i8 %75, label %76 [
i8 58, label %81
i8 47, label %81
i8 0, label %178
]
76: ; preds = %72
%77 = getelementptr inbounds i8, i8* %74, i64 1
store i8 %75, i8* %74
%78 = icmp ult i8* %77, %20
br i1 %78, label %79, label %178
79: ; preds = %76
%80 = getelementptr inbounds i8, i8* %73, i64 1
br label %72
81: ; preds = %72, %72
store i8 0, i8* %74
%82 = load i8, i8* %73
%83 = icmp eq i8 %82, 58
br i1 %83, label %84, label %95
84: ; preds = %81, %89
%85 = phi i8* [ %87, %89 ], [ %73, %81 ]
%86 = phi i8* [ %90, %89 ], [ %12, %81 ]
%87 = getelementptr inbounds i8, i8* %85, i64 1
%88 = load i8, i8* %87
switch i8 %88, label %89 [
i8 0, label %92
i8 47, label %92
]
89: ; preds = %84
%90 = getelementptr inbounds i8, i8* %86, i64 1
store i8 %88, i8* %86
%91 = icmp ult i8* %90, %21
br i1 %91, label %84, label %178
92: ; preds = %84, %84
store i8 0, i8* %86
%93 = call i32 @atoi(i8* %12)
%94 = load i8, i8* %87
br label %95
95: ; preds = %92, %81
%96 = phi i8 [ %94, %92 ], [ %82, %81 ]
%97 = phi i8* [ %87, %92 ], [ %73, %81 ]
%98 = phi i32 [ %93, %92 ], [ %30, %81 ]
%99 = icmp eq i8 %96, 0
br i1 %99, label %110, label %100
100: ; preds = %95, %106
%101 = phi i8 [ %108, %106 ], [ %96, %95 ]
%102 = phi i8* [ %104, %106 ], [ %13, %95 ]
%103 = phi i8* [ %107, %106 ], [ %97, %95 ]
%104 = getelementptr inbounds i8, i8* %102, i64 1
store i8 %101, i8* %102
%105 = icmp ult i8* %104, %22
br i1 %105, label %106, label %178
106: ; preds = %100
%107 = getelementptr inbounds i8, i8* %103, i64 1
%108 = load i8, i8* %107
%109 = icmp eq i8 %108, 0
br i1 %109, label %110, label %100
110: ; preds = %106, %95
%111 = phi i8* [ %97, %95 ], [ %107, %106 ]
%112 = phi i8* [ %13, %95 ], [ %104, %106 ]
store i8 0, i8* %112
%113 = call i32 @bzero(%struct.sockaddr_in* %2, i32 12)
%114 = load i32, i32* @AF_INET
store i32 %114, i32* %23
%115 = call i32 @htons(i32 %98)
store i32 %115, i32* %24
%116 = call i64 @inet_aton(i8* %11, i32* %25)
%117 = icmp eq i64 %116, 0
br i1 %117, label %118, label %129
118: ; preds = %110
%119 = call %struct.hostent* @gethostbyname(i8* %11)
%120 = icmp eq %struct.hostent* %119, null
br i1 %120, label %178, label %121
121: ; preds = %118
%122 = getelementptr inbounds %struct.hostent, %struct.hostent* %119, i64 0, i32 2
%123 = load i32, i32* %122
store i32 %123, i32* %23
%124 = getelementptr inbounds %struct.hostent, %struct.hostent* %119, i64 0, i32 1
%125 = load i32, i32* %124
%126 = getelementptr inbounds %struct.hostent, %struct.hostent* %119, i64 0, i32 0
%127 = load i32, i32* %126
%128 = call i32 @memcpy(i32* %25, i32 %125, i32 %127)
br label %129
129: ; preds = %121, %110
%130 = load i32, i32* @AF_INET
%131 = load i32, i32* @SOCK_STREAM
%132 = call i32 @socket(i32 %130, i32 %131, i32 0)
%133 = icmp slt i32 %132, 0
br i1 %133, label %178, label %134
134: ; preds = %129
%135 = call i64 @connect(i32 %132, %struct.sockaddr* %26, i32 12)
%136 = icmp slt i64 %135, 0
br i1 %136, label %176, label %137
137: ; preds = %134
br i1 %47, label %138, label %141
138: ; preds = %137
%139 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %16, i32 256, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i8* %13, i8* %11)
%140 = icmp ugt i32 %139, 255
br i1 %140, label %176, label %144
141: ; preds = %137
%142 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %16, i32 256, i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.2, i64 0, i64 0), i8* %13, i8* %11, i8* %15)
%143 = icmp ugt i32 %142, 255
br i1 %143, label %176, label %144
144: ; preds = %141, %138
%145 = call i32 @strlen(i8* %16)
%146 = call i64 @write(i32 %132, i8* %16, i32 %145)
%147 = icmp slt i64 %146, 0
br i1 %147, label %176, label %148
148: ; preds = %144
%149 = call i64 @httpreadline(i32 %132, i8* %16, i32 256)
%150 = icmp slt i64 %149, 0
br i1 %150, label %176, label %151
151: ; preds = %148
%152 = call i8* @strchr(i8* %16, i8 signext 32)
%153 = icmp eq i8* %152, null
br i1 %153, label %159, label %154
154: ; preds = %151
%155 = getelementptr inbounds i8, i8* %152, i64 1
%156 = load i8, i8* %155
%157 = sext i8 %156 to i32
switch i32 %157, label %176 [
i32 51, label %158
i32 50, label %159
]
158: ; preds = %154
br label %159
159: ; preds = %158, %154, %151
%160 = phi i1 [ false, %158 ], [ true, %154 ], [ true, %151 ]
%161 = call i64 @httpreadline(i32 %132, i8* %16, i32 256)
%162 = icmp slt i64 %161, 0
br i1 %162, label %176, label %163
163: ; preds = %159, %171
%164 = phi i8* [ %172, %171 ], [ %111, %159 ]
%165 = load i8, i8* %16
switch i8 %165, label %166 [
i8 13, label %175
i8 10, label %175
]
166: ; preds = %163
%167 = call i64 @strncmp(i8* %16, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 9)
%168 = icmp eq i64 %167, 0
br i1 %168, label %169, label %171
169: ; preds = %166
%170 = call i32 @strncpy(i8* %17, i8* %27, i32 512)
br label %171
171: ; preds = %169, %166
%172 = phi i8* [ %17, %169 ], [ %164, %166 ]
%173 = call i64 @httpreadline(i32 %132, i8* %16, i32 256)
%174 = icmp slt i64 %173, 0
br i1 %174, label %176, label %163
175: ; preds = %163, %163
br i1 %160, label %178, label %28
176: ; preds = %159, %154, %148, %144, %141, %138, %134, %171
%177 = call i32 @close(i32 %132)
br label %178
178: ; preds = %175, %129, %118, %61, %51, %76, %72, %89, %100, %176
%179 = phi i32 [ -1, %176 ], [ -1, %100 ], [ -1, %89 ], [ -1, %72 ], [ -1, %76 ], [ -1, %51 ], [ %132, %175 ], [ -1, %129 ], [ -1, %118 ], [ -1, %61 ]
ret i32 %179
}