#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 SSL_CTX_load_verify_locations(int /*<<< orphan*/ *, char *, char *);
int SSL_CTX_set_default_verify_paths(int /*<<< orphan*/ *);
scalar_t__ SSL_CTX_use_PrivateKey_file(int /*<<< orphan*/ *, char *,
                                       int /*<<< orphan*/);
scalar_t__ SSL_CTX_use_certificate_file(int /*<<< orphan*/ *, char *,
                                        int /*<<< orphan*/);
int /*<<< orphan*/ SSL_FILETYPE_PEM;
int /*<<< orphan*/ print_str(char *);
int ssl_load_server_certs(SSL_CTX *ctx, char *cert_file, char *key_file) {
  if (SSL_CTX_load_verify_locations(ctx, cert_file, key_file) != 1) {
    return 1;
  }
  if (SSL_CTX_set_default_verify_paths(ctx) != 1) {
    return 1;
  }
  if (SSL_CTX_use_certificate_file(ctx, cert_file, SSL_FILETYPE_PEM) <= 0) {
    return 1;
  }
  if (SSL_CTX_use_PrivateKey_file(ctx, key_file, SSL_FILETYPE_PEM) <= 0) {
    return 2;
  }
  if (!SSL_CTX_check_private_key(ctx)) {
    print_str("ERROR: private key does not match the public certificate\n");
    return 3;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ssl_load_server_certs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <SSL_CTX_load_verify_locations@plt>
cmp    $0x1,%eax
je     119a <ssl_load_server_certs+0x3a>
movl   $0x1,-0x4(%rbp)
jmp    1241 <ssl_load_server_certs+0xe1>
mov    -0x10(%rbp),%rdi
call   1050 <SSL_CTX_set_default_verify_paths@plt>
cmp    $0x1,%eax
je     11b8 <ssl_load_server_certs+0x58>
movl   $0x1,-0x4(%rbp)
jmp    1241 <ssl_load_server_certs+0xe1>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e21(%rip),%rax
mov    (%rax),%edx
call   1040 <SSL_CTX_use_certificate_file@plt>
cmp    $0x0,%rax
jg     11e4 <ssl_load_server_certs+0x84>
movl   $0x1,-0x4(%rbp)
jmp    1241 <ssl_load_server_certs+0xe1>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2df5(%rip),%rax
mov    (%rax),%edx
call   1070 <SSL_CTX_use_PrivateKey_file@plt>
cmp    $0x0,%rax
jg     1210 <ssl_load_server_certs+0xb0>
movl   $0x2,-0x4(%rbp)
jmp    1241 <ssl_load_server_certs+0xe1>
mov    -0x10(%rbp),%rdi
call   1080 <SSL_CTX_check_private_key@plt>
cmp    $0x0,%eax
jne    123a <ssl_load_server_certs+0xda>
lea    0xdd7(%rip),%rdi
call   1030 <print_str@plt>
movl   $0x3,-0x4(%rbp)
jmp    1241 <ssl_load_server_certs+0xe1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ssl_load_server_certs>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%rbx
call   1060 <SSL_CTX_load_verify_locations@plt>
mov    $0x1,%r14d
cmp    $0x1,%eax
jne    11e6 <ssl_load_server_certs+0x86>
mov    %rbx,%rdi
call   1050 <SSL_CTX_set_default_verify_paths@plt>
cmp    $0x1,%eax
jne    11e6 <ssl_load_server_certs+0x86>
mov    0x2e53(%rip),%r12
mov    (%r12),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <SSL_CTX_use_certificate_file@plt>
test   %rax,%rax
jle    11e6 <ssl_load_server_certs+0x86>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <SSL_CTX_use_PrivateKey_file@plt>
test   %rax,%rax
jle    11e0 <ssl_load_server_certs+0x80>
mov    %rbx,%rdi
call   1080 <SSL_CTX_check_private_key@plt>
xor    %r14d,%r14d
test   %eax,%eax
jne    11e6 <ssl_load_server_certs+0x86>
lea    0xe2d(%rip),%rdi
call   1030 <print_str@plt>
mov    $0x3,%r14d
jmp    11e6 <ssl_load_server_certs+0x86>
mov    $0x2,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SSL_FILETYPE_PEM = global i32 0
@.str = [58 x i8] c"ERROR: private key does not match the public certificate\0A\00"
define i32 @ssl_load_server_certs(i32* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
store i32* %0, i32** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%8 = load i32*, i32** %5
%9 = load i8*, i8** %6
%10 = load i8*, i8** %7
%11 = call i32 @SSL_CTX_load_verify_locations(i32* %8, i8* %9, i8* %10)
%12 = icmp ne i32 %11, 1
br i1 %12, label %13, label %14
13: ; preds = %3
store i32 1, i32* %4
br label %40
14: ; preds = %3
%15 = load i32*, i32** %5
%16 = call i32 @SSL_CTX_set_default_verify_paths(i32* %15)
%17 = icmp ne i32 %16, 1
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 1, i32* %4
br label %40
19: ; preds = %14
%20 = load i32*, i32** %5
%21 = load i8*, i8** %6
%22 = load i32, i32* @SSL_FILETYPE_PEM
%23 = call i64 @SSL_CTX_use_certificate_file(i32* %20, i8* %21, i32 %22)
%24 = icmp sle i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %19
store i32 1, i32* %4
br label %40
26: ; preds = %19
%27 = load i32*, i32** %5
%28 = load i8*, i8** %7
%29 = load i32, i32* @SSL_FILETYPE_PEM
%30 = call i64 @SSL_CTX_use_PrivateKey_file(i32* %27, i8* %28, i32 %29)
%31 = icmp sle i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %26
store i32 2, i32* %4
br label %40
33: ; preds = %26
%34 = load i32*, i32** %5
%35 = call i32 @SSL_CTX_check_private_key(i32* %34)
%36 = icmp ne i32 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %33
%38 = call i32 @print_str(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
store i32 3, i32* %4
br label %40
39: ; preds = %33
store i32 0, i32* %4
br label %40
40: ; preds = %39, %37, %32, %25, %18, %13
%41 = load i32, i32* %4
ret i32 %41
}

LLVM IR (-O2):
@SSL_FILETYPE_PEM = global i32 0
@.str = [58 x i8] c"ERROR: private key does not match the public certificate\0A\00"
define i32 @ssl_load_server_certs(i32* %0, i8* %1, i8* %2) {
%4 = tail call i32 @SSL_CTX_load_verify_locations(i32* %0, i8* %1, i8* %2)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %22
6: ; preds = %3
%7 = tail call i32 @SSL_CTX_set_default_verify_paths(i32* %0)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %22
9: ; preds = %6
%10 = load i32, i32* @SSL_FILETYPE_PEM
%11 = tail call i64 @SSL_CTX_use_certificate_file(i32* %0, i8* %1, i32 %10)
%12 = icmp slt i64 %11, 1
br i1 %12, label %22, label %13
13: ; preds = %9
%14 = load i32, i32* @SSL_FILETYPE_PEM
%15 = tail call i64 @SSL_CTX_use_PrivateKey_file(i32* %0, i8* %2, i32 %14)
%16 = icmp slt i64 %15, 1
br i1 %16, label %22, label %17
17: ; preds = %13
%18 = tail call i32 @SSL_CTX_check_private_key(i32* %0)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i32 @print_str(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %17, %13, %9, %6, %3, %20
%23 = phi i32 [ 3, %20 ], [ 1, %3 ], [ 1, %6 ], [ 1, %9 ], [ 2, %13 ], [ 0, %17 ]
ret i32 %23
}