#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 sockaddr_in6 {
  int /*<<< orphan*/ sin6_port;
};
struct sockaddr {
  int dummy;
};
struct addrinfo {
  struct sockaddr *ai_addr;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};
typedef int /*<<< orphan*/ hints;

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int EINPROGRESS;
int EINTR;
int FD_CLOEXEC;
int /*<<< orphan*/ F_GETFD;
int /*<<< orphan*/ F_SETFD;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ Sactivate_thread();
int /*<<< orphan*/ Sdeactivate_thread();
int /*<<< orphan*/ Slock_object(void *);
int /*<<< orphan*/ Sunlock_object(void *);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int errno;
int fcntl(int, int /*<<< orphan*/, ...);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
scalar_t__ getaddrinfo(char const *, char const *, struct addrinfo *,
                       struct addrinfo **);
int /*<<< orphan*/ htons(unsigned short);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ ss_set_fd_non_blocking(int);
int ss_connect_to_ipv6_host_impl(const char *address, const char *service,
                                 unsigned short port, int blocking) {
  struct addrinfo hints;
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = AF_INET6;
  hints.ai_socktype = SOCK_STREAM;
  Slock_object((void *)address);
  if (service)
    Slock_object((void *)service);
  Sdeactivate_thread();
  struct addrinfo *info;
  int saved_errno = 0;
  if (getaddrinfo(address, service, &hints, &info) || info == NULL) {
    saved_errno = errno;
    Sactivate_thread();
    Sunlock_object((void *)address);
    if (service)
      Sunlock_object((void *)service);
    errno = saved_errno;
    return -1;
  }
  int sock;
  struct addrinfo *tmp;
  int err = 0;
  for (tmp = info; tmp != NULL; tmp = tmp->ai_next) {
    err = 0;
    sock = socket(AF_INET6, SOCK_STREAM, 0);
    if (sock == -1) {
      saved_errno = errno;
      err = -2;
      break;
    }
    fcntl(sock, F_SETFD, fcntl(sock, F_GETFD) | FD_CLOEXEC);
    if (!blocking && !(ss_set_fd_non_blocking(sock))) {
      saved_errno = errno;
      close(sock);
      err = -2;
      break;
    }
    struct sockaddr *in = tmp->ai_addr;
    if (port > 0)
      ((struct sockaddr_in6 *)in)->sin6_port = htons(port);
    int res;
    do {
      res = connect(sock, in, sizeof(struct sockaddr_in6));
    } while (res == -1 && errno == EINTR);
    saved_errno = errno;
    if (res == -1 && errno != EINPROGRESS) {
      close(sock);
      err = -3;
      continue;
    } else
      break;
  }
  Sactivate_thread();
  Sunlock_object((void *)address);
  if (service)
    Sunlock_object((void *)service);
  freeaddrinfo(info);
  errno = saved_errno;
  if (err)
    return err;
  return sock;
}


x86 assembly (clang, -O0):
<ss_connect_to_ipv6_host_impl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %dx,%ax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %ax,-0x1a(%rbp)
mov    %ecx,-0x20(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2dbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <Slock_object@plt>
cmpq   $0x0,-0x18(%rbp)
je     122f <ss_connect_to_ipv6_host_impl+0x5f>
mov    -0x18(%rbp),%rdi
call   1090 <Slock_object@plt>
mov    $0x0,%al
call   1030 <Sdeactivate_thread@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   10d0 <getaddrinfo@plt>
cmp    $0x0,%rax
jne    1267 <ss_connect_to_ipv6_host_impl+0x97>
cmpq   $0x0,-0x40(%rbp)
jne    12af <ss_connect_to_ipv6_host_impl+0xdf>
mov    0x2d4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    $0x0,%al
call   10b0 <Sactivate_thread@plt>
mov    -0x10(%rbp),%rdi
call   10a0 <Sunlock_object@plt>
cmpq   $0x0,-0x18(%rbp)
je     1297 <ss_connect_to_ipv6_host_impl+0xc7>
mov    -0x18(%rbp),%rdi
call   10a0 <Sunlock_object@plt>
mov    -0x44(%rbp),%ecx
mov    0x2d17(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    14a6 <ss_connect_to_ipv6_host_impl+0x2d6>
movl   $0x0,-0x54(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
je     1452 <ss_connect_to_ipv6_host_impl+0x282>
movl   $0x0,-0x54(%rbp)
mov    0x2d09(%rip),%rax
mov    (%rax),%edi
mov    0x2ce8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0xffffffff,-0x48(%rbp)
jne    130e <ss_connect_to_ipv6_host_impl+0x13e>
mov    0x2cbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
movl   $0xfffffffe,-0x54(%rbp)
jmp    1452 <ss_connect_to_ipv6_host_impl+0x282>
mov    -0x48(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    0x2cb5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    -0x48(%rbp),%edi
mov    0x2c86(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1040 <fcntl@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%esi
mov    %eax,%edx
mov    0x2c7e(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1040 <fcntl@plt>
cmpl   $0x0,-0x20(%rbp)
jne    1386 <ss_connect_to_ipv6_host_impl+0x1b6>
mov    -0x48(%rbp),%edi
call   1070 <ss_set_fd_non_blocking@plt>
cmp    $0x0,%eax
jne    1386 <ss_connect_to_ipv6_host_impl+0x1b6>
mov    0x2c4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x48(%rbp),%edi
call   1080 <close@plt>
movl   $0xfffffffe,-0x54(%rbp)
jmp    1452 <ss_connect_to_ipv6_host_impl+0x282>
mov    -0x50(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x60(%rbp)
movzwl -0x1a(%rbp),%eax
cmp    $0x0,%eax
jle    13af <ss_connect_to_ipv6_host_impl+0x1df>
movzwl -0x1a(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,%ecx
mov    -0x60(%rbp),%rax
mov    %ecx,(%rax)
jmp    13b4 <ss_connect_to_ipv6_host_impl+0x1e4>
mov    -0x48(%rbp),%edi
mov    -0x60(%rbp),%rsi
mov    $0x4,%edx
call   10c0 <connect@plt>
mov    %eax,-0x64(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x64(%rbp)
mov    %al,-0x6d(%rbp)
jne    13ef <ss_connect_to_ipv6_host_impl+0x21f>
mov    0x2bda(%rip),%rax
mov    (%rax),%eax
mov    0x2bc1(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
mov    %al,-0x6d(%rbp)
mov    -0x6d(%rbp),%al
test   $0x1,%al
jne    13b4 <ss_connect_to_ipv6_host_impl+0x1e4>
mov    0x2bb7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
jne    143c <ss_connect_to_ipv6_host_impl+0x26c>
mov    0x2ba1(%rip),%rax
mov    (%rax),%eax
mov    0x2bc8(%rip),%rcx
cmp    (%rcx),%eax
je     143c <ss_connect_to_ipv6_host_impl+0x26c>
mov    -0x48(%rbp),%edi
call   1080 <close@plt>
movl   $0xfffffffd,-0x54(%rbp)
jmp    1441 <ss_connect_to_ipv6_host_impl+0x271>
jmp    1452 <ss_connect_to_ipv6_host_impl+0x282>
mov    -0x50(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x50(%rbp)
jmp    12be <ss_connect_to_ipv6_host_impl+0xee>
mov    $0x0,%al
call   10b0 <Sactivate_thread@plt>
mov    -0x10(%rbp),%rdi
call   10a0 <Sunlock_object@plt>
cmpq   $0x0,-0x18(%rbp)
je     1476 <ss_connect_to_ipv6_host_impl+0x2a6>
mov    -0x18(%rbp),%rdi
call   10a0 <Sunlock_object@plt>
mov    -0x40(%rbp),%rdi
call   10e0 <freeaddrinfo@plt>
mov    -0x44(%rbp),%ecx
mov    0x2b2f(%rip),%rax
mov    %ecx,(%rax)
cmpl   $0x0,-0x54(%rbp)
je     14a0 <ss_connect_to_ipv6_host_impl+0x2d0>
mov    -0x54(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    14a6 <ss_connect_to_ipv6_host_impl+0x2d6>
mov    -0x48(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ss_connect_to_ipv6_host_impl>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %ecx,0x24(%rsp)
mov    %edx,0x1c(%rsp)
mov    %rsi,%r14
mov    %rdi,%rbp
lea    0x30(%rsp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x44(%rsp)
mov    0x2db7(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x40(%rsp)
mov    %rbp,%rdi
call   1090 <Slock_object@plt>
test   %r14,%r14
je     122c <ss_connect_to_ipv6_host_impl+0x5c>
mov    %r14,%rdi
call   1090 <Slock_object@plt>
xor    %eax,%eax
call   1030 <Sdeactivate_thread@plt>
lea    0x30(%rsp),%rdx
lea    0x28(%rsp),%rcx
mov    %rbp,%rdi
mov    %r14,%rsi
call   10d0 <getaddrinfo@plt>
test   %rax,%rax
jne    1358 <ss_connect_to_ipv6_host_impl+0x188>
mov    0x28(%rsp),%r13
test   %r13,%r13
je     1358 <ss_connect_to_ipv6_host_impl+0x188>
mov    %rbp,0x8(%rsp)
mov    %r14,0x10(%rsp)
mov    0x2d48(%rip),%r12
mov    0x2d31(%rip),%r15
movzwl 0x1c(%rsp),%eax
mov    %eax,0x20(%rsp)
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
mov    0x2d38(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
cmp    $0xffffffff,%eax
je     1384 <ss_connect_to_ipv6_host_impl+0x1b4>
mov    %eax,%ebp
mov    0x2d25(%rip),%rax
mov    (%rax),%ebx
mov    0x2cfc(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %eax,%eax
call   1040 <fcntl@plt>
mov    0x2cfa(%rip),%rcx
or     (%rcx),%eax
mov    %ebp,%edi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fcntl@plt>
cmpl   $0x0,0x24(%rsp)
jne    12eb <ss_connect_to_ipv6_host_impl+0x11b>
mov    %ebp,%edi
call   1070 <ss_set_fd_non_blocking@plt>
test   %eax,%eax
je     138a <ss_connect_to_ipv6_host_impl+0x1ba>
mov    0x0(%r13),%r14
cmpw   $0x0,0x1c(%rsp)
je     1310 <ss_connect_to_ipv6_host_impl+0x140>
mov    0x20(%rsp),%edi
call   1050 <htons@plt>
mov    %eax,(%r14)
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   10c0 <connect@plt>
mov    (%r12),%ebx
cmp    $0xffffffff,%eax
jne    132d <ss_connect_to_ipv6_host_impl+0x15d>
cmp    (%r15),%ebx
je     1310 <ss_connect_to_ipv6_host_impl+0x140>
cmp    $0xffffffff,%eax
jne    139a <ss_connect_to_ipv6_host_impl+0x1ca>
mov    0x2caf(%rip),%rax
cmp    (%rax),%ebx
je     139a <ss_connect_to_ipv6_host_impl+0x1ca>
mov    %ebp,%edi
call   1080 <close@plt>
mov    0x8(%r13),%r13
test   %r13,%r13
jne    1280 <ss_connect_to_ipv6_host_impl+0xb0>
mov    $0xfffffffd,%ebp
jmp    139a <ss_connect_to_ipv6_host_impl+0x1ca>
mov    0x2c59(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   10b0 <Sactivate_thread@plt>
mov    %rbp,%rdi
call   10a0 <Sunlock_object@plt>
mov    $0xffffffff,%ebp
test   %r14,%r14
je     13ca <ss_connect_to_ipv6_host_impl+0x1fa>
mov    %r14,%rdi
call   10a0 <Sunlock_object@plt>
jmp    13ca <ss_connect_to_ipv6_host_impl+0x1fa>
mov    (%r12),%ebx
jmp    1395 <ss_connect_to_ipv6_host_impl+0x1c5>
mov    (%r12),%ebx
mov    %ebp,%edi
call   1080 <close@plt>
mov    $0xfffffffe,%ebp
mov    0x10(%rsp),%r14
mov    0x8(%rsp),%r15
xor    %eax,%eax
call   10b0 <Sactivate_thread@plt>
mov    %r15,%rdi
call   10a0 <Sunlock_object@plt>
test   %r14,%r14
je     13c0 <ss_connect_to_ipv6_host_impl+0x1f0>
mov    %r14,%rdi
call   10a0 <Sunlock_object@plt>
mov    0x28(%rsp),%rdi
call   10e0 <freeaddrinfo@plt>
mov    0x2be7(%rip),%rax
mov    %ebx,(%rax)
mov    %ebp,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { %struct.sockaddr*, %struct.addrinfo*, i32, i32 }
%struct.sockaddr = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@AF_INET6 = global i32 0
@SOCK_STREAM = global i32 0
@errno = global i32 0
@F_SETFD = global i32 0
@F_GETFD = global i32 0
@FD_CLOEXEC = global i32 0
@EINTR = global i32 0
@EINPROGRESS = global i32 0
define i32 @ss_connect_to_ipv6_host_impl(i8* %0, i8* %1, i16 zeroext %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i16
%9 = alloca i32
%10 = alloca %struct.addrinfo
%11 = alloca %struct.addrinfo*
%12 = alloca i32
%13 = alloca i32
%14 = alloca %struct.addrinfo*
%15 = alloca i32
%16 = alloca %struct.sockaddr*
%17 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i16 %2, i16* %8
store i32 %3, i32* %9
%18 = call i32 @memset(%struct.addrinfo* %10, i32 0, i32 24)
%19 = load i32, i32* @AF_INET6
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 3
store i32 %19, i32* %20
%21 = load i32, i32* @SOCK_STREAM
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 2
store i32 %21, i32* %22
%23 = load i8*, i8** %6
%24 = call i32 @Slock_object(i8* %23)
%25 = load i8*, i8** %7
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %30
27: ; preds = %4
%28 = load i8*, i8** %7
%29 = call i32 @Slock_object(i8* %28)
br label %30
30: ; preds = %27, %4
%31 = call i32 (...) @Sdeactivate_thread()
store i32 0, i32* %12
%32 = load i8*, i8** %6
%33 = load i8*, i8** %7
%34 = call i64 @getaddrinfo(i8* %32, i8* %33, %struct.addrinfo* %10, %struct.addrinfo** %11)
%35 = icmp ne i64 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %30
%37 = load %struct.addrinfo*, %struct.addrinfo** %11
%38 = icmp eq %struct.addrinfo* %37, null
br i1 %38, label %39, label %51
39: ; preds = %36, %30
%40 = load i32, i32* @errno
store i32 %40, i32* %12
%41 = call i32 (...) @Sactivate_thread()
%42 = load i8*, i8** %6
%43 = call i32 @Sunlock_object(i8* %42)
%44 = load i8*, i8** %7
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %49
46: ; preds = %39
%47 = load i8*, i8** %7
%48 = call i32 @Sunlock_object(i8* %47)
br label %49
49: ; preds = %46, %39
%50 = load i32, i32* %12
store i32 %50, i32* @errno
store i32 -1, i32* %5
br label %145
51: ; preds = %36
store i32 0, i32* %15
%52 = load %struct.addrinfo*, %struct.addrinfo** %11
store %struct.addrinfo* %52, %struct.addrinfo** %14
br label %53
53: ; preds = %122, %51
%54 = load %struct.addrinfo*, %struct.addrinfo** %14
%55 = icmp ne %struct.addrinfo* %54, null
br i1 %55, label %56, label %126
56: ; preds = %53
store i32 0, i32* %15
%57 = load i32, i32* @AF_INET6
%58 = load i32, i32* @SOCK_STREAM
%59 = call i32 @socket(i32 %57, i32 %58, i32 0)
store i32 %59, i32* %13
%60 = load i32, i32* %13
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %64
62: ; preds = %56
%63 = load i32, i32* @errno
store i32 %63, i32* %12
store i32 -2, i32* %15
br label %126
64: ; preds = %56
%65 = load i32, i32* %13
%66 = load i32, i32* @F_SETFD
%67 = load i32, i32* %13
%68 = load i32, i32* @F_GETFD
%69 = call i32 (i32, i32, ...) @fcntl(i32 %67, i32 %68)
%70 = load i32, i32* @FD_CLOEXEC
%71 = or i32 %69, %70
%72 = call i32 (i32, i32, ...) @fcntl(i32 %65, i32 %66, i32 %71)
%73 = load i32, i32* %9
%74 = icmp ne i32 %73, 0
br i1 %74, label %83, label %75
75: ; preds = %64
%76 = load i32, i32* %13
%77 = call i32 @ss_set_fd_non_blocking(i32 %76)
%78 = icmp ne i32 %77, 0
br i1 %78, label %83, label %79
79: ; preds = %75
%80 = load i32, i32* @errno
store i32 %80, i32* %12
%81 = load i32, i32* %13
%82 = call i32 @close(i32 %81)
store i32 -2, i32* %15
br label %126
83: ; preds = %75, %64
%84 = load %struct.addrinfo*, %struct.addrinfo** %14
%85 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %84, i32 0, i32 0
%86 = load %struct.sockaddr*, %struct.sockaddr** %85
store %struct.sockaddr* %86, %struct.sockaddr** %16
%87 = load i16, i16* %8
%88 = zext i16 %87 to i32
%89 = icmp sgt i32 %88, 0
br i1 %89, label %90, label %96
90: ; preds = %83
%91 = load i16, i16* %8
%92 = call i32 @htons(i16 zeroext %91)
%93 = load %struct.sockaddr*, %struct.sockaddr** %16
%94 = bitcast %struct.sockaddr* %93 to %struct.sockaddr_in6*
%95 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %94, i32 0, i32 0
store i32 %92, i32* %95
br label %96
96: ; preds = %90, %83
br label %97
97: ; preds = %108, %96
%98 = load i32, i32* %13
%99 = load %struct.sockaddr*, %struct.sockaddr** %16
%100 = call i32 @connect(i32 %98, %struct.sockaddr* %99, i32 4)
store i32 %100, i32* %17
br label %101
101: ; preds = %97
%102 = load i32, i32* %17
%103 = icmp eq i32 %102, -1
br i1 %103, label %104, label %108
104: ; preds = %101
%105 = load i32, i32* @errno
%106 = load i32, i32* @EINTR
%107 = icmp eq i32 %105, %106
br label %108
108: ; preds = %104, %101
%109 = phi i1 [ false, %101 ], [ %107, %104 ]
br i1 %109, label %97, label %110
110: ; preds = %108
%111 = load i32, i32* @errno
store i32 %111, i32* %12
%112 = load i32, i32* %17
%113 = icmp eq i32 %112, -1
br i1 %113, label %114, label %121
114: ; preds = %110
%115 = load i32, i32* @errno
%116 = load i32, i32* @EINPROGRESS
%117 = icmp ne i32 %115, %116
br i1 %117, label %118, label %121
118: ; preds = %114
%119 = load i32, i32* %13
%120 = call i32 @close(i32 %119)
store i32 -3, i32* %15
br label %122
121: ; preds = %114, %110
br label %126
122: ; preds = %118
%123 = load %struct.addrinfo*, %struct.addrinfo** %14
%124 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %123, i32 0, i32 1
%125 = load %struct.addrinfo*, %struct.addrinfo** %124
store %struct.addrinfo* %125, %struct.addrinfo** %14
br label %53
126: ; preds = %121, %79, %62, %53
%127 = call i32 (...) @Sactivate_thread()
%128 = load i8*, i8** %6
%129 = call i32 @Sunlock_object(i8* %128)
%130 = load i8*, i8** %7
%131 = icmp ne i8* %130, null
br i1 %131, label %132, label %135
132: ; preds = %126
%133 = load i8*, i8** %7
%134 = call i32 @Sunlock_object(i8* %133)
br label %135
135: ; preds = %132, %126
%136 = load %struct.addrinfo*, %struct.addrinfo** %11
%137 = call i32 @freeaddrinfo(%struct.addrinfo* %136)
%138 = load i32, i32* %12
store i32 %138, i32* @errno
%139 = load i32, i32* %15
%140 = icmp ne i32 %139, 0
br i1 %140, label %141, label %143
141: ; preds = %135
%142 = load i32, i32* %15
store i32 %142, i32* %5
br label %145
143: ; preds = %135
%144 = load i32, i32* %13
store i32 %144, i32* %5
br label %145
145: ; preds = %143, %141, %49
%146 = load i32, i32* %5
ret i32 %146
}

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