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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
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 socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
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;
  char urlip[256];
  char urlport[32];
  char urlfile[256];
  char buf[256];
  char relocurl[512];
  int fd, portnr, relocated;
  fd = -1;
  portnr = 80;
  up = url;
  do {
    if (strncmp(up, "http://", 7) == 0)
      up += 7;
    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);
    }
    sprintf(buf,
            "GET %s HTTP/1.0\r\n"
            "User-Agent: netflash/100\r\n"
            "Host: %s\r\n"
            "\r\n",
            urlfile, urlip);
    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    $0x580,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0x564(%rbp)
ff ff ff
movl   $0x50,-0x568(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xdca(%rip),%rsi
mov    $0x7,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1256 <openhttp+0x56>
mov    -0x30(%rbp),%rax
add    $0x7,%rax
mov    %rax,-0x30(%rbp)
lea    -0x140(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x3a,%ecx
mov    %al,-0x56d(%rbp)
je     128c <openhttp+0x8c>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x56d(%rbp)
mov    -0x56d(%rbp),%al
test   $0x1,%al
jne    129f <openhttp+0x9f>
jmp    130f <openhttp+0x10f>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    12bb <openhttp+0xbb>
movl   $0xffffffff,-0x4(%rbp)
jmp    174a <openhttp+0x54a>
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     12f9 <openhttp+0xf9>
movl   $0xffffffff,-0x4(%rbp)
jmp    174a <openhttp+0x54a>
jmp    12fe <openhttp+0xfe>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1261 <openhttp+0x61>
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    13cc <openhttp+0x1cc>
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     13b3 <openhttp+0x1b3>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1362 <openhttp+0x162>
jmp    13b3 <openhttp+0x1b3>
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     139d <openhttp+0x19d>
movl   $0xffffffff,-0x4(%rbp)
jmp    174a <openhttp+0x54a>
jmp    13a2 <openhttp+0x1a2>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    133d <openhttp+0x13d>
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x160(%rbp),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x568(%rbp)
lea    -0x260(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     143b <openhttp+0x23b>
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     1425 <openhttp+0x225>
movl   $0xffffffff,-0x4(%rbp)
jmp    174a <openhttp+0x54a>
jmp    142a <openhttp+0x22a>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    13d7 <openhttp+0x1d7>
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    0x2b91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x568(%rbp),%edi
call   1070 <htons@plt>
mov    %eax,-0x18(%rbp)
lea    -0x140(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   10c0 <inet_aton@plt>
cmp    $0x0,%rax
jne    14d4 <openhttp+0x2d4>
lea    -0x140(%rbp),%rdi
call   10a0 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     14c3 <openhttp+0x2c3>
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   10b0 <memcpy@plt>
jmp    14cf <openhttp+0x2cf>
movl   $0xffffffff,-0x4(%rbp)
jmp    174a <openhttp+0x54a>
jmp    14d4 <openhttp+0x2d4>
mov    0x2b0d(%rip),%rax
mov    (%rax),%edi
mov    0x2af4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x564(%rbp)
cmp    $0x0,%eax
jge    1508 <openhttp+0x308>
movl   $0xffffffff,-0x4(%rbp)
jmp    174a <openhttp+0x54a>
mov    -0x564(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1110 <connect@plt>
cmp    $0x0,%rax
jge    153d <openhttp+0x33d>
mov    -0x564(%rbp),%edi
call   1090 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    174a <openhttp+0x54a>
lea    -0x360(%rbp),%rdi
lea    -0x260(%rbp),%rdx
lea    -0x140(%rbp),%rcx
lea    0xaaf(%rip),%rsi
call   1100 <sprintf@plt>
mov    -0x564(%rbp),%eax
mov    %eax,-0x57c(%rbp)
lea    -0x360(%rbp),%rax
mov    %rax,-0x578(%rbp)
lea    -0x360(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x57c(%rbp),%edi
mov    -0x578(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
cmp    $0x0,%rax
jge    15b9 <openhttp+0x3b9>
mov    -0x564(%rbp),%edi
call   1090 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    174a <openhttp+0x54a>
mov    -0x564(%rbp),%edi
lea    -0x360(%rbp),%rsi
mov    $0x100,%edx
call   10d0 <httpreadline@plt>
cmp    $0x0,%rax
jge    15f1 <openhttp+0x3f1>
mov    -0x564(%rbp),%edi
call   1090 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    174a <openhttp+0x54a>
movl   $0x0,-0x56c(%rbp)
lea    -0x360(%rbp),%rdi
mov    $0x20,%esi
call   1080 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     167f <openhttp+0x47f>
mov    -0x38(%rbp),%rax
movsbl 0x1(%rax),%eax
mov    %eax,-0x580(%rbp)
sub    $0x32,%eax
je     165e <openhttp+0x45e>
jmp    1636 <openhttp+0x436>
mov    -0x580(%rbp),%eax
sub    $0x33,%eax
jne    1663 <openhttp+0x463>
jmp    164a <openhttp+0x44a>
mov    -0x56c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x56c(%rbp)
jmp    167a <openhttp+0x47a>
jmp    167a <openhttp+0x47a>
mov    -0x564(%rbp),%edi
call   1090 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    174a <openhttp+0x54a>
jmp    167f <openhttp+0x47f>
jmp    1684 <openhttp+0x484>
mov    -0x564(%rbp),%edi
lea    -0x360(%rbp),%rsi
mov    $0x100,%edx
call   10d0 <httpreadline@plt>
cmp    $0x0,%rax
jge    16bc <openhttp+0x4bc>
mov    -0x564(%rbp),%edi
call   1090 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    174a <openhttp+0x54a>
movsbl -0x360(%rbp),%eax
cmp    $0xa,%eax
je     16dc <openhttp+0x4dc>
movsbl -0x360(%rbp),%eax
cmp    $0xd,%eax
jne    16e1 <openhttp+0x4e1>
jmp    172f <openhttp+0x52f>
lea    -0x360(%rbp),%rdi
lea    0x951(%rip),%rsi
mov    $0x9,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    172a <openhttp+0x52a>
lea    -0x560(%rbp),%rdi
lea    -0x360(%rbp),%rsi
add    $0xa,%rsi
mov    $0x200,%edx
call   1030 <strncpy@plt>
lea    -0x560(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1684 <openhttp+0x484>
jmp    1734 <openhttp+0x534>
cmpl   $0x0,-0x56c(%rbp)
jne    122b <openhttp+0x2b>
mov    -0x564(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x580,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openhttp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x548,%rsp
mov    %rdi,%rbx
lea    0x3f(%rsp),%rbp
lea    0x13f(%rsp),%r13
movl   $0x50,0xc(%rsp)
lea    0x240(%rsp),%r12
mov    %rbx,%rdi
lea    0xdc5(%rip),%rsi
mov    $0x7,%edx
call   1040 <strncmp@plt>
lea    0x23f(%rsp),%rdi
mov    0x2d94(%rip),%rsi
lea    0x7(%rbx),%rcx
test   %rax,%rax
cmove  %rcx,%rbx
lea    0x1(%rbx),%rax
lea    0x141(%rsp),%rcx
nopl   0x0(%rax,%rax,1)
movzbl (%rbx),%edx
mov    $0xffffffff,%r15d
test   %dl,%dl
je     14fb <openhttp+0x2fb>
cmp    $0x2f,%dl
je     12b0 <openhttp+0xb0>
cmp    $0x3a,%dl
je     12b0 <openhttp+0xb0>
mov    %dl,-0x1(%rcx)
cmp    %rdi,%rcx
jae    14fb <openhttp+0x2fb>
add    $0x1,%rbx
add    $0x1,%rcx
add    $0x1,%rax
jmp    1270 <openhttp+0x70>
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0x0,-0x1(%rcx)
mov    (%rbx),%cl
cmp    $0x3a,%cl
jne    130a <openhttp+0x10a>
mov    %rax,%rbx
lea    0x20(%rsp),%rax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%rbx),%ecx
test   %cl,%cl
je     12f0 <openhttp+0xf0>
cmp    $0x2f,%cl
je     12f0 <openhttp+0xf0>
mov    %cl,(%rax)
add    $0x1,%rax
add    $0x1,%rbx
cmp    %rbp,%rax
jb     12d0 <openhttp+0xd0>
jmp    14fb <openhttp+0x2fb>
movb   $0x0,(%rax)
lea    0x20(%rsp),%rdi
call   10f0 <atoi@plt>
mov    0x2ce4(%rip),%rsi
mov    %eax,0xc(%rsp)
mov    (%rbx),%cl
lea    0x40(%rsp),%rax
test   %cl,%cl
je     133b <openhttp+0x13b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %cl,(%rax)
add    $0x1,%rax
cmp    %r13,%rax
jae    14fb <openhttp+0x2fb>
movzbl 0x1(%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
jne    1320 <openhttp+0x120>
movb   $0x0,(%rax)
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    %rsi,%r13
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    0x0(%r13),%eax
mov    %eax,0x14(%rsp)
mov    0xc(%rsp),%edi
call   1070 <htons@plt>
mov    %eax,0x18(%rsp)
lea    0x140(%rsp),%rdi
mov    %rbp,%rsi
call   10c0 <inet_aton@plt>
test   %rax,%rax
jne    13b0 <openhttp+0x1b0>
lea    0x140(%rsp),%rdi
call   10a0 <gethostbyname@plt>
test   %rax,%rax
je     14fb <openhttp+0x2fb>
mov    0x8(%rax),%ecx
mov    %ecx,0x14(%rsp)
mov    (%rax),%edx
mov    0x4(%rax),%esi
lea    0x10(%rsp),%rdi
call   10b0 <memcpy@plt>
mov    0x2c38(%rip),%r13
mov    0x0(%r13),%edi
mov    0x2c1d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
test   %eax,%eax
js     14fb <openhttp+0x2fb>
mov    %eax,%ebp
mov    %eax,%edi
lea    0x10(%rsp),%rsi
mov    $0xc,%edx
call   1110 <connect@plt>
test   %rax,%rax
lea    0x13f(%rsp),%r13
js     14f4 <openhttp+0x2f4>
mov    %r12,%r14
mov    %r12,%rdi
lea    0xc0b(%rip),%rsi
lea    0x40(%rsp),%rdx
lea    0x140(%rsp),%rcx
call   1100 <sprintf@plt>
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   1050 <write@plt>
test   %rax,%rax
js     14f4 <openhttp+0x2f4>
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x100,%edx
call   10d0 <httpreadline@plt>
test   %rax,%rax
js     14f4 <openhttp+0x2f4>
mov    %r12,%rdi
mov    $0x20,%esi
call   1080 <strchr@plt>
mov    $0x1,%cl
test   %rax,%rax
je     146c <openhttp+0x26c>
movsbl 0x1(%rax),%eax
cmp    $0x32,%eax
je     146c <openhttp+0x26c>
cmp    $0x33,%eax
jne    14f4 <openhttp+0x2f4>
xor    %ecx,%ecx
mov    %ecx,0x1c(%rsp)
mov    %ebp,%edi
mov    %r12,%rsi
jmp    1485 <openhttp+0x285>
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x100,%edx
call   10d0 <httpreadline@plt>
test   %rax,%rax
js     14f4 <openhttp+0x2f4>
movzbl 0x240(%rsp),%eax
cmp    $0xa,%al
je     14df <openhttp+0x2df>
cmp    $0xd,%al
je     14df <openhttp+0x2df>
mov    %r12,%r14
mov    %r12,%rdi
lea    0xb8f(%rip),%rsi
mov    $0x9,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1480 <openhttp+0x280>
lea    0x340(%rsp),%rbx
mov    %rbx,%rdi
lea    0x24a(%rsp),%rsi
mov    $0x200,%edx
call   1030 <strncpy@plt>
jmp    1480 <openhttp+0x280>
mov    %ebp,%r15d
cmpb   $0x0,0x1c(%rsp)
lea    0x3f(%rsp),%rbp
je     1231 <openhttp+0x31>
jmp    14fb <openhttp+0x2fb>
mov    %ebp,%edi
call   1090 <close@plt>
mov    %r15d,%eax
add    $0x548,%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 = [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 [256 x i8]
%9 = alloca [32 x i8]
%10 = alloca [256 x i8]
%11 = alloca [256 x i8]
%12 = alloca [512 x i8]
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i8* %0, i8** %3
store i32 -1, i32* %13
store i32 80, i32* %14
%16 = load i8*, i8** %3
store i8* %16, i8** %6
br label %17
17: ; preds = %231, %1
%18 = load i8*, i8** %6
%19 = call i64 @strncmp(i8* %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i8*, i8** %6
%23 = getelementptr inbounds i8, i8* %22, i64 7
store i8* %23, i8** %6
br label %24
24: ; preds = %21, %17
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
store i8* %25, i8** %7
br label %26
26: ; preds = %54, %24
%27 = load i8*, i8** %6
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 58
br i1 %30, label %31, label %36
31: ; preds = %26
%32 = load i8*, i8** %6
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 47
br label %36
36: ; preds = %31, %26
%37 = phi i1 [ false, %26 ], [ %35, %31 ]
br i1 %37, label %38, label %57
38: ; preds = %36
%39 = load i8*, i8** %6
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %38
store i32 -1, i32* %2
br label %236
44: ; preds = %38
%45 = load i8*, i8** %6
%46 = load i8, i8* %45
%47 = load i8*, i8** %7
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %7
store i8 %46, i8* %47
%49 = load i8*, i8** %7
%50 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 255
%51 = icmp uge i8* %49, %50
br i1 %51, label %52, label %53
52: ; preds = %44
store i32 -1, i32* %2
br label %236
53: ; preds = %44
br label %54
54: ; preds = %53
%55 = load i8*, i8** %6
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %6
br label %26
57: ; preds = %36
%58 = load i8*, i8** %7
store i8 0, i8* %58
%59 = load i8*, i8** %6
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp eq i32 %61, 58
br i1 %62, label %63, label %95
63: ; preds = %57
%64 = load i8*, i8** %6
%65 = getelementptr inbounds i8, i8* %64, i32 1
store i8* %65, i8** %6
%66 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
store i8* %66, i8** %7
br label %67
67: ; preds = %88, %63
%68 = load i8*, i8** %6
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %91
72: ; preds = %67
%73 = load i8*, i8** %6
%74 = load i8, i8* %73
%75 = sext i8 %74 to i32
%76 = icmp eq i32 %75, 47
br i1 %76, label %77, label %78
77: ; preds = %72
br label %91
78: ; preds = %72
%79 = load i8*, i8** %6
%80 = load i8, i8* %79
%81 = load i8*, i8** %7
%82 = getelementptr inbounds i8, i8* %81, i32 1
store i8* %82, i8** %7
store i8 %80, i8* %81
%83 = load i8*, i8** %7
%84 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 31
%85 = icmp uge i8* %83, %84
br i1 %85, label %86, label %87
86: ; preds = %78
store i32 -1, i32* %2
br label %236
87: ; preds = %78
br label %88
88: ; preds = %87
%89 = load i8*, i8** %6
%90 = getelementptr inbounds i8, i8* %89, i32 1
store i8* %90, i8** %6
br label %67
91: ; preds = %77, %67
%92 = load i8*, i8** %7
store i8 0, i8* %92
%93 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%94 = call i32 @atoi(i8* %93)
store i32 %94, i32* %14
br label %95
95: ; preds = %91, %57
%96 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
store i8* %96, i8** %7
br label %97
97: ; preds = %112, %95
%98 = load i8*, i8** %6
%99 = load i8, i8* %98
%100 = sext i8 %99 to i32
%101 = icmp ne i32 %100, 0
br i1 %101, label %102, label %115
102: ; preds = %97
%103 = load i8*, i8** %6
%104 = load i8, i8* %103
%105 = load i8*, i8** %7
%106 = getelementptr inbounds i8, i8* %105, i32 1
store i8* %106, i8** %7
store i8 %104, i8* %105
%107 = load i8*, i8** %7
%108 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 255
%109 = icmp uge i8* %107, %108
br i1 %109, label %110, label %111
110: ; preds = %102
store i32 -1, i32* %2
br label %236
111: ; preds = %102
br label %112
112: ; preds = %111
%113 = load i8*, i8** %6
%114 = getelementptr inbounds i8, i8* %113, i32 1
store i8* %114, i8** %6
br label %97
115: ; preds = %97
%116 = load i8*, i8** %7
store i8 0, i8* %116
%117 = call i32 @bzero(%struct.sockaddr_in* %4, i32 12)
%118 = load i32, i32* @AF_INET
%119 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
store i32 %118, i32* %119
%120 = load i32, i32* %14
%121 = call i32 @htons(i32 %120)
%122 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %121, i32* %122
%123 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%124 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%125 = call i64 @inet_aton(i8* %123, i32* %124)
%126 = icmp eq i64 %125, 0
br i1 %126, label %127, label %146
127: ; preds = %115
%128 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%129 = call %struct.hostent* @gethostbyname(i8* %128)
store %struct.hostent* %129, %struct.hostent** %5
%130 = icmp ne %struct.hostent* %129, null
br i1 %130, label %131, label %144
131: ; preds = %127
%132 = load %struct.hostent*, %struct.hostent** %5
%133 = getelementptr inbounds %struct.hostent, %struct.hostent* %132, i32 0, i32 2
%134 = load i32, i32* %133
%135 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
store i32 %134, i32* %135
%136 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%137 = load %struct.hostent*, %struct.hostent** %5
%138 = getelementptr inbounds %struct.hostent, %struct.hostent* %137, i32 0, i32 1
%139 = load i32, i32* %138
%140 = load %struct.hostent*, %struct.hostent** %5
%141 = getelementptr inbounds %struct.hostent, %struct.hostent* %140, i32 0, i32 0
%142 = load i32, i32* %141
%143 = call i32 @memcpy(i32* %136, i32 %139, i32 %142)
br label %145
144: ; preds = %127
store i32 -1, i32* %2
br label %236
145: ; preds = %131
br label %146
146: ; preds = %145, %115
%147 = load i32, i32* @AF_INET
%148 = load i32, i32* @SOCK_STREAM
%149 = call i32 @socket(i32 %147, i32 %148, i32 0)
store i32 %149, i32* %13
%150 = icmp slt i32 %149, 0
br i1 %150, label %151, label %152
151: ; preds = %146
store i32 -1, i32* %2
br label %236
152: ; preds = %146
%153 = load i32, i32* %13
%154 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%155 = call i64 @connect(i32 %153, %struct.sockaddr* %154, i32 12)
%156 = icmp slt i64 %155, 0
br i1 %156, label %157, label %160
157: ; preds = %152
%158 = load i32, i32* %13
%159 = call i32 @close(i32 %158)
store i32 -1, i32* %2
br label %236
160: ; preds = %152
%161 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%162 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%163 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%164 = call i32 @sprintf(i8* %161, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i8* %162, i8* %163)
%165 = load i32, i32* %13
%166 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%167 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%168 = call i32 @strlen(i8* %167)
%169 = call i64 @write(i32 %165, i8* %166, i32 %168)
%170 = icmp slt i64 %169, 0
br i1 %170, label %171, label %174
171: ; preds = %160
%172 = load i32, i32* %13
%173 = call i32 @close(i32 %172)
store i32 -1, i32* %2
br label %236
174: ; preds = %160
%175 = load i32, i32* %13
%176 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%177 = call i64 @httpreadline(i32 %175, i8* %176, i32 256)
%178 = icmp slt i64 %177, 0
br i1 %178, label %179, label %182
179: ; preds = %174
%180 = load i32, i32* %13
%181 = call i32 @close(i32 %180)
store i32 -1, i32* %2
br label %236
182: ; preds = %174
store i32 0, i32* %15
%183 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%184 = call i8* @strchr(i8* %183, i8 signext 32)
store i8* %184, i8** %7
%185 = icmp ne i8* %184, null
br i1 %185, label %186, label %199
186: ; preds = %182
%187 = load i8*, i8** %7
%188 = getelementptr inbounds i8, i8* %187, i64 1
%189 = load i8, i8* %188
%190 = sext i8 %189 to i32
switch i32 %190, label %195 [
i32 51, label %191
i32 50, label %194
]
191: ; preds = %186
%192 = load i32, i32* %15
%193 = add nsw i32 %192, 1
store i32 %193, i32* %15
br label %198
194: ; preds = %186
br label %198
195: ; preds = %186
%196 = load i32, i32* %13
%197 = call i32 @close(i32 %196)
store i32 -1, i32* %2
br label %236
198: ; preds = %194, %191
br label %199
199: ; preds = %198, %182
br label %200
200: ; preds = %229, %199
%201 = load i32, i32* %13
%202 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%203 = call i64 @httpreadline(i32 %201, i8* %202, i32 256)
%204 = icmp slt i64 %203, 0
br i1 %204, label %205, label %208
205: ; preds = %200
%206 = load i32, i32* %13
%207 = call i32 @close(i32 %206)
store i32 -1, i32* %2
br label %236
208: ; preds = %200
%209 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%210 = load i8, i8* %209
%211 = sext i8 %210 to i32
%212 = icmp eq i32 %211, 10
br i1 %212, label %218, label %213
213: ; preds = %208
%214 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%215 = load i8, i8* %214
%216 = sext i8 %215 to i32
%217 = icmp eq i32 %216, 13
br i1 %217, label %218, label %219
218: ; preds = %213, %208
br label %230
219: ; preds = %213
%220 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%221 = call i64 @strncmp(i8* %220, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 9)
%222 = icmp eq i64 %221, 0
br i1 %222, label %223, label %229
223: ; preds = %219
%224 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%225 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%226 = getelementptr inbounds i8, i8* %225, i64 10
%227 = call i32 @strncpy(i8* %224, i8* %226, i32 512)
%228 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
store i8* %228, i8** %6
br label %229
229: ; preds = %223, %219
br label %200
230: ; preds = %218
br label %231
231: ; preds = %230
%232 = load i32, i32* %15
%233 = icmp ne i32 %232, 0
br i1 %233, label %17, label %234
234: ; preds = %231
%235 = load i32, i32* %13
store i32 %235, i32* %2
br label %236
236: ; preds = %234, %205, %195, %179, %171, %157, %151, %144, %110, %86, %52, %43
%237 = load i32, i32* %2
ret i32 %237
}

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 = [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 [512 x i8]
%8 = bitcast %struct.sockaddr_in* %2 to i8*
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 255
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 31
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 255
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
%20 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 10
br label %22
22: ; preds = %126, %1
%23 = phi i8* [ %0, %1 ], [ %115, %126 ]
%24 = phi i32 [ 80, %1 ], [ %55, %126 ]
%25 = call i64 @strncmp(i8* %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%26 = icmp eq i64 %25, 0
%27 = select i1 %26, i64 7, i64 0
%28 = getelementptr i8, i8* %23, i64 %27
br label %29
29: ; preds = %36, %22
%30 = phi i8* [ %28, %22 ], [ %37, %36 ]
%31 = phi i8* [ %9, %22 ], [ %34, %36 ]
%32 = load i8, i8* %30
switch i8 %32, label %33 [
i8 58, label %38
i8 47, label %38
i8 0, label %129
]
33: ; preds = %29
%34 = getelementptr inbounds i8, i8* %31, i64 1
store i8 %32, i8* %31
%35 = icmp ult i8* %34, %14
br i1 %35, label %36, label %129
36: ; preds = %33
%37 = getelementptr inbounds i8, i8* %30, i64 1
br label %29
38: ; preds = %29, %29
store i8 0, i8* %31
%39 = load i8, i8* %30
%40 = icmp eq i8 %39, 58
br i1 %40, label %41, label %52
41: ; preds = %38, %46
%42 = phi i8* [ %44, %46 ], [ %30, %38 ]
%43 = phi i8* [ %47, %46 ], [ %10, %38 ]
%44 = getelementptr inbounds i8, i8* %42, i64 1
%45 = load i8, i8* %44
switch i8 %45, label %46 [
i8 0, label %49
i8 47, label %49
]
46: ; preds = %41
%47 = getelementptr inbounds i8, i8* %43, i64 1
store i8 %45, i8* %43
%48 = icmp ult i8* %47, %15
br i1 %48, label %41, label %129
49: ; preds = %41, %41
store i8 0, i8* %43
%50 = call i32 @atoi(i8* %10)
%51 = load i8, i8* %44
br label %52
52: ; preds = %49, %38
%53 = phi i8 [ %51, %49 ], [ %39, %38 ]
%54 = phi i8* [ %44, %49 ], [ %30, %38 ]
%55 = phi i32 [ %50, %49 ], [ %24, %38 ]
%56 = icmp eq i8 %53, 0
br i1 %56, label %67, label %57
57: ; preds = %52, %63
%58 = phi i8 [ %65, %63 ], [ %53, %52 ]
%59 = phi i8* [ %61, %63 ], [ %11, %52 ]
%60 = phi i8* [ %64, %63 ], [ %54, %52 ]
%61 = getelementptr inbounds i8, i8* %59, i64 1
store i8 %58, i8* %59
%62 = icmp ult i8* %61, %16
br i1 %62, label %63, label %129
63: ; preds = %57
%64 = getelementptr inbounds i8, i8* %60, i64 1
%65 = load i8, i8* %64
%66 = icmp eq i8 %65, 0
br i1 %66, label %67, label %57
67: ; preds = %63, %52
%68 = phi i8* [ %54, %52 ], [ %64, %63 ]
%69 = phi i8* [ %11, %52 ], [ %61, %63 ]
store i8 0, i8* %69
%70 = call i32 @bzero(%struct.sockaddr_in* %2, i32 12)
%71 = load i32, i32* @AF_INET
store i32 %71, i32* %17
%72 = call i32 @htons(i32 %55)
store i32 %72, i32* %18
%73 = call i64 @inet_aton(i8* %9, i32* %19)
%74 = icmp eq i64 %73, 0
br i1 %74, label %75, label %86
75: ; preds = %67
%76 = call %struct.hostent* @gethostbyname(i8* %9)
%77 = icmp eq %struct.hostent* %76, null
br i1 %77, label %129, label %78
78: ; preds = %75
%79 = getelementptr inbounds %struct.hostent, %struct.hostent* %76, i64 0, i32 2
%80 = load i32, i32* %79
store i32 %80, i32* %17
%81 = getelementptr inbounds %struct.hostent, %struct.hostent* %76, i64 0, i32 1
%82 = load i32, i32* %81
%83 = getelementptr inbounds %struct.hostent, %struct.hostent* %76, i64 0, i32 0
%84 = load i32, i32* %83
%85 = call i32 @memcpy(i32* %19, i32 %82, i32 %84)
br label %86
86: ; preds = %78, %67
%87 = load i32, i32* @AF_INET
%88 = load i32, i32* @SOCK_STREAM
%89 = call i32 @socket(i32 %87, i32 %88, i32 0)
%90 = icmp slt i32 %89, 0
br i1 %90, label %129, label %91
91: ; preds = %86
%92 = call i64 @connect(i32 %89, %struct.sockaddr* %20, i32 12)
%93 = icmp slt i64 %92, 0
br i1 %93, label %127, label %94
94: ; preds = %91
%95 = call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i8* %11, i8* %9)
%96 = call i32 @strlen(i8* %12)
%97 = call i64 @write(i32 %89, i8* %12, i32 %96)
%98 = icmp slt i64 %97, 0
br i1 %98, label %127, label %99
99: ; preds = %94
%100 = call i64 @httpreadline(i32 %89, i8* %12, i32 256)
%101 = icmp slt i64 %100, 0
br i1 %101, label %127, label %102
102: ; preds = %99
%103 = call i8* @strchr(i8* %12, i8 signext 32)
%104 = icmp eq i8* %103, null
br i1 %104, label %110, label %105
105: ; preds = %102
%106 = getelementptr inbounds i8, i8* %103, i64 1
%107 = load i8, i8* %106
%108 = sext i8 %107 to i32
switch i32 %108, label %127 [
i32 51, label %109
i32 50, label %110
]
109: ; preds = %105
br label %110
110: ; preds = %109, %105, %102
%111 = phi i1 [ false, %109 ], [ true, %105 ], [ true, %102 ]
%112 = call i64 @httpreadline(i32 %89, i8* %12, i32 256)
%113 = icmp slt i64 %112, 0
br i1 %113, label %127, label %114
114: ; preds = %110, %122
%115 = phi i8* [ %123, %122 ], [ %68, %110 ]
%116 = load i8, i8* %12
switch i8 %116, label %117 [
i8 13, label %126
i8 10, label %126
]
117: ; preds = %114
%118 = call i64 @strncmp(i8* %12, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 9)
%119 = icmp eq i64 %118, 0
br i1 %119, label %120, label %122
120: ; preds = %117
%121 = call i32 @strncpy(i8* %13, i8* %21, i32 512)
br label %122
122: ; preds = %120, %117
%123 = phi i8* [ %13, %120 ], [ %115, %117 ]
%124 = call i64 @httpreadline(i32 %89, i8* %12, i32 256)
%125 = icmp slt i64 %124, 0
br i1 %125, label %127, label %114
126: ; preds = %114, %114
br i1 %111, label %129, label %22
127: ; preds = %110, %105, %99, %94, %91, %122
%128 = call i32 @close(i32 %89)
br label %129
129: ; preds = %126, %86, %75, %33, %29, %46, %57, %127
%130 = phi i32 [ -1, %127 ], [ -1, %57 ], [ -1, %46 ], [ -1, %29 ], [ -1, %33 ], [ %89, %126 ], [ -1, %86 ], [ -1, %75 ]
ret i32 %130
}