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

/* Variables and functions */
int /*<<< orphan*/ *SSL_CTX_new(int /*<<< orphan*/);
int /*<<< orphan*/ SSL_Error(char *);
int /*<<< orphan*/ *SSL_new(int /*<<< orphan*/ *);
int SSL_set_fd(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ SSLv23_client_method();
SSL *SSL_to_server_init(int socket) {
  SSL_CTX *ctx;
  ctx = SSL_CTX_new(SSLv23_client_method());
  if (ctx == NULL) {
    SSL_Error("Fail to init ssl ctx!");
  }
  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_server_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1030 <SSLv23_client_method@plt>
mov    %eax,%edi
call   1070 <SSL_CTX_new@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1184 <SSL_to_server_init+0x34>
lea    0xe81(%rip),%rdi
call   1040 <SSL_Error@plt>
mov    -0x10(%rbp),%rdi
call   1060 <SSL_new@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a8 <SSL_to_server_init+0x58>
lea    0xe73(%rip),%rdi
call   1040 <SSL_Error@plt>
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1050 <SSL_set_fd@plt>
cmp    $0x1,%eax
je     11c9 <SSL_to_server_init+0x79>
lea    0xe63(%rip),%rdi
call   1040 <SSL_Error@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SSL_to_server_init>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
xor    %eax,%eax
call   1030 <SSLv23_client_method@plt>
mov    %eax,%edi
call   1070 <SSL_CTX_new@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1177 <SSL_to_server_init+0x27>
lea    0xe8e(%rip),%rdi
call   1040 <SSL_Error@plt>
mov    %rbx,%rdi
call   1060 <SSL_new@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1193 <SSL_to_server_init+0x43>
lea    0xe88(%rip),%rdi
call   1040 <SSL_Error@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <SSL_set_fd@plt>
cmp    $0x1,%eax
je     11ae <SSL_to_server_init+0x5e>
lea    0xe7e(%rip),%rdi
call   1040 <SSL_Error@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Fail to init ssl ctx!\00"
@.str.1 = [17 x i8] c"Create ssl error\00"
@.str.2 = [13 x i8] c"Set fd error\00"
define i32* @SSL_to_server_init(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32*
store i32 %0, i32* %2
%5 = call i32 (...) @SSLv23_client_method()
%6 = call i32* @SSL_CTX_new(i32 %5)
store i32* %6, i32** %3
%7 = load i32*, i32** %3
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @SSL_Error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %1
%12 = load i32*, i32** %3
%13 = call i32* @SSL_new(i32* %12)
store i32* %13, i32** %4
%14 = load i32*, i32** %4
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @SSL_Error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %11
%19 = load i32*, i32** %4
%20 = load i32, i32* %2
%21 = call i32 @SSL_set_fd(i32* %19, i32 %20)
%22 = icmp ne i32 %21, 1
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 @SSL_Error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %18
%26 = load i32*, i32** %4
ret i32* %26
}

LLVM IR (-O2):
@.str = [22 x i8] c"Fail to init ssl ctx!\00"
@.str.1 = [17 x i8] c"Create ssl error\00"
@.str.2 = [13 x i8] c"Set fd error\00"
define i32* @SSL_to_server_init(i32 %0) {
%2 = tail call i32 (...) @SSLv23_client_method()
%3 = tail call i32* @SSL_CTX_new(i32 %2)
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @SSL_Error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %1
%8 = tail call i32* @SSL_new(i32* %3)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @SSL_Error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = tail call i32 @SSL_set_fd(i32* %8, i32 %0)
%14 = icmp eq i32 %13, 1
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = tail call i32 @SSL_Error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
ret i32* %8
}