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

/* Variables and functions */
int /*<<< orphan*/ ERR_print_errors_fp(int /*<<< orphan*/);
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_new(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_CTX_set_verify(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                      int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_CTX_set_verify_depth(int /*<<< orphan*/ *, int);
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*/ SSL_VERIFY_PEER;
int /*<<< orphan*/ SSL_library_init();
int /*<<< orphan*/ SSL_load_error_strings();
int /*<<< orphan*/ *TLSv1_method();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
SSL_CTX *ssl_init() {
  int err;
  int verify_client = 0;
  size_t client_len;
  char *str;
  char buf[4096];
  SSL_CTX *ctx;
  SSL *ssl;
  SSL_METHOD *meth;
  X509 *client_cert = NULL;
  SSL_library_init();
  SSL_load_error_strings();
  meth = TLSv1_method();
  ctx = SSL_CTX_new(meth);
  if (!ctx) {
    ERR_print_errors_fp(stderr);
    exit(1);
  }
  if (SSL_CTX_use_certificate_file(ctx,
                                   "/usr/local/lxlabs/kloxo/init/backend.crt",
                                   SSL_FILETYPE_PEM) <= 0) {
    ERR_print_errors_fp(stderr);
    exit(1);
  }
  if (SSL_CTX_use_PrivateKey_file(ctx,
                                  "/usr/local/lxlabs/kloxo/init/backend.key",
                                  SSL_FILETYPE_PEM) <= 0) {
    ERR_print_errors_fp(stderr);
    exit(1);
  }
  if (!SSL_CTX_check_private_key(ctx)) {
    fprintf(stderr, "Private key does not match the certificate public key\n");
    exit(1);
  }
  if (verify_client == 1) {
    if (!SSL_CTX_load_verify_locations(ctx, "server_ca.crt", NULL)) {
      ERR_print_errors_fp(stderr);
      exit(1);
    }
    SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, NULL);
    SSL_CTX_set_verify_depth(ctx, 1);
  }
  return ctx;
}


x86 assembly (clang, -O0):
<ssl_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
movl   $0x0,-0x8(%rbp)
movq   $0x0,-0x1040(%rbp)
mov    $0x0,%al
call   1040 <SSL_library_init@plt>
mov    $0x0,%al
call   10c0 <SSL_load_error_strings@plt>
mov    $0x0,%al
call   1070 <TLSv1_method@plt>
mov    %rax,-0x1038(%rbp)
mov    -0x1038(%rbp),%rdi
call   1080 <SSL_CTX_new@plt>
mov    %rax,-0x1028(%rbp)
cmpq   $0x0,-0x1028(%rbp)
jne    1242 <ssl_init+0x72>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
call   10f0 <ERR_print_errors_fp@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x1028(%rbp),%rdi
mov    0x2d98(%rip),%rax
mov    (%rax),%edx
lea    0xda7(%rip),%rsi
call   1050 <SSL_CTX_use_certificate_file@plt>
cmp    $0x0,%rax
jg     1280 <ssl_init+0xb0>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
call   10f0 <ERR_print_errors_fp@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x1028(%rbp),%rdi
mov    0x2d5a(%rip),%rax
mov    (%rax),%edx
lea    0xd92(%rip),%rsi
call   10a0 <SSL_CTX_use_PrivateKey_file@plt>
cmp    $0x0,%rax
jg     12be <ssl_init+0xee>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
call   10f0 <ERR_print_errors_fp@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x1028(%rbp),%rdi
call   10e0 <SSL_CTX_check_private_key@plt>
cmp    $0x0,%eax
jne    12f2 <ssl_init+0x122>
mov    0x2cfe(%rip),%rax
mov    (%rax),%edi
lea    0xd6f(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
cmpl   $0x1,-0x8(%rbp)
jne    135e <ssl_init+0x18e>
mov    -0x1028(%rbp),%rdi
lea    0xd7f(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1090 <SSL_CTX_load_verify_locations@plt>
cmp    $0x0,%eax
jne    1334 <ssl_init+0x164>
mov    0x2cb5(%rip),%rax
mov    (%rax),%edi
call   10f0 <ERR_print_errors_fp@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x1028(%rbp),%rdi
mov    0x2c8e(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <SSL_CTX_set_verify@plt>
mov    -0x1028(%rbp),%rdi
mov    $0x1,%esi
call   10b0 <SSL_CTX_set_verify_depth@plt>
mov    -0x1028(%rbp),%rax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ssl_init>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <SSL_library_init@plt>
xor    %eax,%eax
call   1090 <SSL_load_error_strings@plt>
xor    %eax,%eax
call   1060 <TLSv1_method@plt>
mov    %rax,%rdi
call   1070 <SSL_CTX_new@plt>
test   %rax,%rax
je     1215 <ssl_init+0x75>
mov    %rax,%rbx
mov    0x2e18(%rip),%r14
mov    (%r14),%edx
lea    0xe26(%rip),%rsi
mov    %rax,%rdi
call   1040 <SSL_CTX_use_certificate_file@plt>
test   %rax,%rax
jle    1215 <ssl_init+0x75>
mov    (%r14),%edx
lea    0xe38(%rip),%rsi
mov    %rbx,%rdi
call   1080 <SSL_CTX_use_PrivateKey_file@plt>
test   %rax,%rax
jle    1215 <ssl_init+0x75>
mov    %rbx,%rdi
call   10b0 <SSL_CTX_check_private_key@plt>
test   %eax,%eax
je     122d <ssl_init+0x8d>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
call   10c0 <ERR_print_errors_fp@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
lea    0xe15(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [41 x i8] c"/usr/local/lxlabs/kloxo/init/backend.crt\00"
@SSL_FILETYPE_PEM = global i32 0
@.str.1 = [41 x i8] c"/usr/local/lxlabs/kloxo/init/backend.key\00"
@.str.2 = [55 x i8] c"Private key does not match the certificate public key\0A\00"
@.str.3 = [14 x i8] c"server_ca.crt\00"
@SSL_VERIFY_PEER = global i32 0
define i32* @ssl_init() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i8*
%5 = alloca [4096 x i8]
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
store i32 0, i32* %2
store i32* null, i32** %9
%10 = call i32 (...) @SSL_library_init()
%11 = call i32 (...) @SSL_load_error_strings()
%12 = call i32* (...) @TLSv1_method()
store i32* %12, i32** %8
%13 = load i32*, i32** %8
%14 = call i32* @SSL_CTX_new(i32* %13)
store i32* %14, i32** %6
%15 = load i32*, i32** %6
%16 = icmp ne i32* %15, null
br i1 %16, label %21, label %17
17: ; preds = %0
%18 = load i32, i32* @stderr
%19 = call i32 @ERR_print_errors_fp(i32 %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %0
%22 = load i32*, i32** %6
%23 = load i32, i32* @SSL_FILETYPE_PEM
%24 = call i64 @SSL_CTX_use_certificate_file(i32* %22, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = icmp sle i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = call i32 @ERR_print_errors_fp(i32 %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %21
%31 = load i32*, i32** %6
%32 = load i32, i32* @SSL_FILETYPE_PEM
%33 = call i64 @SSL_CTX_use_PrivateKey_file(i32* %31, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = icmp sle i64 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %30
%36 = load i32, i32* @stderr
%37 = call i32 @ERR_print_errors_fp(i32 %36)
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %30
%40 = load i32*, i32** %6
%41 = call i32 @SSL_CTX_check_private_key(i32* %40)
%42 = icmp ne i32 %41, 0
br i1 %42, label %47, label %43
43: ; preds = %39
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %39
%48 = load i32, i32* %2
%49 = icmp eq i32 %48, 1
br i1 %49, label %50, label %64
50: ; preds = %47
%51 = load i32*, i32** %6
%52 = call i32 @SSL_CTX_load_verify_locations(i32* %51, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32* null)
%53 = icmp ne i32 %52, 0
br i1 %53, label %58, label %54
54: ; preds = %50
%55 = load i32, i32* @stderr
%56 = call i32 @ERR_print_errors_fp(i32 %55)
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %50
%59 = load i32*, i32** %6
%60 = load i32, i32* @SSL_VERIFY_PEER
%61 = call i32 @SSL_CTX_set_verify(i32* %59, i32 %60, i32* null)
%62 = load i32*, i32** %6
%63 = call i32 @SSL_CTX_set_verify_depth(i32* %62, i32 1)
br label %64
64: ; preds = %58, %47
%65 = load i32*, i32** %6
ret i32* %65
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [41 x i8] c"/usr/local/lxlabs/kloxo/init/backend.crt\00"
@SSL_FILETYPE_PEM = global i32 0
@.str.1 = [41 x i8] c"/usr/local/lxlabs/kloxo/init/backend.key\00"
@.str.2 = [55 x i8] c"Private key does not match the certificate public key\0A\00"
@SSL_VERIFY_PEER = global i32 0
define i32* @ssl_init() {
%1 = tail call i32 (...) @SSL_library_init()
%2 = tail call i32 (...) @SSL_load_error_strings()
%3 = tail call i32* (...) @TLSv1_method()
%4 = tail call i32* @SSL_CTX_new(i32* %3)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = tail call i32 @ERR_print_errors_fp(i32 %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = load i32, i32* @SSL_FILETYPE_PEM
%12 = tail call i64 @SSL_CTX_use_certificate_file(i32* %4, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = icmp slt i64 %12, 1
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = tail call i32 @ERR_print_errors_fp(i32 %15)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %10
%19 = load i32, i32* @SSL_FILETYPE_PEM
%20 = tail call i64 @SSL_CTX_use_PrivateKey_file(i32* %4, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = icmp slt i64 %20, 1
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = tail call i32 @ERR_print_errors_fp(i32 %23)
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %18
%27 = tail call i32 @SSL_CTX_check_private_key(i32* %4)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0))
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %26
ret i32* %4
}