#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 */
typedef int /*<<< orphan*/ SSL_CTX;
typedef int /*<<< orphan*/ SSL;

/* Variables and functions */
int /*<<< orphan*/ ERR_error_string_n(int, char *, int);
int ERR_get_error();
int /*<<< orphan*/ *SSL_CTX_new(int /*<<< orphan*/);
int SSL_connect(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_library_init();
int /*<<< orphan*/ SSL_load_error_strings();
int /*<<< orphan*/ *SSL_new(int /*<<< orphan*/ *);
int SSL_set_fd(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ SSLv23_client_method();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int client_ssl_connect(int s, SSL **sslp, SSL_CTX **ctxp) {
  SSL *ssl;
  SSL_CTX *ctx;
  char errmsg[1024];
  int err;
  ssl = NULL;
  ctx = NULL;
  *sslp = NULL;
  *ctxp = NULL;
  SSL_load_error_strings();
  SSL_library_init();
  if (!(ctx = SSL_CTX_new(SSLv23_client_method()))) {
    errmsg[1023] = '\0';
    ERR_error_string_n(ERR_get_error(), errmsg, 1023);
    fprintf(stderr, "servercainfo: SSL_CTX_new(): %s\n", errmsg);
    return (-1);
  };
  *ctxp = ctx;
  if (!(ssl = SSL_new(ctx))) {
    errmsg[1023] = '\0';
    ERR_error_string_n(ERR_get_error(), errmsg, 1023);
    fprintf(stderr, "servercainfo: SSL_new(): %s\n", errmsg);
    return (-1);
  };
  *sslp = ssl;
  if ((err = SSL_set_fd(ssl, s)) != 1) {
    errmsg[1023] = '\0';
    ERR_error_string_n(ERR_get_error(), errmsg, 1023);
    fprintf(stderr, "servercainfo: SSL_set_fd(): %s\n", errmsg);
    return (-1);
  };
  if ((err = SSL_connect(ssl)) != 1) {
    if (err == -1)
      err = ERR_get_error();
    errmsg[1023] = '\0';
    ERR_error_string_n(err, errmsg, 1023);
    fprintf(stderr, "servercainfo: SSL_connect(): %s\n", errmsg);
    return (-1);
  };
  return (0);
}


x86 assembly (clang, -O0):
<client_ssl_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    $0x0,%al
call   10b0 <SSL_load_error_strings@plt>
mov    $0x0,%al
call   1050 <SSL_library_init@plt>
mov    $0x0,%al
call   1030 <SSLv23_client_method@plt>
mov    %eax,%edi
call   1090 <SSL_CTX_new@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    124c <client_ssl_connect+0xac>
movb   $0x0,-0x31(%rbp)
mov    $0x0,%al
call   10c0 <ERR_get_error@plt>
mov    %eax,%edi
lea    -0x430(%rbp),%rsi
mov    $0x3ff,%edx
call   1060 <ERR_error_string_n@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
lea    -0x430(%rbp),%rdx
lea    0xdc5(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    139c <client_ssl_connect+0x1fc>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
call   1070 <SSL_new@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    12b4 <client_ssl_connect+0x114>
movb   $0x0,-0x31(%rbp)
mov    $0x0,%al
call   10c0 <ERR_get_error@plt>
mov    %eax,%edi
lea    -0x430(%rbp),%rsi
mov    $0x3ff,%edx
call   1060 <ERR_error_string_n@plt>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
lea    -0x430(%rbp),%rdx
lea    0xd7e(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    139c <client_ssl_connect+0x1fc>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1040 <SSL_set_fd@plt>
mov    %eax,-0x434(%rbp)
cmp    $0x1,%eax
je     1320 <client_ssl_connect+0x180>
movb   $0x0,-0x31(%rbp)
mov    $0x0,%al
call   10c0 <ERR_get_error@plt>
mov    %eax,%edi
lea    -0x430(%rbp),%rsi
mov    $0x3ff,%edx
call   1060 <ERR_error_string_n@plt>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
lea    -0x430(%rbp),%rdx
lea    0xd2f(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    139c <client_ssl_connect+0x1fc>
mov    -0x20(%rbp),%rdi
call   10a0 <SSL_connect@plt>
mov    %eax,-0x434(%rbp)
cmp    $0x1,%eax
je     1395 <client_ssl_connect+0x1f5>
cmpl   $0xffffffff,-0x434(%rbp)
jne    1352 <client_ssl_connect+0x1b2>
mov    $0x0,%al
call   10c0 <ERR_get_error@plt>
mov    %eax,-0x434(%rbp)
movb   $0x0,-0x31(%rbp)
mov    -0x434(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x3ff,%edx
call   1060 <ERR_error_string_n@plt>
mov    0x2c6c(%rip),%rax
mov    (%rax),%edi
lea    -0x430(%rbp),%rdx
lea    0xcda(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    139c <client_ssl_connect+0x1fc>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<client_ssl_connect>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %edi,%r14d
movq   $0x0,(%rsi)
movq   $0x0,(%rdx)
xor    %eax,%eax
call   10b0 <SSL_load_error_strings@plt>
xor    %eax,%eax
call   1050 <SSL_library_init@plt>
xor    %eax,%eax
call   1030 <SSLv23_client_method@plt>
mov    %eax,%edi
call   1090 <SSL_CTX_new@plt>
test   %rax,%rax
je     1238 <client_ssl_connect+0x98>
mov    %rax,0x0(%rbp)
mov    %rax,%rdi
call   1070 <SSL_new@plt>
test   %rax,%rax
je     1250 <client_ssl_connect+0xb0>
mov    %rax,%rbp
mov    %rax,(%rbx)
mov    %rax,%rdi
mov    %r14d,%esi
call   1040 <SSL_set_fd@plt>
cmp    $0x1,%eax
jne    1268 <client_ssl_connect+0xc8>
mov    %rbp,%rdi
call   10a0 <SSL_connect@plt>
cmp    $0x1,%eax
je     12b5 <client_ssl_connect+0x115>
cmp    $0xffffffff,%eax
jne    1227 <client_ssl_connect+0x87>
xor    %eax,%eax
call   10c0 <ERR_get_error@plt>
movb   $0x0,0x3ff(%rsp)
lea    0xe28(%rip),%rbx
jmp    127e <client_ssl_connect+0xde>
movb   $0x0,0x3ff(%rsp)
xor    %eax,%eax
call   10c0 <ERR_get_error@plt>
lea    0xdb2(%rip),%rbx
jmp    127e <client_ssl_connect+0xde>
movb   $0x0,0x3ff(%rsp)
xor    %eax,%eax
call   10c0 <ERR_get_error@plt>
lea    0xdbb(%rip),%rbx
jmp    127e <client_ssl_connect+0xde>
movb   $0x0,0x3ff(%rsp)
xor    %eax,%eax
call   10c0 <ERR_get_error@plt>
lea    0xdc0(%rip),%rbx
mov    %rsp,%rbp
mov    %eax,%edi
mov    %rbp,%rsi
mov    $0x3ff,%edx
call   1060 <ERR_error_string_n@plt>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1080 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %eax,%eax
jmp    12a9 <client_ssl_connect+0x109>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"servercainfo: SSL_CTX_new(): %s\0A\00"
@.str.1 = [29 x i8] c"servercainfo: SSL_new(): %s\0A\00"
@.str.2 = [32 x i8] c"servercainfo: SSL_set_fd(): %s\0A\00"
@.str.3 = [33 x i8] c"servercainfo: SSL_connect(): %s\0A\00"
define i32 @client_ssl_connect(i32 %0, i32** %1, i32** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32**
%7 = alloca i32**
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca [1024 x i8]
%11 = alloca i32
store i32 %0, i32* %5
store i32** %1, i32*** %6
store i32** %2, i32*** %7
store i32* null, i32** %8
store i32* null, i32** %9
%12 = load i32**, i32*** %6
store i32* null, i32** %12
%13 = load i32**, i32*** %7
store i32* null, i32** %13
%14 = call i32 (...) @SSL_load_error_strings()
%15 = call i32 (...) @SSL_library_init()
%16 = call i32 (...) @SSLv23_client_method()
%17 = call i32* @SSL_CTX_new(i32 %16)
store i32* %17, i32** %9
%18 = icmp ne i32* %17, null
br i1 %18, label %27, label %19
19: ; preds = %3
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 1023
store i8 0, i8* %20
%21 = call i32 (...) @ERR_get_error()
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%23 = call i32 @ERR_error_string_n(i32 %21, i8* %22, i32 1023)
%24 = load i32, i32* @stderr
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%26 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %25)
store i32 -1, i32* %4
br label %74
27: ; preds = %3
%28 = load i32*, i32** %9
%29 = load i32**, i32*** %7
store i32* %28, i32** %29
%30 = load i32*, i32** %9
%31 = call i32* @SSL_new(i32* %30)
store i32* %31, i32** %8
%32 = icmp ne i32* %31, null
br i1 %32, label %41, label %33
33: ; preds = %27
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 1023
store i8 0, i8* %34
%35 = call i32 (...) @ERR_get_error()
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%37 = call i32 @ERR_error_string_n(i32 %35, i8* %36, i32 1023)
%38 = load i32, i32* @stderr
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%40 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %39)
store i32 -1, i32* %4
br label %74
41: ; preds = %27
%42 = load i32*, i32** %8
%43 = load i32**, i32*** %6
store i32* %42, i32** %43
%44 = load i32*, i32** %8
%45 = load i32, i32* %5
%46 = call i32 @SSL_set_fd(i32* %44, i32 %45)
store i32 %46, i32* %11
%47 = icmp ne i32 %46, 1
br i1 %47, label %48, label %56
48: ; preds = %41
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 1023
store i8 0, i8* %49
%50 = call i32 (...) @ERR_get_error()
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%52 = call i32 @ERR_error_string_n(i32 %50, i8* %51, i32 1023)
%53 = load i32, i32* @stderr
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%55 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %54)
store i32 -1, i32* %4
br label %74
56: ; preds = %41
%57 = load i32*, i32** %8
%58 = call i32 @SSL_connect(i32* %57)
store i32 %58, i32* %11
%59 = icmp ne i32 %58, 1
br i1 %59, label %60, label %73
60: ; preds = %56
%61 = load i32, i32* %11
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %65
63: ; preds = %60
%64 = call i32 (...) @ERR_get_error()
store i32 %64, i32* %11
br label %65
65: ; preds = %63, %60
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 1023
store i8 0, i8* %66
%67 = load i32, i32* %11
%68 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%69 = call i32 @ERR_error_string_n(i32 %67, i8* %68, i32 1023)
%70 = load i32, i32* @stderr
%71 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%72 = call i32 @fprintf(i32 %70, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %71)
store i32 -1, i32* %4
br label %74
73: ; preds = %56
store i32 0, i32* %4
br label %74
74: ; preds = %73, %65, %48, %33, %19
%75 = load i32, i32* %4
ret i32 %75
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"servercainfo: SSL_CTX_new(): %s\0A\00"
@.str.1 = [29 x i8] c"servercainfo: SSL_new(): %s\0A\00"
@.str.2 = [32 x i8] c"servercainfo: SSL_set_fd(): %s\0A\00"
@.str.3 = [33 x i8] c"servercainfo: SSL_connect(): %s\0A\00"
define i32 @client_ssl_connect(i32 %0, i32** nocapture writeonly %1, i32** nocapture writeonly %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
store i32* null, i32** %1
store i32* null, i32** %2
%6 = tail call i32 (...) @SSL_load_error_strings()
%7 = tail call i32 (...) @SSL_library_init()
%8 = tail call i32 (...) @SSLv23_client_method()
%9 = tail call i32* @SSL_CTX_new(i32 %8)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 1023
store i8 0, i8* %12
%13 = tail call i32 (...) @ERR_get_error()
br label %33
14: ; preds = %3
store i32* %9, i32** %2
%15 = tail call i32* @SSL_new(i32* %9)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 1023
store i8 0, i8* %18
%19 = tail call i32 (...) @ERR_get_error()
br label %33
20: ; preds = %14
store i32* %15, i32** %1
%21 = tail call i32 @SSL_set_fd(i32* %15, i32 %0)
%22 = icmp eq i32 %21, 1
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 1023
store i8 0, i8* %24
%25 = tail call i32 (...) @ERR_get_error()
br label %33
26: ; preds = %20
%27 = tail call i32 @SSL_connect(i32* %15)
switch i32 %27, label %30 [
i32 1, label %39
i32 -1, label %28
]
28: ; preds = %26
%29 = tail call i32 (...) @ERR_get_error()
br label %30
30: ; preds = %26, %28
%31 = phi i32 [ %29, %28 ], [ %27, %26 ]
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 1023
store i8 0, i8* %32
br label %33
33: ; preds = %11, %17, %23, %30
%34 = phi i32 [ %31, %30 ], [ %25, %23 ], [ %19, %17 ], [ %13, %11 ]
%35 = phi i8* [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), %30 ], [ getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), %23 ], [ getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), %17 ], [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), %11 ]
%36 = call i32 @ERR_error_string_n(i32 %34, i8* %5, i32 1023)
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* %35, i8* %5)
br label %39
39: ; preds = %33, %26
%40 = phi i32 [ 0, %26 ], [ -1, %33 ]
ret i32 %40
}