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

/* Variables and functions */
int /*<<< orphan*/ BIO_CLOSE;
int /*<<< orphan*/ BIO_f_ssl();
int /*<<< orphan*/ BIO_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ BIO_set_ssl(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                               int /*<<< orphan*/);
int /*<<< orphan*/ *SSL_new(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_set_accept_state(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_set_connect_state(int /*<<< orphan*/ *);
BIO *BIO_new_ssl(SSL_CTX *ctx, int client) {
  BIO *ret;
  SSL *ssl;
  if ((ret = BIO_new(BIO_f_ssl())) == NULL)
    goto err;
  if ((ssl = SSL_new(ctx)) == NULL)
    goto err;
  if (client)
    SSL_set_connect_state(ssl);
  else
    SSL_set_accept_state(ssl);
  BIO_set_ssl(ret, ssl, BIO_CLOSE);
  return (ret);
err:
  BIO_free(ret);
  return (NULL);
}


x86 assembly (clang, -O0):
<BIO_new_ssl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    $0x0,%al
call   1030 <BIO_f_ssl@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11a0 <BIO_new_ssl+0x30>
jmp    1200 <BIO_new_ssl+0x90>
mov    -0x10(%rbp),%rdi
call   1040 <SSL_new@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11bc <BIO_new_ssl+0x4c>
jmp    1200 <BIO_new_ssl+0x90>
cmpl   $0x0,-0x14(%rbp)
je     11d4 <BIO_new_ssl+0x64>
mov    -0x28(%rbp),%rdi
call   1050 <SSL_set_connect_state@plt>
jmp    11dd <BIO_new_ssl+0x6d>
mov    -0x28(%rbp),%rdi
call   1060 <SSL_set_accept_state@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    0x2df4(%rip),%rax
mov    (%rax),%edx
call   1090 <BIO_set_ssl@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1211 <BIO_new_ssl+0xa1>
mov    -0x20(%rbp),%rdi
call   1080 <BIO_free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BIO_new_ssl>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbp
xor    %eax,%eax
call   1030 <BIO_f_ssl@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11af <BIO_new_ssl+0x3f>
mov    %rbp,%rdi
call   1040 <SSL_new@plt>
test   %rax,%rax
je     11af <BIO_new_ssl+0x3f>
mov    %rax,%rbp
mov    %rax,%rdi
test   %r14d,%r14d
je     11bb <BIO_new_ssl+0x4b>
call   1050 <SSL_set_connect_state@plt>
jmp    11c0 <BIO_new_ssl+0x50>
mov    %rbx,%rdi
call   1080 <BIO_free@plt>
xor    %ebx,%ebx
jmp    11d4 <BIO_new_ssl+0x64>
call   1060 <SSL_set_accept_state@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1090 <BIO_set_ssl@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@BIO_CLOSE = global i32 0
define i32* @BIO_new_ssl(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
store i32* %0, i32** %4
store i32 %1, i32* %5
%8 = call i32 (...) @BIO_f_ssl()
%9 = call i32* @BIO_new(i32 %8)
store i32* %9, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
br label %32
12: ; preds = %2
%13 = load i32*, i32** %4
%14 = call i32* @SSL_new(i32* %13)
store i32* %14, i32** %7
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %17
16: ; preds = %12
br label %32
17: ; preds = %12
%18 = load i32, i32* %5
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32*, i32** %7
%22 = call i32 @SSL_set_connect_state(i32* %21)
br label %26
23: ; preds = %17
%24 = load i32*, i32** %7
%25 = call i32 @SSL_set_accept_state(i32* %24)
br label %26
26: ; preds = %23, %20
%27 = load i32*, i32** %6
%28 = load i32*, i32** %7
%29 = load i32, i32* @BIO_CLOSE
%30 = call i32 @BIO_set_ssl(i32* %27, i32* %28, i32 %29)
%31 = load i32*, i32** %6
store i32* %31, i32** %3
br label %35
32: ; preds = %16, %11
%33 = load i32*, i32** %6
%34 = call i32 @BIO_free(i32* %33)
store i32* null, i32** %3
br label %35
35: ; preds = %32, %26
%36 = load i32*, i32** %3
ret i32* %36
}

LLVM IR (-O2):
@BIO_CLOSE = global i32 0
define i32* @BIO_new_ssl(i32* %0, i32 %1) {
%3 = tail call i32 (...) @BIO_f_ssl()
%4 = tail call i32* @BIO_new(i32 %3)
%5 = icmp eq i32* %4, null
br i1 %5, label %18, label %6
6: ; preds = %2
%7 = tail call i32* @SSL_new(i32* %0)
%8 = icmp eq i32* %7, null
br i1 %8, label %18, label %9
9: ; preds = %6
%10 = icmp eq i32 %1, 0
br i1 %10, label %13, label %11
11: ; preds = %9
%12 = tail call i32 @SSL_set_connect_state(i32* %7)
br label %15
13: ; preds = %9
%14 = tail call i32 @SSL_set_accept_state(i32* %7)
br label %15
15: ; preds = %13, %11
%16 = load i32, i32* @BIO_CLOSE
%17 = tail call i32 @BIO_set_ssl(i32* %4, i32* %7, i32 %16)
br label %20
18: ; preds = %6, %2
%19 = tail call i32 @BIO_free(i32* %4)
br label %20
20: ; preds = %18, %15
%21 = phi i32* [ null, %18 ], [ %4, %15 ]
ret i32* %21
}