#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 *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, n, 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"
            "\r\n",
            urlfile);
    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    $0x590,%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,-0x571(%rbp)
je     128c <openhttp+0x8c>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x571(%rbp)
mov    -0x571(%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    1743 <openhttp+0x543>
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    1743 <openhttp+0x543>
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    1743 <openhttp+0x543>
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    1743 <openhttp+0x543>
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    1743 <openhttp+0x543>
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    1743 <openhttp+0x543>
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    1743 <openhttp+0x543>
lea    -0x360(%rbp),%rdi
lea    -0x260(%rbp),%rdx
lea    0xab6(%rip),%rsi
call   1100 <sprintf@plt>
mov    -0x564(%rbp),%eax
mov    %eax,-0x584(%rbp)
lea    -0x360(%rbp),%rax
mov    %rax,-0x580(%rbp)
lea    -0x360(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x584(%rbp),%edi
mov    -0x580(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
cmp    $0x0,%rax
jge    15b2 <openhttp+0x3b2>
mov    -0x564(%rbp),%edi
call   1090 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1743 <openhttp+0x543>
mov    -0x564(%rbp),%edi
lea    -0x360(%rbp),%rsi
mov    $0x100,%edx
call   10d0 <httpreadline@plt>
cmp    $0x0,%rax
jge    15ea <openhttp+0x3ea>
mov    -0x564(%rbp),%edi
call   1090 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1743 <openhttp+0x543>
movl   $0x0,-0x570(%rbp)
lea    -0x360(%rbp),%rdi
mov    $0x20,%esi
call   1080 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     1678 <openhttp+0x478>
mov    -0x38(%rbp),%rax
movsbl 0x1(%rax),%eax
mov    %eax,-0x588(%rbp)
sub    $0x32,%eax
je     1657 <openhttp+0x457>
jmp    162f <openhttp+0x42f>
mov    -0x588(%rbp),%eax
sub    $0x33,%eax
jne    165c <openhttp+0x45c>
jmp    1643 <openhttp+0x443>
mov    -0x570(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x570(%rbp)
jmp    1673 <openhttp+0x473>
jmp    1673 <openhttp+0x473>
mov    -0x564(%rbp),%edi
call   1090 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1743 <openhttp+0x543>
jmp    1678 <openhttp+0x478>
jmp    167d <openhttp+0x47d>
mov    -0x564(%rbp),%edi
lea    -0x360(%rbp),%rsi
mov    $0x100,%edx
call   10d0 <httpreadline@plt>
cmp    $0x0,%rax
jge    16b5 <openhttp+0x4b5>
mov    -0x564(%rbp),%edi
call   1090 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1743 <openhttp+0x543>
movsbl -0x360(%rbp),%eax
cmp    $0xa,%eax
je     16d5 <openhttp+0x4d5>
movsbl -0x360(%rbp),%eax
cmp    $0xd,%eax
jne    16da <openhttp+0x4da>
jmp    1728 <openhttp+0x528>
lea    -0x360(%rbp),%rdi
lea    0x94e(%rip),%rsi
mov    $0x9,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1723 <openhttp+0x523>
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    167d <openhttp+0x47d>
jmp    172d <openhttp+0x52d>
cmpl   $0x0,-0x570(%rbp)
jne    122b <openhttp+0x2b>
mov    -0x564(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x590,%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     14eb <openhttp+0x2eb>
cmp    $0x2f,%dl
je     12b0 <openhttp+0xb0>
cmp    $0x3a,%dl
je     12b0 <openhttp+0xb0>
mov    %dl,-0x1(%rcx)
cmp    %rdi,%rcx
jae    14eb <openhttp+0x2eb>
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    14eb <openhttp+0x2eb>
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    14eb <openhttp+0x2eb>
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     14eb <openhttp+0x2eb>
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     14eb <openhttp+0x2eb>
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     14e4 <openhttp+0x2e4>
mov    %r12,%r14
mov    %r12,%rdi
lea    0xc0b(%rip),%rsi
lea    0x40(%rsp),%rdx
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     14e4 <openhttp+0x2e4>
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x100,%edx
call   10d0 <httpreadline@plt>
test   %rax,%rax
js     14e4 <openhttp+0x2e4>
mov    %r12,%rdi
mov    $0x20,%esi
call   1080 <strchr@plt>
mov    $0x1,%cl
test   %rax,%rax
je     1464 <openhttp+0x264>
movsbl 0x1(%rax),%eax
cmp    $0x32,%eax
je     1464 <openhttp+0x264>
cmp    $0x33,%eax
jne    14e4 <openhttp+0x2e4>
xor    %ecx,%ecx
mov    %ecx,0x1c(%rsp)
mov    %ebp,%edi
mov    %r12,%rsi
jmp    1475 <openhttp+0x275>
nop
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x100,%edx
call   10d0 <httpreadline@plt>
test   %rax,%rax
js     14e4 <openhttp+0x2e4>
movzbl 0x240(%rsp),%eax
cmp    $0xa,%al
je     14cf <openhttp+0x2cf>
cmp    $0xd,%al
je     14cf <openhttp+0x2cf>
mov    %r12,%r14
mov    %r12,%rdi
lea    0xb95(%rip),%rsi
mov    $0x9,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1470 <openhttp+0x270>
lea    0x340(%rsp),%rbx
mov    %rbx,%rdi
lea    0x24a(%rsp),%rsi
mov    $0x200,%edx
call   1030 <strncpy@plt>
jmp    1470 <openhttp+0x270>
mov    %ebp,%r15d
cmpb   $0x0,0x1c(%rsp)
lea    0x3f(%rsp),%rbp
je     1231 <openhttp+0x31>
jmp    14eb <openhttp+0x2eb>
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 = [46 x i8] c"GET %s HTTP/1.0\0D\0AUser-Agent: netflash/100\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
%16 = alloca i32
store i8* %0, i8** %3
store i32 -1, i32* %13
store i32 80, i32* %14
%17 = load i8*, i8** %3
store i8* %17, i8** %6
br label %18
18: ; preds = %231, %1
%19 = load i8*, i8** %6
%20 = call i64 @strncmp(i8* %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i8*, i8** %6
%24 = getelementptr inbounds i8, i8* %23, i64 7
store i8* %24, i8** %6
br label %25
25: ; preds = %22, %18
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
store i8* %26, i8** %7
br label %27
27: ; preds = %55, %25
%28 = load i8*, i8** %6
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 58
br i1 %31, label %32, label %37
32: ; preds = %27
%33 = load i8*, i8** %6
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 47
br label %37
37: ; preds = %32, %27
%38 = phi i1 [ false, %27 ], [ %36, %32 ]
br i1 %38, label %39, label %58
39: ; preds = %37
%40 = load i8*, i8** %6
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %39
store i32 -1, i32* %2
br label %236
45: ; preds = %39
%46 = load i8*, i8** %6
%47 = load i8, i8* %46
%48 = load i8*, i8** %7
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %7
store i8 %47, i8* %48
%50 = load i8*, i8** %7
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 255
%52 = icmp uge i8* %50, %51
br i1 %52, label %53, label %54
53: ; preds = %45
store i32 -1, i32* %2
br label %236
54: ; preds = %45
br label %55
55: ; preds = %54
%56 = load i8*, i8** %6
%57 = getelementptr inbounds i8, i8* %56, i32 1
store i8* %57, i8** %6
br label %27
58: ; preds = %37
%59 = load i8*, i8** %7
store i8 0, i8* %59
%60 = load i8*, i8** %6
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp eq i32 %62, 58
br i1 %63, label %64, label %96
64: ; preds = %58
%65 = load i8*, i8** %6
%66 = getelementptr inbounds i8, i8* %65, i32 1
store i8* %66, i8** %6
%67 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
store i8* %67, i8** %7
br label %68
68: ; preds = %89, %64
%69 = load i8*, i8** %6
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = icmp ne i32 %71, 0
br i1 %72, label %73, label %92
73: ; preds = %68
%74 = load i8*, i8** %6
%75 = load i8, i8* %74
%76 = sext i8 %75 to i32
%77 = icmp eq i32 %76, 47
br i1 %77, label %78, label %79
78: ; preds = %73
br label %92
79: ; preds = %73
%80 = load i8*, i8** %6
%81 = load i8, i8* %80
%82 = load i8*, i8** %7
%83 = getelementptr inbounds i8, i8* %82, i32 1
store i8* %83, i8** %7
store i8 %81, i8* %82
%84 = load i8*, i8** %7
%85 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 31
%86 = icmp uge i8* %84, %85
br i1 %86, label %87, label %88
87: ; preds = %79
store i32 -1, i32* %2
br label %236
88: ; preds = %79
br label %89
89: ; preds = %88
%90 = load i8*, i8** %6
%91 = getelementptr inbounds i8, i8* %90, i32 1
store i8* %91, i8** %6
br label %68
92: ; preds = %78, %68
%93 = load i8*, i8** %7
store i8 0, i8* %93
%94 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%95 = call i32 @atoi(i8* %94)
store i32 %95, i32* %14
br label %96
96: ; preds = %92, %58
%97 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
store i8* %97, i8** %7
br label %98
98: ; preds = %113, %96
%99 = load i8*, i8** %6
%100 = load i8, i8* %99
%101 = sext i8 %100 to i32
%102 = icmp ne i32 %101, 0
br i1 %102, label %103, label %116
103: ; preds = %98
%104 = load i8*, i8** %6
%105 = load i8, i8* %104
%106 = load i8*, i8** %7
%107 = getelementptr inbounds i8, i8* %106, i32 1
store i8* %107, i8** %7
store i8 %105, i8* %106
%108 = load i8*, i8** %7
%109 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 255
%110 = icmp uge i8* %108, %109
br i1 %110, label %111, label %112
111: ; preds = %103
store i32 -1, i32* %2
br label %236
112: ; preds = %103
br label %113
113: ; preds = %112
%114 = load i8*, i8** %6
%115 = getelementptr inbounds i8, i8* %114, i32 1
store i8* %115, i8** %6
br label %98
116: ; preds = %98
%117 = load i8*, i8** %7
store i8 0, i8* %117
%118 = call i32 @bzero(%struct.sockaddr_in* %4, i32 12)
%119 = load i32, i32* @AF_INET
%120 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
store i32 %119, i32* %120
%121 = load i32, i32* %14
%122 = call i32 @htons(i32 %121)
%123 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %122, i32* %123
%124 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%125 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%126 = call i64 @inet_aton(i8* %124, i32* %125)
%127 = icmp eq i64 %126, 0
br i1 %127, label %128, label %147
128: ; preds = %116
%129 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%130 = call %struct.hostent* @gethostbyname(i8* %129)
store %struct.hostent* %130, %struct.hostent** %5
%131 = icmp ne %struct.hostent* %130, null
br i1 %131, label %132, label %145
132: ; preds = %128
%133 = load %struct.hostent*, %struct.hostent** %5
%134 = getelementptr inbounds %struct.hostent, %struct.hostent* %133, i32 0, i32 2
%135 = load i32, i32* %134
%136 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
store i32 %135, i32* %136
%137 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%138 = load %struct.hostent*, %struct.hostent** %5
%139 = getelementptr inbounds %struct.hostent, %struct.hostent* %138, i32 0, i32 1
%140 = load i32, i32* %139
%141 = load %struct.hostent*, %struct.hostent** %5
%142 = getelementptr inbounds %struct.hostent, %struct.hostent* %141, i32 0, i32 0
%143 = load i32, i32* %142
%144 = call i32 @memcpy(i32* %137, i32 %140, i32 %143)
br label %146
145: ; preds = %128
store i32 -1, i32* %2
br label %236
146: ; preds = %132
br label %147
147: ; preds = %146, %116
%148 = load i32, i32* @AF_INET
%149 = load i32, i32* @SOCK_STREAM
%150 = call i32 @socket(i32 %148, i32 %149, i32 0)
store i32 %150, i32* %13
%151 = icmp slt i32 %150, 0
br i1 %151, label %152, label %153
152: ; preds = %147
store i32 -1, i32* %2
br label %236
153: ; preds = %147
%154 = load i32, i32* %13
%155 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%156 = call i64 @connect(i32 %154, %struct.sockaddr* %155, i32 12)
%157 = icmp slt i64 %156, 0
br i1 %157, label %158, label %161
158: ; preds = %153
%159 = load i32, i32* %13
%160 = call i32 @close(i32 %159)
store i32 -1, i32* %2
br label %236
161: ; preds = %153
%162 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%163 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%164 = call i32 @sprintf(i8* %162, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), 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 = %161
%172 = load i32, i32* %13
%173 = call i32 @close(i32 %172)
store i32 -1, i32* %2
br label %236
174: ; preds = %161
%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* %16
%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* %16
%193 = add nsw i32 %192, 1
store i32 %193, i32* %16
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* %16
%233 = icmp ne i32 %232, 0
br i1 %233, label %18, 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, %158, %152, %145, %111, %87, %53, %44
%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 = [46 x i8] c"GET %s HTTP/1.0\0D\0AUser-Agent: netflash/100\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 ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%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
}