#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 u_int;
struct timeval {
  int tv_sec;
  int tv_usec;
};
struct sockaddr_in6 {
  scalar_t__ sin6_family;
  void *sin6_port;
  int /*<<< orphan*/ sin6_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  scalar_t__ sin_family;
  void *sin_port;
};
struct addrinfo {
  scalar_t__ ai_family;
  int /*<<< orphan*/ *ai_addr;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ *ai_canonname;
  scalar_t__ ai_addrlen;
  scalar_t__ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  scalar_t__ ai_flags;
};
typedef int /*<<< orphan*/ in_port_t;

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_INET6;
scalar_t__ AF_UNSPEC;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ SHUT_WR;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVTIMEO;
int /*<<< orphan*/ err_msg(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int /*<<< orphan*/ get_http_ipv4(int *, struct sockaddr_in *, char *);
int /*<<< orphan*/ get_http_ipv6(int *, struct sockaddr_in6 *, char *);
scalar_t__ getaddrinfo(char *, int /*<<< orphan*/, struct addrinfo *,
                       struct addrinfo **);
void *htons(int /*<<< orphan*/);
int inet_pton(scalar_t__, char *, int /*<<< orphan*/ *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, struct timeval *,
               int);
int /*<<< orphan*/ shutdown(int, int /*<<< orphan*/);
int socket(scalar_t__, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  u_int trx_fd;
  u_int resv4;
  u_int resv6;
  u_int status = 1;
  char buffer[2000];
  struct addrinfo hints;
  struct addrinfo *rs;
  struct sockaddr_in svr_addr4;
  struct sockaddr_in *pr;
  struct sockaddr_in6 svr_addr6;
  struct timeval tt_wait;
  tt_wait.tv_sec = 3;
  tt_wait.tv_usec = 500000;
  if (argc != 2) {
    usage(argv[0]);
    exit(0);
  }
  hints.ai_flags = AF_INET;
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_protocol = 0;
  hints.ai_addrlen = 0;
  hints.ai_canonname = NULL;
  hints.ai_addr = NULL;
  hints.ai_next = NULL;
  resv4 = inet_pton(AF_INET, argv[1], &svr_addr4.sin_addr);
  resv6 = inet_pton(AF_INET6, argv[1], &svr_addr6.sin6_addr);
  svr_addr4.sin_port = htons((in_port_t)80);
  svr_addr4.sin_family = AF_INET;
  svr_addr6.sin6_port = htons((in_port_t)80);
  svr_addr6.sin6_family = AF_INET6;
  sprintf(buffer, "GET / HTTP/1.1\r\n\r\n");
  while (status == 1) {
    if (resv4 > 0) {
      if ((trx_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
        err_msg("Error creating socket");
      if ((setsockopt(trx_fd, SOL_SOCKET, SO_RCVTIMEO,
                      (struct timeval *)&tt_wait, sizeof(struct timeval))) ==
          -1)
        err_msg("setsockopt()");
      status = 0;
      get_http_ipv4(&trx_fd, &svr_addr4, buffer);
    } else if (resv6 > 0) {
      if ((trx_fd = socket(AF_INET6, SOCK_STREAM, 0)) == -1)
        err_msg("Error creating socket");
      if ((setsockopt(trx_fd, SOL_SOCKET, SO_RCVTIMEO,
                      (struct timeval *)&tt_wait, sizeof(struct timeval))) ==
          -1)
        err_msg("setsockopt()");
      status = 0;
      get_http_ipv6(&trx_fd, &svr_addr6, buffer);
    } else {
      if ((getaddrinfo(argv[1], 0, &hints, &rs)) != 0)
        err_msg(gai_strerror(status));
      resv4 = 1;
      for (; rs != NULL; rs = rs->ai_next) {
        if (rs->ai_family == AF_INET) {
          pr = (struct sockaddr_in *)rs->ai_addr;
          svr_addr4.sin_addr = pr->sin_addr;
          break;
        }
      }
      freeaddrinfo(rs);
    }
  }
  shutdown(trx_fd, SHUT_WR);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x880,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x20(%rbp)
movl   $0x3,-0x878(%rbp)
movl   $0x7a120,-0x874(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1231 <main+0x51>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <usage@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x7f8(%rbp)
mov    0x2d87(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x830(%rbp)
mov    0x2d56(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x800(%rbp)
movq   $0x0,-0x808(%rbp)
movq   $0x0,-0x810(%rbp)
movq   $0x0,-0x818(%rbp)
movq   $0x0,-0x828(%rbp)
movq   $0x0,-0x820(%rbp)
mov    0x2d40(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x850(%rbp),%rdx
call   1090 <inet_pton@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d07(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x870(%rbp),%rdx
add    $0x10,%rdx
call   1090 <inet_pton@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x50,%edi
call   1050 <htons@plt>
mov    %rax,-0x840(%rbp)
mov    0x2ce9(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x848(%rbp)
mov    $0x50,%edi
call   1050 <htons@plt>
mov    %rax,-0x868(%rbp)
mov    0x2caf(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x870(%rbp)
lea    -0x7f0(%rbp),%rdi
lea    0xccf(%rip),%rsi
call   10c0 <sprintf@plt>
cmpl   $0x1,-0x20(%rbp)
jne    1534 <main+0x354>
cmpl   $0x0,-0x18(%rbp)
jle    13db <main+0x1fb>
mov    0x2c8f(%rip),%rax
mov    (%rax),%rdi
mov    0x2c55(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    137c <main+0x19c>
lea    0xc9c(%rip),%rdi
call   10b0 <err_msg@plt>
mov    -0x14(%rbp),%edi
mov    0x2c62(%rip),%rax
mov    (%rax),%esi
mov    0x2c29(%rip),%rax
mov    (%rax),%edx
lea    -0x878(%rbp),%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    13b8 <main+0x1d8>
lea    0xc76(%rip),%rdi
call   10b0 <err_msg@plt>
movl   $0x0,-0x20(%rbp)
lea    -0x7f0(%rbp),%rdx
lea    -0x14(%rbp),%rdi
lea    -0x850(%rbp),%rsi
call   1070 <get_http_ipv4@plt>
jmp    152f <main+0x34f>
cmpl   $0x0,-0x1c(%rbp)
jle    1476 <main+0x296>
mov    0x2bdc(%rip),%rax
mov    (%rax),%rdi
mov    0x2bba(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1417 <main+0x237>
lea    0xc01(%rip),%rdi
call   10b0 <err_msg@plt>
mov    -0x14(%rbp),%edi
mov    0x2bc7(%rip),%rax
mov    (%rax),%esi
mov    0x2b8e(%rip),%rax
mov    (%rax),%edx
lea    -0x878(%rbp),%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1453 <main+0x273>
lea    0xbdb(%rip),%rdi
call   10b0 <err_msg@plt>
movl   $0x0,-0x20(%rbp)
lea    -0x7f0(%rbp),%rdx
lea    -0x14(%rbp),%rdi
lea    -0x870(%rbp),%rsi
call   1080 <get_http_ipv6@plt>
jmp    152a <main+0x34a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %esi,%esi
lea    -0x830(%rbp),%rdx
lea    -0x838(%rbp),%rcx
call   10e0 <getaddrinfo@plt>
cmp    $0x0,%rax
je     14ad <main+0x2cd>
mov    -0x20(%rbp),%edi
call   1060 <gai_strerror@plt>
mov    %rax,%rdi
call   10b0 <err_msg@plt>
movl   $0x1,-0x18(%rbp)
cmpq   $0x0,-0x838(%rbp)
je     151e <main+0x33e>
mov    -0x838(%rbp),%rax
mov    (%rax),%rax
mov    0x2b0d(%rip),%rcx
cmp    (%rcx),%rax
jne    1502 <main+0x322>
mov    -0x838(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x858(%rbp)
mov    -0x858(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x850(%rbp)
jmp    151e <main+0x33e>
jmp    1507 <main+0x327>
mov    -0x838(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x838(%rbp)
jmp    14b4 <main+0x2d4>
mov    -0x838(%rbp),%rdi
call   10f0 <freeaddrinfo@plt>
jmp    152f <main+0x34f>
jmp    1336 <main+0x156>
mov    -0x14(%rbp),%edi
mov    0x2a9a(%rip),%rax
mov    (%rax),%esi
call   1040 <shutdown@plt>
mov    0x2a5c(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x868,%rsp
mov    %rsi,%rbx
movabs $0x7a12000000003,%rax
mov    %rax,0x10(%rsp)
cmp    $0x2,%edi
jne    1344 <main+0x174>
mov    0x2ddd(%rip),%r15
mov    (%r15),%rdi
mov    %rdi,0x88(%rsp)
mov    0x2dbb(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x50(%rsp)
mov    0x2d8c(%rip),%r12
mov    (%r12),%eax
mov    %eax,0x80(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x58(%rsp)
movups %xmm0,0x68(%rsp)
movq   $0x0,0x78(%rsp)
mov    0x8(%rbx),%rsi
lea    0x20(%rsp),%rdx
call   1090 <inet_pton@plt>
mov    %eax,%ebp
mov    0x2d6c(%rip),%r13
mov    0x0(%r13),%rdi
mov    0x8(%rbx),%rsi
lea    0x48(%rsp),%rdx
call   1090 <inet_pton@plt>
mov    %eax,%r14d
mov    $0x50,%edi
call   1050 <htons@plt>
mov    %rax,0x30(%rsp)
mov    (%r15),%rax
mov    %rax,0x28(%rsp)
mov    $0x50,%edi
call   1050 <htons@plt>
mov    %rax,0x40(%rsp)
mov    0x0(%r13),%rax
mov    %rax,0x38(%rsp)
movups 0xd59(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movl   $0xa0d0a,0x9f(%rsp)
test   %ebp,%ebp
jg     13b6 <main+0x1e6>
test   %r14d,%r14d
jle    1353 <main+0x183>
mov    0x0(%r13),%rdi
mov    (%r12),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,0xc(%rsp)
cmp    $0xffffffff,%eax
jne    12f3 <main+0x123>
lea    0xd29(%rip),%rdi
call   10b0 <err_msg@plt>
mov    0xc(%rsp),%eax
mov    0x2cee(%rip),%rcx
mov    (%rcx),%esi
mov    0x2cb5(%rip),%rcx
mov    (%rcx),%edx
lea    0x10(%rsp),%rcx
mov    %eax,%edi
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1328 <main+0x158>
lea    0xd06(%rip),%rdi
call   10b0 <err_msg@plt>
lea    0xc(%rsp),%rdi
lea    0x38(%rsp),%rsi
lea    0x90(%rsp),%rdx
call   1080 <get_http_ipv6@plt>
jmp    1429 <main+0x259>
mov    (%rbx),%rdi
call   10a0 <usage@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    0x8(%rbx),%rdi
lea    0x50(%rsp),%rdx
lea    0x18(%rsp),%rcx
xor    %esi,%esi
call   10d0 <getaddrinfo@plt>
test   %rax,%rax
je     137f <main+0x1af>
mov    $0x1,%edi
call   1060 <gai_strerror@plt>
mov    %rax,%rdi
call   10b0 <err_msg@plt>
mov    0x18(%rsp),%rdi
test   %rdi,%rdi
je     13a3 <main+0x1d3>
mov    (%r15),%rax
nopl   0x0(%rax)
cmp    %rax,(%rdi)
je     13a7 <main+0x1d7>
mov    0x10(%rdi),%rdi
mov    %rdi,0x18(%rsp)
test   %rdi,%rdi
jne    1390 <main+0x1c0>
xor    %edi,%edi
jmp    13b1 <main+0x1e1>
mov    0x8(%rdi),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
call   10e0 <freeaddrinfo@plt>
mov    (%r15),%rdi
mov    (%r12),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,0xc(%rsp)
cmp    $0xffffffff,%eax
jne    13dd <main+0x20d>
lea    0xc3f(%rip),%rdi
call   10b0 <err_msg@plt>
mov    0xc(%rsp),%eax
mov    0x2c04(%rip),%rcx
mov    (%rcx),%esi
mov    0x2bcb(%rip),%rcx
mov    (%rcx),%edx
lea    0x10(%rsp),%rcx
mov    %eax,%edi
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1412 <main+0x242>
lea    0xc1c(%rip),%rdi
call   10b0 <err_msg@plt>
lea    0xc(%rsp),%rdi
lea    0x20(%rsp),%rsi
lea    0x90(%rsp),%rdx
call   1070 <get_http_ipv4@plt>
mov    0xc(%rsp),%edi
mov    0x2ba4(%rip),%rax
mov    (%rax),%esi
call   1040 <shutdown@plt>
mov    0x2b66(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i64, i32*, %struct.addrinfo*, i32*, i64, i64, i32, i64 }
%struct.sockaddr_in = type { i32, i64, i8* }
%struct.sockaddr_in6 = type { i64, i8*, i32 }
%struct.timeval = type { i32, i32 }
@AF_INET = global i64 0
@AF_UNSPEC = global i64 0
@SOCK_STREAM = global i32 0
@AF_INET6 = global i64 0
@.str = [19 x i8] c"GET / HTTP/1.1\0D\0A\0D\0A\00"
@.str.1 = [22 x i8] c"Error creating socket\00"
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@.str.2 = [13 x i8] c"setsockopt()\00"
@SHUT_WR = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [2000 x i8]
%11 = alloca %struct.addrinfo
%12 = alloca %struct.addrinfo*
%13 = alloca %struct.sockaddr_in
%14 = alloca %struct.sockaddr_in*
%15 = alloca %struct.sockaddr_in6
%16 = alloca %struct.timeval
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %9
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 0
store i32 3, i32* %17
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 1
store i32 500000, i32* %18
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 2
br i1 %20, label %21, label %27
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
%25 = call i32 @usage(i8* %24)
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %2
%28 = load i64, i64* @AF_INET
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 7
store i64 %28, i64* %29
%30 = load i64, i64* @AF_UNSPEC
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 0
store i64 %30, i64* %31
%32 = load i32, i32* @SOCK_STREAM
%33 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 6
store i32 %32, i32* %33
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 5
store i64 0, i64* %34
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 4
store i64 0, i64* %35
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 3
store i32* null, i32** %36
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 1
store i32* null, i32** %37
%38 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 2
store %struct.addrinfo* null, %struct.addrinfo** %38
%39 = load i64, i64* @AF_INET
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 0
%44 = call i32 @inet_pton(i64 %39, i8* %42, i32* %43)
store i32 %44, i32* %7
%45 = load i64, i64* @AF_INET6
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load i8*, i8** %47
%49 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %15, i32 0, i32 2
%50 = call i32 @inet_pton(i64 %45, i8* %48, i32* %49)
store i32 %50, i32* %8
%51 = call i8* @htons(i32 80)
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 2
store i8* %51, i8** %52
%53 = load i64, i64* @AF_INET
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 1
store i64 %53, i64* %54
%55 = call i8* @htons(i32 80)
%56 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %15, i32 0, i32 1
store i8* %55, i8** %56
%57 = load i64, i64* @AF_INET6
%58 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %15, i32 0, i32 0
store i64 %57, i64* %58
%59 = getelementptr inbounds [2000 x i8], [2000 x i8]* %10, i64 0, i64 0
%60 = call i32 @sprintf(i8* %59, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %61
61: ; preds = %144, %27
%62 = load i32, i32* %9
%63 = icmp eq i32 %62, 1
br i1 %63, label %64, label %145
64: ; preds = %61
%65 = load i32, i32* %7
%66 = icmp sgt i32 %65, 0
br i1 %66, label %67, label %85
67: ; preds = %64
%68 = load i64, i64* @AF_INET
%69 = load i32, i32* @SOCK_STREAM
%70 = call i32 @socket(i64 %68, i32 %69, i32 0)
store i32 %70, i32* %6
%71 = icmp eq i32 %70, -1
br i1 %71, label %72, label %74
72: ; preds = %67
%73 = call i32 @err_msg(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %74
74: ; preds = %72, %67
%75 = load i32, i32* %6
%76 = load i32, i32* @SOL_SOCKET
%77 = load i32, i32* @SO_RCVTIMEO
%78 = call i32 @setsockopt(i32 %75, i32 %76, i32 %77, %struct.timeval* %16, i32 8)
%79 = icmp eq i32 %78, -1
br i1 %79, label %80, label %82
80: ; preds = %74
%81 = call i32 @err_msg(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %82
82: ; preds = %80, %74
store i32 0, i32* %9
%83 = getelementptr inbounds [2000 x i8], [2000 x i8]* %10, i64 0, i64 0
%84 = call i32 @get_http_ipv4(i32* %6, %struct.sockaddr_in* %13, i8* %83)
br label %144
85: ; preds = %64
%86 = load i32, i32* %8
%87 = icmp sgt i32 %86, 0
br i1 %87, label %88, label %106
88: ; preds = %85
%89 = load i64, i64* @AF_INET6
%90 = load i32, i32* @SOCK_STREAM
%91 = call i32 @socket(i64 %89, i32 %90, i32 0)
store i32 %91, i32* %6
%92 = icmp eq i32 %91, -1
br i1 %92, label %93, label %95
93: ; preds = %88
%94 = call i32 @err_msg(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %95
95: ; preds = %93, %88
%96 = load i32, i32* %6
%97 = load i32, i32* @SOL_SOCKET
%98 = load i32, i32* @SO_RCVTIMEO
%99 = call i32 @setsockopt(i32 %96, i32 %97, i32 %98, %struct.timeval* %16, i32 8)
%100 = icmp eq i32 %99, -1
br i1 %100, label %101, label %103
101: ; preds = %95
%102 = call i32 @err_msg(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %103
103: ; preds = %101, %95
store i32 0, i32* %9
%104 = getelementptr inbounds [2000 x i8], [2000 x i8]* %10, i64 0, i64 0
%105 = call i32 @get_http_ipv6(i32* %6, %struct.sockaddr_in6* %15, i8* %104)
br label %143
106: ; preds = %85
%107 = load i8**, i8*** %5
%108 = getelementptr inbounds i8*, i8** %107, i64 1
%109 = load i8*, i8** %108
%110 = call i64 @getaddrinfo(i8* %109, i32 0, %struct.addrinfo* %11, %struct.addrinfo** %12)
%111 = icmp ne i64 %110, 0
br i1 %111, label %112, label %116
112: ; preds = %106
%113 = load i32, i32* %9
%114 = call i8* @gai_strerror(i32 %113)
%115 = call i32 @err_msg(i8* %114)
br label %116
116: ; preds = %112, %106
store i32 1, i32* %7
br label %117
117: ; preds = %136, %116
%118 = load %struct.addrinfo*, %struct.addrinfo** %12
%119 = icmp ne %struct.addrinfo* %118, null
br i1 %119, label %120, label %140
120: ; preds = %117
%121 = load %struct.addrinfo*, %struct.addrinfo** %12
%122 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %121, i32 0, i32 0
%123 = load i64, i64* %122
%124 = load i64, i64* @AF_INET
%125 = icmp eq i64 %123, %124
br i1 %125, label %126, label %135
126: ; preds = %120
%127 = load %struct.addrinfo*, %struct.addrinfo** %12
%128 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %127, i32 0, i32 1
%129 = load i32*, i32** %128
%130 = bitcast i32* %129 to %struct.sockaddr_in*
store %struct.sockaddr_in* %130, %struct.sockaddr_in** %14
%131 = load %struct.sockaddr_in*, %struct.sockaddr_in** %14
%132 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %131, i32 0, i32 0
%133 = load i32, i32* %132
%134 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 0
store i32 %133, i32* %134
br label %140
135: ; preds = %120
br label %136
136: ; preds = %135
%137 = load %struct.addrinfo*, %struct.addrinfo** %12
%138 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %137, i32 0, i32 2
%139 = load %struct.addrinfo*, %struct.addrinfo** %138
store %struct.addrinfo* %139, %struct.addrinfo** %12
br label %117
140: ; preds = %126, %117
%141 = load %struct.addrinfo*, %struct.addrinfo** %12
%142 = call i32 @freeaddrinfo(%struct.addrinfo* %141)
br label %143
143: ; preds = %140, %103
br label %144
144: ; preds = %143, %82
br label %61
145: ; preds = %61
%146 = load i32, i32* %6
%147 = load i32, i32* @SHUT_WR
%148 = call i32 @shutdown(i32 %146, i32 %147)
%149 = load i32, i32* @EXIT_SUCCESS
%150 = call i32 @exit(i32 %149)
unreachable
}

LLVM IR (-O2):
%struct.addrinfo = type { i64, i32*, %struct.addrinfo*, i32*, i64, i64, i32, i64 }
%struct.sockaddr_in = type { i32, i64, i8* }
%struct.sockaddr_in6 = type { i64, i8*, i32 }
%struct.timeval = type { i32, i32 }
@AF_INET = global i64 0
@AF_UNSPEC = global i64 0
@SOCK_STREAM = global i32 0
@AF_INET6 = global i64 0
@.str = [19 x i8] c"GET / HTTP/1.1\0D\0A\0D\0A\00"
@.str.1 = [22 x i8] c"Error creating socket\00"
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@.str.2 = [13 x i8] c"setsockopt()\00"
@SHUT_WR = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [2000 x i8]
%5 = alloca %struct.addrinfo
%6 = alloca %struct.addrinfo*
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.sockaddr_in6
%9 = alloca %struct.timeval
%10 = bitcast i32* %3 to i8*
%11 = getelementptr inbounds [2000 x i8], [2000 x i8]* %4, i64 0, i64 0
%12 = bitcast %struct.addrinfo* %5 to i8*
%13 = bitcast %struct.addrinfo** %6 to i8*
%14 = bitcast %struct.sockaddr_in* %7 to i8*
%15 = bitcast %struct.sockaddr_in6* %8 to i8*
%16 = bitcast %struct.timeval* %9 to i8*
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i64 0, i32 0
store i32 3, i32* %17
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i64 0, i32 1
store i32 500000, i32* %18
%19 = icmp eq i32 %0, 2
br i1 %19, label %24, label %20
20: ; preds = %2
%21 = load i8*, i8** %1
%22 = tail call i32 @usage(i8* %21)
%23 = tail call i32 @exit(i32 0)
unreachable
24: ; preds = %2
%25 = load i64, i64* @AF_INET
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 7
store i64 %25, i64* %26
%27 = load i64, i64* @AF_UNSPEC
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 0
store i64 %27, i64* %28
%29 = load i32, i32* @SOCK_STREAM
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 6
store i32 %29, i32* %30
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 1
%32 = getelementptr inbounds i8*, i8** %1, i64 1
%33 = bitcast i32** %31 to i8*
%34 = load i8*, i8** %32
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 0
%36 = call i32 @inet_pton(i64 %25, i8* %34, i32* %35)
%37 = load i64, i64* @AF_INET6
%38 = load i8*, i8** %32
%39 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %8, i64 0, i32 2
%40 = call i32 @inet_pton(i64 %37, i8* %38, i32* %39)
%41 = call i8* @htons(i32 80)
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 2
store i8* %41, i8** %42
%43 = load i64, i64* @AF_INET
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 1
store i64 %43, i64* %44
%45 = call i8* @htons(i32 80)
%46 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %8, i64 0, i32 1
store i8* %45, i8** %46
%47 = load i64, i64* @AF_INET6
%48 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %8, i64 0, i32 0
store i64 %47, i64* %48
%49 = icmp sgt i32 %36, 0
br i1 %49, label %50, label %68
50: ; preds = %115, %24
%51 = load i64, i64* @AF_INET
%52 = load i32, i32* @SOCK_STREAM
%53 = call i32 @socket(i64 %51, i32 %52, i32 0)
store i32 %53, i32* %3
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %58
55: ; preds = %50
%56 = call i32 @err_msg(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%57 = load i32, i32* %3
br label %58
58: ; preds = %55, %50
%59 = phi i32 [ %57, %55 ], [ %53, %50 ]
%60 = load i32, i32* @SOL_SOCKET
%61 = load i32, i32* @SO_RCVTIMEO
%62 = call i32 @setsockopt(i32 %59, i32 %60, i32 %61, %struct.timeval* %9, i32 8)
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %66
64: ; preds = %58
%65 = call i32 @err_msg(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %66
66: ; preds = %64, %58
%67 = call i32 @get_http_ipv4(i32* %3, %struct.sockaddr_in* %7, i8* %11)
br label %118
68: ; preds = %24
%69 = icmp sgt i32 %40, 0
br i1 %69, label %70, label %88
70: ; preds = %68
%71 = load i64, i64* @AF_INET6
%72 = load i32, i32* @SOCK_STREAM
%73 = call i32 @socket(i64 %71, i32 %72, i32 0)
store i32 %73, i32* %3
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %78
75: ; preds = %70
%76 = call i32 @err_msg(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%77 = load i32, i32* %3
br label %78
78: ; preds = %75, %70
%79 = phi i32 [ %77, %75 ], [ %73, %70 ]
%80 = load i32, i32* @SOL_SOCKET
%81 = load i32, i32* @SO_RCVTIMEO
%82 = call i32 @setsockopt(i32 %79, i32 %80, i32 %81, %struct.timeval* %9, i32 8)
%83 = icmp eq i32 %82, -1
br i1 %83, label %84, label %86
84: ; preds = %78
%85 = call i32 @err_msg(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %86
86: ; preds = %84, %78
%87 = call i32 @get_http_ipv6(i32* %3, %struct.sockaddr_in6* %8, i8* %11)
br label %118
88: ; preds = %68
%89 = load i8*, i8** %32
%90 = call i64 @getaddrinfo(i8* %89, i32 0, %struct.addrinfo* %5, %struct.addrinfo** %6)
%91 = icmp eq i64 %90, 0
br i1 %91, label %95, label %92
92: ; preds = %88
%93 = call i8* @gai_strerror(i32 1)
%94 = call i32 @err_msg(i8* %93)
br label %95
95: ; preds = %92, %88
%96 = load %struct.addrinfo*, %struct.addrinfo** %6
%97 = icmp eq %struct.addrinfo* %96, null
br i1 %97, label %115, label %98
98: ; preds = %95
%99 = load i64, i64* @AF_INET
br label %100
100: ; preds = %98, %111
%101 = phi %struct.addrinfo* [ %96, %98 ], [ %113, %111 ]
%102 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %101, i64 0, i32 0
%103 = load i64, i64* %102
%104 = icmp eq i64 %103, %99
br i1 %104, label %105, label %111
105: ; preds = %100
%106 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %101, i64 0, i32 1
%107 = bitcast i32** %106 to %struct.sockaddr_in**
%108 = load %struct.sockaddr_in*, %struct.sockaddr_in** %107
%109 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %108, i64 0, i32 0
%110 = load i32, i32* %109
store i32 %110, i32* %35
br label %115
111: ; preds = %100
%112 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %101, i64 0, i32 2
%113 = load %struct.addrinfo*, %struct.addrinfo** %112
store %struct.addrinfo* %113, %struct.addrinfo** %6
%114 = icmp eq %struct.addrinfo* %113, null
br i1 %114, label %115, label %100
115: ; preds = %111, %105, %95
%116 = phi %struct.addrinfo* [ %101, %105 ], [ null, %95 ], [ null, %111 ]
%117 = call i32 @freeaddrinfo(%struct.addrinfo* %116)
br label %50
118: ; preds = %86, %66
%119 = load i32, i32* %3
%120 = load i32, i32* @SHUT_WR
%121 = call i32 @shutdown(i32 %119, i32 %120)
%122 = load i32, i32* @EXIT_SUCCESS
%123 = call i32 @exit(i32 %122)
unreachable
}