#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 *, 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, char *addr, int port, 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 end;
      }
      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 end;
      }
    }
    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);
  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    0xdf8(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2da0(%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   10c0 <getaddrinfo@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
je     128a <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    0xd90(%rip),%rsi
call   1080 <anetSetError@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14f6 <anetTcpGenericConnect+0x326>
mov    -0x68(%rbp),%rax
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
je     148a <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   10f0 <socket@plt>
mov    %eax,-0x30(%rbp)
cmp    $0xffffffff,%eax
jne    12c8 <anetTcpGenericConnect+0xf8>
jmp    1479 <anetTcpGenericConnect+0x2a9>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%esi
call   1090 <anetSetReuseAddr@plt>
cmp    $0xffffffff,%eax
jne    12e2 <anetTcpGenericConnect+0x112>
jmp    14c9 <anetTcpGenericConnect+0x2f9>
mov    -0x2c(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     130c <anetTcpGenericConnect+0x13c>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%esi
call   1030 <anetNonBlock@plt>
cmp    $0x0,%rax
je     130c <anetTcpGenericConnect+0x13c>
jmp    14c9 <anetTcpGenericConnect+0x2f9>
cmpq   $0x0,-0x28(%rbp)
je     1414 <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   10c0 <getaddrinfo@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
je     136f <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    0xca4(%rip),%rsi
call   1080 <anetSetError@plt>
jmp    14e7 <anetTcpGenericConnect+0x317>
mov    -0x70(%rbp),%rax
mov    %rax,-0x80(%rbp)
cmpq   $0x0,-0x80(%rbp)
je     13c5 <anetTcpGenericConnect+0x1f5>
mov    -0x30(%rbp),%edi
mov    -0x80(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x80(%rbp),%rax
mov    (%rax),%edx
call   10a0 <bind@plt>
cmp    $0xffffffff,%eax
je     13af <anetTcpGenericConnect+0x1df>
movl   $0x1,-0x84(%rbp)
jmp    13c5 <anetTcpGenericConnect+0x1f5>
jmp    13b4 <anetTcpGenericConnect+0x1e4>
mov    -0x80(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x80(%rbp)
jmp    1377 <anetTcpGenericConnect+0x1a7>
mov    -0x70(%rbp),%rdi
call   10e0 <freeaddrinfo@plt>
cmpl   $0x0,-0x84(%rbp)
jne    140f <anetTcpGenericConnect+0x23f>
mov    -0x10(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    0x2bdb(%rip),%rax
mov    (%rax),%rdi
call   10d0 <strerror@plt>
mov    -0xa0(%rbp),%rdi
mov    %eax,%edx
lea    0xbfe(%rip),%rsi
call   1080 <anetSetError@plt>
jmp    14e7 <anetTcpGenericConnect+0x317>
jmp    1414 <anetTcpGenericConnect+0x244>
mov    -0x30(%rbp),%edi
mov    -0x78(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x78(%rbp),%rax
mov    (%rax),%edx
call   10b0 <connect@plt>
cmp    $0xffffffff,%eax
jne    1474 <anetTcpGenericConnect+0x2a4>
mov    0x2b8f(%rip),%rax
mov    (%rax),%rax
mov    0x2ba5(%rip),%rcx
cmp    (%rcx),%rax
jne    1460 <anetTcpGenericConnect+0x290>
mov    -0x2c(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1460 <anetTcpGenericConnect+0x290>
jmp    14e7 <anetTcpGenericConnect+0x317>
mov    -0x30(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x30(%rbp)
jmp    1479 <anetTcpGenericConnect+0x2a9>
jmp    14e7 <anetTcpGenericConnect+0x317>
mov    -0x78(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x78(%rbp)
jmp    1292 <anetTcpGenericConnect+0xc2>
cmpq   $0x0,-0x78(%rbp)
jne    14c4 <anetTcpGenericConnect+0x2f4>
mov    -0x10(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    0x2b21(%rip),%rax
mov    (%rax),%rdi
call   10d0 <strerror@plt>
mov    -0xa8(%rbp),%rdi
mov    %eax,%edx
lea    0xb4d(%rip),%rsi
call   1080 <anetSetError@plt>
jmp    14c9 <anetTcpGenericConnect+0x2f9>
cmpl   $0xffffffff,-0x30(%rbp)
je     14e2 <anetTcpGenericConnect+0x312>
mov    -0x30(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x30(%rbp)
jmp    14e7 <anetTcpGenericConnect+0x317>
mov    -0x68(%rbp),%rdi
call   10e0 <freeaddrinfo@plt>
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    $0x48,%rsp
mov    %r8d,%r15d
mov    %rcx,%r14
mov    %edx,%ecx
mov    %rsi,%rbp
mov    %rdi,%r13
lea    0xe0d(%rip),%rdx
lea    0x22(%rsp),%r12
mov    %r12,%rdi
mov    $0x6,%esi
call   1040 <snprintf@plt>
lea    0x28(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x40(%rsp)
mov    0x2da3(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x3c(%rsp)
lea    0x18(%rsp),%rcx
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   10c0 <getaddrinfo@plt>
test   %eax,%eax
je     126c <anetTcpGenericConnect+0x9c>
mov    %eax,%edi
call   1050 <gai_strerror@plt>
lea    0xdb1(%rip),%rsi
mov    %r13,%rdi
mov    %eax,%edx
call   1080 <anetSetError@plt>
mov    $0xffffffff,%ebp
jmp    13e8 <anetTcpGenericConnect+0x218>
mov    0x18(%rsp),%rbx
test   %rbx,%rbx
je     138d <anetTcpGenericConnect+0x1bd>
lea    0x28(%rsp),%r12
mov    %r15d,0x14(%rsp)
jmp    12a4 <anetTcpGenericConnect+0xd4>
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1070 <close@plt>
mov    0x8(%rbx),%rbx
test   %rbx,%rbx
je     138d <anetTcpGenericConnect+0x1bd>
mov    0x18(%rbx),%edi
mov    0x10(%rbx),%edx
mov    0x14(%rbx),%esi
call   10f0 <socket@plt>
cmp    $0xffffffff,%eax
je     1297 <anetTcpGenericConnect+0xc7>
mov    %eax,%ebp
mov    %r13,%rdi
mov    %eax,%esi
call   1090 <anetSetReuseAddr@plt>
cmp    $0xffffffff,%eax
je     13f9 <anetTcpGenericConnect+0x229>
test   $0x1,%r15b
je     12e5 <anetTcpGenericConnect+0x115>
mov    %r13,%rdi
mov    %ebp,%esi
call   1030 <anetNonBlock@plt>
test   %rax,%rax
jne    13f9 <anetTcpGenericConnect+0x229>
test   %r14,%r14
je     1356 <anetTcpGenericConnect+0x186>
mov    %r14,%rdi
xor    %esi,%esi
mov    %r12,%rdx
lea    0x8(%rsp),%rcx
call   10c0 <getaddrinfo@plt>
test   %eax,%eax
jne    1402 <anetTcpGenericConnect+0x232>
mov    %r14,%r15
mov    %r12,%r14
mov    0x8(%rsp),%r12
test   %r12,%r12
je     1412 <anetTcpGenericConnect+0x242>
nopl   0x0(%rax,%rax,1)
mov    (%r12),%edx
mov    0x4(%r12),%esi
mov    %ebp,%edi
call   10a0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1341 <anetTcpGenericConnect+0x171>
mov    0x8(%r12),%r12
test   %r12,%r12
jne    1320 <anetTcpGenericConnect+0x150>
jmp    13b4 <anetTcpGenericConnect+0x1e4>
mov    0x8(%rsp),%rdi
call   10e0 <freeaddrinfo@plt>
mov    %r14,%r12
mov    %r15,%r14
mov    0x14(%rsp),%r15d
mov    (%rbx),%edx
mov    0x4(%rbx),%esi
mov    %ebp,%edi
call   10b0 <connect@plt>
cmp    $0xffffffff,%eax
jne    13de <anetTcpGenericConnect+0x20e>
test   $0x1,%r15b
je     1290 <anetTcpGenericConnect+0xc0>
mov    0x2c70(%rip),%rax
mov    (%rax),%rax
mov    0x2c46(%rip),%rcx
cmp    %rax,(%rcx)
jne    1290 <anetTcpGenericConnect+0xc0>
jmp    13de <anetTcpGenericConnect+0x20e>
mov    0x2c34(%rip),%rax
mov    (%rax),%rdi
call   10d0 <strerror@plt>
lea    0xc69(%rip),%rsi
mov    %r13,%rdi
mov    %eax,%edx
call   1080 <anetSetError@plt>
mov    $0xffffffff,%ebp
jmp    13de <anetTcpGenericConnect+0x20e>
mov    0x8(%rsp),%rdi
call   10e0 <freeaddrinfo@plt>
mov    0x2c03(%rip),%rax
mov    (%rax),%rdi
call   10d0 <strerror@plt>
lea    0xc2f(%rip),%rsi
mov    %r13,%rdi
mov    %eax,%edx
call   1080 <anetSetError@plt>
mov    0x18(%rsp),%rdi
call   10e0 <freeaddrinfo@plt>
mov    %ebp,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebp,%edi
call   1070 <close@plt>
jmp    13ad <anetTcpGenericConnect+0x1dd>
mov    %eax,%edi
call   1050 <gai_strerror@plt>
lea    0xbf9(%rip),%rsi
jmp    13d4 <anetTcpGenericConnect+0x204>
xor    %edi,%edi
jmp    13b9 <anetTcpGenericConnect+0x1e9>

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 %163
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 %159
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 %159
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, %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, %110, %79
%160 = load %struct.addrinfo*, %struct.addrinfo** %16
%161 = call i32 @freeaddrinfo(%struct.addrinfo* %160)
%162 = load i32, i32* %12
store i32 %162, i32* %6
br label %163
163: ; preds = %159, %33
%164 = load i32, i32* %6
ret i32 %164
}

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 %100, 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 %110
32: ; preds = %25, %96
%33 = phi %struct.addrinfo* [ %23, %25 ], [ %98, %96 ]
%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 %96, 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 %82, 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 %73, 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 %106
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 %71, 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 %79
71: ; preds = %59
%72 = load %struct.addrinfo*, %struct.addrinfo** %9
br label %73
73: ; preds = %53, %71
%74 = phi %struct.addrinfo* [ %72, %71 ], [ null, %53 ]
%75 = call i32 @freeaddrinfo(%struct.addrinfo* %74)
%76 = load i64, i64* @errno
%77 = call i32 @strerror(i64 %76)
%78 = call i32 @anetSetError(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %77)
br label %106
79: ; preds = %63
%80 = load %struct.addrinfo*, %struct.addrinfo** %9
%81 = call i32 @freeaddrinfo(%struct.addrinfo* %80)
br label %82
82: ; preds = %79, %49
%83 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %33, i64 0, i32 1
%84 = load i32, i32* %83
%85 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %33, i64 0, i32 0
%86 = load i32, i32* %85
%87 = call i32 @connect(i32 %40, i32 %84, i32 %86)
%88 = icmp eq i32 %87, -1
br i1 %88, label %89, label %106
89: ; preds = %82
%90 = load i64, i64* @errno
%91 = load i64, i64* @EINPROGRESS
%92 = icmp ne i64 %90, %91
%93 = or i1 %27, %92
br i1 %93, label %94, label %106
94: ; preds = %89
%95 = call i32 @close(i32 %40)
br label %96
96: ; preds = %32, %94
%97 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %33, i64 0, i32 2
%98 = load %struct.addrinfo*, %struct.addrinfo** %97
%99 = icmp eq %struct.addrinfo* %98, null
br i1 %99, label %100, label %32
100: ; preds = %96, %22
%101 = load i64, i64* @errno
%102 = call i32 @strerror(i64 %101)
%103 = call i32 @anetSetError(i8* %0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %102)
br label %106
104: ; preds = %42, %46
%105 = call i32 @close(i32 %40)
br label %106
106: ; preds = %89, %82, %73, %56, %100, %104
%107 = phi i32 [ -1, %104 ], [ -1, %100 ], [ %40, %56 ], [ %40, %73 ], [ %40, %82 ], [ %40, %89 ]
%108 = load %struct.addrinfo*, %struct.addrinfo** %8
%109 = call i32 @freeaddrinfo(%struct.addrinfo* %108)
br label %110
110: ; preds = %106, %29
%111 = phi i32 [ -1, %29 ], [ %107, %106 ]
ret i32 %111
}