#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__ {
  int length;
  int /*<<< orphan*/ data;
};
typedef TYPE_1__ BUF_MEM;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ BIO_FLAGS_BASE64_NO_NL;
int /*<<< orphan*/ BIO_NOCLOSE;
int /*<<< orphan*/ BIO_f_base64();
int /*<<< orphan*/ BIO_flush(int /*<<< orphan*/ *);
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_close(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ BIO_set_flags(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ BIO_write(int /*<<< orphan*/ *, unsigned char *, int);
int /*<<< orphan*/ memcpy(unsigned char *, int /*<<< orphan*/, int);
void b64_enc(unsigned char *in, int in_len, unsigned char *out, int *out_len) {
  BIO *bio, *b64;
  BUF_MEM *bptr;
  b64 = BIO_new(BIO_f_base64());
  bio = BIO_new(BIO_s_mem());
  bio = BIO_push(b64, bio);
  BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL);
  BIO_write(bio, in, in_len);
  BIO_flush(bio);
  BIO_get_mem_ptr(bio, &bptr);
  BIO_set_close(bio, BIO_NOCLOSE);
  BIO_free_all(bio);
  memcpy(out, bptr->data, bptr->length);
  *out_len = bptr->length;
}


x86 assembly (clang, -O0):
<b64_enc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    $0x0,%al
call   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   10c0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <BIO_push@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
call   1060 <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
call   10d0 <BIO_flush@plt>
mov    -0x28(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   10a0 <BIO_get_mem_ptr@plt>
mov    -0x28(%rbp),%rdi
mov    0x2da9(%rip),%rax
mov    (%rax),%esi
call   1030 <BIO_set_close@plt>
mov    -0x28(%rbp),%rdi
call   1090 <BIO_free_all@plt>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
call   1070 <memcpy@plt>
mov    -0x38(%rbp),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<b64_enc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%r12d
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   10c0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rbp,%rdi
mov    %rax,%rsi
call   1040 <BIO_push@plt>
mov    %rax,%rbp
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1060 <BIO_set_flags@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   10b0 <BIO_write@plt>
mov    %rbp,%rdi
call   10d0 <BIO_flush@plt>
lea    0x8(%rsp),%rsi
mov    %rbp,%rdi
call   10a0 <BIO_get_mem_ptr@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1030 <BIO_set_close@plt>
mov    %rbp,%rdi
call   1090 <BIO_free_all@plt>
mov    0x8(%rsp),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %r15,%rdi
call   1070 <memcpy@plt>
mov    0x8(%rsp),%rax
mov    (%rax),%eax
mov    %eax,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32 }
@BIO_FLAGS_BASE64_NO_NL = global i32 0
@BIO_NOCLOSE = global i32 0
define void @b64_enc(i8* %0, i32 %1, i8* %2, i32* nocapture writeonly %3) {
%5 = alloca %struct.TYPE_3__*
%6 = bitcast %struct.TYPE_3__** %5 to i8*
%7 = tail call i32 (...) @BIO_f_base64()
%8 = tail call i32* @BIO_new(i32 %7)
%9 = tail call i32 (...) @BIO_s_mem()
%10 = tail call i32* @BIO_new(i32 %9)
%11 = tail call i32* @BIO_push(i32* %8, i32* %10)
%12 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%13 = tail call i32 @BIO_set_flags(i32* %11, i32 %12)
%14 = tail call i32 @BIO_write(i32* %11, i8* %0, i32 %1)
%15 = tail call i32 @BIO_flush(i32* %11)
%16 = call i32 @BIO_get_mem_ptr(i32* %11, %struct.TYPE_3__** %5)
%17 = load i32, i32* @BIO_NOCLOSE
%18 = call i32 @BIO_set_close(i32* %11, i32 %17)
%19 = call i32 @BIO_free_all(i32* %11)
%20 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%21 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %20, i64 0, i32 1
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %20, i64 0, i32 0
%24 = load i32, i32* %23
%25 = call i32 @memcpy(i8* %2, i32 %22, i32 %24)
%26 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%27 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %26, i64 0, i32 0
%28 = load i32, i32* %27
store i32 %28, i32* %3
ret void
}