#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_FLAGS_BASE64_NO_NL;
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_flags(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ BIO_write(int /*<<< orphan*/ *, unsigned char const *,
                             size_t);
char *malloc(size_t);
int /*<<< orphan*/ memcpy(char *, int /*<<< orphan*/, size_t);
size_t Base64Encode(const unsigned char *In, size_t Len, char **Out) {
  BUF_MEM *bufferPtr;
  BIO *bio = BIO_push(BIO_new(BIO_f_base64()), BIO_new(BIO_s_mem()));
  BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL);
  BIO_write(bio, In, Len);
  BIO_flush(bio);
  BIO_get_mem_ptr(bio, &bufferPtr);
  size_t len = bufferPtr->length;
  *Out = malloc(len + 1);
  memcpy(*Out, bufferPtr->data, len);
  (*Out)[len] = 0x00;
  BIO_free_all(bio);
  return len;
}


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

x86 assembly (clang, -O2):
<Base64Encode>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
xor    %eax,%eax
call   1040 <BIO_f_base64@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   10c0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1030 <BIO_push@plt>
mov    %rax,%r13
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdi
call   1050 <BIO_set_flags@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   10b0 <BIO_write@plt>
mov    %r13,%rdi
call   10d0 <BIO_flush@plt>
lea    0x8(%rsp),%rsi
mov    %r13,%rdi
call   10a0 <BIO_get_mem_ptr@plt>
mov    0x8(%rsp),%r15
mov    (%r15),%rbx
lea    0x1(%rbx),%rdi
call   1070 <malloc@plt>
mov    %rax,(%r14)
mov    0x8(%r15),%esi
mov    %rax,%rdi
mov    %rbx,%rdx
call   1060 <memcpy@plt>
mov    (%r14),%rax
movb   $0x0,(%rax,%rbx,1)
mov    %r13,%rdi
call   1090 <BIO_free_all@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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