#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__ {
  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*/ *, unsigned char const *,
                             size_t);
void base64(const unsigned char *buffer, size_t len, char **b64text) {
  static BIO *bio, *b64;
  static BUF_MEM *bufferPtr;
  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, buffer, len);
  (void)BIO_flush(bio);
  BIO_get_mem_ptr(bio, &bufferPtr);
  (void)BIO_set_close(bio, BIO_NOCLOSE);
  BIO_free_all(bio);
  *b64text = (*bufferPtr).data;
  return;
}


x86 assembly (clang, -O0):
<base64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rax,0x2eb7(%rip)
mov    $0x0,%al
call   10b0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rax,0x2e9a(%rip)
mov    0x2e9b(%rip),%rdi
mov    0x2e8c(%rip),%rsi
call   1040 <BIO_push@plt>
mov    %rax,0x2e80(%rip)
mov    0x2e79(%rip),%rdi
mov    0x2dd2(%rip),%rax
mov    (%rax),%esi
call   1060 <BIO_set_flags@plt>
mov    0x2e64(%rip),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   10a0 <BIO_write@plt>
mov    0x2e50(%rip),%rdi
call   10c0 <BIO_flush@plt>
mov    0x2e44(%rip),%rdi
lea    0x2e4d(%rip),%rsi
call   1090 <BIO_get_mem_ptr@plt>
mov    0x2e31(%rip),%rdi
mov    0x2d9a(%rip),%rax
mov    (%rax),%esi
call   1030 <BIO_set_close@plt>
mov    0x2e1c(%rip),%rdi
call   1080 <BIO_free_all@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rax,0x2ebd(%rip)
xor    %eax,%eax
call   10b0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rax,0x2ea0(%rip)
mov    0x2ea1(%rip),%rdi
mov    %rax,%rsi
call   1040 <BIO_push@plt>
mov    %rax,0x2e8a(%rip)
mov    0x2de3(%rip),%rcx
mov    (%rcx),%esi
mov    %rax,%rdi
call   1060 <BIO_set_flags@plt>
mov    0x2e72(%rip),%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   10a0 <BIO_write@plt>
mov    0x2e60(%rip),%rdi
call   10c0 <BIO_flush@plt>
mov    0x2e54(%rip),%rdi
lea    0x2e5d(%rip),%rsi
call   1090 <BIO_get_mem_ptr@plt>
mov    0x2e41(%rip),%rdi
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
call   1030 <BIO_set_close@plt>
mov    0x2e2c(%rip),%rdi
call   1080 <BIO_free_all@plt>
mov    0x2e30(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i8* }
@base64.bio = internal global i32* null
@base64.b64 = internal global i32* null
@base64.bufferPtr = internal global %struct.TYPE_3__* null
@BIO_FLAGS_BASE64_NO_NL = global i32 0
@BIO_NOCLOSE = global i32 0
define void @base64(i8* %0, i64 %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8**
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8** %2, i8*** %6
%7 = call i32 (...) @BIO_f_base64()
%8 = call i32* @BIO_new(i32 %7)
store i32* %8, i32** @base64.b64
%9 = call i32 (...) @BIO_s_mem()
%10 = call i32* @BIO_new(i32 %9)
store i32* %10, i32** @base64.bio
%11 = load i32*, i32** @base64.b64
%12 = load i32*, i32** @base64.bio
%13 = call i32* @BIO_push(i32* %11, i32* %12)
store i32* %13, i32** @base64.bio
%14 = load i32*, i32** @base64.bio
%15 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%16 = call i32 @BIO_set_flags(i32* %14, i32 %15)
%17 = load i32*, i32** @base64.bio
%18 = load i8*, i8** %4
%19 = load i64, i64* %5
%20 = call i32 @BIO_write(i32* %17, i8* %18, i64 %19)
%21 = load i32*, i32** @base64.bio
%22 = call i32 @BIO_flush(i32* %21)
%23 = load i32*, i32** @base64.bio
%24 = call i32 @BIO_get_mem_ptr(i32* %23, %struct.TYPE_3__** @base64.bufferPtr)
%25 = load i32*, i32** @base64.bio
%26 = load i32, i32* @BIO_NOCLOSE
%27 = call i32 @BIO_set_close(i32* %25, i32 %26)
%28 = load i32*, i32** @base64.bio
%29 = call i32 @BIO_free_all(i32* %28)
%30 = load %struct.TYPE_3__*, %struct.TYPE_3__** @base64.bufferPtr
%31 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %30, i32 0, i32 0
%32 = load i8*, i8** %31
%33 = load i8**, i8*** %6
store i8* %32, i8** %33
ret void
}

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