#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*/ *);
long BIO_get_mem_data(int /*<<< orphan*/ *, unsigned char **);
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 *, int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, long);
int B64_encode(unsigned char *in, int inl, unsigned char *out) {
  BIO *bmem, *b64;
  unsigned char *i_encb64;
  long i_encb64l = 0;
  b64 = BIO_new(BIO_f_base64());
  BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
  bmem = BIO_new(BIO_s_mem());
  b64 = BIO_push(b64, bmem);
  BIO_write(b64, in, inl);
  BIO_flush(b64);
  i_encb64l = BIO_get_mem_data(bmem, &i_encb64);
  memcpy(out, i_encb64, i_encb64l);
  BIO_free_all(b64);
  return i_encb64l;
}


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

x86 assembly (clang, -O2):
<B64_encode>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%r12
xor    %eax,%eax
call   1040 <BIO_f_base64@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rax,%rbp
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1050 <BIO_set_flags@plt>
xor    %eax,%eax
call   10a0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1070 <BIO_new@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %rax,%rsi
call   1030 <BIO_push@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
call   1090 <BIO_write@plt>
mov    %rbp,%rdi
call   10c0 <BIO_flush@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   10b0 <BIO_get_mem_data@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rsi
mov    %r14,%rdi
mov    %rax,%rdx
call   1060 <memcpy@plt>
mov    %rbp,%rdi
call   1080 <BIO_free_all@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define i32 @B64_encode(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = tail call i32 (...) @BIO_f_base64()
%7 = tail call i32* @BIO_new(i32 %6)
%8 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%9 = tail call i32 @BIO_set_flags(i32* %7, i32 %8)
%10 = tail call i32 (...) @BIO_s_mem()
%11 = tail call i32* @BIO_new(i32 %10)
%12 = tail call i32* @BIO_push(i32* %7, i32* %11)
%13 = tail call i32 @BIO_write(i32* %12, i8* %0, i32 %1)
%14 = tail call i32 @BIO_flush(i32* %12)
%15 = call i64 @BIO_get_mem_data(i32* %11, i8** %4)
%16 = load i8*, i8** %4
%17 = call i32 @memcpy(i8* %2, i8* %16, i64 %15)
%18 = call i32 @BIO_free_all(i32* %12)
%19 = trunc i64 %15 to i32
ret i32 %19
}