#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*/ uint16_t;
struct timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
struct in_addr {
  int dummy;
};
struct sockaddr_in {
  struct in_addr sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  scalar_t__ h_addr;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ so_error;
typedef int /*<<< orphan*/ server;
typedef int /*<<< orphan*/ netio_tv;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EINPROGRESS;
int /*<<< orphan*/ FATAL_ERROR(char *, ...);
int /*<<< orphan*/ FD_SET(unsigned int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ LOG(char *, ...);
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_ERROR;
int /*<<< orphan*/ SO_RCVTIMEO;
int /*<<< orphan*/ connect(int, struct sockaddr *, int);
int errno;
int /*<<< orphan*/ free(char *);
struct hostent *gethostbyname(char const *);
int /*<<< orphan*/ getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
scalar_t__ malloc(size_t const);
int /*<<< orphan*/ memcpy(char *, char const *, size_t const);
scalar_t__ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, struct timeval *);
int send(int, char const *, size_t const, int /*<<< orphan*/);
int /*<<< orphan*/ set_sock_blocking_mode(int);
int /*<<< orphan*/ set_sock_nonblocking_mode(int);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int);
int main(int argc, char *argv[]) {
  const char *h = "localhost";
  const int p = 8080;
  struct sockaddr_in server;
  struct hostent *hostinfo = NULL;
  LOG("Running gethosbyname() on %s", h);
  hostinfo = gethostbyname(h);
  if (hostinfo == NULL) {
    FATAL_ERROR("Unknown host %s, %i: %s", h, errno, strerror(errno));
    return 5;
  }
  int sock;
  if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == (-1)) {
    FATAL_ERROR("Socket creation error, %i: %s", errno, strerror(errno));
  }
  server.sin_family = AF_INET;
  server.sin_port = htons((uint16_t)p);
  server.sin_addr = *(struct in_addr *)hostinfo->h_addr;
  set_sock_nonblocking_mode(sock);
  int conn_to = 5;
  int netio_to = 10;
  LOG("Connecting to %s:%i", h, p);
  if (!connect(sock, (struct sockaddr *)&server, sizeof(server)) ||
      errno != EINPROGRESS) {
    FATAL_ERROR("Connection error (%s:%d), %i: %s", h, p, errno,
                strerror(errno));
  }
  fd_set fdset;
  FD_ZERO(&fdset);
  FD_SET((unsigned int)(sock), &fdset);
  struct timeval conn_tv;
  conn_tv.tv_sec = conn_to;
  conn_tv.tv_usec = 0;
  if (select(sock + 1, NULL, &fdset, NULL, &conn_tv) <= 0) {
    FATAL_ERROR("Connection timeout (%s:%d), %i: %s", h, p, errno,
                strerror(errno));
  }
  int so_error;
  socklen_t len = sizeof(so_error);
  getsockopt(sock, SOL_SOCKET, SO_ERROR, &so_error, &len);
  if (so_error != 0) {
    FATAL_ERROR("Connection error (%s:%d), %i: %s", h, p, so_error,
                strerror(so_error));
  }
  set_sock_blocking_mode(sock);
  struct timeval netio_tv;
  netio_tv.tv_sec = netio_to;
  netio_tv.tv_usec = 0;
  if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&netio_tv,
                 sizeof(netio_tv))) {
    FATAL_ERROR("Error setting network I/O timeout");
  }
  LOG("Connected to %s:%i", h, p);
  const char buffer[] = "GET / HTTP/1.1\015\012";
  const size_t buffer_len = sizeof(buffer);
  char *str = (char *)malloc(buffer_len + 1);
  memcpy(str, buffer, buffer_len);
  str[buffer_len] = '\0';
  LOG("Sending <%s> into the connection", str);
  free(str);
  return send(sock, buffer, buffer_len, 0);
  LOG("Now quitting, leaving connection as is");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xdc0(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x1f90,-0x1c(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   10f0 <LOG@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <gethostbyname@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12ce <main+0xae>
mov    -0x18(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    0x2d21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x94(%rbp)
mov    0x2d12(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0xa0(%rbp),%rsi
mov    -0x94(%rbp),%edx
mov    %eax,%ecx
lea    0xd6c(%rip),%rdi
mov    $0x0,%al
call   1130 <FATAL_ERROR@plt>
movl   $0x5,-0x4(%rbp)
jmp    15fb <main+0x3db>
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
mov    0x2cda(%rip),%rax
mov    (%rax),%esi
mov    0x2ce9(%rip),%rax
mov    (%rax),%edx
call   1140 <socket@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
jne    132d <main+0x10d>
mov    0x2caf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa4(%rbp)
mov    0x2ca0(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0xa4(%rbp),%esi
mov    %eax,%edx
lea    0xd19(%rip),%rdi
mov    $0x0,%al
call   1130 <FATAL_ERROR@plt>
mov    0x2cac(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    $0x1f90,%edi
call   1050 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x34(%rbp),%edi
call   1070 <set_sock_nonblocking_mode@plt>
movl   $0x5,-0x38(%rbp)
movl   $0xa,-0x3c(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xcea(%rip),%rdi
mov    $0x1f90,%edx
mov    $0x0,%al
call   10f0 <LOG@plt>
mov    -0x34(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   1100 <connect@plt>
cmp    $0x0,%eax
je     13b1 <main+0x191>
mov    0x2c10(%rip),%rax
mov    (%rax),%eax
mov    0x2c2f(%rip),%rcx
cmp    (%rcx),%eax
je     13fc <main+0x1dc>
mov    -0x18(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    0x2bed(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa8(%rbp)
mov    0x2bde(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0xb0(%rbp),%rsi
mov    -0xa8(%rbp),%ecx
mov    %eax,%r8d
lea    0xc81(%rip),%rdi
mov    $0x1f90,%edx
mov    $0x0,%al
call   1130 <FATAL_ERROR@plt>
lea    -0x40(%rbp),%rdi
call   10c0 <FD_ZERO@plt>
mov    -0x34(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   1120 <FD_SET@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x50(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x34(%rbp),%edi
add    $0x1,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x40(%rbp),%rdx
lea    -0x50(%rbp),%r8
mov    %rcx,%rsi
call   10d0 <select@plt>
cmp    $0x0,%rax
jg     148e <main+0x26e>
mov    -0x18(%rbp),%rax
mov    %rax,-0xc0(%rbp)
mov    0x2b5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xb4(%rbp)
mov    0x2b4c(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0xc0(%rbp),%rsi
mov    -0xb4(%rbp),%ecx
mov    %eax,%r8d
lea    0xc10(%rip),%rdi
mov    $0x1f90,%edx
mov    $0x0,%al
call   1130 <FATAL_ERROR@plt>
movl   $0x4,-0x58(%rbp)
mov    -0x34(%rbp),%edi
mov    0x2b49(%rip),%rax
mov    (%rax),%esi
mov    0x2b00(%rip),%rax
mov    (%rax),%edx
lea    -0x54(%rbp),%rcx
lea    -0x58(%rbp),%r8
call   1080 <getsockopt@plt>
cmpl   $0x0,-0x54(%rbp)
je     1500 <main+0x2e0>
mov    -0x18(%rbp),%rax
mov    %rax,-0xd0(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0xc4(%rbp)
mov    -0x54(%rbp),%edi
call   1110 <strerror@plt>
mov    -0xd0(%rbp),%rsi
mov    -0xc4(%rbp),%ecx
mov    %eax,%r8d
lea    0xb7d(%rip),%rdi
mov    $0x1f90,%edx
mov    $0x0,%al
call   1130 <FATAL_ERROR@plt>
mov    -0x34(%rbp),%edi
call   1090 <set_sock_blocking_mode@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x68(%rbp)
movq   $0x0,-0x60(%rbp)
mov    -0x34(%rbp),%edi
mov    0x2ac8(%rip),%rax
mov    (%rax),%esi
mov    0x2a97(%rip),%rax
mov    (%rax),%edx
lea    -0x68(%rbp),%rcx
mov    $0x10,%r8d
call   1040 <setsockopt@plt>
cmp    $0x0,%rax
je     1552 <main+0x332>
lea    0xb6a(%rip),%rdi
mov    $0x0,%al
call   1130 <FATAL_ERROR@plt>
mov    -0x18(%rbp),%rsi
lea    0xb7a(%rip),%rdi
mov    $0x1f90,%edx
mov    $0x0,%al
call   10f0 <LOG@plt>
mov    0xba0(%rip),%rax
mov    %rax,-0x80(%rbp)
mov    0xb9d(%rip),%rax
mov    %rax,-0x78(%rbp)
mov    0xb9b(%rip),%al
mov    %al,-0x70(%rbp)
movq   $0x11,-0x88(%rbp)
mov    $0x12,%edi
call   10e0 <malloc@plt>
mov    %rax,-0x90(%rbp)
mov    -0x90(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    $0x11,%edx
call   10b0 <memcpy@plt>
mov    -0x90(%rbp),%rax
movb   $0x0,0x11(%rax)
mov    -0x90(%rbp),%rsi
lea    0xb18(%rip),%rdi
mov    $0x0,%al
call   10f0 <LOG@plt>
mov    -0x90(%rbp),%rdi
call   1030 <free@plt>
mov    -0x34(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x11,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
lea    0xdd9(%rip),%rdi
lea    0xdc8(%rip),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   10f0 <LOG@plt>
mov    %rbx,%rdi
call   10a0 <gethostbyname@plt>
test   %rax,%rax
je     14be <main+0x29e>
mov    %rax,%rbx
mov    0x2d83(%rip),%r15
mov    (%r15),%edi
mov    0x2d51(%rip),%rax
mov    (%rax),%esi
mov    0x2d60(%rip),%rax
mov    (%rax),%edx
call   1140 <socket@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    12a3 <main+0x83>
mov    0x2d2b(%rip),%rax
mov    (%rax),%r14d
mov    %r14d,%edi
call   1110 <strerror@plt>
lea    0xda8(%rip),%rdi
mov    %r14d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1130 <FATAL_ERROR@plt>
mov    (%r15),%eax
mov    %eax,0x18(%rsp)
mov    $0x1f90,%edi
call   1050 <htons@plt>
mov    %eax,0x14(%rsp)
mov    (%rbx),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    %ebp,%edi
call   1070 <set_sock_nonblocking_mode@plt>
lea    0xd8e(%rip),%rdi
lea    0xd2a(%rip),%rsi
mov    $0x1f90,%edx
xor    %eax,%eax
call   10f0 <LOG@plt>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   1100 <connect@plt>
mov    0x2cb6(%rip),%r14
mov    (%r14),%ebx
test   %eax,%eax
je     130c <main+0xec>
mov    0x2cd0(%rip),%rax
cmp    (%rax),%ebx
je     1332 <main+0x112>
mov    %ebx,%edi
call   1110 <strerror@plt>
lea    0xd57(%rip),%rdi
lea    0xcdf(%rip),%rsi
mov    $0x1f90,%edx
mov    %ebx,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1130 <FATAL_ERROR@plt>
lea    0x1c(%rsp),%rbx
mov    %rbx,%rdi
call   10c0 <FD_ZERO@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1120 <FD_SET@plt>
movl   $0x5,0x30(%rsp)
movq   $0x0,0x38(%rsp)
mov    %ebp,%edi
add    $0x1,%edi
lea    0x30(%rsp),%r8
xor    %esi,%esi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   10d0 <select@plt>
test   %rax,%rax
jg     139e <main+0x17e>
mov    (%r14),%ebx
mov    %ebx,%edi
call   1110 <strerror@plt>
lea    0xd0c(%rip),%rdi
lea    0xc73(%rip),%rsi
mov    $0x1f90,%edx
mov    %ebx,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1130 <FATAL_ERROR@plt>
movl   $0x4,0x8(%rsp)
mov    0x2c3b(%rip),%r14
mov    (%r14),%esi
mov    0x2bf1(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
lea    0x8(%rsp),%r8
mov    %ebp,%edi
call   1080 <getsockopt@plt>
mov    0xc(%rsp),%ebx
test   %ebx,%ebx
je     13f8 <main+0x1d8>
mov    %ebx,%edi
call   1110 <strerror@plt>
lea    0xc91(%rip),%rdi
lea    0xc19(%rip),%rsi
mov    $0x1f90,%edx
mov    %ebx,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1130 <FATAL_ERROR@plt>
mov    %ebp,%edi
call   1090 <set_sock_blocking_mode@plt>
movl   $0xa,0x20(%rsp)
movq   $0x0,0x28(%rsp)
mov    (%r14),%esi
mov    0x2ba6(%rip),%rax
mov    (%rax),%edx
lea    0x20(%rsp),%rcx
mov    %ebp,%edi
mov    $0x10,%r8d
call   1040 <setsockopt@plt>
test   %rax,%rax
je     1441 <main+0x221>
lea    0xc7b(%rip),%rdi
xor    %eax,%eax
call   1130 <FATAL_ERROR@plt>
lea    0xc8f(%rip),%rdi
lea    0xbb1(%rip),%rsi
mov    $0x1f90,%edx
xor    %eax,%eax
call   10f0 <LOG@plt>
movaps 0xcae(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movb   $0x0,0x50(%rsp)
mov    $0x12,%edi
call   10e0 <malloc@plt>
mov    %rax,%rbx
lea    0x40(%rsp),%r14
mov    $0x11,%edx
mov    %rax,%rdi
mov    %r14,%rsi
call   10b0 <memcpy@plt>
movb   $0x0,0x11(%rbx)
lea    0xc51(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10f0 <LOG@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x11,%edx
mov    %ebp,%edi
mov    %r14,%rsi
xor    %ecx,%ecx
call   1060 <send@plt>
jmp    14ec <main+0x2cc>
mov    0x2aeb(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1110 <strerror@plt>
lea    0xb52(%rip),%rdi
lea    0xb24(%rip),%rsi
mov    %ebx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1130 <FATAL_ERROR@plt>
mov    $0x5,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
%struct.timeval = type { i32, i64 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"localhost\00"
@.str.1 = [29 x i8] c"Running gethosbyname() on %s\00"
@.str.2 = [24 x i8] c"Unknown host %s, %i: %s\00"
@errno = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.3 = [30 x i8] c"Socket creation error, %i: %s\00"
@.str.4 = [20 x i8] c"Connecting to %s:%i\00"
@EINPROGRESS = global i32 0
@.str.5 = [33 x i8] c"Connection error (%s:%d), %i: %s\00"
@.str.6 = [35 x i8] c"Connection timeout (%s:%d), %i: %s\00"
@SOL_SOCKET = global i32 0
@SO_ERROR = global i32 0
@SO_RCVTIMEO = global i32 0
@.str.7 = [34 x i8] c"Error setting network I/O timeout\00"
@.str.8 = [19 x i8] c"Connected to %s:%i\00"
@__const.main.buffer = [17 x i8] c"GET / HTTP/1.1\0D\0A\00"
@.str.9 = [33 x i8] c"Sending <%s> into the connection\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca %struct.hostent*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca %struct.timeval
%15 = alloca i32
%16 = alloca i32
%17 = alloca %struct.timeval
%18 = alloca [17 x i8]
%19 = alloca i64
%20 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %6
store i32 8080, i32* %7
store %struct.hostent* null, %struct.hostent** %9
%21 = load i8*, i8** %6
%22 = call i32 (i8*, ...) @LOG(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %6
%24 = call %struct.hostent* @gethostbyname(i8* %23)
store %struct.hostent* %24, %struct.hostent** %9
%25 = load %struct.hostent*, %struct.hostent** %9
%26 = icmp eq %struct.hostent* %25, null
br i1 %26, label %27, label %33
27: ; preds = %2
%28 = load i8*, i8** %6
%29 = load i32, i32* @errno
%30 = load i32, i32* @errno
%31 = call i32 @strerror(i32 %30)
%32 = call i32 (i8*, ...) @FATAL_ERROR(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %28, i32 %29, i32 %31)
store i32 5, i32* %3
br label %136
33: ; preds = %2
%34 = load i32, i32* @AF_INET
%35 = load i32, i32* @SOCK_STREAM
%36 = load i32, i32* @IPPROTO_TCP
%37 = call i32 @socket(i32 %34, i32 %35, i32 %36)
store i32 %37, i32* %10
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %44
39: ; preds = %33
%40 = load i32, i32* @errno
%41 = load i32, i32* @errno
%42 = call i32 @strerror(i32 %41)
%43 = call i32 (i8*, ...) @FATAL_ERROR(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %40, i32 %42)
br label %44
44: ; preds = %39, %33
%45 = load i32, i32* @AF_INET
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %45, i32* %46
%47 = call i32 @htons(i32 8080)
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %47, i32* %48
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%50 = load %struct.hostent*, %struct.hostent** %9
%51 = getelementptr inbounds %struct.hostent, %struct.hostent* %50, i32 0, i32 0
%52 = load i64, i64* %51
%53 = inttoptr i64 %52 to %struct.in_addr*
%54 = bitcast %struct.in_addr* %49 to i8*
%55 = bitcast %struct.in_addr* %53 to i8*
%56 = load i32, i32* %10
%57 = call i32 @set_sock_nonblocking_mode(i32 %56)
store i32 5, i32* %11
store i32 10, i32* %12
%58 = load i8*, i8** %6
%59 = call i32 (i8*, ...) @LOG(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %58, i32 8080)
%60 = load i32, i32* %10
%61 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%62 = call i32 @connect(i32 %60, %struct.sockaddr* %61, i32 12)
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %68
64: ; preds = %44
%65 = load i32, i32* @errno
%66 = load i32, i32* @EINPROGRESS
%67 = icmp ne i32 %65, %66
br i1 %67, label %68, label %74
68: ; preds = %64, %44
%69 = load i8*, i8** %6
%70 = load i32, i32* @errno
%71 = load i32, i32* @errno
%72 = call i32 @strerror(i32 %71)
%73 = call i32 (i8*, ...) @FATAL_ERROR(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* %69, i32 8080, i32 %70, i32 %72)
br label %74
74: ; preds = %68, %64
%75 = call i32 @FD_ZERO(i32* %13)
%76 = load i32, i32* %10
%77 = call i32 @FD_SET(i32 %76, i32* %13)
%78 = load i32, i32* %11
%79 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
store i32 %78, i32* %79
%80 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 1
store i64 0, i64* %80
%81 = load i32, i32* %10
%82 = add nsw i32 %81, 1
%83 = call i64 @select(i32 %82, i32* null, i32* %13, i32* null, %struct.timeval* %14)
%84 = icmp sle i64 %83, 0
br i1 %84, label %85, label %91
85: ; preds = %74
%86 = load i8*, i8** %6
%87 = load i32, i32* @errno
%88 = load i32, i32* @errno
%89 = call i32 @strerror(i32 %88)
%90 = call i32 (i8*, ...) @FATAL_ERROR(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i8* %86, i32 8080, i32 %87, i32 %89)
br label %91
91: ; preds = %85, %74
store i32 4, i32* %16
%92 = load i32, i32* %10
%93 = load i32, i32* @SOL_SOCKET
%94 = load i32, i32* @SO_ERROR
%95 = call i32 @getsockopt(i32 %92, i32 %93, i32 %94, i32* %15, i32* %16)
%96 = load i32, i32* %15
%97 = icmp ne i32 %96, 0
br i1 %97, label %98, label %104
98: ; preds = %91
%99 = load i8*, i8** %6
%100 = load i32, i32* %15
%101 = load i32, i32* %15
%102 = call i32 @strerror(i32 %101)
%103 = call i32 (i8*, ...) @FATAL_ERROR(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* %99, i32 8080, i32 %100, i32 %102)
br label %104
104: ; preds = %98, %91
%105 = load i32, i32* %10
%106 = call i32 @set_sock_blocking_mode(i32 %105)
%107 = load i32, i32* %12
%108 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 0
store i32 %107, i32* %108
%109 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 1
store i64 0, i64* %109
%110 = load i32, i32* %10
%111 = load i32, i32* @SOL_SOCKET
%112 = load i32, i32* @SO_RCVTIMEO
%113 = bitcast %struct.timeval* %17 to i8*
%114 = call i64 @setsockopt(i32 %110, i32 %111, i32 %112, i8* %113, i32 16)
%115 = icmp ne i64 %114, 0
br i1 %115, label %116, label %118
116: ; preds = %104
%117 = call i32 (i8*, ...) @FATAL_ERROR(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0))
br label %118
118: ; preds = %116, %104
%119 = load i8*, i8** %6
%120 = call i32 (i8*, ...) @LOG(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* %119, i32 8080)
%121 = bitcast [17 x i8]* %18 to i8*
store i64 17, i64* %19
%122 = call i64 @malloc(i64 18)
%123 = inttoptr i64 %122 to i8*
store i8* %123, i8** %20
%124 = load i8*, i8** %20
%125 = getelementptr inbounds [17 x i8], [17 x i8]* %18, i64 0, i64 0
%126 = call i32 @memcpy(i8* %124, i8* %125, i64 17)
%127 = load i8*, i8** %20
%128 = getelementptr inbounds i8, i8* %127, i64 17
store i8 0, i8* %128
%129 = load i8*, i8** %20
%130 = call i32 (i8*, ...) @LOG(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.9, i64 0, i64 0), i8* %129)
%131 = load i8*, i8** %20
%132 = call i32 @free(i8* %131)
%133 = load i32, i32* %10
%134 = getelementptr inbounds [17 x i8], [17 x i8]* %18, i64 0, i64 0
%135 = call i32 @send(i32 %133, i8* %134, i64 17, i32 0)
store i32 %135, i32* %3
br label %136
136: ; preds = %118, %27
%137 = load i32, i32* %3
ret i32 %137
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.timeval = type { i32, i64 }
%struct.hostent = type { i64 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"localhost\00"
@.str.1 = [29 x i8] c"Running gethosbyname() on %s\00"
@.str.2 = [24 x i8] c"Unknown host %s, %i: %s\00"
@errno = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.3 = [30 x i8] c"Socket creation error, %i: %s\00"
@.str.4 = [20 x i8] c"Connecting to %s:%i\00"
@EINPROGRESS = global i32 0
@.str.5 = [33 x i8] c"Connection error (%s:%d), %i: %s\00"
@.str.6 = [35 x i8] c"Connection timeout (%s:%d), %i: %s\00"
@SOL_SOCKET = global i32 0
@SO_ERROR = global i32 0
@SO_RCVTIMEO = global i32 0
@.str.7 = [34 x i8] c"Error setting network I/O timeout\00"
@.str.8 = [19 x i8] c"Connected to %s:%i\00"
@__const.main.buffer = [17 x i8] c"GET / HTTP/1.1\0D\0A\00"
@.str.9 = [33 x i8] c"Sending <%s> into the connection\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca %struct.timeval
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.timeval
%9 = alloca [17 x i8]
%10 = bitcast %struct.sockaddr_in* %3 to i8*
%11 = tail call i32 (i8*, ...) @LOG(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%12 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq %struct.hostent* %12, null
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @errno
%16 = tail call i32 @strerror(i32 %15)
%17 = tail call i32 (i8*, ...) @FATAL_ERROR(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %16)
br label %96
18: ; preds = %2
%19 = load i32, i32* @AF_INET
%20 = load i32, i32* @SOCK_STREAM
%21 = load i32, i32* @IPPROTO_TCP
%22 = tail call i32 @socket(i32 %19, i32 %20, i32 %21)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %28
24: ; preds = %18
%25 = load i32, i32* @errno
%26 = tail call i32 @strerror(i32 %25)
%27 = tail call i32 (i8*, ...) @FATAL_ERROR(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %25, i32 %26)
br label %28
28: ; preds = %24, %18
%29 = load i32, i32* @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %29, i32* %30
%31 = tail call i32 @htons(i32 8080)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %31, i32* %32
%33 = getelementptr inbounds %struct.hostent, %struct.hostent* %12, i64 0, i32 0
%34 = load i64, i64* %33
%35 = inttoptr i64 %34 to i32*
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
%37 = load i32, i32* %35
store i32 %37, i32* %36
%38 = tail call i32 @set_sock_nonblocking_mode(i32 %22)
%39 = tail call i32 (i8*, ...) @LOG(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 8080)
%40 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%41 = call i32 @connect(i32 %22, %struct.sockaddr* %40, i32 12)
%42 = icmp ne i32 %41, 0
%43 = load i32, i32* @errno
%44 = load i32, i32* @EINPROGRESS
%45 = icmp eq i32 %43, %44
%46 = select i1 %42, i1 %45, i1 false
br i1 %46, label %50, label %47
47: ; preds = %28
%48 = call i32 @strerror(i32 %43)
%49 = call i32 (i8*, ...) @FATAL_ERROR(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 8080, i32 %43, i32 %48)
br label %50
50: ; preds = %28, %47
%51 = bitcast i32* %4 to i8*
%52 = call i32 @FD_ZERO(i32* %4)
%53 = call i32 @FD_SET(i32 %22, i32* %4)
%54 = bitcast %struct.timeval* %5 to i8*
%55 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
store i32 5, i32* %55
%56 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
store i64 0, i64* %56
%57 = add nsw i32 %22, 1
%58 = call i64 @select(i32 %57, i32* null, i32* %4, i32* null, %struct.timeval* %5)
%59 = icmp slt i64 %58, 1
br i1 %59, label %60, label %64
60: ; preds = %50
%61 = load i32, i32* @errno
%62 = call i32 @strerror(i32 %61)
%63 = call i32 (i8*, ...) @FATAL_ERROR(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 8080, i32 %61, i32 %62)
br label %64
64: ; preds = %60, %50
%65 = bitcast i32* %6 to i8*
%66 = bitcast i32* %7 to i8*
store i32 4, i32* %7
%67 = load i32, i32* @SOL_SOCKET
%68 = load i32, i32* @SO_ERROR
%69 = call i32 @getsockopt(i32 %22, i32 %67, i32 %68, i32* %6, i32* %7)
%70 = load i32, i32* %6
%71 = icmp eq i32 %70, 0
br i1 %71, label %75, label %72
72: ; preds = %64
%73 = call i32 @strerror(i32 %70)
%74 = call i32 (i8*, ...) @FATAL_ERROR(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 8080, i32 %70, i32 %73)
br label %75
75: ; preds = %72, %64
%76 = call i32 @set_sock_blocking_mode(i32 %22)
%77 = bitcast %struct.timeval* %8 to i8*
%78 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i64 0, i32 0
store i32 10, i32* %78
%79 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i64 0, i32 1
store i64 0, i64* %79
%80 = load i32, i32* @SOL_SOCKET
%81 = load i32, i32* @SO_RCVTIMEO
%82 = call i64 @setsockopt(i32 %22, i32 %80, i32 %81, i8* %77, i32 16)
%83 = icmp eq i64 %82, 0
br i1 %83, label %86, label %84
84: ; preds = %75
%85 = call i32 (i8*, ...) @FATAL_ERROR(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0))
br label %86
86: ; preds = %84, %75
%87 = call i32 (i8*, ...) @LOG(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 8080)
%88 = getelementptr inbounds [17 x i8], [17 x i8]* %9, i64 0, i64 0
%89 = call i64 @malloc(i64 18)
%90 = inttoptr i64 %89 to i8*
%91 = call i32 @memcpy(i8* %90, i8* %88, i64 17)
%92 = getelementptr inbounds i8, i8* %90, i64 17
store i8 0, i8* %92
%93 = call i32 (i8*, ...) @LOG(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.9, i64 0, i64 0), i8* %90)
%94 = call i32 @free(i8* %90)
%95 = call i32 @send(i32 %22, i8* %88, i64 17, i32 0)
br label %96
96: ; preds = %86, %14
%97 = phi i32 [ 5, %14 ], [ %95, %86 ]
ret i32 %97
}