#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 addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};
typedef int /*<<< orphan*/ portstr;
typedef int /*<<< orphan*/ hints;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
scalar_t__ EINPROGRESS;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ anetNonBlock(char *, int);
int /*<<< orphan*/ anetSetError(char *, char *, int /*<<< orphan*/);
int anetSetReuseAddr(char *, int);
int bind(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int /*<<< orphan*/ gai_strerror(int);
int getaddrinfo(char const *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(scalar_t__);
int anetTcpGenericConnect(char *err, const char *addr, int port,
                          const char *source_addr, int flags) {
  int s = -1, rv;
  char portstr[6];
  struct addrinfo hints, *servinfo, *bservinfo, *p, *b;
  snprintf(portstr, sizeof(portstr), "%d", port);
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  if ((rv = getaddrinfo(addr, portstr, &hints, &servinfo)) != 0) {
    anetSetError(err, "%s", gai_strerror(rv));
    return -1;
  }
  for (p = servinfo; p != NULL; p = p->ai_next) {
    if ((s = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1)
      continue;
    if (anetSetReuseAddr(err, s) == -1)
      goto error;
    if (flags & 1 && anetNonBlock(err, s) != 0)
      goto error;
    if (source_addr) {
      int bound = 0;
      if ((rv = getaddrinfo(source_addr, NULL, &hints, &bservinfo)) != 0) {
        anetSetError(err, "%s", gai_strerror(rv));
        goto error;
      }
      for (b = bservinfo; b != NULL; b = b->ai_next) {
        if (bind(s, b->ai_addr, b->ai_addrlen) != -1) {
          bound = 1;
          break;
        }
      }
      freeaddrinfo(bservinfo);
      if (!bound) {
        anetSetError(err, "bind: %s", strerror(errno));
        goto error;
      }
    }
    if (connect(s, p->ai_addr, p->ai_addrlen) == -1) {
      if (errno == EINPROGRESS && flags & 1)
        goto end;
      close(s);
      s = -1;
      continue;
    }
    goto end;
  }
  if (p == NULL)
    anetSetError(err, "creating socket: %s", strerror(errno));
error:
  if (s != -1) {
    close(s);
    s = -1;
  }
end:
  freeaddrinfo(servinfo);
  if (s == -1 && source_addr && (flags & 2)) {
    return anetTcpGenericConnect(err, addr, port, NULL, flags);
  } else {
    return s;
  }
}


x86 assembly (clang, -O0):
<anetTcpGenericConnect>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
movl   $0xffffffff,-0x30(%rbp)
lea    -0x3a(%rbp),%rdi
mov    -0x1c(%rbp),%ecx
mov    $0x6,%esi
lea    0xde8(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2d90(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x3a(%rbp),%rsi
lea    -0x60(%rbp),%rdx
lea    -0x68(%rbp),%rcx
call   10d0 <getaddrinfo@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
je     129a <anetTcpGenericConnect+0xba>
mov    -0x10(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x34(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    -0x90(%rbp),%rdi
mov    %eax,%edx
lea    0xd80(%rip),%rsi
call   1080 <anetSetError@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    154a <anetTcpGenericConnect+0x36a>
mov    -0x68(%rbp),%rax
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
je     149a <anetTcpGenericConnect+0x2ba>
mov    -0x78(%rbp),%rax
mov    0x18(%rax),%edi
mov    -0x78(%rbp),%rax
mov    0x14(%rax),%esi
mov    -0x78(%rbp),%rax
mov    0x10(%rax),%edx
call   1100 <socket@plt>
mov    %eax,-0x30(%rbp)
cmp    $0xffffffff,%eax
jne    12d8 <anetTcpGenericConnect+0xf8>
jmp    1489 <anetTcpGenericConnect+0x2a9>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%esi
call   10a0 <anetSetReuseAddr@plt>
cmp    $0xffffffff,%eax
jne    12f2 <anetTcpGenericConnect+0x112>
jmp    14d9 <anetTcpGenericConnect+0x2f9>
mov    -0x2c(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     131c <anetTcpGenericConnect+0x13c>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%esi
call   1030 <anetNonBlock@plt>
cmp    $0x0,%rax
je     131c <anetTcpGenericConnect+0x13c>
jmp    14d9 <anetTcpGenericConnect+0x2f9>
cmpq   $0x0,-0x28(%rbp)
je     1424 <anetTcpGenericConnect+0x244>
movl   $0x0,-0x84(%rbp)
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x60(%rbp),%rdx
lea    -0x70(%rbp),%rcx
call   10d0 <getaddrinfo@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
je     137f <anetTcpGenericConnect+0x19f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x34(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    -0x98(%rbp),%rdi
mov    %eax,%edx
lea    0xc94(%rip),%rsi
call   1080 <anetSetError@plt>
jmp    14d9 <anetTcpGenericConnect+0x2f9>
mov    -0x70(%rbp),%rax
mov    %rax,-0x80(%rbp)
cmpq   $0x0,-0x80(%rbp)
je     13d5 <anetTcpGenericConnect+0x1f5>
mov    -0x30(%rbp),%edi
mov    -0x80(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x80(%rbp),%rax
mov    (%rax),%edx
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
je     13bf <anetTcpGenericConnect+0x1df>
movl   $0x1,-0x84(%rbp)
jmp    13d5 <anetTcpGenericConnect+0x1f5>
jmp    13c4 <anetTcpGenericConnect+0x1e4>
mov    -0x80(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x80(%rbp)
jmp    1387 <anetTcpGenericConnect+0x1a7>
mov    -0x70(%rbp),%rdi
call   10f0 <freeaddrinfo@plt>
cmpl   $0x0,-0x84(%rbp)
jne    141f <anetTcpGenericConnect+0x23f>
mov    -0x10(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    0x2bcb(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
mov    -0xa0(%rbp),%rdi
mov    %eax,%edx
lea    0xbee(%rip),%rsi
call   1080 <anetSetError@plt>
jmp    14d9 <anetTcpGenericConnect+0x2f9>
jmp    1424 <anetTcpGenericConnect+0x244>
mov    -0x30(%rbp),%edi
mov    -0x78(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x78(%rbp),%rax
mov    (%rax),%edx
call   10c0 <connect@plt>
cmp    $0xffffffff,%eax
jne    1484 <anetTcpGenericConnect+0x2a4>
mov    0x2b7f(%rip),%rax
mov    (%rax),%rax
mov    0x2b95(%rip),%rcx
cmp    (%rcx),%rax
jne    1470 <anetTcpGenericConnect+0x290>
mov    -0x2c(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1470 <anetTcpGenericConnect+0x290>
jmp    14f7 <anetTcpGenericConnect+0x317>
mov    -0x30(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x30(%rbp)
jmp    1489 <anetTcpGenericConnect+0x2a9>
jmp    14f7 <anetTcpGenericConnect+0x317>
mov    -0x78(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x78(%rbp)
jmp    12a2 <anetTcpGenericConnect+0xc2>
cmpq   $0x0,-0x78(%rbp)
jne    14d4 <anetTcpGenericConnect+0x2f4>
mov    -0x10(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    0x2b11(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
mov    -0xa8(%rbp),%rdi
mov    %eax,%edx
lea    0xb3d(%rip),%rsi
call   1080 <anetSetError@plt>
jmp    14d9 <anetTcpGenericConnect+0x2f9>
cmpl   $0xffffffff,-0x30(%rbp)
je     14f2 <anetTcpGenericConnect+0x312>
mov    -0x30(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x30(%rbp)
jmp    14f7 <anetTcpGenericConnect+0x317>
mov    -0x68(%rbp),%rdi
call   10f0 <freeaddrinfo@plt>
cmpl   $0xffffffff,-0x30(%rbp)
jne    1544 <anetTcpGenericConnect+0x364>
cmpq   $0x0,-0x28(%rbp)
je     1544 <anetTcpGenericConnect+0x364>
mov    -0x2c(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     1544 <anetTcpGenericConnect+0x364>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x2c(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%ecx
call   1090 <anetTcpGenericConnect@plt>
mov    %eax,-0x4(%rbp)
jmp    154a <anetTcpGenericConnect+0x36a>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<anetTcpGenericConnect>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %r8d,0x1c(%rsp)
mov    %rcx,%r12
mov    %edx,%r15d
mov    %rsi,%r13
mov    %rdi,%rbx
lea    0xdfa(%rip),%rdx
lea    0x32(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x6,%esi
mov    %r15d,%ecx
call   1040 <snprintf@plt>
lea    0x38(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x50(%rsp)
mov    0x2d8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4c(%rsp)
lea    0x28(%rsp),%rcx
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   10d0 <getaddrinfo@plt>
test   %eax,%eax
je     1282 <anetTcpGenericConnect+0xa2>
mov    %eax,%edi
call   1050 <gai_strerror@plt>
lea    0xd9b(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1080 <anetSetError@plt>
mov    $0xffffffff,%ebp
jmp    143f <anetTcpGenericConnect+0x25f>
mov    %r12,0x20(%rsp)
mov    0x28(%rsp),%r14
test   %r14,%r14
mov    0x1c(%rsp),%r12d
je     13ad <anetTcpGenericConnect+0x1cd>
mov    %rbx,0x8(%rsp)
jmp    12c4 <anetTcpGenericConnect+0xe4>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1070 <close@plt>
mov    0x8(%r14),%r14
test   %r14,%r14
je     13ad <anetTcpGenericConnect+0x1cd>
mov    0x18(%r14),%edi
mov    0x10(%r14),%edx
mov    0x14(%r14),%esi
call   1100 <socket@plt>
cmp    $0xffffffff,%eax
je     12b7 <anetTcpGenericConnect+0xd7>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %eax,%esi
call   10a0 <anetSetReuseAddr@plt>
cmp    $0xffffffff,%eax
je     1401 <anetTcpGenericConnect+0x221>
test   $0x1,%r12b
je     1308 <anetTcpGenericConnect+0x128>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <anetNonBlock@plt>
test   %rax,%rax
jne    1401 <anetTcpGenericConnect+0x221>
mov    0x20(%rsp),%rdi
test   %rdi,%rdi
je     1370 <anetTcpGenericConnect+0x190>
xor    %esi,%esi
lea    0x38(%rsp),%rdx
lea    0x10(%rsp),%rcx
call   10d0 <getaddrinfo@plt>
test   %eax,%eax
jne    1450 <anetTcpGenericConnect+0x270>
mov    %r15d,%ebx
mov    0x10(%rsp),%r15
test   %r15,%r15
je     1460 <anetTcpGenericConnect+0x280>
nopl   0x0(%rax)
mov    (%r15),%edx
mov    0x4(%r15),%esi
mov    %ebp,%edi
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
jne    135e <anetTcpGenericConnect+0x17e>
mov    0x8(%r15),%r15
test   %r15,%r15
jne    1340 <anetTcpGenericConnect+0x160>
jmp    13cf <anetTcpGenericConnect+0x1ef>
mov    0x10(%rsp),%rdi
call   10f0 <freeaddrinfo@plt>
mov    %ebx,%r15d
mov    0x8(%rsp),%rbx
mov    (%r14),%edx
mov    0x4(%r14),%esi
mov    %ebp,%edi
call   10c0 <connect@plt>
cmp    $0xffffffff,%eax
jne    140d <anetTcpGenericConnect+0x22d>
test   $0x1,%r12b
je     12b0 <anetTcpGenericConnect+0xd0>
mov    0x2c50(%rip),%rax
mov    (%rax),%rax
mov    0x2c26(%rip),%rcx
cmp    %rax,(%rcx)
jne    12b0 <anetTcpGenericConnect+0xd0>
jmp    140d <anetTcpGenericConnect+0x22d>
mov    0x2c14(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
lea    0xc49(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1080 <anetSetError@plt>
jmp    1408 <anetTcpGenericConnect+0x228>
mov    0x10(%rsp),%rdi
mov    %ebx,%r15d
mov    0x8(%rsp),%rbx
call   10f0 <freeaddrinfo@plt>
mov    0x2be0(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
lea    0xc0c(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1080 <anetSetError@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    $0xffffffff,%ebp
mov    0x28(%rsp),%rdi
call   10f0 <freeaddrinfo@plt>
test   $0x2,%r12b
je     143f <anetTcpGenericConnect+0x25f>
cmpq   $0x0,0x20(%rsp)
je     143f <anetTcpGenericConnect+0x25f>
cmp    $0xffffffff,%ebp
jne    143f <anetTcpGenericConnect+0x25f>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r15d,%edx
xor    %ecx,%ecx
mov    %r12d,%r8d
call   1090 <anetTcpGenericConnect@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%edi
call   1050 <gai_strerror@plt>
lea    0xbab(%rip),%rsi
jmp    13f7 <anetTcpGenericConnect+0x217>
mov    %ebx,%r15d
mov    0x8(%rsp),%rbx
xor    %edi,%edi
jmp    13dc <anetTcpGenericConnect+0x1fc>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, %struct.addrinfo*, i32, i32, i32 }
@.str = [3 x i8] c"%d\00"
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [9 x i8] c"bind: %s\00"
@errno = global i64 0
@EINPROGRESS = global i64 0
@.str.3 = [20 x i8] c"creating socket: %s\00"
define i32 @anetTcpGenericConnect(i8* %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca [6 x i8]
%15 = alloca %struct.addrinfo
%16 = alloca %struct.addrinfo*
%17 = alloca %struct.addrinfo*
%18 = alloca %struct.addrinfo*
%19 = alloca %struct.addrinfo*
%20 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
store i32 -1, i32* %12
%21 = getelementptr inbounds [6 x i8], [6 x i8]* %14, i64 0, i64 0
%22 = load i32, i32* %9
%23 = call i32 @snprintf(i8* %21, i32 6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = call i32 @memset(%struct.addrinfo* %15, i32 0, i32 32)
%25 = load i32, i32* @AF_UNSPEC
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %15, i32 0, i32 5
store i32 %25, i32* %26
%27 = load i32, i32* @SOCK_STREAM
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %15, i32 0, i32 4
store i32 %27, i32* %28
%29 = load i8*, i8** %8
%30 = getelementptr inbounds [6 x i8], [6 x i8]* %14, i64 0, i64 0
%31 = call i32 @getaddrinfo(i8* %29, i8* %30, %struct.addrinfo* %15, %struct.addrinfo** %16)
store i32 %31, i32* %13
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %5
%34 = load i8*, i8** %7
%35 = load i32, i32* %13
%36 = call i32 @gai_strerror(i32 %35)
%37 = call i32 @anetSetError(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %36)
store i32 -1, i32* %6
br label %179
38: ; preds = %5
%39 = load %struct.addrinfo*, %struct.addrinfo** %16
store %struct.addrinfo* %39, %struct.addrinfo** %18
br label %40
40: ; preds = %139, %38
%41 = load %struct.addrinfo*, %struct.addrinfo** %18
%42 = icmp ne %struct.addrinfo* %41, null
br i1 %42, label %43, label %143
43: ; preds = %40
%44 = load %struct.addrinfo*, %struct.addrinfo** %18
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %44, i32 0, i32 5
%46 = load i32, i32* %45
%47 = load %struct.addrinfo*, %struct.addrinfo** %18
%48 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %47, i32 0, i32 4
%49 = load i32, i32* %48
%50 = load %struct.addrinfo*, %struct.addrinfo** %18
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %50, i32 0, i32 3
%52 = load i32, i32* %51
%53 = call i32 @socket(i32 %46, i32 %49, i32 %52)
store i32 %53, i32* %12
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %56
55: ; preds = %43
br label %139
56: ; preds = %43
%57 = load i8*, i8** %7
%58 = load i32, i32* %12
%59 = call i32 @anetSetReuseAddr(i8* %57, i32 %58)
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %62
61: ; preds = %56
br label %152
62: ; preds = %56
%63 = load i32, i32* %11
%64 = and i32 %63, 1
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %72
66: ; preds = %62
%67 = load i8*, i8** %7
%68 = load i32, i32* %12
%69 = call i64 @anetNonBlock(i8* %67, i32 %68)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %66
br label %152
72: ; preds = %66, %62
%73 = load i8*, i8** %10
%74 = icmp ne i8* %73, null
br i1 %74, label %75, label %116
75: ; preds = %72
store i32 0, i32* %20
%76 = load i8*, i8** %10
%77 = call i32 @getaddrinfo(i8* %76, i8* null, %struct.addrinfo* %15, %struct.addrinfo** %17)
store i32 %77, i32* %13
%78 = icmp ne i32 %77, 0
br i1 %78, label %79, label %84
79: ; preds = %75
%80 = load i8*, i8** %7
%81 = load i32, i32* %13
%82 = call i32 @gai_strerror(i32 %81)
%83 = call i32 @anetSetError(i8* %80, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %82)
br label %152
84: ; preds = %75
%85 = load %struct.addrinfo*, %struct.addrinfo** %17
store %struct.addrinfo* %85, %struct.addrinfo** %19
br label %86
86: ; preds = %101, %84
%87 = load %struct.addrinfo*, %struct.addrinfo** %19
%88 = icmp ne %struct.addrinfo* %87, null
br i1 %88, label %89, label %105
89: ; preds = %86
%90 = load i32, i32* %12
%91 = load %struct.addrinfo*, %struct.addrinfo** %19
%92 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %91, i32 0, i32 1
%93 = load i32, i32* %92
%94 = load %struct.addrinfo*, %struct.addrinfo** %19
%95 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %94, i32 0, i32 0
%96 = load i32, i32* %95
%97 = call i32 @bind(i32 %90, i32 %93, i32 %96)
%98 = icmp ne i32 %97, -1
br i1 %98, label %99, label %100
99: ; preds = %89
store i32 1, i32* %20
br label %105
100: ; preds = %89
br label %101
101: ; preds = %100
%102 = load %struct.addrinfo*, %struct.addrinfo** %19
%103 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %102, i32 0, i32 2
%104 = load %struct.addrinfo*, %struct.addrinfo** %103
store %struct.addrinfo* %104, %struct.addrinfo** %19
br label %86
105: ; preds = %99, %86
%106 = load %struct.addrinfo*, %struct.addrinfo** %17
%107 = call i32 @freeaddrinfo(%struct.addrinfo* %106)
%108 = load i32, i32* %20
%109 = icmp ne i32 %108, 0
br i1 %109, label %115, label %110
110: ; preds = %105
%111 = load i8*, i8** %7
%112 = load i64, i64* @errno
%113 = call i32 @strerror(i64 %112)
%114 = call i32 @anetSetError(i8* %111, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %113)
br label %152
115: ; preds = %105
br label %116
116: ; preds = %115, %72
%117 = load i32, i32* %12
%118 = load %struct.addrinfo*, %struct.addrinfo** %18
%119 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %118, i32 0, i32 1
%120 = load i32, i32* %119
%121 = load %struct.addrinfo*, %struct.addrinfo** %18
%122 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %121, i32 0, i32 0
%123 = load i32, i32* %122
%124 = call i32 @connect(i32 %117, i32 %120, i32 %123)
%125 = icmp eq i32 %124, -1
br i1 %125, label %126, label %138
126: ; preds = %116
%127 = load i64, i64* @errno
%128 = load i64, i64* @EINPROGRESS
%129 = icmp eq i64 %127, %128
br i1 %129, label %130, label %135
130: ; preds = %126
%131 = load i32, i32* %11
%132 = and i32 %131, 1
%133 = icmp ne i32 %132, 0
br i1 %133, label %134, label %135
134: ; preds = %130
br label %159
135: ; preds = %130, %126
%136 = load i32, i32* %12
%137 = call i32 @close(i32 %136)
store i32 -1, i32* %12
br label %139
138: ; preds = %116
br label %159
139: ; preds = %135, %55
%140 = load %struct.addrinfo*, %struct.addrinfo** %18
%141 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %140, i32 0, i32 2
%142 = load %struct.addrinfo*, %struct.addrinfo** %141
store %struct.addrinfo* %142, %struct.addrinfo** %18
br label %40
143: ; preds = %40
%144 = load %struct.addrinfo*, %struct.addrinfo** %18
%145 = icmp eq %struct.addrinfo* %144, null
br i1 %145, label %146, label %151
146: ; preds = %143
%147 = load i8*, i8** %7
%148 = load i64, i64* @errno
%149 = call i32 @strerror(i64 %148)
%150 = call i32 @anetSetError(i8* %147, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %149)
br label %151
151: ; preds = %146, %143
br label %152
152: ; preds = %151, %110, %79, %71, %61
%153 = load i32, i32* %12
%154 = icmp ne i32 %153, -1
br i1 %154, label %155, label %158
155: ; preds = %152
%156 = load i32, i32* %12
%157 = call i32 @close(i32 %156)
store i32 -1, i32* %12
br label %158
158: ; preds = %155, %152
br label %159
159: ; preds = %158, %138, %134
%160 = load %struct.addrinfo*, %struct.addrinfo** %16
%161 = call i32 @freeaddrinfo(%struct.addrinfo* %160)
%162 = load i32, i32* %12
%163 = icmp eq i32 %162, -1
br i1 %163, label %164, label %177
164: ; preds = %159
%165 = load i8*, i8** %10
%166 = icmp ne i8* %165, null
br i1 %166, label %167, label %177
167: ; preds = %164
%168 = load i32, i32* %11
%169 = and i32 %168, 2
%170 = icmp ne i32 %169, 0
br i1 %170, label %171, label %177
171: ; preds = %167
%172 = load i8*, i8** %7
%173 = load i8*, i8** %8
%174 = load i32, i32* %9
%175 = load i32, i32* %11
%176 = call i32 @anetTcpGenericConnect(i8* %172, i8* %173, i32 %174, i8* null, i32 %175)
store i32 %176, i32* %6
br label %179
177: ; preds = %167, %164, %159
%178 = load i32, i32* %12
store i32 %178, i32* %6
br label %179
179: ; preds = %177, %171, %33
%180 = load i32, i32* %6
ret i32 %180
}

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