#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SSL_CTX_check_private_key(int /*<<< orphan*/ *);
scalar_t__ SSL_CTX_use_PrivateKey_file(int /*<<< orphan*/ *, char const *,
                                       int /*<<< orphan*/);
scalar_t__ SSL_CTX_use_certificate_file(int /*<<< orphan*/ *, char const *,
                                        int /*<<< orphan*/);
int /*<<< orphan*/ SSL_FILETYPE_PEM;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ *stderr;
void load_certificate(SSL_CTX *ctx, const char *cert, const char *key) {
  if (SSL_CTX_use_certificate_file(ctx, cert, SSL_FILETYPE_PEM) <= 0) {
    {
      FILE *pf = fopen("server.log", "a");
      fprintf(pf, "%s\n", "[error] certificate is invalid");
      fclose(pf);
    };
    fprintf(stderr, "%s\n", "[error] certificate is invalid");
    exit(1);
  };
  if (SSL_CTX_use_PrivateKey_file(ctx, key, SSL_FILETYPE_PEM) <= 0) {
    {
      FILE *pf = fopen("server.log", "a");
      fprintf(pf, "%s\n", "[error] private key is invalid");
      fclose(pf);
    };
    fprintf(stderr, "%s\n", "[error] private key is invalid");
    exit(1);
  };
  if (!SSL_CTX_check_private_key(ctx)) {
    {
      FILE *pf = fopen("server.log", "a");
      fprintf(pf, "%s\n", "[error] key pair does not match");
      fclose(pf);
    };
    fprintf(stderr, "%s\n", "[error] key pair does not match");
    exit(1);
  };
}


x86 assembly (clang, -O0):
<load_certificate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2e55(%rip),%rax
mov    (%rax),%edx
call   1040 <SSL_CTX_use_certificate_file@plt>
cmp    $0x0,%rax
jg     1202 <load_certificate+0x92>
lea    0xe55(%rip),%rdi
lea    0xe59(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe47(%rip),%rsi
lea    0xe44(%rip),%rdx
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%rdi
lea    0xe21(%rip),%rsi
lea    0xe1e(%rip),%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2dd7(%rip),%rax
mov    (%rax),%edx
call   1060 <SSL_CTX_use_PrivateKey_file@plt>
cmp    $0x0,%rax
jg     1280 <load_certificate+0x110>
lea    0xdd7(%rip),%rdi
lea    0xddb(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xdc9(%rip),%rsi
lea    0xde5(%rip),%rdx
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%rdi
lea    0xda3(%rip),%rsi
lea    0xdbf(%rip),%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1090 <SSL_CTX_check_private_key@plt>
cmp    $0x0,%eax
jne    12f0 <load_certificate+0x180>
lea    0xd67(%rip),%rdi
lea    0xd6b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xd59(%rip),%rsi
lea    0xd94(%rip),%rdx
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2d08(%rip),%rax
mov    (%rax),%rdi
lea    0xd33(%rip),%rsi
lea    0xd6e(%rip),%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_certificate>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rdi,%rbx
mov    0x2e66(%rip),%r15
mov    (%r15),%edx
call   1040 <SSL_CTX_use_certificate_file@plt>
test   %rax,%rax
jle    11b4 <load_certificate+0x44>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <SSL_CTX_use_PrivateKey_file@plt>
test   %rax,%rax
jle    11da <load_certificate+0x6a>
mov    %rbx,%rdi
call   1090 <SSL_CTX_check_private_key@plt>
test   %eax,%eax
je     1200 <load_certificate+0x90>
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe45(%rip),%rdi
lea    0xe49(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xe3c(%rip),%r14
lea    0xe39(%rip),%r15
jmp    1224 <load_certificate+0xb4>
lea    0xe1f(%rip),%rdi
lea    0xe23(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xe16(%rip),%r14
lea    0xe32(%rip),%r15
jmp    1224 <load_certificate+0xb4>
lea    0xdf9(%rip),%rdi
lea    0xdfd(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xdf0(%rip),%r14
lea    0xe2b(%rip),%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@SSL_FILETYPE_PEM = global i32 0
@.str = [11 x i8] c"server.log\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [31 x i8] c"[error] certificate is invalid\00"
@stderr = global i32* null
@.str.4 = [31 x i8] c"[error] private key is invalid\00"
@.str.5 = [32 x i8] c"[error] key pair does not match\00"
define void @load_certificate(i32* %0, i8* %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
store i32* %0, i32** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%10 = load i32*, i32** %4
%11 = load i8*, i8** %5
%12 = load i32, i32* @SSL_FILETYPE_PEM
%13 = call i64 @SSL_CTX_use_certificate_file(i32* %10, i8* %11, i32 %12)
%14 = icmp sle i64 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %3
%16 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %7
%17 = load i32*, i32** %7
%18 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%19 = load i32*, i32** %7
%20 = call i32 @fclose(i32* %19)
%21 = load i32*, i32** @stderr
%22 = call i32 @fprintf(i32* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %3
%25 = load i32*, i32** %4
%26 = load i8*, i8** %6
%27 = load i32, i32* @SSL_FILETYPE_PEM
%28 = call i64 @SSL_CTX_use_PrivateKey_file(i32* %25, i8* %26, i32 %27)
%29 = icmp sle i64 %28, 0
br i1 %29, label %30, label %39
30: ; preds = %24
%31 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %31, i32** %8
%32 = load i32*, i32** %8
%33 = call i32 @fprintf(i32* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%34 = load i32*, i32** %8
%35 = call i32 @fclose(i32* %34)
%36 = load i32*, i32** @stderr
%37 = call i32 @fprintf(i32* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %24
%40 = load i32*, i32** %4
%41 = call i32 @SSL_CTX_check_private_key(i32* %40)
%42 = icmp ne i32 %41, 0
br i1 %42, label %52, label %43
43: ; preds = %39
%44 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %44, i32** %9
%45 = load i32*, i32** %9
%46 = call i32 @fprintf(i32* %45, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
%47 = load i32*, i32** %9
%48 = call i32 @fclose(i32* %47)
%49 = load i32*, i32** @stderr
%50 = call i32 @fprintf(i32* %49, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %39
ret void
}

LLVM IR (-O2):
@SSL_FILETYPE_PEM = global i32 0
@.str = [11 x i8] c"server.log\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [31 x i8] c"[error] certificate is invalid\00"
@stderr = global i32* null
@.str.4 = [31 x i8] c"[error] private key is invalid\00"
@.str.5 = [32 x i8] c"[error] key pair does not match\00"
define void @load_certificate(i32* %0, i8* %1, i8* %2) {
%4 = load i32, i32* @SSL_FILETYPE_PEM
%5 = tail call i64 @SSL_CTX_use_certificate_file(i32* %0, i8* %1, i32 %4)
%6 = icmp slt i64 %5, 1
br i1 %6, label %7, label %14
7: ; preds = %3
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @fprintf(i32* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%10 = tail call i32 @fclose(i32* %8)
%11 = load i32*, i32** @stderr
%12 = tail call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %3
%15 = load i32, i32* @SSL_FILETYPE_PEM
%16 = tail call i64 @SSL_CTX_use_PrivateKey_file(i32* %0, i8* %2, i32 %15)
%17 = icmp slt i64 %16, 1
br i1 %17, label %18, label %25
18: ; preds = %14
%19 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 @fprintf(i32* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%21 = tail call i32 @fclose(i32* %19)
%22 = load i32*, i32** @stderr
%23 = tail call i32 @fprintf(i32* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %14
%26 = tail call i32 @SSL_CTX_check_private_key(i32* %0)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %25
%29 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%30 = tail call i32 @fprintf(i32* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
%31 = tail call i32 @fclose(i32* %29)
%32 = load i32*, i32** @stderr
%33 = tail call i32 @fprintf(i32* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
%34 = tail call i32 @exit(i32 1)
unreachable
35: ; preds = %25
ret void
}