#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 */

/* Type definitions */
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ BIO_CLOSE;
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*/ *);
long BIO_get_mem_data(int /*<<< orphan*/ *, char **);
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*/ *, char const *, int);
char *malloc(long);
int /*<<< orphan*/ memcpy(char *, char *, long);
char *base64(const char *in, int in_len, int *out_len) {
  BIO *buf, *b64;
  char *ptr, *out;
  long len;
  buf = BIO_new(BIO_s_mem());
  BIO_set_close(buf, BIO_CLOSE);
  b64 = BIO_new(BIO_f_base64());
  BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
  BIO_push(b64, buf);
  BIO_write(b64, in, in_len);
  BIO_flush(b64);
  len = BIO_get_mem_data(buf, &ptr);
  out = malloc((len + 1) * sizeof(char));
  memcpy(out, ptr, len);
  out[len] = '\0';
  *out_len = len + 1;
  BIO_free_all(b64);
  return out;
}


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

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

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

LLVM IR (-O2):
@BIO_CLOSE = global i32 0
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define i8* @base64(i8* %0, i32 %1, i32* nocapture writeonly %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = tail call i32 (...) @BIO_s_mem()
%7 = tail call i32* @BIO_new(i32 %6)
%8 = load i32, i32* @BIO_CLOSE
%9 = tail call i32 @BIO_set_close(i32* %7, i32 %8)
%10 = tail call i32 (...) @BIO_f_base64()
%11 = tail call i32* @BIO_new(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_push(i32* %11, i32* %7)
%15 = tail call i32 @BIO_write(i32* %11, i8* %0, i32 %1)
%16 = tail call i32 @BIO_flush(i32* %11)
%17 = call i64 @BIO_get_mem_data(i32* %7, i8** %4)
%18 = add nsw i64 %17, 1
%19 = call i8* @malloc(i64 %18)
%20 = load i8*, i8** %4
%21 = call i32 @memcpy(i8* %19, i8* %20, i64 %17)
%22 = getelementptr inbounds i8, i8* %19, i64 %17
store i8 0, i8* %22
%23 = trunc i64 %18 to i32
store i32 %23, i32* %2
%24 = call i32 @BIO_free_all(i32* %11)
ret i8* %19
}