#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  scalar_t__ *h_addr_list;
};
typedef int /*<<< orphan*/ servaddr;
typedef int /*<<< orphan*/ in_addr_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, size_t);
int recvfrom(int, char *, size_t, int /*<<< orphan*/, int /*<<< orphan*/ *,
             int /*<<< orphan*/ *);
int sendto(int, char *, int const, int /*<<< orphan*/, struct sockaddr *, int);
int snprintf(char *, size_t, char *, char const *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strstr(char const *, char const *);
int main(int argc, char **argv) {
  const char *prefix = "http://";
  const char *url = argc > 1 ? argv[1] : "http://google.com";
  if (strstr(url, prefix) == 0) {
    fprintf(stderr, "Invalid URL '%s', must start with '%s'\n", url, prefix);
    return EXIT_FAILURE;
  }
  url = url + strlen(prefix);
  const char *path = strstr(url, "/");
  int hostname_len = 0;
  if (!path) {
    hostname_len = strlen(url);
    path = "/";
  } else {
    hostname_len = path - url;
  }
  char hostname[hostname_len + 1];
  hostname[hostname_len] = '\0';
  strncpy(hostname, url, hostname_len);
  struct hostent *h = gethostbyname(hostname);
  if (0 == h || h->h_addr_list[0] == 0) {
    fprintf(stderr, "Unable to resolve host '%s'\n", hostname);
    return EXIT_FAILURE;
  }
  int s = socket(AF_INET, SOCK_STREAM, 0);
  if (0 == s) {
    fprintf(stderr, "Unable to open socket, reason: %s\n", strerror(errno));
    return EXIT_FAILURE;
  }
  struct sockaddr_in servaddr, cliaddr;
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = *(in_addr_t *)h->h_addr_list[0];
  servaddr.sin_port = htons(80);
  int res = connect(s, (struct sockaddr *)&servaddr, sizeof(servaddr));
  if (0 != res) {
    fprintf(stderr, "Unable to connect to host, reason: %s\n", strerror(errno));
    close(s);
    return EXIT_FAILURE;
  }
  size_t buffer_size = 256 * 1024;
  char *buffer = (char *)malloc(buffer_size);
  memset(buffer, 0, buffer_size);
  const int real_size =
      snprintf(buffer, buffer_size, "GET %s HTTP/1.0\n\n", path);
  res = sendto(s, buffer, real_size, 0, (struct sockaddr *)&servaddr,
               sizeof(servaddr));
  if (res != real_size) {
    fprintf(stderr, "Unable to send request, reason: %s\n", strerror(errno));
    free(buffer);
    buffer = 0;
    close(s);
    s = 0;
    return EXIT_FAILURE;
  }
  int received_bytes = 0;
  do {
    received_bytes = recvfrom(s, buffer, buffer_size - 1, 0, NULL, NULL);
    if (received_bytes > 0) {
      buffer[received_bytes] = '\0';
      fprintf(stdout, "%s", buffer);
    }
  } while (received_bytes > 0);
  fprintf(stdout, "\n");
  free(buffer);
  buffer = 0;
  close(s);
  s = 0;
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xdd0(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1252 <main+0x42>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x98(%rbp)
jmp    1265 <main+0x55>
lea    0xdaf(%rip),%rax
mov    %rax,-0x98(%rbp)
jmp    1265 <main+0x55>
mov    -0x98(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1120 <strstr@plt>
cmp    $0x0,%rax
jne    12b7 <main+0xa7>
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xd7b(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2d13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    16b4 <main+0x4a4>
mov    -0x20(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0xa0(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xd1d(%rip),%rsi
call   1120 <strstr@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1320 <main+0x110>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x2c(%rbp)
lea    0xcef(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    132e <main+0x11e>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0xa8(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x40(%rbp)
movslq -0x2c(%rbp),%rax
movb   $0x0,(%rdi,%rax,1)
mov    -0x20(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0xa8(%rbp),%rdi
call   10b0 <gethostbyname@plt>
mov    %rax,-0x48(%rbp)
xor    %eax,%eax
cmp    -0x48(%rbp),%rax
je     139b <main+0x18b>
mov    -0x48(%rbp),%rax
mov    (%rax),%rax
cmpq   $0x0,(%rax)
jne    13d1 <main+0x1c1>
mov    -0xa8(%rbp),%rdx
mov    0x2c2f(%rip),%rax
mov    (%rax),%edi
lea    0xc90(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2c00(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    16ad <main+0x49d>
mov    0x2c10(%rip),%rax
mov    (%rax),%edi
mov    0x2bef(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,-0x50(%rbp)
xor    %eax,%eax
cmp    -0x50(%rbp),%eax
jne    1444 <main+0x234>
mov    0x2bd9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xac(%rbp)
mov    0x2bba(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0xac(%rbp),%edi
mov    %rax,%rdx
lea    0xc3a(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2b8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    16ad <main+0x49d>
lea    -0x60(%rbp),%rdi
mov    $0xc,%esi
call   10f0 <bzero@plt>
mov    0x2b8f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    -0x48(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    $0x50,%edi
call   1060 <htons@plt>
mov    %eax,-0x60(%rbp)
mov    -0x50(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0xc,%edx
call   1100 <connect@plt>
mov    %eax,-0x74(%rbp)
xor    %eax,%eax
cmp    -0x74(%rbp),%eax
je     14ed <main+0x2dd>
mov    0x2b38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xb0(%rbp)
mov    0x2b19(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0xb0(%rbp),%edi
mov    %rax,%rdx
lea    0xbbc(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x50(%rbp),%edi
call   10a0 <close@plt>
mov    0x2ae4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    16ad <main+0x49d>
movq   $0x40000,-0x80(%rbp)
mov    -0x80(%rbp),%rdi
call   10d0 <malloc@plt>
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rdi
mov    -0x80(%rbp),%rdx
xor    %esi,%esi
call   1080 <memset@plt>
mov    -0x88(%rbp),%rdi
mov    -0x80(%rbp),%rsi
mov    -0x28(%rbp),%rcx
lea    0xb7c(%rip),%rdx
call   1070 <snprintf@plt>
mov    %eax,-0x8c(%rbp)
mov    -0x50(%rbp),%edi
mov    -0x88(%rbp),%rsi
mov    -0x8c(%rbp),%edx
lea    -0x60(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1090 <sendto@plt>
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%eax
cmp    -0x8c(%rbp),%eax
je     15dd <main+0x3cd>
mov    0x2a66(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xb4(%rbp)
mov    0x2a47(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0xb4(%rbp),%edi
mov    %rax,%rdx
lea    0xb23(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x88(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x88(%rbp)
mov    -0x50(%rbp),%edi
call   10a0 <close@plt>
movl   $0x0,-0x50(%rbp)
mov    0x29f4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    16ad <main+0x49d>
movl   $0x0,-0x90(%rbp)
mov    -0x50(%rbp),%edi
mov    -0x88(%rbp),%rsi
mov    -0x80(%rbp),%rdx
sub    $0x1,%rdx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   10e0 <recvfrom@plt>
mov    %eax,-0x90(%rbp)
cmpl   $0x0,-0x90(%rbp)
jle    164b <main+0x43b>
mov    -0x88(%rbp),%rax
movslq -0x90(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    0x2984(%rip),%rax
mov    (%rax),%edi
mov    -0x88(%rbp),%rdx
lea    0xa9b(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
jmp    1650 <main+0x440>
cmpl   $0x0,-0x90(%rbp)
jg     15e7 <main+0x3d7>
mov    0x2954(%rip),%rax
mov    (%rax),%edi
lea    0xa4c(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x88(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x88(%rbp)
mov    -0x50(%rbp),%edi
call   10a0 <close@plt>
movl   $0x0,-0x50(%rbp)
mov    0x290f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jl     123c <main+0x1c>
mov    0x8(%rsi),%r14
jmp    1243 <main+0x23>
lea    0xdc5(%rip),%r14
lea    0xdb6(%rip),%rsi
mov    %r14,%rdi
call   1130 <strstr@plt>
test   %rax,%rax
je     1282 <main+0x62>
lea    0xda2(%rip),%rdi
call   1050 <strlen@plt>
cltq
add    %rax,%r14
mov    %r14,%rdi
mov    $0x2f,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     12b1 <main+0x91>
mov    %rax,%r15
sub    %r14d,%eax
jmp    12c0 <main+0xa0>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
lea    0xd88(%rip),%rsi
lea    0xd67(%rip),%rcx
mov    %r14,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    0x2d16(%rip),%rax
mov    (%rax),%eax
jmp    1547 <main+0x327>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0xd46(%rip),%r15
mov    %rsp,%r13
lea    0x1(%rax),%ecx
mov    %rsp,%rbx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
movslq %eax,%rdx
movb   $0x0,(%rdx,%rbx,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strncpy@plt>
mov    %rbx,%rdi
call   10c0 <gethostbyname@plt>
test   %rax,%rax
je     13ac <main+0x18c>
mov    %rax,%r12
mov    (%rax),%rax
cmpq   $0x0,(%rax)
je     13ac <main+0x18c>
mov    %r13,-0x30(%rbp)
mov    0x2cd3(%rip),%r13
mov    0x0(%r13),%edi
mov    0x2cb0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
test   %eax,%eax
je     13d4 <main+0x1b4>
mov    %eax,%r14d
lea    -0x40(%rbp),%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   1100 <bzero@plt>
mov    0x0(%r13),%eax
mov    %eax,-0x38(%rbp)
mov    (%r12),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    $0x50,%edi
call   1060 <htons@plt>
mov    %eax,-0x40(%rbp)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1110 <connect@plt>
test   %eax,%eax
je     1410 <main+0x1f0>
mov    0x2c54(%rip),%rax
mov    (%rax),%ebx
mov    0x2c3b(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xce7(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
jmp    152f <main+0x30f>
mov    0x2c25(%rip),%rax
mov    (%rax),%edi
lea    0xc86(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    0x2bf3(%rip),%rax
mov    (%rax),%eax
jmp    1544 <main+0x324>
mov    0x2bfd(%rip),%rax
mov    (%rax),%ebx
mov    0x2be4(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xc6d(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    0x2bbb(%rip),%rax
mov    (%rax),%eax
mov    -0x30(%rbp),%r13
jmp    1544 <main+0x324>
mov    $0x40000,%edi
call   10e0 <malloc@plt>
mov    %rax,%rbx
mov    $0x40000,%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1090 <memset@plt>
lea    0xc76(%rip),%rdx
mov    $0x40000,%esi
mov    %rbx,%rdi
mov    %r15,%rcx
call   1080 <snprintf@plt>
mov    %eax,%r15d
lea    -0x40(%rbp),%r8
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   10a0 <sendto@plt>
cmp    %r15d,%eax
jne    14fb <main+0x2db>
mov    $0x3ffff,%edx
mov    %r14d,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   10f0 <recvfrom@plt>
test   %eax,%eax
jle    14d3 <main+0x2b3>
mov    0x2b2d(%rip),%r12
lea    0xc4d(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %eax,%eax
movb   $0x0,(%rbx,%rax,1)
mov    (%r12),%edi
mov    %r15,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    $0x3ffff,%edx
mov    %r14d,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   10f0 <recvfrom@plt>
test   %eax,%eax
jg     14a0 <main+0x280>
mov    0x2ade(%rip),%rax
mov    (%rax),%edi
lea    0xbd6(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2ab7(%rip),%rbx
jmp    1536 <main+0x316>
mov    0x2ad6(%rip),%rax
mov    (%rax),%r15d
mov    0x2abc(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xba1(%rip),%rsi
mov    %r15d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2a8a(%rip),%rbx
mov    -0x30(%rbp),%r13
mov    %r14d,%edi
call   10b0 <close@plt>
mov    (%rbx),%eax
mov    %r13,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i64* }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [8 x i8] c"http://\00"
@.str.1 = [18 x i8] c"http://google.com\00"
@stderr = global i32 0
@.str.2 = [40 x i8] c"Invalid URL '%s', must start with '%s'\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [29 x i8] c"Unable to resolve host '%s'\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.5 = [35 x i8] c"Unable to open socket, reason: %s\0A\00"
@errno = global i32 0
@.str.6 = [39 x i8] c"Unable to connect to host, reason: %s\0A\00"
@.str.7 = [18 x i8] c"GET %s HTTP/1.0\0A\0A\00"
@.str.8 = [36 x i8] c"Unable to send request, reason: %s\0A\00"
@stdout = global i32 0
@.str.9 = [3 x i8] c"%s\00"
@.str.10 = [2 x i8] c"\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca %struct.hostent*
%13 = alloca i32
%14 = alloca i32
%15 = alloca %struct.sockaddr_in
%16 = alloca %struct.sockaddr_in
%17 = alloca i32
%18 = alloca i64
%19 = alloca i8*
%20 = alloca i32
%21 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %6
%22 = load i32, i32* %4
%23 = icmp sgt i32 %22, 1
br i1 %23, label %24, label %28
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
br label %29
28: ; preds = %2
br label %29
29: ; preds = %28, %24
%30 = phi i8* [ %27, %24 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), %28 ]
store i8* %30, i8** %7
%31 = load i8*, i8** %7
%32 = load i8*, i8** %6
%33 = call i8* @strstr(i8* %31, i8* %32)
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %41
35: ; preds = %29
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %7
%38 = load i8*, i8** %6
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %37, i8* %38)
%40 = load i32, i32* @EXIT_FAILURE
store i32 %40, i32* %3
br label %187
41: ; preds = %29
%42 = load i8*, i8** %7
%43 = load i8*, i8** %6
%44 = call i32 @strlen(i8* %43)
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %42, i64 %45
store i8* %46, i8** %7
%47 = load i8*, i8** %7
%48 = call i8* @strstr(i8* %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %48, i8** %8
store i32 0, i32* %9
%49 = load i8*, i8** %8
%50 = icmp ne i8* %49, null
br i1 %50, label %54, label %51
51: ; preds = %41
%52 = load i8*, i8** %7
%53 = call i32 @strlen(i8* %52)
store i32 %53, i32* %9
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8** %8
br label %61
54: ; preds = %41
%55 = load i8*, i8** %8
%56 = load i8*, i8** %7
%57 = ptrtoint i8* %55 to i64
%58 = ptrtoint i8* %56 to i64
%59 = sub i64 %57, %58
%60 = trunc i64 %59 to i32
store i32 %60, i32* %9
br label %61
61: ; preds = %54, %51
%62 = load i32, i32* %9
%63 = add nsw i32 %62, 1
%64 = zext i32 %63 to i64
%65 = call i8* @llvm.stacksave()
store i8* %65, i8** %10
%66 = alloca i8, i64 %64
store i64 %64, i64* %11
%67 = load i32, i32* %9
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %66, i64 %68
store i8 0, i8* %69
%70 = load i8*, i8** %7
%71 = load i32, i32* %9
%72 = call i32 @strncpy(i8* %66, i8* %70, i32 %71)
%73 = call %struct.hostent* @gethostbyname(i8* %66)
store %struct.hostent* %73, %struct.hostent** %12
%74 = load %struct.hostent*, %struct.hostent** %12
%75 = icmp eq %struct.hostent* null, %74
br i1 %75, label %83, label %76
76: ; preds = %61
%77 = load %struct.hostent*, %struct.hostent** %12
%78 = getelementptr inbounds %struct.hostent, %struct.hostent* %77, i32 0, i32 0
%79 = load i64*, i64** %78
%80 = getelementptr inbounds i64, i64* %79, i64 0
%81 = load i64, i64* %80
%82 = icmp eq i64 %81, 0
br i1 %82, label %83, label %87
83: ; preds = %76, %61
%84 = load i32, i32* @stderr
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %66)
%86 = load i32, i32* @EXIT_FAILURE
store i32 %86, i32* %3
store i32 1, i32* %13
br label %185
87: ; preds = %76
%88 = load i32, i32* @AF_INET
%89 = load i32, i32* @SOCK_STREAM
%90 = call i32 @socket(i32 %88, i32 %89, i32 0)
store i32 %90, i32* %14
%91 = load i32, i32* %14
%92 = icmp eq i32 0, %91
br i1 %92, label %93, label %99
93: ; preds = %87
%94 = load i32, i32* @stderr
%95 = load i32, i32* @errno
%96 = call i8* @strerror(i32 %95)
%97 = call i32 (i32, i8*, ...) @fprintf(i32 %94, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* %96)
%98 = load i32, i32* @EXIT_FAILURE
store i32 %98, i32* %3
store i32 1, i32* %13
br label %185
99: ; preds = %87
%100 = call i32 @bzero(%struct.sockaddr_in* %15, i32 12)
%101 = load i32, i32* @AF_INET
%102 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %15, i32 0, i32 2
store i32 %101, i32* %102
%103 = load %struct.hostent*, %struct.hostent** %12
%104 = getelementptr inbounds %struct.hostent, %struct.hostent* %103, i32 0, i32 0
%105 = load i64*, i64** %104
%106 = getelementptr inbounds i64, i64* %105, i64 0
%107 = load i64, i64* %106
%108 = inttoptr i64 %107 to i32*
%109 = load i32, i32* %108
%110 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %15, i32 0, i32 1
%111 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %110, i32 0, i32 0
store i32 %109, i32* %111
%112 = call i32 @htons(i32 80)
%113 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %15, i32 0, i32 0
store i32 %112, i32* %113
%114 = load i32, i32* %14
%115 = bitcast %struct.sockaddr_in* %15 to %struct.sockaddr*
%116 = call i32 @connect(i32 %114, %struct.sockaddr* %115, i32 12)
store i32 %116, i32* %17
%117 = load i32, i32* %17
%118 = icmp ne i32 0, %117
br i1 %118, label %119, label %127
119: ; preds = %99
%120 = load i32, i32* @stderr
%121 = load i32, i32* @errno
%122 = call i8* @strerror(i32 %121)
%123 = call i32 (i32, i8*, ...) @fprintf(i32 %120, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0), i8* %122)
%124 = load i32, i32* %14
%125 = call i32 @close(i32 %124)
%126 = load i32, i32* @EXIT_FAILURE
store i32 %126, i32* %3
store i32 1, i32* %13
br label %185
127: ; preds = %99
store i64 262144, i64* %18
%128 = load i64, i64* %18
%129 = call i64 @malloc(i64 %128)
%130 = inttoptr i64 %129 to i8*
store i8* %130, i8** %19
%131 = load i8*, i8** %19
%132 = load i64, i64* %18
%133 = call i32 @memset(i8* %131, i32 0, i64 %132)
%134 = load i8*, i8** %19
%135 = load i64, i64* %18
%136 = load i8*, i8** %8
%137 = call i32 @snprintf(i8* %134, i64 %135, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i8* %136)
store i32 %137, i32* %20
%138 = load i32, i32* %14
%139 = load i8*, i8** %19
%140 = load i32, i32* %20
%141 = bitcast %struct.sockaddr_in* %15 to %struct.sockaddr*
%142 = call i32 @sendto(i32 %138, i8* %139, i32 %140, i32 0, %struct.sockaddr* %141, i32 12)
store i32 %142, i32* %17
%143 = load i32, i32* %17
%144 = load i32, i32* %20
%145 = icmp ne i32 %143, %144
br i1 %145, label %146, label %156
146: ; preds = %127
%147 = load i32, i32* @stderr
%148 = load i32, i32* @errno
%149 = call i8* @strerror(i32 %148)
%150 = call i32 (i32, i8*, ...) @fprintf(i32 %147, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0), i8* %149)
%151 = load i8*, i8** %19
%152 = call i32 @free(i8* %151)
store i8* null, i8** %19
%153 = load i32, i32* %14
%154 = call i32 @close(i32 %153)
store i32 0, i32* %14
%155 = load i32, i32* @EXIT_FAILURE
store i32 %155, i32* %3
store i32 1, i32* %13
br label %185
156: ; preds = %127
store i32 0, i32* %21
br label %157
157: ; preds = %174, %156
%158 = load i32, i32* %14
%159 = load i8*, i8** %19
%160 = load i64, i64* %18
%161 = sub i64 %160, 1
%162 = call i32 @recvfrom(i32 %158, i8* %159, i64 %161, i32 0, i32* null, i32* null)
store i32 %162, i32* %21
%163 = load i32, i32* %21
%164 = icmp sgt i32 %163, 0
br i1 %164, label %165, label %173
165: ; preds = %157
%166 = load i8*, i8** %19
%167 = load i32, i32* %21
%168 = sext i32 %167 to i64
%169 = getelementptr inbounds i8, i8* %166, i64 %168
store i8 0, i8* %169
%170 = load i32, i32* @stdout
%171 = load i8*, i8** %19
%172 = call i32 (i32, i8*, ...) @fprintf(i32 %170, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* %171)
br label %173
173: ; preds = %165, %157
br label %174
174: ; preds = %173
%175 = load i32, i32* %21
%176 = icmp sgt i32 %175, 0
br i1 %176, label %157, label %177
177: ; preds = %174
%178 = load i32, i32* @stdout
%179 = call i32 (i32, i8*, ...) @fprintf(i32 %178, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%180 = load i8*, i8** %19
%181 = call i32 @free(i8* %180)
store i8* null, i8** %19
%182 = load i32, i32* %14
%183 = call i32 @close(i32 %182)
store i32 0, i32* %14
%184 = load i32, i32* @EXIT_SUCCESS
store i32 %184, i32* %3
store i32 1, i32* %13
br label %185
185: ; preds = %177, %146, %119, %93, %83
%186 = load i8*, i8** %10
br label %187
187: ; preds = %185, %35
%188 = load i32, i32* %3
ret i32 %188
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i64* }
%struct.sockaddr = type { i32 }
@.str = [8 x i8] c"http://\00"
@.str.1 = [18 x i8] c"http://google.com\00"
@stderr = global i32 0
@.str.2 = [40 x i8] c"Invalid URL '%s', must start with '%s'\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [29 x i8] c"Unable to resolve host '%s'\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.5 = [35 x i8] c"Unable to open socket, reason: %s\0A\00"
@errno = global i32 0
@.str.6 = [39 x i8] c"Unable to connect to host, reason: %s\0A\00"
@.str.7 = [18 x i8] c"GET %s HTTP/1.0\0A\0A\00"
@.str.8 = [36 x i8] c"Unable to send request, reason: %s\0A\00"
@stdout = global i32 0
@.str.9 = [3 x i8] c"%s\00"
@.str.10 = [2 x i8] c"\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
br label %8
8: ; preds = %2, %5
%9 = phi i8* [ %7, %5 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), %2 ]
%10 = tail call i8* @strstr(i8* dereferenceable(1) %9, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
br label %115
16: ; preds = %8
%17 = tail call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %9, i64 %18
%20 = tail call i8* @strchr(i8* dereferenceable(1) %19, i32 47)
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = tail call i32 @strlen(i8* %19)
br label %29
24: ; preds = %16
%25 = ptrtoint i8* %20 to i64
%26 = ptrtoint i8* %19 to i64
%27 = sub i64 %25, %26
%28 = trunc i64 %27 to i32
br label %29
29: ; preds = %24, %22
%30 = phi i32 [ %28, %24 ], [ %23, %22 ]
%31 = phi i8* [ %20, %24 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), %22 ]
%32 = add nsw i32 %30, 1
%33 = zext i32 %32 to i64
%34 = tail call i8* @llvm.stacksave()
%35 = alloca i8, i64 %33
%36 = sext i32 %30 to i64
%37 = getelementptr inbounds i8, i8* %35, i64 %36
store i8 0, i8* %37
%38 = call i32 @strncpy(i8* %35, i8* %19, i32 %30)
%39 = call %struct.hostent* @gethostbyname(i8* %35)
%40 = icmp eq %struct.hostent* %39, null
br i1 %40, label %46, label %41
41: ; preds = %29
%42 = getelementptr inbounds %struct.hostent, %struct.hostent* %39, i64 0, i32 0
%43 = load i64*, i64** %42
%44 = load i64, i64* %43
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %41, %29
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %35)
%49 = load i32, i32* @EXIT_FAILURE
br label %113
50: ; preds = %41
%51 = load i32, i32* @AF_INET
%52 = load i32, i32* @SOCK_STREAM
%53 = call i32 @socket(i32 %51, i32 %52, i32 0)
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %61
55: ; preds = %50
%56 = load i32, i32* @stderr
%57 = load i32, i32* @errno
%58 = call i8* @strerror(i32 %57)
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* %58)
%60 = load i32, i32* @EXIT_FAILURE
br label %113
61: ; preds = %50
%62 = bitcast %struct.sockaddr_in* %3 to i8*
%63 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%64 = load i32, i32* @AF_INET
%65 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %64, i32* %65
%66 = load i64*, i64** %42
%67 = load i64, i64* %66
%68 = inttoptr i64 %67 to i32*
%69 = load i32, i32* %68
%70 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %69, i32* %70
%71 = call i32 @htons(i32 80)
%72 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %71, i32* %72
%73 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%74 = call i32 @connect(i32 %53, %struct.sockaddr* %73, i32 12)
%75 = icmp eq i32 %74, 0
br i1 %75, label %81, label %76
76: ; preds = %61
%77 = load i32, i32* @stderr
%78 = load i32, i32* @errno
%79 = call i8* @strerror(i32 %78)
%80 = call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0), i8* %79)
br label %109
81: ; preds = %61
%82 = call i64 @malloc(i64 262144)
%83 = inttoptr i64 %82 to i8*
%84 = call i32 @memset(i8* %83, i32 0, i64 262144)
%85 = call i32 @snprintf(i8* %83, i64 262144, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i8* %31)
%86 = call i32 @sendto(i32 %53, i8* %83, i32 %85, i32 0, %struct.sockaddr* %73, i32 12)
%87 = icmp eq i32 %86, %85
br i1 %87, label %88, label %91
88: ; preds = %81
%89 = call i32 @recvfrom(i32 %53, i8* %83, i64 262143, i32 0, i32* null, i32* null)
%90 = icmp sgt i32 %89, 0
br i1 %90, label %97, label %105
91: ; preds = %81
%92 = load i32, i32* @stderr
%93 = load i32, i32* @errno
%94 = call i8* @strerror(i32 %93)
%95 = call i32 (i32, i8*, ...) @fprintf(i32 %92, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0), i8* %94)
%96 = call i32 @free(i8* %83)
br label %109
97: ; preds = %88, %97
%98 = phi i32 [ %103, %97 ], [ %89, %88 ]
%99 = zext i32 %98 to i64
%100 = getelementptr inbounds i8, i8* %83, i64 %99
store i8 0, i8* %100
%101 = load i32, i32* @stdout
%102 = call i32 (i32, i8*, ...) @fprintf(i32 %101, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* %83)
%103 = call i32 @recvfrom(i32 %53, i8* %83, i64 262143, i32 0, i32* null, i32* null)
%104 = icmp sgt i32 %103, 0
br i1 %104, label %97, label %105
105: ; preds = %97, %88
%106 = load i32, i32* @stdout
%107 = call i32 (i32, i8*, ...) @fprintf(i32 %106, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%108 = call i32 @free(i8* %83)
br label %109
109: ; preds = %91, %105, %76
%110 = phi i32* [ @EXIT_FAILURE, %76 ], [ @EXIT_FAILURE, %91 ], [ @EXIT_SUCCESS, %105 ]
%111 = call i32 @close(i32 %53)
%112 = load i32, i32* %110
br label %113
113: ; preds = %55, %109, %46
%114 = phi i32 [ %49, %46 ], [ %60, %55 ], [ %112, %109 ]
br label %115
115: ; preds = %113, %12
%116 = phi i32 [ %15, %12 ], [ %114, %113 ]
ret i32 %116
}