#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ addr;
typedef int /*<<< orphan*/ SSL_CTX;
typedef int /*<<< orphan*/ SSL;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SSL_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *SSL_CTX_new(int /*<<< orphan*/);
int SSL_connect(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *SSL_new(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_set_fd(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ SSLv23_client_method();
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int check(void *context) {
  int output = 0;
  SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
  SSL *ssl = NULL;
  struct sockaddr_in addr;
  int fd = socket(PF_INET, SOCK_STREAM, 0);
  bzero(&addr, sizeof(addr));
  addr.sin_family = AF_INET;
  addr.sin_port = htons(4433);
  addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) != 0) {
    output = -1;
    goto exit;
  }
  ssl = SSL_new(ctx);
  SSL_set_fd(ssl, fd);
  if (SSL_connect(ssl) == -1)
    output = -1;
exit:
  close(fd);
  SSL_CTX_free(ctx);
  if (ssl)
    SSL_free(ssl);
  return output;
}


x86 assembly (clang, -O0):
<check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1030 <SSLv23_client_method@plt>
mov    %eax,%edi
call   10a0 <SSL_CTX_new@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x34(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    $0x1151,%edi
call   1060 <htons@plt>
mov    %eax,-0x2c(%rbp)
lea    0xdb9(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x30(%rbp)
mov    -0x34(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <connect@plt>
cmp    $0x0,%rax
je     1276 <check+0xa6>
movl   $0xffffffff,-0xc(%rbp)
jmp    12ad <check+0xdd>
mov    -0x18(%rbp),%rdi
call   1080 <SSL_new@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1050 <SSL_set_fd@plt>
mov    -0x20(%rbp),%rdi
call   10b0 <SSL_connect@plt>
cmp    $0xffffffff,%eax
jne    12a8 <check+0xd8>
movl   $0xffffffff,-0xc(%rbp)
jmp    12ad <check+0xdd>
mov    -0x34(%rbp),%edi
call   1070 <close@plt>
mov    -0x18(%rbp),%rdi
call   10c0 <SSL_CTX_free@plt>
cmpq   $0x0,-0x20(%rbp)
je     12d2 <check+0x102>
mov    -0x20(%rbp),%rdi
call   1040 <SSL_free@plt>
mov    -0xc(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
xor    %r15d,%r15d
xor    %eax,%eax
call   1030 <SSLv23_client_method@plt>
mov    %eax,%edi
call   10a0 <SSL_CTX_new@plt>
mov    %rax,%r14
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,%ebp
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    $0x1151,%edi
call   1060 <htons@plt>
mov    %eax,0xc(%rsp)
lea    0xdc3(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,0x8(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10e0 <connect@plt>
test   %rax,%rax
je     1261 <check+0x91>
mov    $0xffffffff,%ebx
jmp    1288 <check+0xb8>
mov    %r14,%rdi
call   1080 <SSL_new@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %ebp,%esi
call   1050 <SSL_set_fd@plt>
mov    %r15,%rdi
call   10b0 <SSL_connect@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
sete   %bl
neg    %ebx
mov    %ebp,%edi
call   1070 <close@plt>
mov    %r14,%rdi
call   10c0 <SSL_CTX_free@plt>
test   %r15,%r15
je     12a4 <check+0xd4>
mov    %r15,%rdi
call   1040 <SSL_free@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
define i32 @check(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%8 = call i32 (...) @SSLv23_client_method()
%9 = call i32* @SSL_CTX_new(i32 %8)
store i32* %9, i32** %4
store i32* null, i32** %5
%10 = load i32, i32* @PF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %7
%13 = call i32 @bzero(%struct.sockaddr_in* %6, i32 12)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %14, i32* %15
%16 = call i32 @htons(i32 4433)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %16, i32* %17
%18 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 0
store i32 %18, i32* %20
%21 = load i32, i32* %7
%22 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%23 = call i64 @connect(i32 %21, %struct.sockaddr* %22, i32 12)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %1
store i32 -1, i32* %3
br label %37
26: ; preds = %1
%27 = load i32*, i32** %4
%28 = call i32* @SSL_new(i32* %27)
store i32* %28, i32** %5
%29 = load i32*, i32** %5
%30 = load i32, i32* %7
%31 = call i32 @SSL_set_fd(i32* %29, i32 %30)
%32 = load i32*, i32** %5
%33 = call i32 @SSL_connect(i32* %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %36
35: ; preds = %26
store i32 -1, i32* %3
br label %36
36: ; preds = %35, %26
br label %37
37: ; preds = %36, %25
%38 = load i32, i32* %7
%39 = call i32 @close(i32 %38)
%40 = load i32*, i32** %4
%41 = call i32 @SSL_CTX_free(i32* %40)
%42 = load i32*, i32** %5
%43 = icmp ne i32* %42, null
br i1 %43, label %44, label %47
44: ; preds = %37
%45 = load i32*, i32** %5
%46 = call i32 @SSL_free(i32* %45)
br label %47
47: ; preds = %44, %37
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
define i32 @check(i8* nocapture readnone %0) {
%2 = alloca %struct.sockaddr_in
%3 = tail call i32 (...) @SSLv23_client_method()
%4 = tail call i32* @SSL_CTX_new(i32 %3)
%5 = bitcast %struct.sockaddr_in* %2 to i8*
%6 = load i32, i32* @PF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = call i32 @bzero(%struct.sockaddr_in* %2, i32 12)
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %10, i32* %11
%12 = tail call i32 @htons(i32 4433)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %12, i32* %13
%14 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
store i32 %14, i32* %15
%16 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%17 = call i64 @connect(i32 %8, %struct.sockaddr* %16, i32 12)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %1
%20 = call i32* @SSL_new(i32* %4)
%21 = call i32 @SSL_set_fd(i32* %20, i32 %8)
%22 = call i32 @SSL_connect(i32* %20)
%23 = icmp eq i32 %22, -1
%24 = sext i1 %23 to i32
br label %25
25: ; preds = %19, %1
%26 = phi i32* [ null, %1 ], [ %20, %19 ]
%27 = phi i32 [ -1, %1 ], [ %24, %19 ]
%28 = call i32 @close(i32 %8)
%29 = call i32 @SSL_CTX_free(i32* %4)
%30 = icmp eq i32* %26, null
br i1 %30, label %33, label %31
31: ; preds = %25
%32 = call i32 @SSL_free(i32* %26)
br label %33
33: ; preds = %31, %25
ret i32 %27
}