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

/* Variables and functions */
int /*<<< orphan*/ BIO_f_buffer();
int /*<<< orphan*/ BIO_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ *BIO_new_ssl_connect(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_push(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx) {
  BIO *ret = NULL, *buf = NULL, *ssl = NULL;
  if ((buf = BIO_new(BIO_f_buffer())) == NULL)
    goto err;
  if ((ssl = BIO_new_ssl_connect(ctx)) == NULL)
    goto err;
  if ((ret = BIO_push(buf, ssl)) == NULL)
    goto err;
  return (ret);
err:
  BIO_free(buf);
  BIO_free(ssl);
  return (NULL);
}


x86 assembly (clang, -O0):
<BIO_new_buffer_ssl_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    $0x0,%al
call   1040 <BIO_f_buffer@plt>
mov    %eax,%edi
call   1050 <BIO_new@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1195 <BIO_new_buffer_ssl_connect+0x45>
jmp    11de <BIO_new_buffer_ssl_connect+0x8e>
mov    -0x10(%rbp),%rdi
call   1070 <BIO_new_ssl_connect@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11b1 <BIO_new_buffer_ssl_connect+0x61>
jmp    11de <BIO_new_buffer_ssl_connect+0x8e>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <BIO_push@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11d1 <BIO_new_buffer_ssl_connect+0x81>
jmp    11de <BIO_new_buffer_ssl_connect+0x8e>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11f8 <BIO_new_buffer_ssl_connect+0xa8>
mov    -0x20(%rbp),%rdi
call   1060 <BIO_free@plt>
mov    -0x28(%rbp),%rdi
call   1060 <BIO_free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BIO_new_buffer_ssl_connect>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <BIO_f_buffer@plt>
mov    %eax,%edi
call   1050 <BIO_new@plt>
mov    %rax,%r14
test   %rax,%rax
je     1194 <BIO_new_buffer_ssl_connect+0x44>
mov    %r15,%rdi
call   1070 <BIO_new_ssl_connect@plt>
test   %rax,%rax
je     1192 <BIO_new_buffer_ssl_connect+0x42>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <BIO_push@plt>
test   %rax,%rax
jne    11a6 <BIO_new_buffer_ssl_connect+0x56>
jmp    1194 <BIO_new_buffer_ssl_connect+0x44>
xor    %ebx,%ebx
mov    %r14,%rdi
call   1060 <BIO_free@plt>
mov    %rbx,%rdi
call   1060 <BIO_free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32* @BIO_new_buffer_ssl_connect(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
store i32* %0, i32** %3
store i32* null, i32** %4
store i32* null, i32** %5
store i32* null, i32** %6
%7 = call i32 (...) @BIO_f_buffer()
%8 = call i32* @BIO_new(i32 %7)
store i32* %8, i32** %5
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
br label %24
11: ; preds = %1
%12 = load i32*, i32** %3
%13 = call i32* @BIO_new_ssl_connect(i32* %12)
store i32* %13, i32** %6
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %11
br label %24
16: ; preds = %11
%17 = load i32*, i32** %5
%18 = load i32*, i32** %6
%19 = call i32* @BIO_push(i32* %17, i32* %18)
store i32* %19, i32** %4
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %22
21: ; preds = %16
br label %24
22: ; preds = %16
%23 = load i32*, i32** %4
store i32* %23, i32** %2
br label %29
24: ; preds = %21, %15, %10
%25 = load i32*, i32** %5
%26 = call i32 @BIO_free(i32* %25)
%27 = load i32*, i32** %6
%28 = call i32 @BIO_free(i32* %27)
store i32* null, i32** %2
br label %29
29: ; preds = %24, %22
%30 = load i32*, i32** %2
ret i32* %30
}

LLVM IR (-O2):
define i32* @BIO_new_buffer_ssl_connect(i32* %0) {
%2 = tail call i32 (...) @BIO_f_buffer()
%3 = tail call i32* @BIO_new(i32 %2)
%4 = icmp eq i32* %3, null
br i1 %4, label %11, label %5
5: ; preds = %1
%6 = tail call i32* @BIO_new_ssl_connect(i32* %0)
%7 = icmp eq i32* %6, null
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = tail call i32* @BIO_push(i32* %3, i32* %6)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %8, %5, %1
%12 = phi i32* [ null, %1 ], [ null, %5 ], [ %6, %8 ]
%13 = tail call i32 @BIO_free(i32* %3)
%14 = tail call i32 @BIO_free(i32* %12)
br label %15
15: ; preds = %8, %11
%16 = phi i32* [ null, %11 ], [ %9, %8 ]
ret i32* %16
}