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

/* Variables and functions */
int /*<<< orphan*/ SSL_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *SSL_CTX_new(int /*<<< orphan*/);
int SSL_CTX_use_certificate_file(int /*<<< orphan*/ *, char const *,
                                 int /*<<< orphan*/);
int /*<<< orphan*/ SSL_FILETYPE_PEM;
int /*<<< orphan*/ SSL_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *SSL_get_certificate(int /*<<< orphan*/ *);
int /*<<< orphan*/ *SSL_new(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSLv23_server_method();
int ssl_init();
int /*<<< orphan*/ ssl_x509_refcount_inc(int /*<<< orphan*/ *);
X509 *ssl_x509_load(const char *filename) {
  X509 *crt = NULL;
  SSL_CTX *tmpctx;
  SSL *tmpssl;
  int rv;
  if (ssl_init() == -1)
    return NULL;
  tmpctx = SSL_CTX_new(SSLv23_server_method());
  if (!tmpctx)
    goto leave1;
  rv = SSL_CTX_use_certificate_file(tmpctx, filename, SSL_FILETYPE_PEM);
  if (rv != 1)
    goto leave2;
  tmpssl = SSL_new(tmpctx);
  if (!tmpssl)
    goto leave2;
  crt = SSL_get_certificate(tmpssl);
  if (crt)
    ssl_x509_refcount_inc(crt);
  SSL_free(tmpssl);
leave2:
  SSL_CTX_free(tmpctx);
leave1:
  return crt;
}


x86 assembly (clang, -O0):
<ssl_x509_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   10b0 <ssl_init@plt>
cmp    $0xffffffff,%eax
jne    11c1 <ssl_x509_load+0x31>
movq   $0x0,-0x8(%rbp)
jmp    1263 <ssl_x509_load+0xd3>
mov    $0x0,%al
call   1040 <SSLv23_server_method@plt>
mov    %eax,%edi
call   1080 <SSL_CTX_new@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e3 <ssl_x509_load+0x53>
jmp    125b <ssl_x509_load+0xcb>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2df6(%rip),%rax
mov    (%rax),%edx
call   1070 <SSL_CTX_use_certificate_file@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
je     120b <ssl_x509_load+0x7b>
jmp    1252 <ssl_x509_load+0xc2>
mov    -0x20(%rbp),%rdi
call   1060 <SSL_new@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1228 <ssl_x509_load+0x98>
jmp    1252 <ssl_x509_load+0xc2>
mov    -0x28(%rbp),%rdi
call   1090 <SSL_get_certificate@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1249 <ssl_x509_load+0xb9>
mov    -0x18(%rbp),%rdi
call   1050 <ssl_x509_refcount_inc@plt>
mov    -0x28(%rbp),%rdi
call   1030 <SSL_free@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <SSL_CTX_free@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ssl_x509_load>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
xor    %ebx,%ebx
xor    %eax,%eax
call   10b0 <ssl_init@plt>
cmp    $0xffffffff,%eax
je     1213 <ssl_x509_load+0x83>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <SSLv23_server_method@plt>
mov    %eax,%edi
call   1080 <SSL_CTX_new@plt>
test   %rax,%rax
je     1213 <ssl_x509_load+0x83>
mov    %rax,%r14
mov    0x2e23(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <SSL_CTX_use_certificate_file@plt>
cmp    $0x1,%eax
jne    1209 <ssl_x509_load+0x79>
mov    %r14,%rdi
call   1060 <SSL_new@plt>
test   %rax,%rax
je     1209 <ssl_x509_load+0x79>
mov    %rax,%r15
mov    %rax,%rdi
call   1090 <SSL_get_certificate@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11ff <ssl_x509_load+0x6f>
mov    %rbx,%rdi
call   1050 <ssl_x509_refcount_inc@plt>
mov    %r15,%rdi
call   1030 <SSL_free@plt>
jmp    120b <ssl_x509_load+0x7b>
xor    %ebx,%ebx
mov    %r14,%rdi
call   10a0 <SSL_CTX_free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SSL_FILETYPE_PEM = global i32 0
define i32* @ssl_x509_load(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
store i8* %0, i8** %3
store i32* null, i32** %4
%8 = call i32 (...) @ssl_init()
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %11
10: ; preds = %1
store i32* null, i32** %2
br label %47
11: ; preds = %1
%12 = call i32 (...) @SSLv23_server_method()
%13 = call i32* @SSL_CTX_new(i32 %12)
store i32* %13, i32** %5
%14 = load i32*, i32** %5
%15 = icmp ne i32* %14, null
br i1 %15, label %17, label %16
16: ; preds = %11
br label %45
17: ; preds = %11
%18 = load i32*, i32** %5
%19 = load i8*, i8** %3
%20 = load i32, i32* @SSL_FILETYPE_PEM
%21 = call i32 @SSL_CTX_use_certificate_file(i32* %18, i8* %19, i32 %20)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp ne i32 %22, 1
br i1 %23, label %24, label %25
24: ; preds = %17
br label %42
25: ; preds = %17
%26 = load i32*, i32** %5
%27 = call i32* @SSL_new(i32* %26)
store i32* %27, i32** %6
%28 = load i32*, i32** %6
%29 = icmp ne i32* %28, null
br i1 %29, label %31, label %30
30: ; preds = %25
br label %42
31: ; preds = %25
%32 = load i32*, i32** %6
%33 = call i32* @SSL_get_certificate(i32* %32)
store i32* %33, i32** %4
%34 = load i32*, i32** %4
%35 = icmp ne i32* %34, null
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = load i32*, i32** %4
%38 = call i32 @ssl_x509_refcount_inc(i32* %37)
br label %39
39: ; preds = %36, %31
%40 = load i32*, i32** %6
%41 = call i32 @SSL_free(i32* %40)
br label %42
42: ; preds = %39, %30, %24
%43 = load i32*, i32** %5
%44 = call i32 @SSL_CTX_free(i32* %43)
br label %45
45: ; preds = %42, %16
%46 = load i32*, i32** %4
store i32* %46, i32** %2
br label %47
47: ; preds = %45, %10
%48 = load i32*, i32** %2
ret i32* %48
}

LLVM IR (-O2):
@SSL_FILETYPE_PEM = global i32 0
define i32* @ssl_x509_load(i8* %0) {
%2 = tail call i32 (...) @ssl_init()
%3 = icmp eq i32 %2, -1
br i1 %3, label %25, label %4
4: ; preds = %1
%5 = tail call i32 (...) @SSLv23_server_method()
%6 = tail call i32* @SSL_CTX_new(i32 %5)
%7 = icmp eq i32* %6, null
br i1 %7, label %25, label %8
8: ; preds = %4
%9 = load i32, i32* @SSL_FILETYPE_PEM
%10 = tail call i32 @SSL_CTX_use_certificate_file(i32* %6, i8* %0, i32 %9)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %22
12: ; preds = %8
%13 = tail call i32* @SSL_new(i32* %6)
%14 = icmp eq i32* %13, null
br i1 %14, label %22, label %15
15: ; preds = %12
%16 = tail call i32* @SSL_get_certificate(i32* %13)
%17 = icmp eq i32* %16, null
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = tail call i32 @ssl_x509_refcount_inc(i32* %16)
br label %20
20: ; preds = %18, %15
%21 = tail call i32 @SSL_free(i32* %13)
br label %22
22: ; preds = %12, %8, %20
%23 = phi i32* [ null, %8 ], [ %16, %20 ], [ null, %12 ]
%24 = tail call i32 @SSL_CTX_free(i32* %6)
br label %25
25: ; preds = %22, %4, %1
%26 = phi i32* [ null, %1 ], [ %23, %22 ], [ null, %4 ]
ret i32* %26
}