#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*/ ERR_clear_error();
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_chain_file(int /*<<< orphan*/ *,
                                              char const *);
int /*<<< orphan*/ SSL_FILETYPE_PEM;
int zopenssl_SSL_CTX_set_cert(SSL_CTX *ctx, const char *cert_file,
                              const char *key_file) {
  ERR_clear_error();
  if ((!cert_file) ||
      (SSL_CTX_use_certificate_chain_file(ctx, cert_file) <= 0)) {
    return (-1);
  }
  if ((!key_file) ||
      (SSL_CTX_use_PrivateKey_file(ctx, key_file, SSL_FILETYPE_PEM) <= 0)) {
    return (-1);
  }
  if (!SSL_CTX_check_private_key(ctx)) {
    return (-1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<zopenssl_SSL_CTX_set_cert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    $0x0,%al
call   1040 <ERR_clear_error@plt>
cmpq   $0x0,-0x18(%rbp)
je     117d <zopenssl_SSL_CTX_set_cert+0x3d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <SSL_CTX_use_certificate_chain_file@plt>
cmp    $0x0,%rax
jg     1189 <zopenssl_SSL_CTX_set_cert+0x49>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e5 <zopenssl_SSL_CTX_set_cert+0xa5>
cmpq   $0x0,-0x20(%rbp)
je     11b4 <zopenssl_SSL_CTX_set_cert+0x74>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2e45(%rip),%rax
mov    (%rax),%edx
call   1050 <SSL_CTX_use_PrivateKey_file@plt>
cmp    $0x0,%rax
jg     11c0 <zopenssl_SSL_CTX_set_cert+0x80>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e5 <zopenssl_SSL_CTX_set_cert+0xa5>
mov    -0x10(%rbp),%rdi
call   1060 <SSL_CTX_check_private_key@plt>
cmp    $0x0,%eax
jne    11de <zopenssl_SSL_CTX_set_cert+0x9e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e5 <zopenssl_SSL_CTX_set_cert+0xa5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zopenssl_SSL_CTX_set_cert>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %rdi,%r15
xor    %eax,%eax
call   1040 <ERR_clear_error@plt>
mov    $0xffffffff,%r14d
test   %rbx,%rbx
je     119e <zopenssl_SSL_CTX_set_cert+0x5e>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <SSL_CTX_use_certificate_chain_file@plt>
test   %rbp,%rbp
je     119e <zopenssl_SSL_CTX_set_cert+0x5e>
test   %rax,%rax
jle    119e <zopenssl_SSL_CTX_set_cert+0x5e>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    %rbp,%rsi
call   1050 <SSL_CTX_use_PrivateKey_file@plt>
test   %rax,%rax
jle    119e <zopenssl_SSL_CTX_set_cert+0x5e>
mov    %r15,%rdi
call   1060 <SSL_CTX_check_private_key@plt>
cmp    $0x1,%eax
sbb    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SSL_FILETYPE_PEM = global i32 0
define i32 @zopenssl_SSL_CTX_set_cert(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 = call i32 (...) @ERR_clear_error()
%9 = load i8*, i8** %6
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %16
11: ; preds = %3
%12 = load i32*, i32** %5
%13 = load i8*, i8** %6
%14 = call i64 @SSL_CTX_use_certificate_chain_file(i32* %12, i8* %13)
%15 = icmp sle i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %11, %3
store i32 -1, i32* %4
br label %33
17: ; preds = %11
%18 = load i8*, i8** %7
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %26
20: ; preds = %17
%21 = load i32*, i32** %5
%22 = load i8*, i8** %7
%23 = load i32, i32* @SSL_FILETYPE_PEM
%24 = call i64 @SSL_CTX_use_PrivateKey_file(i32* %21, i8* %22, i32 %23)
%25 = icmp sle i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %20, %17
store i32 -1, i32* %4
br label %33
27: ; preds = %20
%28 = load i32*, i32** %5
%29 = call i32 @SSL_CTX_check_private_key(i32* %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %32, label %31
31: ; preds = %27
store i32 -1, i32* %4
br label %33
32: ; preds = %27
store i32 0, i32* %4
br label %33
33: ; preds = %32, %31, %26, %16
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
@SSL_FILETYPE_PEM = global i32 0
define i32 @zopenssl_SSL_CTX_set_cert(i32* %0, i8* %1, i8* %2) {
%4 = tail call i32 (...) @ERR_clear_error()
%5 = icmp eq i8* %1, null
br i1 %5, label %19, label %6
6: ; preds = %3
%7 = tail call i64 @SSL_CTX_use_certificate_chain_file(i32* %0, i8* %1)
%8 = icmp slt i64 %7, 1
%9 = icmp eq i8* %2, null
%10 = or i1 %9, %8
br i1 %10, label %19, label %11
11: ; preds = %6
%12 = load i32, i32* @SSL_FILETYPE_PEM
%13 = tail call i64 @SSL_CTX_use_PrivateKey_file(i32* %0, i8* %2, i32 %12)
%14 = icmp slt i64 %13, 1
br i1 %14, label %19, label %15
15: ; preds = %11
%16 = tail call i32 @SSL_CTX_check_private_key(i32* %0)
%17 = icmp eq i32 %16, 0
%18 = sext i1 %17 to i32
br label %19
19: ; preds = %15, %11, %3, %6
%20 = phi i32 [ -1, %6 ], [ -1, %3 ], [ -1, %11 ], [ %18, %15 ]
ret i32 %20
}