#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 */
struct timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ er;

/* Variables and functions */
int EINPROGRESS;
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ O_NONBLOCK;
scalar_t__ SK_clearsockflags(int, int /*<<< orphan*/);
scalar_t__ SK_setsockflags(int, int /*<<< orphan*/);
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_ERROR;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int *);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int);
int SK_connect_inner(int *retsock, struct addrinfo *res, int timeout,
                     char *hostname, int port) {
  int sock, flags, sel, gs, er;
  socklen_t erlen = sizeof(er);
  struct timeval ptm;
  fd_set rset, wset;
  sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
  if (sock < 0) {
    fprintf(stderr, "SK_connect(%s, %d): socket(): %d (%s)\n", hostname, port,
            errno, strerror(errno));
    return -1;
  }
  if (SK_setsockflags(sock, O_NONBLOCK) < 0) {
    fprintf(stderr, "SK_connect(%s, %d): setsockflags(): %d (%s)\n", hostname,
            port, errno, strerror(errno));
    close(sock);
    return -1;
  }
  if ((connect(sock, res->ai_addr, res->ai_addrlen)) < 0 &&
      errno != EINPROGRESS) {
    fprintf(stderr, "SK_connect(%s, %d): connect(): %d (%s)\n", hostname, port,
            errno, strerror(errno));
    close(sock);
    return -1;
  }
  FD_ZERO(&rset);
  FD_SET(sock, &rset);
  wset = rset;
  ptm.tv_usec = 0;
  ptm.tv_sec = timeout;
  if ((sel = select(sock + 1, &rset, &wset, NULL, &ptm)) == 0) {
    fprintf(stderr, "*");
    close(sock);
    return -1;
  }
  if (sel < 0) {
    fprintf(stderr, "SK_connect(%s, %d): select(): %d (%s)\n", hostname, port,
            errno, strerror(errno));
    close(sock);
    return -1;
  }
  gs = getsockopt(sock, SOL_SOCKET, SO_ERROR, &er, &erlen);
  if (gs < 0 || er) {
    fprintf(stderr, "SK_connect(%s, %d): select(): %d (%s)\n", hostname, port,
            er, strerror(er));
    close(sock);
    return -1;
  }
  if (SK_clearsockflags(sock, O_NONBLOCK) < 0) {
    fprintf(stderr, "SK_connect(%s, %d): clearsockflags(): %d (%s)\n", hostname,
            port, errno, strerror(errno));
    close(sock);
    return -1;
  }
  *retsock = sock;
  return 0;
}


x86 assembly (clang, -O0):
<SK_connect_inner>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
movl   $0x4,-0x44(%rbp)
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edx
call   10d0 <socket@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    125b <SK_connect_inner+0xab>
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    0x2da3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    -0x70(%rbp),%rdx
mov    -0x68(%rbp),%ecx
mov    -0x64(%rbp),%r8d
mov    %rax,%r9
lea    0xdb8(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15f9 <SK_connect_inner+0x449>
mov    -0x30(%rbp),%edi
mov    0x2d7b(%rip),%rax
mov    (%rax),%esi
call   1030 <SK_setsockflags@plt>
cmp    $0x0,%rax
jge    12e9 <SK_connect_inner+0x139>
mov    0x2d4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x7c(%rbp)
mov    0x2d23(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x78(%rbp)
mov    0x2d17(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x8c(%rbp),%edi
mov    -0x88(%rbp),%rdx
mov    -0x7c(%rbp),%ecx
mov    -0x78(%rbp),%r8d
mov    %rax,%r9
lea    0xd59(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15f9 <SK_connect_inner+0x449>
mov    -0x30(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
call   10a0 <connect@plt>
cmp    $0x0,%rax
jge    139f <SK_connect_inner+0x1ef>
mov    0x2cb1(%rip),%rax
mov    (%rax),%eax
mov    0x2cc0(%rip),%rcx
cmp    (%rcx),%eax
je     139f <SK_connect_inner+0x1ef>
mov    0x2ca1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa4(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x94(%rbp)
mov    0x2c76(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x90(%rbp)
mov    0x2c67(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0xa4(%rbp),%edi
mov    -0xa0(%rbp),%rdx
mov    -0x94(%rbp),%ecx
mov    -0x90(%rbp),%r8d
mov    %rax,%r9
lea    0xcd0(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15f9 <SK_connect_inner+0x449>
lea    -0x5c(%rbp),%rdi
call   1080 <FD_ZERO@plt>
mov    -0x30(%rbp),%edi
lea    -0x5c(%rbp),%rsi
call   10c0 <FD_SET@plt>
mov    -0x5c(%rbp),%eax
mov    %eax,-0x60(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x30(%rbp),%edi
add    $0x1,%edi
lea    -0x5c(%rbp),%rsi
lea    -0x60(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x58(%rbp),%r8
call   1090 <select@plt>
mov    %eax,-0x38(%rbp)
cmp    $0x0,%eax
jne    141a <SK_connect_inner+0x26a>
mov    0x2bd2(%rip),%rax
mov    (%rax),%edi
lea    0xc7d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15f9 <SK_connect_inner+0x449>
cmpl   $0x0,-0x38(%rbp)
jge    14a3 <SK_connect_inner+0x2f3>
mov    0x2b9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xbc(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0xac(%rbp)
mov    0x2b72(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa8(%rbp)
mov    0x2b63(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0xbc(%rbp),%edi
mov    -0xb8(%rbp),%rdx
mov    -0xac(%rbp),%ecx
mov    -0xa8(%rbp),%r8d
mov    %rax,%r9
lea    0xbf6(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15f9 <SK_connect_inner+0x449>
mov    -0x30(%rbp),%edi
mov    0x2b3b(%rip),%rax
mov    (%rax),%esi
mov    0x2b02(%rip),%rax
mov    (%rax),%edx
lea    -0x40(%rbp),%rcx
lea    -0x44(%rbp),%r8
call   1060 <getsockopt@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jl     14dc <SK_connect_inner+0x32c>
cmpl   $0x0,-0x40(%rbp)
je     154f <SK_connect_inner+0x39f>
mov    0x2ae5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xd4(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0xd0(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0xc4(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0xc0(%rbp)
mov    -0x40(%rbp),%edi
call   10b0 <strerror@plt>
mov    -0xd4(%rbp),%edi
mov    -0xd0(%rbp),%rdx
mov    -0xc4(%rbp),%ecx
mov    -0xc0(%rbp),%r8d
mov    %rax,%r9
lea    0xb4a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15f9 <SK_connect_inner+0x449>
mov    -0x30(%rbp),%edi
mov    0x2a87(%rip),%rax
mov    (%rax),%esi
call   1050 <SK_clearsockflags@plt>
cmp    $0x0,%rax
jge    15e9 <SK_connect_inner+0x439>
mov    0x2a57(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xec(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0xe8(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0xdc(%rbp)
mov    0x2a2c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xd8(%rbp)
mov    0x2a1d(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0xec(%rbp),%edi
mov    -0xe8(%rbp),%rdx
mov    -0xdc(%rbp),%ecx
mov    -0xd8(%rbp),%r8d
mov    %rax,%r9
lea    0xad7(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15f9 <SK_connect_inner+0x449>
mov    -0x30(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SK_connect_inner>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8d,%r14d
mov    %rcx,%r12
mov    %edx,%r13d
mov    %rsi,%rbp
mov    %rdi,%r15
movl   $0x4,0x10(%rsp)
mov    0x10(%rsi),%edi
mov    0x8(%rsi),%edx
mov    0xc(%rsi),%esi
call   10d0 <socket@plt>
test   %eax,%eax
js     12de <SK_connect_inner+0x12e>
mov    %eax,%ebx
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1030 <SK_setsockflags@plt>
test   %rax,%rax
js     1318 <SK_connect_inner+0x168>
mov    0x0(%rbp),%edx
mov    0x4(%rbp),%esi
mov    %ebx,%edi
call   10a0 <connect@plt>
test   %rax,%rax
jns    1230 <SK_connect_inner+0x80>
mov    0x2da1(%rip),%rax
mov    (%rax),%ebp
mov    0x2db0(%rip),%rax
cmp    (%rax),%ebp
jne    1354 <SK_connect_inner+0x1a4>
lea    0xc(%rsp),%rbp
mov    %rbp,%rdi
call   1080 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   10c0 <FD_SET@plt>
mov    0xc(%rsp),%eax
mov    %eax,0x8(%rsp)
movq   $0x0,0x20(%rsp)
mov    %r13d,0x18(%rsp)
mov    %ebx,%edi
add    $0x1,%edi
lea    0x8(%rsp),%rdx
lea    0x18(%rsp),%r8
mov    %rbp,%rsi
xor    %ecx,%ecx
call   1090 <select@plt>
test   %eax,%eax
je     133b <SK_connect_inner+0x18b>
js     136e <SK_connect_inner+0x1be>
mov    0x2d5d(%rip),%rax
mov    (%rax),%esi
mov    0x2d24(%rip),%rax
mov    (%rax),%edx
lea    0x14(%rsp),%rcx
lea    0x10(%rsp),%r8
mov    %ebx,%edi
call   1060 <getsockopt@plt>
mov    0x14(%rsp),%ebp
test   %eax,%eax
js     1383 <SK_connect_inner+0x1d3>
test   %ebp,%ebp
jne    1383 <SK_connect_inner+0x1d3>
mov    0x2d1e(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1050 <SK_clearsockflags@plt>
test   %rax,%rax
js     13cc <SK_connect_inner+0x21c>
mov    %ebx,(%r15)
xor    %eax,%eax
jmp    13bd <SK_connect_inner+0x20d>
mov    0x2ce3(%rip),%rax
mov    (%rax),%ebx
mov    0x2cd2(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10b0 <strerror@plt>
lea    0xd02(%rip),%rsi
mov    %ebx,%edi
mov    %r12,%rdx
mov    %r14d,%ecx
mov    %ebp,%r8d
mov    %rax,%r9
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    13b8 <SK_connect_inner+0x208>
mov    0x2ca9(%rip),%rax
mov    (%rax),%r15d
mov    0x2c97(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10b0 <strerror@plt>
lea    0xcee(%rip),%rsi
jmp    139b <SK_connect_inner+0x1eb>
mov    0x2c86(%rip),%rax
mov    (%rax),%edi
lea    0xd31(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    13b1 <SK_connect_inner+0x201>
mov    0x2c6d(%rip),%rax
mov    (%rax),%r15d
mov    %ebp,%edi
call   10b0 <strerror@plt>
lea    0xce8(%rip),%rsi
jmp    139b <SK_connect_inner+0x1eb>
mov    0x2c53(%rip),%rax
mov    (%rax),%r15d
mov    0x2c41(%rip),%rax
mov    (%rax),%ebp
jmp    138d <SK_connect_inner+0x1dd>
mov    0x2c3e(%rip),%rax
mov    (%rax),%r15d
mov    %ebp,%edi
call   10b0 <strerror@plt>
lea    0xce3(%rip),%rsi
mov    %r15d,%edi
mov    %r12,%rdx
mov    %r14d,%ecx
mov    %ebp,%r8d
mov    %rax,%r9
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    $0xffffffff,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2bf5(%rip),%rax
mov    (%rax),%r15d
mov    0x2be3(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10b0 <strerror@plt>
lea    0xcb8(%rip),%rsi
jmp    139b <SK_connect_inner+0x1eb>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
%struct.timeval = type { i32, i64 }
@stderr = global i32 0
@.str = [39 x i8] c"SK_connect(%s, %d): socket(): %d (%s)\0A\00"
@errno = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [45 x i8] c"SK_connect(%s, %d): setsockflags(): %d (%s)\0A\00"
@EINPROGRESS = global i32 0
@.str.2 = [40 x i8] c"SK_connect(%s, %d): connect(): %d (%s)\0A\00"
@.str.3 = [2 x i8] c"*\00"
@.str.4 = [39 x i8] c"SK_connect(%s, %d): select(): %d (%s)\0A\00"
@SOL_SOCKET = global i32 0
@SO_ERROR = global i32 0
@.str.5 = [47 x i8] c"SK_connect(%s, %d): clearsockflags(): %d (%s)\0A\00"
define i32 @SK_connect_inner(i32* %0, %struct.addrinfo* %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca %struct.addrinfo*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca %struct.timeval
%19 = alloca i32
%20 = alloca i32
store i32* %0, i32** %7
store %struct.addrinfo* %1, %struct.addrinfo** %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
store i32 4, i32* %17
%21 = load %struct.addrinfo*, %struct.addrinfo** %8
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %21, i32 0, i32 4
%23 = load i32, i32* %22
%24 = load %struct.addrinfo*, %struct.addrinfo** %8
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %24, i32 0, i32 3
%26 = load i32, i32* %25
%27 = load %struct.addrinfo*, %struct.addrinfo** %8
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %27, i32 0, i32 2
%29 = load i32, i32* %28
%30 = call i32 @socket(i32 %23, i32 %26, i32 %29)
store i32 %30, i32* %12
%31 = load i32, i32* %12
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %41
33: ; preds = %5
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %10
%36 = load i32, i32* %11
%37 = load i32, i32* @errno
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %35, i32 %36, i32 %37, i8* %39)
store i32 -1, i32* %6
br label %148
41: ; preds = %5
%42 = load i32, i32* %12
%43 = load i32, i32* @O_NONBLOCK
%44 = call i64 @SK_setsockflags(i32 %42, i32 %43)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %56
46: ; preds = %41
%47 = load i32, i32* @stderr
%48 = load i8*, i8** %10
%49 = load i32, i32* %11
%50 = load i32, i32* @errno
%51 = load i32, i32* @errno
%52 = call i8* @strerror(i32 %51)
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %48, i32 %49, i32 %50, i8* %52)
%54 = load i32, i32* %12
%55 = call i32 @close(i32 %54)
store i32 -1, i32* %6
br label %148
56: ; preds = %41
%57 = load i32, i32* %12
%58 = load %struct.addrinfo*, %struct.addrinfo** %8
%59 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %58, i32 0, i32 1
%60 = load i32, i32* %59
%61 = load %struct.addrinfo*, %struct.addrinfo** %8
%62 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %61, i32 0, i32 0
%63 = load i32, i32* %62
%64 = call i64 @connect(i32 %57, i32 %60, i32 %63)
%65 = icmp slt i64 %64, 0
br i1 %65, label %66, label %80
66: ; preds = %56
%67 = load i32, i32* @errno
%68 = load i32, i32* @EINPROGRESS
%69 = icmp ne i32 %67, %68
br i1 %69, label %70, label %80
70: ; preds = %66
%71 = load i32, i32* @stderr
%72 = load i8*, i8** %10
%73 = load i32, i32* %11
%74 = load i32, i32* @errno
%75 = load i32, i32* @errno
%76 = call i8* @strerror(i32 %75)
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %72, i32 %73, i32 %74, i8* %76)
%78 = load i32, i32* %12
%79 = call i32 @close(i32 %78)
store i32 -1, i32* %6
br label %148
80: ; preds = %66, %56
%81 = call i32 @FD_ZERO(i32* %19)
%82 = load i32, i32* %12
%83 = call i32 @FD_SET(i32 %82, i32* %19)
%84 = load i32, i32* %19
store i32 %84, i32* %20
%85 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 1
store i64 0, i64* %85
%86 = load i32, i32* %9
%87 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 0
store i32 %86, i32* %87
%88 = load i32, i32* %12
%89 = add nsw i32 %88, 1
%90 = call i32 @select(i32 %89, i32* %19, i32* %20, i32* null, %struct.timeval* %18)
store i32 %90, i32* %14
%91 = icmp eq i32 %90, 0
br i1 %91, label %92, label %97
92: ; preds = %80
%93 = load i32, i32* @stderr
%94 = call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%95 = load i32, i32* %12
%96 = call i32 @close(i32 %95)
store i32 -1, i32* %6
br label %148
97: ; preds = %80
%98 = load i32, i32* %14
%99 = icmp slt i32 %98, 0
br i1 %99, label %100, label %110
100: ; preds = %97
%101 = load i32, i32* @stderr
%102 = load i8*, i8** %10
%103 = load i32, i32* %11
%104 = load i32, i32* @errno
%105 = load i32, i32* @errno
%106 = call i8* @strerror(i32 %105)
%107 = call i32 (i32, i8*, ...) @fprintf(i32 %101, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8* %102, i32 %103, i32 %104, i8* %106)
%108 = load i32, i32* %12
%109 = call i32 @close(i32 %108)
store i32 -1, i32* %6
br label %148
110: ; preds = %97
%111 = load i32, i32* %12
%112 = load i32, i32* @SOL_SOCKET
%113 = load i32, i32* @SO_ERROR
%114 = call i32 @getsockopt(i32 %111, i32 %112, i32 %113, i32* %16, i32* %17)
store i32 %114, i32* %15
%115 = load i32, i32* %15
%116 = icmp slt i32 %115, 0
br i1 %116, label %120, label %117
117: ; preds = %110
%118 = load i32, i32* %16
%119 = icmp ne i32 %118, 0
br i1 %119, label %120, label %130
120: ; preds = %117, %110
%121 = load i32, i32* @stderr
%122 = load i8*, i8** %10
%123 = load i32, i32* %11
%124 = load i32, i32* %16
%125 = load i32, i32* %16
%126 = call i8* @strerror(i32 %125)
%127 = call i32 (i32, i8*, ...) @fprintf(i32 %121, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8* %122, i32 %123, i32 %124, i8* %126)
%128 = load i32, i32* %12
%129 = call i32 @close(i32 %128)
store i32 -1, i32* %6
br label %148
130: ; preds = %117
%131 = load i32, i32* %12
%132 = load i32, i32* @O_NONBLOCK
%133 = call i64 @SK_clearsockflags(i32 %131, i32 %132)
%134 = icmp slt i64 %133, 0
br i1 %134, label %135, label %145
135: ; preds = %130
%136 = load i32, i32* @stderr
%137 = load i8*, i8** %10
%138 = load i32, i32* %11
%139 = load i32, i32* @errno
%140 = load i32, i32* @errno
%141 = call i8* @strerror(i32 %140)
%142 = call i32 (i32, i8*, ...) @fprintf(i32 %136, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), i8* %137, i32 %138, i32 %139, i8* %141)
%143 = load i32, i32* %12
%144 = call i32 @close(i32 %143)
store i32 -1, i32* %6
br label %148
145: ; preds = %130
%146 = load i32, i32* %12
%147 = load i32*, i32** %7
store i32 %146, i32* %147
store i32 0, i32* %6
br label %148
148: ; preds = %145, %135, %120, %100, %92, %70, %46, %33
%149 = load i32, i32* %6
ret i32 %149
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
%struct.timeval = type { i32, i64 }
@stderr = global i32 0
@.str = [39 x i8] c"SK_connect(%s, %d): socket(): %d (%s)\0A\00"
@errno = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [45 x i8] c"SK_connect(%s, %d): setsockflags(): %d (%s)\0A\00"
@EINPROGRESS = global i32 0
@.str.2 = [40 x i8] c"SK_connect(%s, %d): connect(): %d (%s)\0A\00"
@.str.3 = [2 x i8] c"*\00"
@.str.4 = [39 x i8] c"SK_connect(%s, %d): select(): %d (%s)\0A\00"
@SOL_SOCKET = global i32 0
@SO_ERROR = global i32 0
@.str.5 = [47 x i8] c"SK_connect(%s, %d): clearsockflags(): %d (%s)\0A\00"
define i32 @SK_connect_inner(i32* nocapture writeonly %0, %struct.addrinfo* nocapture %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.timeval
%9 = alloca i32
%10 = alloca i32
%11 = bitcast i32* %6 to i8*
%12 = bitcast i32* %7 to i8*
store i32 4, i32* %7
%13 = bitcast %struct.timeval* %8 to i8*
%14 = bitcast i32* %9 to i8*
%15 = bitcast i32* %10 to i8*
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 4
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 3
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 2
%21 = load i32, i32* %20
%22 = tail call i32 @socket(i32 %17, i32 %19, i32 %21)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %5
%25 = load i32, i32* @stderr
%26 = load i32, i32* @errno
%27 = tail call i8* @strerror(i32 %26)
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %3, i32 %4, i32 %26, i8* %27)
br label %100
29: ; preds = %5
%30 = load i32, i32* @O_NONBLOCK
%31 = tail call i64 @SK_setsockflags(i32 %22, i32 %30)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %29
%34 = load i32, i32* @stderr
%35 = load i32, i32* @errno
%36 = tail call i8* @strerror(i32 %35)
%37 = tail call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %3, i32 %4, i32 %35, i8* %36)
%38 = tail call i32 @close(i32 %22)
br label %100
39: ; preds = %29
%40 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 1
%41 = load i32, i32* %40
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %1, i64 0, i32 0
%43 = load i32, i32* %42
%44 = tail call i64 @connect(i32 %22, i32 %41, i32 %43)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %55
46: ; preds = %39
%47 = load i32, i32* @errno
%48 = load i32, i32* @EINPROGRESS
%49 = icmp eq i32 %47, %48
br i1 %49, label %55, label %50
50: ; preds = %46
%51 = load i32, i32* @stderr
%52 = tail call i8* @strerror(i32 %47)
%53 = tail call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %3, i32 %4, i32 %47, i8* %52)
%54 = tail call i32 @close(i32 %22)
br label %100
55: ; preds = %46, %39
%56 = call i32 @FD_ZERO(i32* %9)
%57 = call i32 @FD_SET(i32 %22, i32* %9)
%58 = load i32, i32* %9
store i32 %58, i32* %10
%59 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i64 0, i32 1
store i64 0, i64* %59
%60 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i64 0, i32 0
store i32 %2, i32* %60
%61 = add nuw nsw i32 %22, 1
%62 = call i32 @select(i32 %61, i32* %9, i32* %10, i32* null, %struct.timeval* %8)
%63 = icmp eq i32 %62, 0
br i1 %63, label %64, label %68
64: ; preds = %55
%65 = load i32, i32* @stderr
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%67 = call i32 @close(i32 %22)
br label %100
68: ; preds = %55
%69 = icmp slt i32 %62, 0
br i1 %69, label %70, label %76
70: ; preds = %68
%71 = load i32, i32* @stderr
%72 = load i32, i32* @errno
%73 = call i8* @strerror(i32 %72)
%74 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8* %3, i32 %4, i32 %72, i8* %73)
%75 = call i32 @close(i32 %22)
br label %100
76: ; preds = %68
%77 = load i32, i32* @SOL_SOCKET
%78 = load i32, i32* @SO_ERROR
%79 = call i32 @getsockopt(i32 %22, i32 %77, i32 %78, i32* %6, i32* %7)
%80 = icmp slt i32 %79, 0
%81 = load i32, i32* %6
%82 = icmp ne i32 %81, 0
%83 = select i1 %80, i1 true, i1 %82
br i1 %83, label %84, label %89
84: ; preds = %76
%85 = load i32, i32* @stderr
%86 = call i8* @strerror(i32 %81)
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8* %3, i32 %4, i32 %81, i8* %86)
%88 = call i32 @close(i32 %22)
br label %100
89: ; preds = %76
%90 = load i32, i32* @O_NONBLOCK
%91 = call i64 @SK_clearsockflags(i32 %22, i32 %90)
%92 = icmp slt i64 %91, 0
br i1 %92, label %93, label %99
93: ; preds = %89
%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 ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), i8* %3, i32 %4, i32 %95, i8* %96)
%98 = call i32 @close(i32 %22)
br label %100
99: ; preds = %89
store i32 %22, i32* %0
br label %100
100: ; preds = %99, %93, %84, %70, %64, %50, %33, %24
%101 = phi i32 [ -1, %24 ], [ -1, %33 ], [ -1, %50 ], [ -1, %64 ], [ -1, %70 ], [ -1, %84 ], [ -1, %93 ], [ 0, %99 ]
ret i32 %101
}