#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_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_new(int /*<<< orphan*/);
int /*<<< orphan*/ BIO_push(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int BIO_read(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ BIO_s_mem();
int /*<<< orphan*/ BIO_set_flags(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ BIO_write(int /*<<< orphan*/ *, char const *, int);
int base64expansion(int);
int base64enc(char *b64, int len, const char *pt) {
  BIO *bio_64 = BIO_new(BIO_f_base64());
  BIO *bio_mem = BIO_new(BIO_s_mem());
  BIO_push(bio_64, bio_mem);
  BIO_set_flags(bio_64, BIO_FLAGS_BASE64_NO_NL);
  BIO_write(bio_64, pt, len);
  BIO_flush(bio_64);
  int lenOut = base64expansion(len);
  int ret = BIO_read(bio_mem, b64, lenOut);
  BIO_free_all(bio_64);
  return ret;
}


x86 assembly (clang, -O0):
<base64enc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   10b0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <BIO_push@plt>
mov    -0x20(%rbp),%rdi
mov    0x2df1(%rip),%rax
mov    (%rax),%esi
call   1060 <BIO_set_flags@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   10a0 <BIO_write@plt>
mov    -0x20(%rbp),%rdi
call   10c0 <BIO_flush@plt>
mov    -0xc(%rbp),%edi
call   1080 <base64expansion@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1040 <BIO_read@plt>
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1090 <BIO_free_all@plt>
mov    -0x30(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64enc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %esi,%r12d
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   10b0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <BIO_push@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <BIO_set_flags@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   10a0 <BIO_write@plt>
mov    %rbx,%rdi
call   10c0 <BIO_flush@plt>
mov    %r12d,%edi
call   1080 <base64expansion@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <BIO_read@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1090 <BIO_free_all@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define i32 @base64enc(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%11 = call i32 (...) @BIO_f_base64()
%12 = call i32* @BIO_new(i32 %11)
store i32* %12, i32** %7
%13 = call i32 (...) @BIO_s_mem()
%14 = call i32* @BIO_new(i32 %13)
store i32* %14, i32** %8
%15 = load i32*, i32** %7
%16 = load i32*, i32** %8
%17 = call i32 @BIO_push(i32* %15, i32* %16)
%18 = load i32*, i32** %7
%19 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%20 = call i32 @BIO_set_flags(i32* %18, i32 %19)
%21 = load i32*, i32** %7
%22 = load i8*, i8** %6
%23 = load i32, i32* %5
%24 = call i32 @BIO_write(i32* %21, i8* %22, i32 %23)
%25 = load i32*, i32** %7
%26 = call i32 @BIO_flush(i32* %25)
%27 = load i32, i32* %5
%28 = call i32 @base64expansion(i32 %27)
store i32 %28, i32* %9
%29 = load i32*, i32** %8
%30 = load i8*, i8** %4
%31 = load i32, i32* %9
%32 = call i32 @BIO_read(i32* %29, i8* %30, i32 %31)
store i32 %32, i32* %10
%33 = load i32*, i32** %7
%34 = call i32 @BIO_free_all(i32* %33)
%35 = load i32, i32* %10
ret i32 %35
}

LLVM IR (-O2):
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define i32 @base64enc(i8* %0, i32 %1, i8* %2) {
%4 = tail call i32 (...) @BIO_f_base64()
%5 = tail call i32* @BIO_new(i32 %4)
%6 = tail call i32 (...) @BIO_s_mem()
%7 = tail call i32* @BIO_new(i32 %6)
%8 = tail call i32 @BIO_push(i32* %5, i32* %7)
%9 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%10 = tail call i32 @BIO_set_flags(i32* %5, i32 %9)
%11 = tail call i32 @BIO_write(i32* %5, i8* %2, i32 %1)
%12 = tail call i32 @BIO_flush(i32* %5)
%13 = tail call i32 @base64expansion(i32 %1)
%14 = tail call i32 @BIO_read(i32* %7, i8* %0, i32 %13)
%15 = tail call i32 @BIO_free_all(i32* %5)
ret i32 %14
}