#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_CTX;
typedef int /*<<< orphan*/ SSL;
typedef int /*<<< orphan*/ EVP_PKEY;

/* Variables and functions */
int SSL_CTX_check_private_key(int /*<<< orphan*/ *);
int /*<<< orphan*/ *SSL_CTX_new(int /*<<< orphan*/);
int SSL_CTX_use_PrivateKey(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int SSL_CTX_use_certificate(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_Error(char *);
int /*<<< orphan*/ *SSL_new(int /*<<< orphan*/ *);
int SSL_set_fd(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ SSLv23_server_method();
SSL *SSL_to_client_init(int socket, X509 *cert, EVP_PKEY *key) {
  SSL_CTX *ctx;
  ctx = SSL_CTX_new(SSLv23_server_method());
  if (ctx == NULL)
    SSL_Error("Fail to init ssl ctx!");
  if (cert && key) {
    if (SSL_CTX_use_certificate(ctx, cert) != 1)
      SSL_Error("Certificate error");
    if (SSL_CTX_use_PrivateKey(ctx, key) != 1)
      SSL_Error("key error");
    if (SSL_CTX_check_private_key(ctx) != 1)
      SSL_Error("Private key does not match the certificate public key");
  }
  SSL *ssl = SSL_new(ctx);
  if (ssl == NULL)
    SSL_Error("Create ssl error");
  if (SSL_set_fd(ssl, socket) != 1)
    SSL_Error("Set fd error");
  return ssl;
}


x86 assembly (clang, -O0):
<SSL_to_client_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1030 <SSLv23_server_method@plt>
mov    %eax,%edi
call   1070 <SSL_CTX_new@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11bc <SSL_to_client_init+0x3c>
lea    0xe49(%rip),%rdi
call   1040 <SSL_Error@plt>
cmpq   $0x0,-0x10(%rbp)
je     1239 <SSL_to_client_init+0xb9>
cmpq   $0x0,-0x18(%rbp)
je     1239 <SSL_to_client_init+0xb9>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10a0 <SSL_CTX_use_certificate@plt>
cmp    $0x1,%eax
je     11f4 <SSL_to_client_init+0x74>
lea    0xe27(%rip),%rdi
call   1040 <SSL_Error@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <SSL_CTX_use_PrivateKey@plt>
cmp    $0x1,%eax
je     1216 <SSL_to_client_init+0x96>
lea    0xe17(%rip),%rdi
call   1040 <SSL_Error@plt>
mov    -0x20(%rbp),%rdi
call   1090 <SSL_CTX_check_private_key@plt>
cmp    $0x1,%eax
je     1234 <SSL_to_client_init+0xb4>
lea    0xe03(%rip),%rdi
call   1040 <SSL_Error@plt>
jmp    1239 <SSL_to_client_init+0xb9>
mov    -0x20(%rbp),%rdi
call   1060 <SSL_new@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    125d <SSL_to_client_init+0xdd>
lea    0xe10(%rip),%rdi
call   1040 <SSL_Error@plt>
mov    -0x28(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1050 <SSL_set_fd@plt>
cmp    $0x1,%eax
je     127e <SSL_to_client_init+0xfe>
lea    0xe00(%rip),%rdi
call   1040 <SSL_Error@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SSL_to_client_init>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %edi,%r14d
xor    %eax,%eax
call   1030 <SSLv23_server_method@plt>
mov    %eax,%edi
call   1070 <SSL_CTX_new@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11b2 <SSL_to_client_init+0x32>
lea    0xe53(%rip),%rdi
call   1040 <SSL_Error@plt>
test   %rbp,%rbp
je     120d <SSL_to_client_init+0x8d>
test   %r15,%r15
je     120d <SSL_to_client_init+0x8d>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10a0 <SSL_CTX_use_certificate@plt>
cmp    $0x1,%eax
je     11d8 <SSL_to_client_init+0x58>
lea    0xe43(%rip),%rdi
call   1040 <SSL_Error@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <SSL_CTX_use_PrivateKey@plt>
cmp    $0x1,%eax
je     11f4 <SSL_to_client_init+0x74>
lea    0xe39(%rip),%rdi
call   1040 <SSL_Error@plt>
mov    %rbx,%rdi
call   1090 <SSL_CTX_check_private_key@plt>
cmp    $0x1,%eax
je     120d <SSL_to_client_init+0x8d>
lea    0xe2a(%rip),%rdi
call   1040 <SSL_Error@plt>
mov    %rbx,%rdi
call   1060 <SSL_new@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1229 <SSL_to_client_init+0xa9>
lea    0xe44(%rip),%rdi
call   1040 <SSL_Error@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1050 <SSL_set_fd@plt>
cmp    $0x1,%eax
je     1245 <SSL_to_client_init+0xc5>
lea    0xe39(%rip),%rdi
call   1040 <SSL_Error@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Fail to init ssl ctx!\00"
@.str.1 = [18 x i8] c"Certificate error\00"
@.str.2 = [10 x i8] c"key error\00"
@.str.3 = [54 x i8] c"Private key does not match the certificate public key\00"
@.str.4 = [17 x i8] c"Create ssl error\00"
@.str.5 = [13 x i8] c"Set fd error\00"
define i32* @SSL_to_client_init(i32 %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%9 = call i32 (...) @SSLv23_server_method()
%10 = call i32* @SSL_CTX_new(i32 %9)
store i32* %10, i32** %7
%11 = load i32*, i32** %7
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = call i32 @SSL_Error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %3
%16 = load i32*, i32** %5
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %42
18: ; preds = %15
%19 = load i32*, i32** %6
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %42
21: ; preds = %18
%22 = load i32*, i32** %7
%23 = load i32*, i32** %5
%24 = call i32 @SSL_CTX_use_certificate(i32* %22, i32* %23)
%25 = icmp ne i32 %24, 1
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 @SSL_Error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %26, %21
%29 = load i32*, i32** %7
%30 = load i32*, i32** %6
%31 = call i32 @SSL_CTX_use_PrivateKey(i32* %29, i32* %30)
%32 = icmp ne i32 %31, 1
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = call i32 @SSL_Error(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %33, %28
%36 = load i32*, i32** %7
%37 = call i32 @SSL_CTX_check_private_key(i32* %36)
%38 = icmp ne i32 %37, 1
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = call i32 @SSL_Error(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0))
br label %41
41: ; preds = %39, %35
br label %42
42: ; preds = %41, %18, %15
%43 = load i32*, i32** %7
%44 = call i32* @SSL_new(i32* %43)
store i32* %44, i32** %8
%45 = load i32*, i32** %8
%46 = icmp eq i32* %45, null
br i1 %46, label %47, label %49
47: ; preds = %42
%48 = call i32 @SSL_Error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %49
49: ; preds = %47, %42
%50 = load i32*, i32** %8
%51 = load i32, i32* %4
%52 = call i32 @SSL_set_fd(i32* %50, i32 %51)
%53 = icmp ne i32 %52, 1
br i1 %53, label %54, label %56
54: ; preds = %49
%55 = call i32 @SSL_Error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %56
56: ; preds = %54, %49
%57 = load i32*, i32** %8
ret i32* %57
}

LLVM IR (-O2):
@.str = [22 x i8] c"Fail to init ssl ctx!\00"
@.str.1 = [18 x i8] c"Certificate error\00"
@.str.2 = [10 x i8] c"key error\00"
@.str.3 = [54 x i8] c"Private key does not match the certificate public key\00"
@.str.4 = [17 x i8] c"Create ssl error\00"
@.str.5 = [13 x i8] c"Set fd error\00"
define i32* @SSL_to_client_init(i32 %0, i32* %1, i32* %2) {
%4 = tail call i32 (...) @SSLv23_server_method()
%5 = tail call i32* @SSL_CTX_new(i32 %4)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @SSL_Error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %3
%10 = icmp ne i32* %1, null
%11 = icmp ne i32* %2, null
%12 = and i1 %10, %11
br i1 %12, label %13, label %28
13: ; preds = %9
%14 = tail call i32 @SSL_CTX_use_certificate(i32* %5, i32* %1)
%15 = icmp eq i32 %14, 1
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = tail call i32 @SSL_Error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %13
%19 = tail call i32 @SSL_CTX_use_PrivateKey(i32* %5, i32* %2)
%20 = icmp eq i32 %19, 1
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = tail call i32 @SSL_Error(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
%24 = tail call i32 @SSL_CTX_check_private_key(i32* %5)
%25 = icmp eq i32 %24, 1
br i1 %25, label %28, label %26
26: ; preds = %23
%27 = tail call i32 @SSL_Error(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %23, %26, %9
%29 = tail call i32* @SSL_new(i32* %5)
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = tail call i32 @SSL_Error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %33
33: ; preds = %31, %28
%34 = tail call i32 @SSL_set_fd(i32* %29, i32 %0)
%35 = icmp eq i32 %34, 1
br i1 %35, label %38, label %36
36: ; preds = %33
%37 = tail call i32 @SSL_Error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %38
38: ; preds = %36, %33
ret i32* %29
}