#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 pollfd {
  int fd;
  int events;
  int revents;
};
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  struct addrinfo *ai_next;
  scalar_t__ ai_flags;
};
typedef int /*<<< orphan*/ sockret;
typedef int socklen_t;
typedef int /*<<< orphan*/ hints;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
scalar_t__ EINPROGRESS;
int /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
int O_NONBLOCK;
int POLLOUT;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_ERROR;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ errno;
int fcntl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
scalar_t__ getaddrinfo(char const *, char const *, struct addrinfo *,
                       struct addrinfo **);
scalar_t__ getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *,
                      int *);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
scalar_t__ poll(struct pollfd *, int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int mod_websocket_connect(const char *host, const char *service) {
  struct addrinfo hints;
  struct addrinfo *res = NULL;
  struct addrinfo *ai = NULL;
  int flags, fd = -1, sockret = -1;
  socklen_t socklen = sizeof(sockret);
  struct pollfd pollfd;
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = 0;
  if (getaddrinfo(host, service, &hints, &res) != 0) {
    return -1;
  }
  for (ai = res; ai; ai = ai->ai_next) {
    fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
    if (fd < 0) {
      break;
    }
    if ((flags = fcntl(fd, F_GETFL, 0)) < 0 ||
        fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
      close(fd);
      fd = -1;
      continue;
    }
    pollfd.fd = fd;
    pollfd.events = POLLOUT;
    if (connect(fd, ai->ai_addr, ai->ai_addrlen) < 0 && errno != EINPROGRESS) {
      close(fd);
      fd = -1;
      continue;
    }
    if (poll(&pollfd, 1, 5000) == 0) {
      close(fd);
      fd = -1;
      continue;
    }
    if ((pollfd.revents & POLLOUT) &&
        getsockopt(fd, SOL_SOCKET, SO_ERROR, &sockret, &socklen) == 0 &&
        sockret == 0) {
      break;
    }
    close(fd);
    fd = -1;
  }
  freeaddrinfo(res);
  return fd;
}


x86 assembly (clang, -O0):
<mod_websocket_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
movl   $0xffffffff,-0x58(%rbp)
movl   $0xffffffff,-0x5c(%rbp)
movl   $0x4,-0x60(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2dc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x48(%rbp),%rcx
call   1090 <getaddrinfo@plt>
cmp    $0x0,%rax
je     1220 <mod_websocket_connect+0x90>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c7 <mod_websocket_connect+0x237>
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
je     13b8 <mod_websocket_connect+0x228>
mov    -0x50(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x50(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x50(%rbp),%rax
mov    0x8(%rax),%edx
call   10b0 <socket@plt>
mov    %eax,-0x58(%rbp)
cmpl   $0x0,-0x58(%rbp)
jge    125f <mod_websocket_connect+0xcf>
jmp    13b8 <mod_websocket_connect+0x228>
mov    -0x58(%rbp),%edi
mov    0x2d2f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x54(%rbp)
cmp    $0x0,%eax
jl     12a4 <mod_websocket_connect+0x114>
mov    -0x58(%rbp),%edi
mov    0x2d30(%rip),%rax
mov    (%rax),%esi
mov    -0x54(%rbp),%edx
mov    0x2d44(%rip),%rax
or     (%rax),%edx
call   1030 <fcntl@plt>
cmp    $0x0,%eax
jge    12b8 <mod_websocket_connect+0x128>
mov    -0x58(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x58(%rbp)
jmp    13a7 <mod_websocket_connect+0x217>
mov    -0x58(%rbp),%eax
mov    %eax,-0x70(%rbp)
mov    0x2d33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x58(%rbp),%edi
mov    -0x50(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x50(%rbp),%rax
mov    (%rax),%edx
call   1080 <connect@plt>
cmp    $0x0,%rax
jge    1317 <mod_websocket_connect+0x187>
mov    0x2cb8(%rip),%rax
mov    (%rax),%rax
mov    0x2cd6(%rip),%rcx
cmp    (%rcx),%rax
je     1317 <mod_websocket_connect+0x187>
mov    -0x58(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x58(%rbp)
jmp    13a7 <mod_websocket_connect+0x217>
lea    -0x70(%rbp),%rdi
mov    $0x1,%esi
mov    $0x1388,%edx
call   1070 <poll@plt>
cmp    $0x0,%rax
jne    1348 <mod_websocket_connect+0x1b8>
mov    -0x58(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x58(%rbp)
jmp    13a7 <mod_websocket_connect+0x217>
mov    -0x68(%rbp),%eax
mov    0x2ca6(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1398 <mod_websocket_connect+0x208>
mov    -0x58(%rbp),%edi
mov    0x2c79(%rip),%rax
mov    (%rax),%esi
mov    0x2c30(%rip),%rax
mov    (%rax),%edx
lea    -0x5c(%rbp),%rcx
lea    -0x60(%rbp),%r8
call   1060 <getsockopt@plt>
cmp    $0x0,%rax
jne    1398 <mod_websocket_connect+0x208>
cmpl   $0x0,-0x5c(%rbp)
jne    1398 <mod_websocket_connect+0x208>
jmp    13b8 <mod_websocket_connect+0x228>
mov    -0x58(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x58(%rbp)
mov    -0x50(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x50(%rbp)
jmp    1228 <mod_websocket_connect+0x98>
mov    -0x48(%rbp),%rdi
call   10a0 <freeaddrinfo@plt>
mov    -0x58(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mod_websocket_connect>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movq   $0x0,0x10(%rsp)
movl   $0xffffffff,0xc(%rsp)
ff
movl   $0x4,0x1c(%rsp)
lea    0x30(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x40(%rsp)
mov    0x2dcb(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x3c(%rsp)
movq   $0x0,0x50(%rsp)
lea    0x10(%rsp),%rcx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1090 <getaddrinfo@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    1352 <mod_websocket_connect+0x1c2>
mov    0x10(%rsp),%rbx
test   %rbx,%rbx
je     133a <mod_websocket_connect+0x1aa>
mov    0x2d6e(%rip),%r13
mov    0x2d87(%rip),%r15
mov    0x2da0(%rip),%r12
mov    0x2db9(%rip),%r14
jmp    1264 <mod_websocket_connect+0xd4>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1050 <close@plt>
mov    0x18(%rbx),%rbx
test   %rbx,%rbx
je     1343 <mod_websocket_connect+0x1b3>
mov    0x10(%rbx),%edi
mov    0x8(%rbx),%edx
mov    0xc(%rbx),%esi
call   10b0 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1348 <mod_websocket_connect+0x1b8>
mov    0x0(%r13),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
test   %eax,%eax
js     1250 <mod_websocket_connect+0xc0>
mov    (%r15),%esi
or     (%r12),%eax
mov    %ebp,%edi
mov    %eax,%edx
call   1030 <fcntl@plt>
test   %eax,%eax
js     1250 <mod_websocket_connect+0xc0>
mov    %ebp,0x20(%rsp)
mov    (%r14),%eax
mov    %eax,0x24(%rsp)
mov    (%rbx),%edx
mov    0x4(%rbx),%esi
mov    %ebp,%edi
call   1080 <connect@plt>
test   %rax,%rax
jns    12d7 <mod_websocket_connect+0x147>
mov    0x2ce4(%rip),%rax
mov    (%rax),%rax
mov    0x2d02(%rip),%rcx
cmp    (%rcx),%rax
jne    1250 <mod_websocket_connect+0xc0>
lea    0x20(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1388,%edx
call   1070 <poll@plt>
test   %rax,%rax
je     1250 <mod_websocket_connect+0xc0>
mov    (%r14),%eax
test   %eax,0x28(%rsp)
je     1250 <mod_websocket_connect+0xc0>
mov    0x2cd8(%rip),%rax
mov    (%rax),%esi
mov    0x2c8f(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
lea    0xc(%rsp),%rcx
lea    0x1c(%rsp),%r8
call   1060 <getsockopt@plt>
test   %rax,%rax
jne    1250 <mod_websocket_connect+0xc0>
cmpl   $0x0,0xc(%rsp)
jne    1250 <mod_websocket_connect+0xc0>
jmp    1348 <mod_websocket_connect+0x1b8>
mov    $0xffffffff,%ebp
xor    %edi,%edi
jmp    134d <mod_websocket_connect+0x1bd>
mov    $0xffffffff,%ebp
mov    0x10(%rsp),%rdi
call   10a0 <freeaddrinfo@plt>
mov    %ebp,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo*, i64 }
%struct.pollfd = type { i32, i32, i32 }
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@POLLOUT = global i32 0
@errno = global i64 0
@EINPROGRESS = global i64 0
@SOL_SOCKET = global i32 0
@SO_ERROR = global i32 0
define i32 @mod_websocket_connect(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.addrinfo
%7 = alloca %struct.addrinfo*
%8 = alloca %struct.addrinfo*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca %struct.pollfd
store i8* %0, i8** %4
store i8* %1, i8** %5
store %struct.addrinfo* null, %struct.addrinfo** %7
store %struct.addrinfo* null, %struct.addrinfo** %8
store i32 -1, i32* %10
store i32 -1, i32* %11
store i32 4, i32* %12
%14 = call i32 @memset(%struct.addrinfo* %6, i32 0, i32 40)
%15 = load i32, i32* @AF_UNSPEC
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 4
store i32 %15, i32* %16
%17 = load i32, i32* @SOCK_STREAM
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 3
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 6
store i64 0, i64* %19
%20 = load i8*, i8** %4
%21 = load i8*, i8** %5
%22 = call i64 @getaddrinfo(i8* %20, i8* %21, %struct.addrinfo* %6, %struct.addrinfo** %7)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %2
store i32 -1, i32* %3
br label %114
25: ; preds = %2
%26 = load %struct.addrinfo*, %struct.addrinfo** %7
store %struct.addrinfo* %26, %struct.addrinfo** %8
br label %27
27: ; preds = %106, %25
%28 = load %struct.addrinfo*, %struct.addrinfo** %8
%29 = icmp ne %struct.addrinfo* %28, null
br i1 %29, label %30, label %110
30: ; preds = %27
%31 = load %struct.addrinfo*, %struct.addrinfo** %8
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %31, i32 0, i32 4
%33 = load i32, i32* %32
%34 = load %struct.addrinfo*, %struct.addrinfo** %8
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i32 0, i32 3
%36 = load i32, i32* %35
%37 = load %struct.addrinfo*, %struct.addrinfo** %8
%38 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %37, i32 0, i32 2
%39 = load i32, i32* %38
%40 = call i32 @socket(i32 %33, i32 %36, i32 %39)
store i32 %40, i32* %10
%41 = load i32, i32* %10
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %30
br label %110
44: ; preds = %30
%45 = load i32, i32* %10
%46 = load i32, i32* @F_GETFL
%47 = call i32 @fcntl(i32 %45, i32 %46, i32 0)
store i32 %47, i32* %9
%48 = icmp slt i32 %47, 0
br i1 %48, label %57, label %49
49: ; preds = %44
%50 = load i32, i32* %10
%51 = load i32, i32* @F_SETFL
%52 = load i32, i32* %9
%53 = load i32, i32* @O_NONBLOCK
%54 = or i32 %52, %53
%55 = call i32 @fcntl(i32 %50, i32 %51, i32 %54)
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %49, %44
%58 = load i32, i32* %10
%59 = call i32 @close(i32 %58)
store i32 -1, i32* %10
br label %106
60: ; preds = %49
%61 = load i32, i32* %10
%62 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %13, i32 0, i32 0
store i32 %61, i32* %62
%63 = load i32, i32* @POLLOUT
%64 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %13, i32 0, i32 1
store i32 %63, i32* %64
%65 = load i32, i32* %10
%66 = load %struct.addrinfo*, %struct.addrinfo** %8
%67 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %66, i32 0, i32 1
%68 = load i32, i32* %67
%69 = load %struct.addrinfo*, %struct.addrinfo** %8
%70 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %69, i32 0, i32 0
%71 = load i32, i32* %70
%72 = call i64 @connect(i32 %65, i32 %68, i32 %71)
%73 = icmp slt i64 %72, 0
br i1 %73, label %74, label %81
74: ; preds = %60
%75 = load i64, i64* @errno
%76 = load i64, i64* @EINPROGRESS
%77 = icmp ne i64 %75, %76
br i1 %77, label %78, label %81
78: ; preds = %74
%79 = load i32, i32* %10
%80 = call i32 @close(i32 %79)
store i32 -1, i32* %10
br label %106
81: ; preds = %74, %60
%82 = call i64 @poll(%struct.pollfd* %13, i32 1, i32 5000)
%83 = icmp eq i64 %82, 0
br i1 %83, label %84, label %87
84: ; preds = %81
%85 = load i32, i32* %10
%86 = call i32 @close(i32 %85)
store i32 -1, i32* %10
br label %106
87: ; preds = %81
%88 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %13, i32 0, i32 2
%89 = load i32, i32* %88
%90 = load i32, i32* @POLLOUT
%91 = and i32 %89, %90
%92 = icmp ne i32 %91, 0
br i1 %92, label %93, label %103
93: ; preds = %87
%94 = load i32, i32* %10
%95 = load i32, i32* @SOL_SOCKET
%96 = load i32, i32* @SO_ERROR
%97 = call i64 @getsockopt(i32 %94, i32 %95, i32 %96, i32* %11, i32* %12)
%98 = icmp eq i64 %97, 0
br i1 %98, label %99, label %103
99: ; preds = %93
%100 = load i32, i32* %11
%101 = icmp eq i32 %100, 0
br i1 %101, label %102, label %103
102: ; preds = %99
br label %110
103: ; preds = %99, %93, %87
%104 = load i32, i32* %10
%105 = call i32 @close(i32 %104)
store i32 -1, i32* %10
br label %106
106: ; preds = %103, %84, %78, %57
%107 = load %struct.addrinfo*, %struct.addrinfo** %8
%108 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %107, i32 0, i32 5
%109 = load %struct.addrinfo*, %struct.addrinfo** %108
store %struct.addrinfo* %109, %struct.addrinfo** %8
br label %27
110: ; preds = %102, %43, %27
%111 = load %struct.addrinfo*, %struct.addrinfo** %7
%112 = call i32 @freeaddrinfo(%struct.addrinfo* %111)
%113 = load i32, i32* %10
store i32 %113, i32* %3
br label %114
114: ; preds = %110, %24
%115 = load i32, i32* %3
ret i32 %115
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo*, i64 }
%struct.pollfd = type { i32, i32, i32 }
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@POLLOUT = global i32 0
@errno = global i64 0
@EINPROGRESS = global i64 0
@SOL_SOCKET = global i32 0
@SO_ERROR = global i32 0
define i32 @mod_websocket_connect(i8* %0, i8* %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.pollfd
%8 = bitcast %struct.addrinfo* %3 to i8*
%9 = bitcast %struct.addrinfo** %4 to i8*
store %struct.addrinfo* null, %struct.addrinfo** %4
%10 = bitcast i32* %5 to i8*
store i32 -1, i32* %5
%11 = bitcast i32* %6 to i8*
store i32 4, i32* %6
%12 = bitcast %struct.pollfd* %7 to i8*
%13 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 40)
%14 = load i32, i32* @AF_UNSPEC
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %14, i32* %15
%16 = load i32, i32* @SOCK_STREAM
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %16, i32* %17
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 6
store i64 0, i64* %18
%19 = call i64 @getaddrinfo(i8* %0, i8* %1, %struct.addrinfo* %3, %struct.addrinfo** %4)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %88
21: ; preds = %2
%22 = load %struct.addrinfo*, %struct.addrinfo** %4
%23 = icmp eq %struct.addrinfo* %22, null
br i1 %23, label %84, label %24
24: ; preds = %21
%25 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %7, i64 0, i32 0
%26 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %7, i64 0, i32 1
%27 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %7, i64 0, i32 2
br label %28
28: ; preds = %24, %76
%29 = phi %struct.addrinfo* [ %22, %24 ], [ %79, %76 ]
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %29, i64 0, i32 4
%31 = load i32, i32* %30
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %29, i64 0, i32 3
%33 = load i32, i32* %32
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %29, i64 0, i32 2
%35 = load i32, i32* %34
%36 = call i32 @socket(i32 %31, i32 %33, i32 %35)
%37 = icmp slt i32 %36, 0
br i1 %37, label %81, label %38
38: ; preds = %28
%39 = load i32, i32* @F_GETFL
%40 = call i32 @fcntl(i32 %36, i32 %39, i32 0)
%41 = icmp slt i32 %40, 0
br i1 %41, label %76, label %42
42: ; preds = %38
%43 = load i32, i32* @F_SETFL
%44 = load i32, i32* @O_NONBLOCK
%45 = or i32 %44, %40
%46 = call i32 @fcntl(i32 %36, i32 %43, i32 %45)
%47 = icmp slt i32 %46, 0
br i1 %47, label %76, label %48
48: ; preds = %42
store i32 %36, i32* %25
%49 = load i32, i32* @POLLOUT
store i32 %49, i32* %26
%50 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %29, i64 0, i32 1
%51 = load i32, i32* %50
%52 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %29, i64 0, i32 0
%53 = load i32, i32* %52
%54 = call i64 @connect(i32 %36, i32 %51, i32 %53)
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %60
56: ; preds = %48
%57 = load i64, i64* @errno
%58 = load i64, i64* @EINPROGRESS
%59 = icmp eq i64 %57, %58
br i1 %59, label %60, label %76
60: ; preds = %56, %48
%61 = call i64 @poll(%struct.pollfd* %7, i32 1, i32 5000)
%62 = icmp eq i64 %61, 0
br i1 %62, label %76, label %63
63: ; preds = %60
%64 = load i32, i32* %27
%65 = load i32, i32* @POLLOUT
%66 = and i32 %65, %64
%67 = icmp eq i32 %66, 0
br i1 %67, label %76, label %68
68: ; preds = %63
%69 = load i32, i32* @SOL_SOCKET
%70 = load i32, i32* @SO_ERROR
%71 = call i64 @getsockopt(i32 %36, i32 %69, i32 %70, i32* %5, i32* %6)
%72 = icmp eq i64 %71, 0
%73 = load i32, i32* %5
%74 = icmp eq i32 %73, 0
%75 = select i1 %72, i1 %74, i1 false
br i1 %75, label %81, label %76
76: ; preds = %63, %68, %60, %56, %38, %42
%77 = call i32 @close(i32 %36)
%78 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %29, i64 0, i32 5
%79 = load %struct.addrinfo*, %struct.addrinfo** %78
%80 = icmp eq %struct.addrinfo* %79, null
br i1 %80, label %81, label %28
81: ; preds = %68, %28, %76
%82 = phi i32 [ -1, %76 ], [ %36, %28 ], [ %36, %68 ]
%83 = load %struct.addrinfo*, %struct.addrinfo** %4
br label %84
84: ; preds = %81, %21
%85 = phi %struct.addrinfo* [ null, %21 ], [ %83, %81 ]
%86 = phi i32 [ -1, %21 ], [ %82, %81 ]
%87 = call i32 @freeaddrinfo(%struct.addrinfo* %85)
br label %88
88: ; preds = %2, %84
%89 = phi i32 [ %86, %84 ], [ -1, %2 ]
ret i32 %89
}