#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  size_t length;
  int /*<<< orphan*/ data;
};
typedef TYPE_1__ BUF_MEM;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ BIO_CTRL_FLUSH;
int /*<<< orphan*/ BIO_FLAGS_BASE64_NO_NL;
int /*<<< orphan*/ BIO_ctrl(int /*<<< orphan*/ *, int /*<<< orphan*/,
                            int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_f_base64();
int /*<<< orphan*/ BIO_free_all(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_get_mem_ptr(int /*<<< orphan*/ *, TYPE_1__ **);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ *BIO_push(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_s_mem();
int /*<<< orphan*/ BIO_set_flags(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ BIO_write(int /*<<< orphan*/ *, void const *, int);
int /*<<< orphan*/ memcpy(char *, int /*<<< orphan*/, size_t);
size_t base64encrypt(const void *data, int data_len, char *buffer) {
  BIO *b64 = BIO_new(BIO_f_base64());
  BIO *bio = BIO_new(BIO_s_mem());
  bio = BIO_push(b64, bio);
  BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL);
  BIO_write(bio, data, data_len);
  BIO_ctrl(bio, BIO_CTRL_FLUSH, 0, NULL);
  BUF_MEM *bptr = NULL;
  BIO_get_mem_ptr(bio, &bptr);
  size_t slen = bptr->length;
  memcpy(buffer, bptr->data, slen);
  buffer[slen] = '\0';
  BIO_free_all(bio);
  return slen;
}


x86 assembly (clang, -O0):
<base64encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1040 <BIO_f_base64@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   10c0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <BIO_push@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
call   1050 <BIO_set_flags@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   10b0 <BIO_write@plt>
mov    -0x28(%rbp),%rdi
mov    0x2dd3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1080 <BIO_ctrl@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   10a0 <BIO_get_mem_ptr@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%esi
mov    -0x38(%rbp),%rdx
call   1060 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
call   1090 <BIO_free_all@plt>
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64encrypt>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbp
xor    %eax,%eax
call   1040 <BIO_f_base64@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   10c0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <BIO_push@plt>
mov    %rax,%rbx
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <BIO_set_flags@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
call   10b0 <BIO_write@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
call   1080 <BIO_ctrl@plt>
movq   $0x0,(%rsp)
mov    %rsp,%rsi
mov    %rbx,%rdi
call   10a0 <BIO_get_mem_ptr@plt>
mov    (%rsp),%rax
mov    (%rax),%rbp
mov    0x8(%rax),%esi
mov    %r14,%rdi
mov    %rbp,%rdx
call   1060 <memcpy@plt>
movb   $0x0,(%r14,%rbp,1)
mov    %rbx,%rdi
call   1090 <BIO_free_all@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64, i32 }
@BIO_FLAGS_BASE64_NO_NL = global i32 0
@BIO_CTRL_FLUSH = global i32 0
define i64 @base64encrypt(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca %struct.TYPE_3__*
%10 = alloca i64
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%11 = call i32 (...) @BIO_f_base64()
%12 = call i32* @BIO_new(i32 %11)
store i32* %12, i32** %7
%13 = call i32 (...) @BIO_s_mem()
%14 = call i32* @BIO_new(i32 %13)
store i32* %14, i32** %8
%15 = load i32*, i32** %7
%16 = load i32*, i32** %8
%17 = call i32* @BIO_push(i32* %15, i32* %16)
store i32* %17, i32** %8
%18 = load i32*, i32** %8
%19 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%20 = call i32 @BIO_set_flags(i32* %18, i32 %19)
%21 = load i32*, i32** %8
%22 = load i8*, i8** %4
%23 = load i32, i32* %5
%24 = call i32 @BIO_write(i32* %21, i8* %22, i32 %23)
%25 = load i32*, i32** %8
%26 = load i32, i32* @BIO_CTRL_FLUSH
%27 = call i32 @BIO_ctrl(i32* %25, i32 %26, i32 0, i32* null)
store %struct.TYPE_3__* null, %struct.TYPE_3__** %9
%28 = load i32*, i32** %8
%29 = call i32 @BIO_get_mem_ptr(i32* %28, %struct.TYPE_3__** %9)
%30 = load %struct.TYPE_3__*, %struct.TYPE_3__** %9
%31 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %30, i32 0, i32 0
%32 = load i64, i64* %31
store i64 %32, i64* %10
%33 = load i8*, i8** %6
%34 = load %struct.TYPE_3__*, %struct.TYPE_3__** %9
%35 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %34, i32 0, i32 1
%36 = load i32, i32* %35
%37 = load i64, i64* %10
%38 = call i32 @memcpy(i8* %33, i32 %36, i64 %37)
%39 = load i8*, i8** %6
%40 = load i64, i64* %10
%41 = getelementptr inbounds i8, i8* %39, i64 %40
store i8 0, i8* %41
%42 = load i32*, i32** %8
%43 = call i32 @BIO_free_all(i32* %42)
%44 = load i64, i64* %10
ret i64 %44
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64, i32 }
@BIO_FLAGS_BASE64_NO_NL = global i32 0
@BIO_CTRL_FLUSH = global i32 0
define i64 @base64encrypt(i8* %0, i32 %1, i8* %2) {
%4 = alloca %struct.TYPE_3__*
%5 = tail call i32 (...) @BIO_f_base64()
%6 = tail call i32* @BIO_new(i32 %5)
%7 = tail call i32 (...) @BIO_s_mem()
%8 = tail call i32* @BIO_new(i32 %7)
%9 = tail call i32* @BIO_push(i32* %6, i32* %8)
%10 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%11 = tail call i32 @BIO_set_flags(i32* %9, i32 %10)
%12 = tail call i32 @BIO_write(i32* %9, i8* %0, i32 %1)
%13 = load i32, i32* @BIO_CTRL_FLUSH
%14 = tail call i32 @BIO_ctrl(i32* %9, i32 %13, i32 0, i32* null)
%15 = bitcast %struct.TYPE_3__** %4 to i8*
store %struct.TYPE_3__* null, %struct.TYPE_3__** %4
%16 = call i32 @BIO_get_mem_ptr(i32* %9, %struct.TYPE_3__** %4)
%17 = load %struct.TYPE_3__*, %struct.TYPE_3__** %4
%18 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %17, i64 0, i32 0
%19 = load i64, i64* %18
%20 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %17, i64 0, i32 1
%21 = load i32, i32* %20
%22 = call i32 @memcpy(i8* %2, i32 %21, i64 %19)
%23 = getelementptr inbounds i8, i8* %2, i64 %19
store i8 0, i8* %23
%24 = call i32 @BIO_free_all(i32* %9)
ret i64 %19
}