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

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ SSL_connect(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_set_fd(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
scalar_t__ getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int sslConnect(SSL *ssl, char *node, char *service) {
  struct addrinfo hints, *lst, *p;
  int sd;
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  if (getaddrinfo(node, service, &hints, &lst) == 0) {
    for (p = lst; p; p = p->ai_next) {
      if ((sd = socket(p->ai_family, p->ai_socktype, 0)) >= 0) {
        if (connect(sd, p->ai_addr, p->ai_addrlen) == 0) {
          SSL_set_fd(ssl, sd);
          if (SSL_connect(ssl) >= 0) {
            freeaddrinfo(lst);
            return sd;
          }
        }
        close(sd);
      }
    }
    freeaddrinfo(lst);
  }
  return -1;
}


x86 assembly (clang, -O0):
<sslConnect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   1080 <getaddrinfo@plt>
cmp    $0x0,%rax
jne    128d <sslConnect+0x10d>
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     1284 <sslConnect+0x104>
mov    -0x48(%rbp),%rax
mov    0xc(%rax),%edi
mov    -0x48(%rbp),%rax
mov    0x8(%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x4c(%rbp)
cmp    $0x0,%eax
jl     126e <sslConnect+0xee>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x48(%rbp),%rax
mov    (%rax),%edx
call   1070 <connect@plt>
cmp    $0x0,%rax
jne    1266 <sslConnect+0xe6>
mov    -0x10(%rbp),%rdi
mov    -0x4c(%rbp),%esi
call   1030 <SSL_set_fd@plt>
mov    -0x10(%rbp),%rdi
call   1060 <SSL_connect@plt>
cmp    $0x0,%rax
jl     1261 <sslConnect+0xe1>
mov    -0x40(%rbp),%rdi
call   1090 <freeaddrinfo@plt>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1294 <sslConnect+0x114>
jmp    1266 <sslConnect+0xe6>
mov    -0x4c(%rbp),%edi
call   1050 <close@plt>
jmp    1273 <sslConnect+0xf3>
mov    -0x48(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x48(%rbp)
jmp    11e3 <sslConnect+0x63>
mov    -0x40(%rbp),%rdi
call   1090 <freeaddrinfo@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sslConnect>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
mov    0x2e1d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1080 <getaddrinfo@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
jne    125f <sslConnect+0xdf>
mov    0x8(%rsp),%rbx
mov    $0xffffffff,%r14d
test   %rbx,%rbx
jne    1210 <sslConnect+0x90>
xor    %edi,%edi
jmp    125a <sslConnect+0xda>
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1050 <close@plt>
mov    0x10(%rbx),%rbx
test   %rbx,%rbx
je     1255 <sslConnect+0xd5>
mov    0x8(%rbx),%esi
mov    0xc(%rbx),%edi
xor    %edx,%edx
call   10a0 <socket@plt>
test   %eax,%eax
js     1207 <sslConnect+0x87>
mov    %eax,%ebp
mov    (%rbx),%edx
mov    0x4(%rbx),%esi
mov    %eax,%edi
call   1070 <connect@plt>
test   %rax,%rax
jne    1200 <sslConnect+0x80>
mov    %r15,%rdi
mov    %ebp,%esi
call   1030 <SSL_set_fd@plt>
mov    %r15,%rdi
call   1060 <SSL_connect@plt>
test   %rax,%rax
js     1200 <sslConnect+0x80>
mov    0x8(%rsp),%rdi
mov    %ebp,%r14d
jmp    125a <sslConnect+0xda>
mov    0x8(%rsp),%rdi
call   1090 <freeaddrinfo@plt>
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, %struct.addrinfo* }
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
define i32 @sslConnect(i32* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.addrinfo
%9 = alloca %struct.addrinfo*
%10 = alloca %struct.addrinfo*
%11 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%12 = call i32 @memset(%struct.addrinfo* %8, i32 0, i32 24)
%13 = load i32, i32* @AF_UNSPEC
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 3
store i32 %13, i32* %14
%15 = load i32, i32* @SOCK_STREAM
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 2
store i32 %15, i32* %16
%17 = load i8*, i8** %6
%18 = load i8*, i8** %7
%19 = call i64 @getaddrinfo(i8* %17, i8* %18, %struct.addrinfo* %8, %struct.addrinfo** %9)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %68
21: ; preds = %3
%22 = load %struct.addrinfo*, %struct.addrinfo** %9
store %struct.addrinfo* %22, %struct.addrinfo** %10
br label %23
23: ; preds = %61, %21
%24 = load %struct.addrinfo*, %struct.addrinfo** %10
%25 = icmp ne %struct.addrinfo* %24, null
br i1 %25, label %26, label %65
26: ; preds = %23
%27 = load %struct.addrinfo*, %struct.addrinfo** %10
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %27, i32 0, i32 3
%29 = load i32, i32* %28
%30 = load %struct.addrinfo*, %struct.addrinfo** %10
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %30, i32 0, i32 2
%32 = load i32, i32* %31
%33 = call i32 @socket(i32 %29, i32 %32, i32 0)
store i32 %33, i32* %11
%34 = icmp sge i32 %33, 0
br i1 %34, label %35, label %60
35: ; preds = %26
%36 = load i32, i32* %11
%37 = load %struct.addrinfo*, %struct.addrinfo** %10
%38 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %37, i32 0, i32 1
%39 = load i32, i32* %38
%40 = load %struct.addrinfo*, %struct.addrinfo** %10
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i32 0, i32 0
%42 = load i32, i32* %41
%43 = call i64 @connect(i32 %36, i32 %39, i32 %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %57
45: ; preds = %35
%46 = load i32*, i32** %5
%47 = load i32, i32* %11
%48 = call i32 @SSL_set_fd(i32* %46, i32 %47)
%49 = load i32*, i32** %5
%50 = call i64 @SSL_connect(i32* %49)
%51 = icmp sge i64 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %45
%53 = load %struct.addrinfo*, %struct.addrinfo** %9
%54 = call i32 @freeaddrinfo(%struct.addrinfo* %53)
%55 = load i32, i32* %11
store i32 %55, i32* %4
br label %69
56: ; preds = %45
br label %57
57: ; preds = %56, %35
%58 = load i32, i32* %11
%59 = call i32 @close(i32 %58)
br label %60
60: ; preds = %57, %26
br label %61
61: ; preds = %60
%62 = load %struct.addrinfo*, %struct.addrinfo** %10
%63 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %62, i32 0, i32 4
%64 = load %struct.addrinfo*, %struct.addrinfo** %63
store %struct.addrinfo* %64, %struct.addrinfo** %10
br label %23
65: ; preds = %23
%66 = load %struct.addrinfo*, %struct.addrinfo** %9
%67 = call i32 @freeaddrinfo(%struct.addrinfo* %66)
br label %68
68: ; preds = %65, %3
store i32 -1, i32* %4
br label %69
69: ; preds = %68, %52
%70 = load i32, i32* %4
ret i32 %70
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, %struct.addrinfo* }
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
define i32 @sslConnect(i32* %0, i8* %1, i8* %2) {
%4 = alloca %struct.addrinfo
%5 = alloca %struct.addrinfo*
%6 = bitcast %struct.addrinfo* %4 to i8*
%7 = bitcast %struct.addrinfo** %5 to i8*
%8 = call i32 @memset(%struct.addrinfo* %4, i32 0, i32 24)
%9 = load i32, i32* @AF_UNSPEC
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 3
store i32 %9, i32* %10
%11 = load i32, i32* @SOCK_STREAM
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 2
store i32 %11, i32* %12
%13 = call i64 @getaddrinfo(i8* %1, i8* %2, %struct.addrinfo* %4, %struct.addrinfo** %5)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %51
15: ; preds = %3
%16 = load %struct.addrinfo*, %struct.addrinfo** %5
%17 = icmp eq %struct.addrinfo* %16, null
br i1 %17, label %47, label %18
18: ; preds = %15, %41
%19 = phi %struct.addrinfo* [ %43, %41 ], [ %16, %15 ]
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %19, i64 0, i32 3
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %19, i64 0, i32 2
%23 = load i32, i32* %22
%24 = call i32 @socket(i32 %21, i32 %23, i32 0)
%25 = icmp sgt i32 %24, -1
br i1 %25, label %26, label %41
26: ; preds = %18
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %19, i64 0, i32 1
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %19, i64 0, i32 0
%30 = load i32, i32* %29
%31 = call i64 @connect(i32 %24, i32 %28, i32 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %26
%34 = call i32 @SSL_set_fd(i32* %0, i32 %24)
%35 = call i64 @SSL_connect(i32* %0)
%36 = icmp sgt i64 %35, -1
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = load %struct.addrinfo*, %struct.addrinfo** %5
br label %47
39: ; preds = %33, %26
%40 = call i32 @close(i32 %24)
br label %41
41: ; preds = %18, %39
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %19, i64 0, i32 4
%43 = load %struct.addrinfo*, %struct.addrinfo** %42
%44 = icmp eq %struct.addrinfo* %43, null
br i1 %44, label %45, label %18
45: ; preds = %41
%46 = load %struct.addrinfo*, %struct.addrinfo** %5
br label %47
47: ; preds = %15, %45, %37
%48 = phi %struct.addrinfo* [ %38, %37 ], [ %46, %45 ], [ null, %15 ]
%49 = phi i32 [ %24, %37 ], [ -1, %45 ], [ -1, %15 ]
%50 = call i32 @freeaddrinfo(%struct.addrinfo* %48)
br label %51
51: ; preds = %47, %3
%52 = phi i32 [ -1, %3 ], [ %49, %47 ]
ret i32 %52
}