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

/* Variables and functions */
int EADDRNOTAVAIL;
int EINPROGRESS;
int /*<<< orphan*/ PF_UNSPEC;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(char const *, char const *, struct addrinfo *,
                struct addrinfo **);
scalar_t__ m_malloc(int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ set_sock_priority(int);
int /*<<< orphan*/ setnonblocking(int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
char *strerror(int);
int strlen(char *);
int connect_remote(const char *remotehost, const char *remoteport,
                   int nonblocking, char **errstring) {
  struct addrinfo *res0 = NULL, *res = NULL, hints;
  int sock;
  int err;
  if (errstring != NULL)
    *errstring = NULL;
  memset(&hints, 0, sizeof(hints));
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_family = PF_UNSPEC;
  err = getaddrinfo(remotehost, remoteport, &hints, &res0);
  if (err) {
    if (errstring != NULL && *errstring == NULL) {
      int len;
      len = 100 + strlen(gai_strerror(err));
      *errstring = (char *)m_malloc(len);
      snprintf(*errstring, len, "Error resolving '%s' port '%s'. %s",
               remotehost, remoteport, gai_strerror(err));
    }
    return -1;
  }
  sock = -1;
  err = EADDRNOTAVAIL;
  for (res = res0; res; res = res->ai_next) {
    sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
    if (sock < 0) {
      err = errno;
      continue;
    }
    if (nonblocking) {
      setnonblocking(sock);
    }
    if (connect(sock, res->ai_addr, res->ai_addrlen) < 0) {
      if (errno == EINPROGRESS && nonblocking) {
        break;
      } else {
        err = errno;
        close(sock);
        sock = -1;
        continue;
      }
    }
    break;
  }
  if (sock < 0 && !(errno == EINPROGRESS && nonblocking)) {
    if (errstring != NULL && *errstring == NULL) {
      int len;
      len = 20 + strlen(strerror(err));
      *errstring = (char *)m_malloc(len);
      snprintf(*errstring, len, "Error connecting: %s", strerror(err));
    }
  } else {
    set_sock_priority(sock);
  }
  freeaddrinfo(res0);
  if (sock > 0 && errstring != NULL && *errstring != NULL) {
    free(*errstring);
    (*errstring) = NULL;
    ;
  }
  return sock;
}


x86 assembly (clang, -O0):
<connect_remote>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1220 <connect_remote+0x40>
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
lea    -0x58(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1080 <memset@plt>
mov    0x2d91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2da5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x58(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   10d0 <getaddrinfo@plt>
mov    %eax,-0x60(%rbp)
cmpl   $0x0,-0x60(%rbp)
je     1306 <connect_remote+0x126>
cmpq   $0x0,-0x28(%rbp)
je     12fa <connect_remote+0x11a>
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
jne    12fa <connect_remote+0x11a>
mov    -0x60(%rbp),%edi
call   1070 <gai_strerror@plt>
mov    %rax,%rdi
call   1050 <strlen@plt>
add    $0x64,%eax
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%edi
call   10a0 <m_malloc@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x88(%rbp)
mov    -0x64(%rbp),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x60(%rbp),%edi
call   1070 <gai_strerror@plt>
mov    -0x88(%rbp),%rdi
mov    -0x7c(%rbp),%esi
mov    -0x78(%rbp),%rcx
mov    -0x70(%rbp),%r8
mov    %rax,%r9
lea    0xd0d(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14f2 <connect_remote+0x312>
movl   $0xffffffff,-0x5c(%rbp)
mov    0x2cc4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     13f2 <connect_remote+0x212>
mov    -0x38(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x38(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%edx
call   1100 <socket@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jge    1364 <connect_remote+0x184>
mov    0x2c66(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
jmp    13e1 <connect_remote+0x201>
cmpl   $0x0,-0x1c(%rbp)
je     1376 <connect_remote+0x196>
mov    -0x5c(%rbp),%edi
call   10b0 <setnonblocking@plt>
mov    -0x5c(%rbp),%edi
mov    -0x38(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
call   10c0 <connect@plt>
cmp    $0x0,%rax
jge    13dc <connect_remote+0x1fc>
mov    0x2c24(%rip),%rax
mov    (%rax),%eax
mov    0x2c3b(%rip),%rcx
cmp    (%rcx),%eax
jne    13bc <connect_remote+0x1dc>
cmpl   $0x0,-0x1c(%rbp)
je     13bc <connect_remote+0x1dc>
jmp    13f2 <connect_remote+0x212>
mov    0x2bfd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    -0x5c(%rbp),%edi
call   1090 <close@plt>
movl   $0xffffffff,-0x5c(%rbp)
jmp    13e1 <connect_remote+0x201>
jmp    13f2 <connect_remote+0x212>
mov    -0x38(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    1321 <connect_remote+0x141>
cmpl   $0x0,-0x5c(%rbp)
jge    14a1 <connect_remote+0x2c1>
mov    0x2bbd(%rip),%rax
mov    (%rax),%eax
mov    0x2bd4(%rip),%rcx
cmp    (%rcx),%eax
jne    141e <connect_remote+0x23e>
cmpl   $0x0,-0x1c(%rbp)
jne    14a1 <connect_remote+0x2c1>
cmpq   $0x0,-0x28(%rbp)
je     149c <connect_remote+0x2bc>
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
jne    149c <connect_remote+0x2bc>
mov    -0x60(%rbp),%edi
call   10e0 <strerror@plt>
mov    %rax,%rdi
call   1050 <strlen@plt>
add    $0x14,%eax
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%edi
call   10a0 <m_malloc@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x98(%rbp)
mov    -0x68(%rbp),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x60(%rbp),%edi
call   10e0 <strerror@plt>
mov    -0x98(%rbp),%rdi
mov    -0x8c(%rbp),%esi
mov    %rax,%rcx
lea    0xb8e(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
jmp    14a9 <connect_remote+0x2c9>
mov    -0x5c(%rbp),%edi
call   1040 <set_sock_priority@plt>
mov    -0x30(%rbp),%rdi
call   10f0 <freeaddrinfo@plt>
cmpl   $0x0,-0x5c(%rbp)
jle    14ec <connect_remote+0x30c>
cmpq   $0x0,-0x28(%rbp)
je     14ec <connect_remote+0x30c>
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
je     14ec <connect_remote+0x30c>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x5c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<connect_remote>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rcx,%r14
mov    %edx,%r13d
mov    %rsi,%r15
mov    %rdi,%r12
movq   $0x0,0x8(%rsp)
test   %rcx,%rcx
je     120f <connect_remote+0x2f>
movq   $0x0,(%r14)
lea    0x18(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1080 <memset@plt>
mov    0x2d9e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x24(%rsp)
mov    0x2db1(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
lea    0x8(%rsp),%rcx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   10d0 <getaddrinfo@plt>
test   %eax,%eax
je     12b9 <connect_remote+0xd9>
mov    $0xffffffff,%ebp
test   %r14,%r14
je     138c <connect_remote+0x1ac>
cmpq   $0x0,(%r14)
jne    138c <connect_remote+0x1ac>
mov    %eax,%ebx
mov    %eax,%edi
call   1070 <gai_strerror@plt>
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0x64(%rax),%edi
mov    %edi,0x14(%rsp)
call   10a0 <m_malloc@plt>
mov    %rax,%r13
mov    %rax,(%r14)
mov    %ebx,%edi
call   1070 <gai_strerror@plt>
lea    0xd63(%rip),%rdx
mov    %r13,%rdi
mov    0x14(%rsp),%esi
mov    %r12,%rcx
mov    %r15,%r8
mov    %rax,%r9
xor    %eax,%eax
call   1060 <snprintf@plt>
jmp    138c <connect_remote+0x1ac>
mov    0x8(%rsp),%rbx
test   %rbx,%rbx
je     1336 <connect_remote+0x156>
mov    0x2cf6(%rip),%r12
jmp    12e5 <connect_remote+0x105>
nopl   0x0(%rax)
mov    %ebp,%edi
call   1090 <close@plt>
mov    $0xffffffff,%ebp
mov    0x18(%rbx),%rbx
test   %rbx,%rbx
je     1345 <connect_remote+0x165>
mov    0x10(%rbx),%edi
mov    0x8(%rbx),%edx
mov    0xc(%rbx),%esi
call   1100 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1330 <connect_remote+0x150>
test   %r13d,%r13d
je     1305 <connect_remote+0x125>
mov    %ebp,%edi
call   10b0 <setnonblocking@plt>
mov    (%rbx),%edx
mov    0x4(%rbx),%esi
mov    %ebp,%edi
call   10c0 <connect@plt>
test   %rax,%rax
jns    135e <connect_remote+0x17e>
mov    (%r12),%r15d
test   %r13d,%r13d
je     12d0 <connect_remote+0xf0>
mov    0x2cba(%rip),%rax
cmp    (%rax),%r15d
jne    12d0 <connect_remote+0xf0>
jmp    135e <connect_remote+0x17e>
nopl   (%rax)
mov    (%r12),%r15d
jmp    12dc <connect_remote+0xfc>
mov    0x2c9b(%rip),%rax
mov    (%rax),%r15d
mov    $0xffffffff,%ebp
test   %r13d,%r13d
je     139d <connect_remote+0x1bd>
mov    0x2c6f(%rip),%rax
mov    0x2c88(%rip),%rcx
mov    (%rcx),%ecx
cmp    %ecx,(%rax)
jne    139d <connect_remote+0x1bd>
mov    %ebp,%edi
call   1040 <set_sock_priority@plt>
mov    0x8(%rsp),%rdi
call   10f0 <freeaddrinfo@plt>
test   %r14,%r14
je     138c <connect_remote+0x1ac>
test   %ebp,%ebp
jle    138c <connect_remote+0x1ac>
mov    (%r14),%rdi
test   %rdi,%rdi
je     138c <connect_remote+0x1ac>
call   1030 <free@plt>
movq   $0x0,(%r14)
mov    %ebp,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
test   %r14,%r14
je     1365 <connect_remote+0x185>
cmpq   $0x0,(%r14)
jne    1365 <connect_remote+0x185>
mov    %r15d,%edi
call   10e0 <strerror@plt>
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0x14(%rax),%ebx
mov    %ebx,%edi
call   10a0 <m_malloc@plt>
mov    %rax,%r12
mov    %rax,(%r14)
mov    %r15d,%edi
call   10e0 <strerror@plt>
lea    0xc4c(%rip),%rdx
mov    %r12,%rdi
mov    %ebx,%esi
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <snprintf@plt>
jmp    1365 <connect_remote+0x185>

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

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