#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;

/* Variables and functions */
int /*<<< orphan*/ SSL_CTX_check_private_key(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_CTX_load_verify_locations(int /*<<< orphan*/ *, char *,
                                                 int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_CTX_set_client_CA_list(int /*<<< orphan*/ *,
                                              int /*<<< orphan*/);
int /*<<< orphan*/ SSL_CTX_use_PrivateKey_file(int /*<<< orphan*/ *, char *,
                                               int /*<<< orphan*/);
int /*<<< orphan*/ SSL_CTX_use_certificate_file(int /*<<< orphan*/ *, char *,
                                                int /*<<< orphan*/);
int /*<<< orphan*/ SSL_FILETYPE_PEM;
int /*<<< orphan*/ SSL_load_client_CA_file(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ ssl_fatal(char *);
int /*<<< orphan*/ stderr;
int ssl_load_certificates(SSL_CTX *ctx, char *root, char *cert, char *key) {
  if (!(*root && *cert && *key)) {
    fprintf(stderr, "Warning, server is unsecured!\n");
    return -1;
  }
  if (!SSL_CTX_load_verify_locations(ctx, root, NULL))
    ssl_fatal("verify");
  SSL_CTX_set_client_CA_list(ctx, SSL_load_client_CA_file(root));
  if (!SSL_CTX_use_certificate_file(ctx, cert, SSL_FILETYPE_PEM))
    ssl_fatal("cert");
  if (!SSL_CTX_use_PrivateKey_file(ctx, key, SSL_FILETYPE_PEM))
    ssl_fatal("key");
  if (!SSL_CTX_check_private_key(ctx))
    ssl_fatal("cert/key");
  return 0;
}


x86 assembly (clang, -O0):
<ssl_load_certificates>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11c8 <ssl_load_certificates+0x48>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11c8 <ssl_load_certificates+0x48>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11e9 <ssl_load_certificates+0x69>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a6 <ssl_load_certificates+0x126>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <SSL_CTX_load_verify_locations@plt>
cmp    $0x0,%eax
jne    120f <ssl_load_certificates+0x8f>
lea    0xe15(%rip),%rdi
call   1040 <ssl_fatal@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <SSL_load_client_CA_file@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
call   1030 <SSL_CTX_set_client_CA_list@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2dae(%rip),%rax
mov    (%rax),%edx
call   1050 <SSL_CTX_use_certificate_file@plt>
cmp    $0x0,%eax
jne    1256 <ssl_load_certificates+0xd6>
lea    0xdd5(%rip),%rdi
call   1040 <ssl_fatal@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    0x2d83(%rip),%rax
mov    (%rax),%edx
call   1090 <SSL_CTX_use_PrivateKey_file@plt>
cmp    $0x0,%eax
jne    1281 <ssl_load_certificates+0x101>
lea    0xdb4(%rip),%rdi
call   1040 <ssl_fatal@plt>
mov    -0x10(%rbp),%rdi
call   10a0 <SSL_CTX_check_private_key@plt>
cmp    $0x0,%eax
jne    129f <ssl_load_certificates+0x11f>
lea    0xd91(%rip),%rdi
call   1040 <ssl_fatal@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ssl_load_certificates>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmpb   $0x0,(%rsi)
je     1235 <ssl_load_certificates+0xb5>
mov    %rdx,%r12
cmpb   $0x0,(%rdx)
je     1235 <ssl_load_certificates+0xb5>
mov    %rcx,%r14
cmpb   $0x0,(%rcx)
je     1235 <ssl_load_certificates+0xb5>
mov    %rsi,%rbx
mov    %rdi,%r15
xor    %edx,%edx
call   1070 <SSL_CTX_load_verify_locations@plt>
test   %eax,%eax
jne    11c6 <ssl_load_certificates+0x46>
lea    0xe5e(%rip),%rdi
call   1040 <ssl_fatal@plt>
mov    %rbx,%rdi
call   1080 <SSL_load_client_CA_file@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1030 <SSL_CTX_set_client_CA_list@plt>
mov    0x2e09(%rip),%rbx
mov    (%rbx),%edx
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <SSL_CTX_use_certificate_file@plt>
test   %eax,%eax
jne    11fc <ssl_load_certificates+0x7c>
lea    0xe2f(%rip),%rdi
call   1040 <ssl_fatal@plt>
mov    (%rbx),%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   1090 <SSL_CTX_use_PrivateKey_file@plt>
test   %eax,%eax
jne    1219 <ssl_load_certificates+0x99>
lea    0xe1c(%rip),%rdi
call   1040 <ssl_fatal@plt>
mov    %r15,%rdi
call   10a0 <SSL_CTX_check_private_key@plt>
xor    %ebx,%ebx
test   %eax,%eax
jne    124f <ssl_load_certificates+0xcf>
lea    0xdfd(%rip),%rdi
call   1040 <ssl_fatal@plt>
jmp    124f <ssl_load_certificates+0xcf>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
lea    0xdbb(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"Warning, server is unsecured!\0A\00"
@.str.1 = [7 x i8] c"verify\00"
@SSL_FILETYPE_PEM = global i32 0
@.str.2 = [5 x i8] c"cert\00"
@.str.3 = [4 x i8] c"key\00"
@.str.4 = [9 x i8] c"cert/key\00"
define i32 @ssl_load_certificates(i32* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i32* %0, i32** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%10 = load i8*, i8** %7
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %4
%15 = load i8*, i8** %8
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = load i8*, i8** %9
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %19, %14, %4
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %61
27: ; preds = %19
%28 = load i32*, i32** %6
%29 = load i8*, i8** %7
%30 = call i32 @SSL_CTX_load_verify_locations(i32* %28, i8* %29, i32* null)
%31 = icmp ne i32 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %27
%33 = call i32 @ssl_fatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %27
%35 = load i32*, i32** %6
%36 = load i8*, i8** %7
%37 = call i32 @SSL_load_client_CA_file(i8* %36)
%38 = call i32 @SSL_CTX_set_client_CA_list(i32* %35, i32 %37)
%39 = load i32*, i32** %6
%40 = load i8*, i8** %8
%41 = load i32, i32* @SSL_FILETYPE_PEM
%42 = call i32 @SSL_CTX_use_certificate_file(i32* %39, i8* %40, i32 %41)
%43 = icmp ne i32 %42, 0
br i1 %43, label %46, label %44
44: ; preds = %34
%45 = call i32 @ssl_fatal(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %46
46: ; preds = %44, %34
%47 = load i32*, i32** %6
%48 = load i8*, i8** %9
%49 = load i32, i32* @SSL_FILETYPE_PEM
%50 = call i32 @SSL_CTX_use_PrivateKey_file(i32* %47, i8* %48, i32 %49)
%51 = icmp ne i32 %50, 0
br i1 %51, label %54, label %52
52: ; preds = %46
%53 = call i32 @ssl_fatal(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %54
54: ; preds = %52, %46
%55 = load i32*, i32** %6
%56 = call i32 @SSL_CTX_check_private_key(i32* %55)
%57 = icmp ne i32 %56, 0
br i1 %57, label %60, label %58
58: ; preds = %54
%59 = call i32 @ssl_fatal(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %60
60: ; preds = %58, %54
store i32 0, i32* %5
br label %61
61: ; preds = %60, %24
%62 = load i32, i32* %5
ret i32 %62
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"Warning, server is unsecured!\0A\00"
@.str.1 = [7 x i8] c"verify\00"
@SSL_FILETYPE_PEM = global i32 0
@.str.2 = [5 x i8] c"cert\00"
@.str.3 = [4 x i8] c"key\00"
@.str.4 = [9 x i8] c"cert/key\00"
define i32 @ssl_load_certificates(i32* %0, i8* %1, i8* %2, i8* %3) {
%5 = load i8, i8* %1
%6 = icmp eq i8 %5, 0
br i1 %6, label %13, label %7
7: ; preds = %4
%8 = load i8, i8* %2
%9 = icmp eq i8 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = load i8, i8* %3
%12 = icmp eq i8 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10, %7, %4
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %40
16: ; preds = %10
%17 = tail call i32 @SSL_CTX_load_verify_locations(i32* %0, i8* %1, i32* null)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = tail call i32 @ssl_fatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %16
%22 = tail call i32 @SSL_load_client_CA_file(i8* %1)
%23 = tail call i32 @SSL_CTX_set_client_CA_list(i32* %0, i32 %22)
%24 = load i32, i32* @SSL_FILETYPE_PEM
%25 = tail call i32 @SSL_CTX_use_certificate_file(i32* %0, i8* %2, i32 %24)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = tail call i32 @ssl_fatal(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %21
%30 = load i32, i32* @SSL_FILETYPE_PEM
%31 = tail call i32 @SSL_CTX_use_PrivateKey_file(i32* %0, i8* %3, i32 %30)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = tail call i32 @ssl_fatal(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %35
35: ; preds = %33, %29
%36 = tail call i32 @SSL_CTX_check_private_key(i32* %0)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = tail call i32 @ssl_fatal(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %40
40: ; preds = %35, %38, %13
%41 = phi i32 [ -1, %13 ], [ 0, %38 ], [ 0, %35 ]
ret i32 %41
}