#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_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_CTX_load_verify_locations(int /*<<< orphan*/ *,
                                                 char const *,
                                                 int /*<<< orphan*/ *);
int /*<<< orphan*/ *SSL_CTX_new(int /*<<< orphan*/);
int /*<<< orphan*/ SSL_CTX_set_cipher_list(int /*<<< orphan*/ *, char const *);
int /*<<< orphan*/ SSL_CTX_set_mode(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ SSL_CTX_set_verify(int /*<<< orphan*/ *, int,
                                      int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_CTX_use_PrivateKey_file(int /*<<< orphan*/ *,
                                               char const *,
                                               int /*<<< orphan*/);
int /*<<< orphan*/ SSL_CTX_use_certificate_chain_file(int /*<<< orphan*/ *,
                                                      char const *);
int /*<<< orphan*/ SSL_FILETYPE_PEM;
int /*<<< orphan*/ SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER;
int SSL_VERIFY_CLIENT_ONCE;
int SSL_VERIFY_FAIL_IF_NO_PEER_CERT;
int SSL_VERIFY_PEER;
int /*<<< orphan*/ SSLv23_server_method();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
SSL_CTX *setup_ctx(const char *cert_file, const char *key_file,
                   const char *ca_file, const char *cipher) {
  SSL_CTX *ctx;
  (void)cipher;
  ctx = SSL_CTX_new(SSLv23_server_method());
  if (NULL == ctx)
    goto out;
  SSL_CTX_set_mode(ctx, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
  if (ca_file != NULL) {
    if (!SSL_CTX_load_verify_locations(ctx, ca_file, NULL)) {
      fprintf(stderr, "%s: err loading ca file\n", ca_file);
      goto out_free;
    }
    SSL_CTX_set_verify(ctx,
                       SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE |
                           SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
                       NULL);
  }
  if (cert_file && key_file) {
    if (!SSL_CTX_use_certificate_chain_file(ctx, cert_file)) {
      fprintf(stderr, "%s: err loading cert file\n", cert_file);
      goto out_free;
    }
    if (!SSL_CTX_use_PrivateKey_file(ctx, key_file, SSL_FILETYPE_PEM)) {
      fprintf(stderr, "%s: err loading key file\n", key_file);
      goto out_free;
    }
  }
  if (cipher != NULL) {
    fprintf(stderr, "Cipher spec: %s\n", cipher);
    if (!SSL_CTX_set_cipher_list(ctx, cipher)) {
      fprintf(stderr, "Failed to set cipher spec\n");
      goto out_free;
    }
  }
  goto out;
out_free:
  SSL_CTX_free(ctx);
  ctx = NULL;
out:
  return ctx;
}


x86 assembly (clang, -O0):
<setup_ctx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    $0x0,%al
call   1030 <SSLv23_server_method@plt>
mov    %eax,%edi
call   1070 <SSL_CTX_new@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    11db <setup_ctx+0x3b>
jmp    135d <setup_ctx+0x1bd>
mov    -0x28(%rbp),%rdi
mov    0x2df2(%rip),%rax
mov    (%rax),%esi
call   10c0 <SSL_CTX_set_mode@plt>
cmpq   $0x0,-0x18(%rbp)
je     125a <setup_ctx+0xba>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1080 <SSL_CTX_load_verify_locations@plt>
cmp    $0x0,%eax
jne    1232 <setup_ctx+0x92>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdda(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    134c <setup_ctx+0x1ac>
mov    -0x28(%rbp),%rdi
mov    0x2d83(%rip),%rax
mov    (%rax),%esi
mov    0x2da2(%rip),%rax
or     (%rax),%esi
mov    0x2d69(%rip),%rax
or     (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <SSL_CTX_set_verify@plt>
cmpq   $0x0,-0x8(%rbp)
je     12ea <setup_ctx+0x14a>
cmpq   $0x0,-0x10(%rbp)
je     12ea <setup_ctx+0x14a>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <SSL_CTX_use_certificate_chain_file@plt>
cmp    $0x0,%eax
jne    12a6 <setup_ctx+0x106>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xd7f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    134c <setup_ctx+0x1ac>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2d2b(%rip),%rax
mov    (%rax),%edx
call   1090 <SSL_CTX_use_PrivateKey_file@plt>
cmp    $0x0,%eax
jne    12e5 <setup_ctx+0x145>
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd5b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    134c <setup_ctx+0x1ac>
jmp    12ea <setup_ctx+0x14a>
cmpq   $0x0,-0x20(%rbp)
je     1347 <setup_ctx+0x1a7>
mov    0x2ccc(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xd45(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10a0 <SSL_CTX_set_cipher_list@plt>
cmp    $0x0,%eax
jne    1342 <setup_ctx+0x1a2>
mov    0x2c9b(%rip),%rax
mov    (%rax),%edi
lea    0xd29(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    134c <setup_ctx+0x1ac>
jmp    1347 <setup_ctx+0x1a7>
jmp    135d <setup_ctx+0x1bd>
mov    -0x28(%rbp),%rdi
call   10b0 <SSL_CTX_free@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_ctx>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%r12
xor    %eax,%eax
call   1030 <SSLv23_server_method@plt>
mov    %eax,%edi
call   1070 <SSL_CTX_new@plt>
test   %rax,%rax
je     12e2 <setup_ctx+0x142>
mov    %rax,%rbx
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10c0 <SSL_CTX_set_mode@plt>
test   %r13,%r13
je     121f <setup_ctx+0x7f>
mov    %rbx,%rdi
mov    %r13,%rsi
xor    %edx,%edx
call   1080 <SSL_CTX_load_verify_locations@plt>
test   %eax,%eax
je     1296 <setup_ctx+0xf6>
mov    0x2dbf(%rip),%rax
mov    0x2de0(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2da5(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
xor    %edx,%edx
call   1050 <SSL_CTX_set_verify@plt>
test   %r12,%r12
je     1250 <setup_ctx+0xb0>
test   %r15,%r15
je     1250 <setup_ctx+0xb0>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <SSL_CTX_use_certificate_chain_file@plt>
test   %eax,%eax
je     12ab <setup_ctx+0x10b>
mov    0x2da1(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <SSL_CTX_use_PrivateKey_file@plt>
test   %eax,%eax
je     12c0 <setup_ctx+0x120>
test   %r14,%r14
je     12e4 <setup_ctx+0x144>
mov    0x2d68(%rip),%r15
mov    (%r15),%edi
lea    0xde4(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10a0 <SSL_CTX_set_cipher_list@plt>
test   %eax,%eax
jne    12e4 <setup_ctx+0x144>
mov    (%r15),%edi
lea    0xdd2(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    12da <setup_ctx+0x13a>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
lea    0xd5a(%rip),%rsi
mov    %r13,%rdx
jmp    12d3 <setup_ctx+0x133>
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
lea    0xd5e(%rip),%rsi
mov    %r12,%rdx
jmp    12d3 <setup_ctx+0x133>
mov    0x2d01(%rip),%rax
mov    (%rax),%edi
lea    0xd64(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   10b0 <SSL_CTX_free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"%s: err loading ca file\0A\00"
@SSL_VERIFY_PEER = global i32 0
@SSL_VERIFY_CLIENT_ONCE = global i32 0
@SSL_VERIFY_FAIL_IF_NO_PEER_CERT = global i32 0
@.str.1 = [27 x i8] c"%s: err loading cert file\0A\00"
@SSL_FILETYPE_PEM = global i32 0
@.str.2 = [26 x i8] c"%s: err loading key file\0A\00"
@.str.3 = [17 x i8] c"Cipher spec: %s\0A\00"
@.str.4 = [27 x i8] c"Failed to set cipher spec\0A\00"
define i32* @setup_ctx(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%10 = load i8*, i8** %8
%11 = call i32 (...) @SSLv23_server_method()
%12 = call i32* @SSL_CTX_new(i32 %11)
store i32* %12, i32** %9
%13 = load i32*, i32** %9
%14 = icmp eq i32* null, %13
br i1 %14, label %15, label %16
15: ; preds = %4
br label %84
16: ; preds = %4
%17 = load i32*, i32** %9
%18 = load i32, i32* @SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER
%19 = call i32 @SSL_CTX_set_mode(i32* %17, i32 %18)
%20 = load i8*, i8** %7
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %39
22: ; preds = %16
%23 = load i32*, i32** %9
%24 = load i8*, i8** %7
%25 = call i32 @SSL_CTX_load_verify_locations(i32* %23, i8* %24, i32* null)
%26 = icmp ne i32 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %7
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %29)
br label %81
31: ; preds = %22
%32 = load i32*, i32** %9
%33 = load i32, i32* @SSL_VERIFY_PEER
%34 = load i32, i32* @SSL_VERIFY_CLIENT_ONCE
%35 = or i32 %33, %34
%36 = load i32, i32* @SSL_VERIFY_FAIL_IF_NO_PEER_CERT
%37 = or i32 %35, %36
%38 = call i32 @SSL_CTX_set_verify(i32* %32, i32 %37, i32* null)
br label %39
39: ; preds = %31, %16
%40 = load i8*, i8** %5
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %65
42: ; preds = %39
%43 = load i8*, i8** %6
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %65
45: ; preds = %42
%46 = load i32*, i32** %9
%47 = load i8*, i8** %5
%48 = call i32 @SSL_CTX_use_certificate_chain_file(i32* %46, i8* %47)
%49 = icmp ne i32 %48, 0
br i1 %49, label %54, label %50
50: ; preds = %45
%51 = load i32, i32* @stderr
%52 = load i8*, i8** %5
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %52)
br label %81
54: ; preds = %45
%55 = load i32*, i32** %9
%56 = load i8*, i8** %6
%57 = load i32, i32* @SSL_FILETYPE_PEM
%58 = call i32 @SSL_CTX_use_PrivateKey_file(i32* %55, i8* %56, i32 %57)
%59 = icmp ne i32 %58, 0
br i1 %59, label %64, label %60
60: ; preds = %54
%61 = load i32, i32* @stderr
%62 = load i8*, i8** %6
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %62)
br label %81
64: ; preds = %54
br label %65
65: ; preds = %64, %42, %39
%66 = load i8*, i8** %8
%67 = icmp ne i8* %66, null
br i1 %67, label %68, label %80
68: ; preds = %65
%69 = load i32, i32* @stderr
%70 = load i8*, i8** %8
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %70)
%72 = load i32*, i32** %9
%73 = load i8*, i8** %8
%74 = call i32 @SSL_CTX_set_cipher_list(i32* %72, i8* %73)
%75 = icmp ne i32 %74, 0
br i1 %75, label %79, label %76
76: ; preds = %68
%77 = load i32, i32* @stderr
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %81
79: ; preds = %68
br label %80
80: ; preds = %79, %65
br label %84
81: ; preds = %76, %60, %50, %27
%82 = load i32*, i32** %9
%83 = call i32 @SSL_CTX_free(i32* %82)
store i32* null, i32** %9
br label %84
84: ; preds = %81, %80, %15
%85 = load i32*, i32** %9
ret i32* %85
}

LLVM IR (-O2):
@SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"%s: err loading ca file\0A\00"
@SSL_VERIFY_PEER = global i32 0
@SSL_VERIFY_CLIENT_ONCE = global i32 0
@SSL_VERIFY_FAIL_IF_NO_PEER_CERT = global i32 0
@.str.1 = [27 x i8] c"%s: err loading cert file\0A\00"
@SSL_FILETYPE_PEM = global i32 0
@.str.2 = [26 x i8] c"%s: err loading key file\0A\00"
@.str.3 = [17 x i8] c"Cipher spec: %s\0A\00"
@.str.4 = [27 x i8] c"Failed to set cipher spec\0A\00"
define i32* @setup_ctx(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = tail call i32 (...) @SSLv23_server_method()
%6 = tail call i32* @SSL_CTX_new(i32 %5)
%7 = icmp eq i32* %6, null
br i1 %7, label %54, label %8
8: ; preds = %4
%9 = load i32, i32* @SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER
%10 = tail call i32 @SSL_CTX_set_mode(i32* %6, i32 %9)
%11 = icmp eq i8* %2, null
br i1 %11, label %25, label %12
12: ; preds = %8
%13 = tail call i32 @SSL_CTX_load_verify_locations(i32* %6, i8* %2, i32* null)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %52
18: ; preds = %12
%19 = load i32, i32* @SSL_VERIFY_PEER
%20 = load i32, i32* @SSL_VERIFY_CLIENT_ONCE
%21 = or i32 %20, %19
%22 = load i32, i32* @SSL_VERIFY_FAIL_IF_NO_PEER_CERT
%23 = or i32 %21, %22
%24 = tail call i32 @SSL_CTX_set_verify(i32* %6, i32 %23, i32* null)
br label %25
25: ; preds = %18, %8
%26 = icmp ne i8* %0, null
%27 = icmp ne i8* %1, null
%28 = and i1 %26, %27
br i1 %28, label %29, label %42
29: ; preds = %25
%30 = tail call i32 @SSL_CTX_use_certificate_chain_file(i32* %6, i8* %0)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i32, i32* @stderr
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %52
35: ; preds = %29
%36 = load i32, i32* @SSL_FILETYPE_PEM
%37 = tail call i32 @SSL_CTX_use_PrivateKey_file(i32* %6, i8* %1, i32 %36)
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = load i32, i32* @stderr
%41 = tail call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %1)
br label %52
42: ; preds = %35, %25
%43 = icmp eq i8* %3, null
br i1 %43, label %54, label %44
44: ; preds = %42
%45 = load i32, i32* @stderr
%46 = tail call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%47 = tail call i32 @SSL_CTX_set_cipher_list(i32* %6, i8* %3)
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %44
%50 = load i32, i32* @stderr
%51 = tail call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %52
52: ; preds = %49, %39, %32, %15
%53 = tail call i32 @SSL_CTX_free(i32* %6)
br label %54
54: ; preds = %42, %44, %4, %52
%55 = phi i32* [ null, %4 ], [ %6, %44 ], [ null, %52 ], [ %6, %42 ]
ret i32* %55
}