#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 pollfd {
  int fd;
  int /*<<< orphan*/ events;
};
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  scalar_t__ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  scalar_t__ ai_flags;
};
typedef int /*<<< orphan*/ SSL_CTX;
typedef int /*<<< orphan*/ SSL;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
scalar_t__ EINPROGRESS;
int /*<<< orphan*/ POLLOUT;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SSL_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *SSL_new(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_set_fd(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ do_connect(int /*<<< orphan*/ *);
scalar_t__ do_shutdown(int /*<<< orphan*/ *);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ ns_set_non_blocking_mode(int);
int /*<<< orphan*/ poll(struct pollfd *, int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ *setup_ctx(char const *, char const *, char const *,
                              char const *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, scalar_t__);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
char *strdup(char const *);
char *strerror(scalar_t__);
int /*<<< orphan*/ test_content(int /*<<< orphan*/ *);
int do_test(const char *caddr, const char *cert_chain, const char *client_cert,
            const char *client_key, const char *cipher,
            int verify_server_name) {
  struct addrinfo hints, *rp;
  struct pollfd pfd;
  char *addr = strdup(caddr);
  char *port;
  SSL_CTX *ctx;
  SSL *ssl;
  int ret = 0;
  int fd;
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = 0;
  hints.ai_protocol = 0;
  port = strchr(addr, ':');
  if (port != NULL) {
    *port = '\0';
    port++;
  } else {
    port = "443";
  }
  ret = getaddrinfo(addr, port, &hints, &rp);
  if (ret != 0) {
    fprintf(stderr, "getaddrinfo(%s): %s\n", addr, gai_strerror(ret));
    ret = 0;
    goto out;
  }
  if (rp == NULL) {
    fprintf(stderr, "could not resolve %s\n", addr);
    goto out;
  }
  ctx = setup_ctx(cert_chain, client_cert, client_key, cipher);
  if (NULL == ctx)
    goto out;
  if (verify_server_name) {
  }
  ssl = SSL_new(ctx);
  if (NULL == ssl)
    goto out_ctx;
  fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
  if (fd < 0) {
    fprintf(stderr, "socket: %s\n", strerror(errno));
    goto out_ssl;
  }
  if (connect(fd, rp->ai_addr, rp->ai_addrlen)) {
    if (errno != EINPROGRESS) {
      fprintf(stderr, "connect: %s\n", strerror(errno));
      goto out_close;
    }
  }
  ns_set_non_blocking_mode(fd);
  if (!SSL_set_fd(ssl, fd))
    goto out_close;
  pfd.events = POLLOUT;
  pfd.fd = fd;
  poll(&pfd, 1, -1);
  if (do_connect(ssl) <= 0) {
    printf("TLS connect failed\n");
    goto shutdown;
  }
  if (!test_content(ssl)) {
    printf("TLS data xfer failed\n");
    goto shutdown;
  }
  ret = 1;
shutdown:
  if (do_shutdown(ssl) > 0 && ret) {
    printf("SUCCESS\n");
  } else {
    ret = 0;
  }
out_close:
  close(fd);
out_ssl:
  SSL_free(ssl);
out_ctx:
  SSL_CTX_free(ctx);
out:
  freeaddrinfo(rp);
  free(addr);
  return ret;
}


x86 assembly (clang, -O0):
<do_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1150 <strdup@plt>
mov    %rax,-0x68(%rbp)
movl   $0x0,-0x84(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   10c0 <memset@plt>
mov    0x2d17(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2cf3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x68(%rbp),%rdi
mov    $0x3a,%esi
call   1090 <strchr@plt>
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x70(%rbp)
je     1317 <do_test+0xa7>
mov    -0x70(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x70(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x70(%rbp)
jmp    1322 <do_test+0xb2>
lea    0xce2(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    -0x68(%rbp),%rdi
mov    -0x70(%rbp),%rsi
lea    -0x50(%rbp),%rdx
lea    -0x58(%rbp),%rcx
call   1140 <getaddrinfo@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
je     139c <do_test+0x12c>
mov    0x2c77(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x94(%rbp)
mov    -0x68(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x84(%rbp),%edi
call   10b0 <gai_strerror@plt>
mov    -0x94(%rbp),%edi
mov    -0x90(%rbp),%rdx
mov    %rax,%rcx
lea    0xc7e(%rip),%rsi
mov    $0x0,%al
call   10f0 <fprintf@plt>
movl   $0x0,-0x84(%rbp)
jmp    15ff <do_test+0x38f>
cmpq   $0x0,-0x58(%rbp)
jne    13c7 <do_test+0x157>
mov    0x2c1a(%rip),%rax
mov    (%rax),%edi
mov    -0x68(%rbp),%rdx
lea    0xc5e(%rip),%rsi
mov    $0x0,%al
call   10f0 <fprintf@plt>
jmp    15ff <do_test+0x38f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1050 <setup_ctx@plt>
mov    %rax,-0x78(%rbp)
xor    %eax,%eax
cmp    -0x78(%rbp),%rax
jne    13f1 <do_test+0x181>
jmp    15ff <do_test+0x38f>
cmpl   $0x0,-0x2c(%rbp)
je     1400 <do_test+0x190>
jmp    1400 <do_test+0x190>
mov    -0x78(%rbp),%rdi
call   10e0 <SSL_new@plt>
mov    %rax,-0x80(%rbp)
xor    %eax,%eax
cmp    -0x80(%rbp),%rax
jne    141e <do_test+0x1ae>
jmp    15f6 <do_test+0x386>
mov    -0x58(%rbp),%rax
mov    0x14(%rax),%edi
mov    -0x58(%rbp),%rax
mov    0x10(%rax),%esi
mov    -0x58(%rbp),%rax
mov    0x8(%rax),%rdx
call   1190 <socket@plt>
mov    %eax,-0x88(%rbp)
cmpl   $0x0,-0x88(%rbp)
jge    1486 <do_test+0x216>
mov    0x2b75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x98(%rbp)
mov    0x2b56(%rip),%rax
mov    (%rax),%rdi
call   1160 <strerror@plt>
mov    -0x98(%rbp),%edi
mov    %rax,%rdx
lea    0xbb5(%rip),%rsi
mov    $0x0,%al
call   10f0 <fprintf@plt>
jmp    15ed <do_test+0x37d>
mov    -0x88(%rbp),%edi
mov    -0x58(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x58(%rbp),%rax
mov    (%rax),%edx
call   1130 <connect@plt>
cmp    $0x0,%rax
je     1501 <do_test+0x291>
mov    0x2b09(%rip),%rax
mov    (%rax),%rax
mov    0x2b27(%rip),%rcx
cmp    (%rcx),%rax
je     14fc <do_test+0x28c>
mov    0x2aff(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x9c(%rbp)
mov    0x2ae0(%rip),%rax
mov    (%rax),%rdi
call   1160 <strerror@plt>
mov    -0x9c(%rbp),%edi
mov    %rax,%rdx
lea    0xb4b(%rip),%rsi
mov    $0x0,%al
call   10f0 <fprintf@plt>
jmp    15e2 <do_test+0x372>
jmp    1501 <do_test+0x291>
mov    -0x88(%rbp),%edi
call   1040 <ns_set_non_blocking_mode@plt>
mov    -0x80(%rbp),%rdi
mov    -0x88(%rbp),%esi
call   1080 <SSL_set_fd@plt>
cmp    $0x0,%eax
jne    1529 <do_test+0x2b9>
jmp    15e2 <do_test+0x372>
mov    0x2ac8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x88(%rbp),%eax
mov    %eax,-0x60(%rbp)
lea    -0x60(%rbp),%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1110 <poll@plt>
mov    -0x80(%rbp),%rdi
call   1060 <do_connect@plt>
cmp    $0x0,%rax
jg     1575 <do_test+0x305>
lea    0xadd(%rip),%rdi
call   10a0 <printf@plt>
jmp    15a2 <do_test+0x332>
mov    -0x80(%rbp),%rdi
call   1170 <test_content@plt>
cmp    $0x0,%eax
jne    1598 <do_test+0x328>
lea    0xace(%rip),%rdi
call   10a0 <printf@plt>
jmp    15a2 <do_test+0x332>
movl   $0x1,-0x84(%rbp)
mov    -0x80(%rbp),%rdi
call   1100 <do_shutdown@plt>
cmp    $0x0,%rax
jle    15d3 <do_test+0x363>
cmpl   $0x0,-0x84(%rbp)
je     15d3 <do_test+0x363>
lea    0xaa9(%rip),%rdi
call   10a0 <printf@plt>
jmp    15dd <do_test+0x36d>
movl   $0x0,-0x84(%rbp)
jmp    15e2 <do_test+0x372>
mov    -0x88(%rbp),%edi
call   10d0 <close@plt>
mov    -0x80(%rbp),%rdi
call   1070 <SSL_free@plt>
mov    -0x78(%rbp),%rdi
call   1120 <SSL_CTX_free@plt>
mov    -0x58(%rbp),%rdi
call   1180 <freeaddrinfo@plt>
mov    -0x68(%rbp),%rdi
call   1030 <free@plt>
mov    -0x84(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%rbp
call   1150 <strdup@plt>
mov    %rax,%rbx
lea    0x18(%rsp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   10c0 <memset@plt>
mov    0x2d2e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x2c(%rsp)
mov    0x2d09(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
movq   $0x0,0x30(%rsp)
movq   $0x0,0x20(%rsp)
mov    %rbx,%rdi
mov    $0x3a,%esi
call   10a0 <strchr@plt>
test   %rax,%rax
je     12ea <do_test+0x7a>
movb   $0x0,(%rax)
add    $0x1,%rax
jmp    12f1 <do_test+0x81>
lea    0xd0f(%rip),%rax
lea    0x18(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1140 <getaddrinfo@plt>
test   %eax,%eax
je     1357 <do_test+0xe7>
mov    0x2cb7(%rip),%rcx
mov    (%rcx),%ebp
mov    %eax,%edi
call   10b0 <gai_strerror@plt>
lea    0xce3(%rip),%rsi
xor    %r13d,%r13d
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   10f0 <fprintf@plt>
mov    0x8(%rsp),%rdi
call   1180 <freeaddrinfo@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r13d,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmpq   $0x0,0x8(%rsp)
je     1471 <do_test+0x201>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1050 <setup_ctx@plt>
test   %rax,%rax
je     1493 <do_test+0x223>
mov    %rax,%r14
mov    %rax,%rdi
call   10e0 <SSL_new@plt>
test   %rax,%rax
je     149b <do_test+0x22b>
mov    %rax,%r15
mov    0x8(%rsp),%rax
mov    0x14(%rax),%edi
mov    0x10(%rax),%esi
mov    0x8(%rax),%rdx
call   1190 <socket@plt>
test   %eax,%eax
js     14a3 <do_test+0x233>
mov    %eax,%r12d
mov    0x8(%rsp),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %r12d,%edi
call   1130 <connect@plt>
test   %rax,%rax
je     13e4 <do_test+0x174>
mov    0x2be7(%rip),%rax
mov    (%rax),%rdi
mov    0x2c05(%rip),%rax
cmp    (%rax),%rdi
jne    14d3 <do_test+0x263>
mov    %r12d,%edi
call   1040 <ns_set_non_blocking_mode@plt>
mov    %r15,%rdi
mov    %r12d,%esi
call   1090 <SSL_set_fd@plt>
xor    %r13d,%r13d
test   %eax,%eax
je     1516 <do_test+0x2a6>
mov    0x2bef(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    %r12d,0x10(%rsp)
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1110 <poll@plt>
mov    %r15,%rdi
call   1070 <do_connect@plt>
test   %rax,%rax
jle    14f9 <do_test+0x289>
mov    %r15,%rdi
call   1170 <test_content@plt>
test   %eax,%eax
je     1502 <do_test+0x292>
mov    %r15,%rdi
call   1100 <do_shutdown@plt>
test   %rax,%rax
jle    1516 <do_test+0x2a6>
lea    0xbfc(%rip),%rdi
call   1060 <puts@plt>
mov    $0x1,%r13d
jmp    1516 <do_test+0x2a6>
mov    0x2b50(%rip),%rax
mov    (%rax),%edi
lea    0xb98(%rip),%rsi
xor    %r13d,%r13d
mov    %rbx,%rdx
xor    %eax,%eax
call   10f0 <fprintf@plt>
jmp    1333 <do_test+0xc3>
xor    %r13d,%r13d
jmp    1333 <do_test+0xc3>
xor    %r13d,%r13d
jmp    1526 <do_test+0x2b6>
mov    0x2b1e(%rip),%rax
mov    (%rax),%ebp
mov    0x2b05(%rip),%rax
mov    (%rax),%rdi
call   1160 <strerror@plt>
lea    0xb6d(%rip),%rsi
xor    %r13d,%r13d
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10f0 <fprintf@plt>
jmp    151e <do_test+0x2ae>
mov    0x2aee(%rip),%rax
mov    (%rax),%ebp
call   1160 <strerror@plt>
lea    0xb53(%rip),%rsi
xor    %r13d,%r13d
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10f0 <fprintf@plt>
jmp    1516 <do_test+0x2a6>
lea    0xb65(%rip),%rdi
jmp    1509 <do_test+0x299>
lea    0xb3f(%rip),%rdi
call   1060 <puts@plt>
mov    %r15,%rdi
call   1100 <do_shutdown@plt>
mov    %r12d,%edi
call   10d0 <close@plt>
mov    %r15,%rdi
call   1080 <SSL_free@plt>
mov    %r14,%rdi
call   1120 <SSL_CTX_free@plt>
jmp    1333 <do_test+0xc3>

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

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i64, i32, i32, i64 }
%struct.pollfd = type { i32, i32 }
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str = [4 x i8] c"443\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"getaddrinfo(%s): %s\0A\00"
@.str.2 = [22 x i8] c"could not resolve %s\0A\00"
@.str.3 = [12 x i8] c"socket: %s\0A\00"
@errno = global i64 0
@EINPROGRESS = global i64 0
@.str.4 = [13 x i8] c"connect: %s\0A\00"
@POLLOUT = global i32 0
@str = [21 x i8] c"TLS data xfer failed\00"
@str.8 = [8 x i8] c"SUCCESS\00"
@str.9 = [19 x i8] c"TLS connect failed\00"
define i32 @do_test(i8* nocapture %0, i8* %1, i8* %2, i8* %3, i8* %4, i32 %5) {
%7 = alloca %struct.addrinfo
%8 = alloca %struct.addrinfo*
%9 = alloca %struct.pollfd
%10 = bitcast %struct.addrinfo* %7 to i8*
%11 = bitcast %struct.addrinfo** %8 to i8*
%12 = bitcast %struct.pollfd* %9 to i8*
%13 = tail call i8* @strdup(i8* %0)
%14 = call i32 @memset(%struct.addrinfo* %7, i32 0, i32 32)
%15 = load i32, i32* @AF_UNSPEC
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i64 0, i32 4
store i32 %15, i32* %16
%17 = load i32, i32* @SOCK_STREAM
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i64 0, i32 3
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i64 0, i32 5
store i64 0, i64* %19
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i64 0, i32 2
store i64 0, i64* %20
%21 = call i8* @strchr(i8* dereferenceable(1) %13, i8 signext 58)
%22 = icmp eq i8* %21, null
br i1 %22, label %25, label %23
23: ; preds = %6
store i8 0, i8* %21
%24 = getelementptr inbounds i8, i8* %21, i64 1
br label %25
25: ; preds = %6, %23
%26 = phi i8* [ %24, %23 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %6 ]
%27 = call i32 @getaddrinfo(i8* %13, i8* %26, %struct.addrinfo* %7, %struct.addrinfo** %8)
%28 = icmp eq i32 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %25
%30 = load i32, i32* @stderr
%31 = call i8* @gai_strerror(i32 %27)
%32 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %13, i8* %31)
br label %108
33: ; preds = %25
%34 = load %struct.addrinfo*, %struct.addrinfo** %8
%35 = icmp eq %struct.addrinfo* %34, null
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %13)
br label %108
39: ; preds = %33
%40 = call i32* @setup_ctx(i8* %1, i8* %2, i8* %3, i8* %4)
%41 = icmp eq i32* %40, null
br i1 %41, label %108, label %42
42: ; preds = %39
%43 = call i32* @SSL_new(i32* %40)
%44 = icmp eq i32* %43, null
br i1 %44, label %105, label %45
45: ; preds = %42
%46 = load %struct.addrinfo*, %struct.addrinfo** %8
%47 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %46, i64 0, i32 4
%48 = load i32, i32* %47
%49 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %46, i64 0, i32 3
%50 = load i32, i32* %49
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %46, i64 0, i32 2
%52 = load i64, i64* %51
%53 = call i32 @socket(i32 %48, i32 %50, i64 %52)
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %60
55: ; preds = %45
%56 = load i32, i32* @stderr
%57 = load i64, i64* @errno
%58 = call i8* @strerror(i64 %57)
%59 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %58)
br label %102
60: ; preds = %45
%61 = load %struct.addrinfo*, %struct.addrinfo** %8
%62 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %61, i64 0, i32 1
%63 = load i32, i32* %62
%64 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %61, i64 0, i32 0
%65 = load i32, i32* %64
%66 = call i64 @connect(i32 %53, i32 %63, i32 %65)
%67 = icmp eq i64 %66, 0
br i1 %67, label %76, label %68
68: ; preds = %60
%69 = load i64, i64* @errno
%70 = load i64, i64* @EINPROGRESS
%71 = icmp eq i64 %69, %70
br i1 %71, label %76, label %72
72: ; preds = %68
%73 = load i32, i32* @stderr
%74 = call i8* @strerror(i64 %69)
%75 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %74)
br label %99
76: ; preds = %68, %60
%77 = call i32 @ns_set_non_blocking_mode(i32 %53)
%78 = call i32 @SSL_set_fd(i32* %43, i32 %53)
%79 = icmp eq i32 %78, 0
br i1 %79, label %99, label %80
80: ; preds = %76
%81 = load i32, i32* @POLLOUT
%82 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %9, i64 0, i32 1
store i32 %81, i32* %82
%83 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %9, i64 0, i32 0
store i32 %53, i32* %83
%84 = call i32 @poll(%struct.pollfd* %9, i32 1, i32 -1)
%85 = call i64 @do_connect(i32* %43)
%86 = icmp slt i64 %85, 1
br i1 %86, label %90, label %87
87: ; preds = %80
%88 = call i32 @test_content(i32* %43)
%89 = icmp eq i32 %88, 0
br i1 %89, label %90, label %94
90: ; preds = %87, %80
%91 = phi i8* [ getelementptr inbounds ([19 x i8], [19 x i8]* @str.9, i64 0, i64 0), %80 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0), %87 ]
%92 = call i32 @puts(i8* dereferenceable(1) %91)
%93 = call i64 @do_shutdown(i32* %43)
br label %99
94: ; preds = %87
%95 = call i64 @do_shutdown(i32* %43)
%96 = icmp sgt i64 %95, 0
br i1 %96, label %97, label %99
97: ; preds = %94
%98 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.8, i64 0, i64 0))
br label %99
99: ; preds = %90, %94, %97, %76, %72
%100 = phi i32 [ 0, %72 ], [ 1, %97 ], [ 0, %76 ], [ 0, %94 ], [ 0, %90 ]
%101 = call i32 @close(i32 %53)
br label %102
102: ; preds = %99, %55
%103 = phi i32 [ 0, %55 ], [ %100, %99 ]
%104 = call i32 @SSL_free(i32* %43)
br label %105
105: ; preds = %42, %102
%106 = phi i32 [ 0, %42 ], [ %103, %102 ]
%107 = call i32 @SSL_CTX_free(i32* %40)
br label %108
108: ; preds = %39, %105, %36, %29
%109 = phi i32 [ 0, %29 ], [ 0, %36 ], [ 0, %39 ], [ %106, %105 ]
%110 = load %struct.addrinfo*, %struct.addrinfo** %8
%111 = call i32 @freeaddrinfo(%struct.addrinfo* %110)
%112 = call i32 @free(i8* %13)
ret i32 %109
}