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

/* Variables and functions */
int /*<<< orphan*/ ERR_clear_error();
int SSL_CTX_check_private_key(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_CTX_free(int /*<<< orphan*/ *);
int SSL_CTX_load_verify_locations(int /*<<< orphan*/ *, char const *,
                                  int /*<<< orphan*/ *);
int /*<<< orphan*/ *SSL_CTX_new(int /*<<< orphan*/ const *);
int /*<<< orphan*/ SSL_CTX_set_options(int /*<<< orphan*/ *,
                                       int /*<<< orphan*/);
int SSL_CTX_use_PrivateKey_file(int /*<<< orphan*/ *, char const *,
                                int /*<<< orphan*/);
int SSL_CTX_use_certificate_chain_file(int /*<<< orphan*/ *, char const *);
int SSL_CTX_use_certificate_file(int /*<<< orphan*/ *, char const *,
                                 int /*<<< orphan*/);
int /*<<< orphan*/ SSL_FILETYPE_PEM;
int /*<<< orphan*/ SSL_OP_ALL;
int /*<<< orphan*/ *SSLv23_server_method();
int /*<<< orphan*/ zfatal(char *);
int /*<<< orphan*/ zinfo(char *);
SSL_CTX *zopenssl_SSL_CTX_create_server(const char *cert_file,
                                        const char *key_file) {
  const SSL_METHOD *method = SSLv23_server_method();
  SSL_CTX *ctx = SSL_CTX_new(method);
  if (!ctx) {
    zfatal("FATAL SSL_CTX_new");
  }
  SSL_CTX_set_options(ctx, SSL_OP_ALL);
  ERR_clear_error();
  if ((!cert_file) || (!key_file)) {
    zinfo("ERR cert_file or key_file is null");
    goto err;
  }
  if (SSL_CTX_load_verify_locations(ctx, cert_file, NULL) != 1) {
    zinfo("ERR SSL_CTX_load_verify_locations");
    goto err;
  }
  if ((SSL_CTX_use_certificate_chain_file(ctx, cert_file) != 1) &&
      (SSL_CTX_use_certificate_file(ctx, cert_file, SSL_FILETYPE_PEM) != 1)) {
    zinfo("ERR SSL_CTX_use_certificate_chain_file AND "
          "SSL_CTX_use_certificate_file");
    goto err;
  }
  if (SSL_CTX_use_PrivateKey_file(ctx, key_file, SSL_FILETYPE_PEM) != 1) {
    zinfo("ERR SSL_CTX_use_PrivateKey_file");
    goto err;
  }
  if (SSL_CTX_check_private_key(ctx) != 1) {
    zinfo("ERR SSL_CTX_check_private_key");
    goto err;
  }
  return ctx;
err:
  SSL_CTX_free(ctx);
  return 0;
}


x86 assembly (clang, -O0):
<zopenssl_SSL_CTX_create_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   1050 <SSLv23_server_method@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   10a0 <SSL_CTX_new@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ff <zopenssl_SSL_CTX_create_server+0x3f>
lea    0xe06(%rip),%rdi
call   1040 <zfatal@plt>
mov    -0x28(%rbp),%rdi
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
call   1030 <SSL_CTX_set_options@plt>
mov    $0x0,%al
call   1080 <ERR_clear_error@plt>
cmpq   $0x0,-0x10(%rbp)
je     122e <zopenssl_SSL_CTX_create_server+0x6e>
cmpq   $0x0,-0x18(%rbp)
jne    123f <zopenssl_SSL_CTX_create_server+0x7f>
lea    0xddd(%rip),%rdi
call   1090 <zinfo@plt>
jmp    1310 <zopenssl_SSL_CTX_create_server+0x150>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   10b0 <SSL_CTX_load_verify_locations@plt>
cmp    $0x1,%eax
je     126a <zopenssl_SSL_CTX_create_server+0xaa>
lea    0xdd4(%rip),%rdi
call   1090 <zinfo@plt>
jmp    1310 <zopenssl_SSL_CTX_create_server+0x150>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <SSL_CTX_use_certificate_chain_file@plt>
cmp    $0x1,%eax
je     12b0 <zopenssl_SSL_CTX_create_server+0xf0>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2d59(%rip),%rax
mov    (%rax),%edx
call   1070 <SSL_CTX_use_certificate_file@plt>
cmp    $0x1,%eax
je     12b0 <zopenssl_SSL_CTX_create_server+0xf0>
lea    0xdb0(%rip),%rdi
call   1090 <zinfo@plt>
jmp    1310 <zopenssl_SSL_CTX_create_server+0x150>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2d29(%rip),%rax
mov    (%rax),%edx
call   10c0 <SSL_CTX_use_PrivateKey_file@plt>
cmp    $0x1,%eax
je     12e0 <zopenssl_SSL_CTX_create_server+0x120>
lea    0xdc8(%rip),%rdi
call   1090 <zinfo@plt>
jmp    1310 <zopenssl_SSL_CTX_create_server+0x150>
mov    -0x28(%rbp),%rdi
call   10e0 <SSL_CTX_check_private_key@plt>
cmp    $0x1,%eax
je     1303 <zopenssl_SSL_CTX_create_server+0x143>
lea    0xdc5(%rip),%rdi
call   1090 <zinfo@plt>
jmp    1310 <zopenssl_SSL_CTX_create_server+0x150>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1321 <zopenssl_SSL_CTX_create_server+0x161>
mov    -0x28(%rbp),%rdi
call   10d0 <SSL_CTX_free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zopenssl_SSL_CTX_create_server>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   1050 <SSLv23_server_method@plt>
mov    %rax,%rdi
call   10a0 <SSL_CTX_new@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11ee <zopenssl_SSL_CTX_create_server+0x2e>
lea    0xe17(%rip),%rdi
call   1040 <zfatal@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1030 <SSL_CTX_set_options@plt>
xor    %eax,%eax
call   1080 <ERR_clear_error@plt>
lea    0xe05(%rip),%rdi
test   %r15,%r15
je     12a2 <zopenssl_SSL_CTX_create_server+0xe2>
test   %r14,%r14
je     12a2 <zopenssl_SSL_CTX_create_server+0xe2>
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   10b0 <SSL_CTX_load_verify_locations@plt>
cmp    $0x1,%eax
jne    1289 <zopenssl_SSL_CTX_create_server+0xc9>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <SSL_CTX_use_certificate_chain_file@plt>
cmp    $0x1,%eax
je     125a <zopenssl_SSL_CTX_create_server+0x9a>
mov    0x2da0(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <SSL_CTX_use_certificate_file@plt>
cmp    $0x1,%eax
jne    129b <zopenssl_SSL_CTX_create_server+0xdb>
mov    0x2d87(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   10c0 <SSL_CTX_use_PrivateKey_file@plt>
cmp    $0x1,%eax
jne    1292 <zopenssl_SSL_CTX_create_server+0xd2>
mov    %rbx,%rdi
call   10e0 <SSL_CTX_check_private_key@plt>
cmp    $0x1,%eax
je     12b1 <zopenssl_SSL_CTX_create_server+0xf1>
lea    0xe37(%rip),%rdi
jmp    12a2 <zopenssl_SSL_CTX_create_server+0xe2>
lea    0xda4(%rip),%rdi
jmp    12a2 <zopenssl_SSL_CTX_create_server+0xe2>
lea    0xe05(%rip),%rdi
jmp    12a2 <zopenssl_SSL_CTX_create_server+0xe2>
lea    0xdb4(%rip),%rdi
call   1090 <zinfo@plt>
mov    %rbx,%rdi
call   10d0 <SSL_CTX_free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [18 x i8] c"FATAL SSL_CTX_new\00"
@SSL_OP_ALL = global i32 0
@.str.1 = [34 x i8] c"ERR cert_file or key_file is null\00"
@.str.2 = [34 x i8] c"ERR SSL_CTX_load_verify_locations\00"
@SSL_FILETYPE_PEM = global i32 0
@.str.3 = [72 x i8] c"ERR SSL_CTX_use_certificate_chain_file AND SSL_CTX_use_certificate_file\00"
@.str.4 = [32 x i8] c"ERR SSL_CTX_use_PrivateKey_file\00"
@.str.5 = [30 x i8] c"ERR SSL_CTX_check_private_key\00"
define i32* @zopenssl_SSL_CTX_create_server(i8* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = call i32* (...) @SSLv23_server_method()
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = call i32* @SSL_CTX_new(i32* %9)
store i32* %10, i32** %7
%11 = load i32*, i32** %7
%12 = icmp ne i32* %11, null
br i1 %12, label %15, label %13
13: ; preds = %2
%14 = call i32 @zfatal(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
%16 = load i32*, i32** %7
%17 = load i32, i32* @SSL_OP_ALL
%18 = call i32 @SSL_CTX_set_options(i32* %16, i32 %17)
%19 = call i32 (...) @ERR_clear_error()
%20 = load i8*, i8** %4
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = load i8*, i8** %5
%24 = icmp ne i8* %23, null
br i1 %24, label %27, label %25
25: ; preds = %22, %15
%26 = call i32 @zinfo(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %63
27: ; preds = %22
%28 = load i32*, i32** %7
%29 = load i8*, i8** %4
%30 = call i32 @SSL_CTX_load_verify_locations(i32* %28, i8* %29, i32* null)
%31 = icmp ne i32 %30, 1
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 @zinfo(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %63
34: ; preds = %27
%35 = load i32*, i32** %7
%36 = load i8*, i8** %4
%37 = call i32 @SSL_CTX_use_certificate_chain_file(i32* %35, i8* %36)
%38 = icmp ne i32 %37, 1
br i1 %38, label %39, label %47
39: ; preds = %34
%40 = load i32*, i32** %7
%41 = load i8*, i8** %4
%42 = load i32, i32* @SSL_FILETYPE_PEM
%43 = call i32 @SSL_CTX_use_certificate_file(i32* %40, i8* %41, i32 %42)
%44 = icmp ne i32 %43, 1
br i1 %44, label %45, label %47
45: ; preds = %39
%46 = call i32 @zinfo(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.3, i64 0, i64 0))
br label %63
47: ; preds = %39, %34
%48 = load i32*, i32** %7
%49 = load i8*, i8** %5
%50 = load i32, i32* @SSL_FILETYPE_PEM
%51 = call i32 @SSL_CTX_use_PrivateKey_file(i32* %48, i8* %49, i32 %50)
%52 = icmp ne i32 %51, 1
br i1 %52, label %53, label %55
53: ; preds = %47
%54 = call i32 @zinfo(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
br label %63
55: ; preds = %47
%56 = load i32*, i32** %7
%57 = call i32 @SSL_CTX_check_private_key(i32* %56)
%58 = icmp ne i32 %57, 1
br i1 %58, label %59, label %61
59: ; preds = %55
%60 = call i32 @zinfo(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
br label %63
61: ; preds = %55
%62 = load i32*, i32** %7
store i32* %62, i32** %3
br label %66
63: ; preds = %59, %53, %45, %32, %25
%64 = load i32*, i32** %7
%65 = call i32 @SSL_CTX_free(i32* %64)
store i32* null, i32** %3
br label %66
66: ; preds = %63, %61
%67 = load i32*, i32** %3
ret i32* %67
}

LLVM IR (-O2):
@.str = [18 x i8] c"FATAL SSL_CTX_new\00"
@SSL_OP_ALL = global i32 0
@.str.1 = [34 x i8] c"ERR cert_file or key_file is null\00"
@.str.2 = [34 x i8] c"ERR SSL_CTX_load_verify_locations\00"
@SSL_FILETYPE_PEM = global i32 0
@.str.3 = [72 x i8] c"ERR SSL_CTX_use_certificate_chain_file AND SSL_CTX_use_certificate_file\00"
@.str.4 = [32 x i8] c"ERR SSL_CTX_use_PrivateKey_file\00"
@.str.5 = [30 x i8] c"ERR SSL_CTX_check_private_key\00"
define i32* @zopenssl_SSL_CTX_create_server(i8* %0, i8* %1) {
%3 = tail call i32* (...) @SSLv23_server_method()
%4 = tail call i32* @SSL_CTX_new(i32* %3)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @zfatal(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %2
%9 = load i32, i32* @SSL_OP_ALL
%10 = tail call i32 @SSL_CTX_set_options(i32* %4, i32 %9)
%11 = tail call i32 (...) @ERR_clear_error()
%12 = icmp ne i8* %0, null
%13 = icmp ne i8* %1, null
%14 = and i1 %12, %13
br i1 %14, label %15, label %32
15: ; preds = %8
%16 = tail call i32 @SSL_CTX_load_verify_locations(i32* %4, i8* %0, i32* null)
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %32
18: ; preds = %15
%19 = tail call i32 @SSL_CTX_use_certificate_chain_file(i32* %4, i8* %0)
%20 = icmp eq i32 %19, 1
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = load i32, i32* @SSL_FILETYPE_PEM
%23 = tail call i32 @SSL_CTX_use_certificate_file(i32* %4, i8* %0, i32 %22)
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %32
25: ; preds = %21, %18
%26 = load i32, i32* @SSL_FILETYPE_PEM
%27 = tail call i32 @SSL_CTX_use_PrivateKey_file(i32* %4, i8* %1, i32 %26)
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = tail call i32 @SSL_CTX_check_private_key(i32* %4)
%31 = icmp eq i32 %30, 1
br i1 %31, label %36, label %32
32: ; preds = %29, %25, %21, %15, %8
%33 = phi i8* [ getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), %8 ], [ getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), %15 ], [ getelementptr inbounds ([72 x i8], [72 x i8]* @.str.3, i64 0, i64 0), %21 ], [ getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), %25 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), %29 ]
%34 = tail call i32 @zinfo(i8* %33)
%35 = tail call i32 @SSL_CTX_free(i32* %4)
br label %36
36: ; preds = %29, %32
%37 = phi i32* [ null, %32 ], [ %4, %29 ]
ret i32* %37
}