#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_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int length;
  char *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*/ *, void const *, int);
int /*<<< orphan*/ BUF_MEM_grow(TYPE_1__ *, int);
char *encode64(const void *b64_encode_this, int encode_this_many_bytes) {
  BIO *b64_bio, *mem_bio;
  BUF_MEM *mem_bio_mem_ptr;
  b64_bio = BIO_new(BIO_f_base64());
  mem_bio = BIO_new(BIO_s_mem());
  BIO_push(b64_bio, mem_bio);
  BIO_set_flags(b64_bio, BIO_FLAGS_BASE64_NO_NL);
  BIO_write(b64_bio, b64_encode_this, encode_this_many_bytes);
  BIO_flush(b64_bio);
  BIO_get_mem_ptr(mem_bio, &mem_bio_mem_ptr);
  BIO_set_close(mem_bio, BIO_NOCLOSE);
  BIO_free_all(b64_bio);
  BUF_MEM_grow(mem_bio_mem_ptr, (*mem_bio_mem_ptr).length + 1);
  (*mem_bio_mem_ptr).data[(*mem_bio_mem_ptr).length] = '\0';
  return (*mem_bio_mem_ptr).data;
}


x86 assembly (clang, -O0):
<encode64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1060 <BIO_f_base64@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   10c0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <BIO_push@plt>
mov    -0x18(%rbp),%rdi
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
call   1070 <BIO_set_flags@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   10b0 <BIO_write@plt>
mov    -0x18(%rbp),%rdi
call   10d0 <BIO_flush@plt>
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   10a0 <BIO_get_mem_ptr@plt>
mov    -0x20(%rbp),%rdi
mov    0x2db5(%rip),%rax
mov    (%rax),%esi
call   1040 <BIO_set_close@plt>
mov    -0x18(%rbp),%rdi
call   1090 <BIO_free_all@plt>
mov    -0x28(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
add    $0x1,%esi
call   1030 <BUF_MEM_grow@plt>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x28(%rbp),%rcx
movslq (%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encode64>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
xor    %eax,%eax
call   1060 <BIO_f_base64@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   10c0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <BIO_push@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <BIO_set_flags@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   10b0 <BIO_write@plt>
mov    %rbx,%rdi
call   10d0 <BIO_flush@plt>
mov    %rsp,%rsi
mov    %rbp,%rdi
call   10a0 <BIO_get_mem_ptr@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1040 <BIO_set_close@plt>
mov    %rbx,%rdi
call   1090 <BIO_free_all@plt>
mov    (%rsp),%rdi
mov    (%rdi),%esi
add    $0x1,%esi
call   1030 <BUF_MEM_grow@plt>
mov    (%rsp),%rax
mov    0x8(%rax),%rcx
movslq (%rax),%rax
movb   $0x0,(%rcx,%rax,1)
mov    (%rsp),%rax
mov    0x8(%rax),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i8* }
@BIO_FLAGS_BASE64_NO_NL = global i32 0
@BIO_NOCLOSE = global i32 0
define i8* @encode64(i8* %0, i32 %1) {
%3 = alloca %struct.TYPE_4__*
%4 = bitcast %struct.TYPE_4__** %3 to i8*
%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* %6, i32 %10)
%12 = tail call i32 @BIO_write(i32* %6, i8* %0, i32 %1)
%13 = tail call i32 @BIO_flush(i32* %6)
%14 = call i32 @BIO_get_mem_ptr(i32* %8, %struct.TYPE_4__** %3)
%15 = load i32, i32* @BIO_NOCLOSE
%16 = call i32 @BIO_set_close(i32* %8, i32 %15)
%17 = call i32 @BIO_free_all(i32* %6)
%18 = load %struct.TYPE_4__*, %struct.TYPE_4__** %3
%19 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %18, i64 0, i32 0
%20 = load i32, i32* %19
%21 = add nsw i32 %20, 1
%22 = call i32 @BUF_MEM_grow(%struct.TYPE_4__* %18, i32 %21)
%23 = load %struct.TYPE_4__*, %struct.TYPE_4__** %3
%24 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %23, i64 0, i32 1
%25 = load i8*, i8** %24
%26 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %23, i64 0, i32 0
%27 = load i32, i32* %26
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
store i8 0, i8* %29
%30 = load %struct.TYPE_4__*, %struct.TYPE_4__** %3
%31 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %30, i64 0, i32 1
%32 = load i8*, i8** %31
ret i8* %32
}