#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 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*/);
scalar_t__ BIO_should_retry(int /*<<< orphan*/ *);
int BIO_write(int /*<<< orphan*/ *, unsigned char *, int);
unsigned char *cod_base64(unsigned char *data, int len, int *lenoutput) {
  BIO *b64 = BIO_new(BIO_f_base64());
  BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
  BIO *mem = BIO_new(BIO_s_mem());
  BIO_push(b64, mem);
  int done = 0;
  int res = 0;
  while (!done) {
    res = BIO_write(b64, data, len);
    if (res <= 0) {
      if (BIO_should_retry(b64)) {
        continue;
      } else {
      }
    } else
      done = 1;
  }
  BIO_flush(b64);
  unsigned char *output;
  *lenoutput = BIO_get_mem_data(mem, &output);
  return output;
}


x86 assembly (clang, -O0):
<cod_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   1040 <BIO_f_base64@plt>
mov    %eax,%edi
call   1060 <BIO_new@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e20(%rip),%rax
mov    (%rax),%esi
call   1050 <BIO_set_flags@plt>
mov    $0x0,%al
call   1090 <BIO_s_mem@plt>
mov    %eax,%edi
call   1060 <BIO_new@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <BIO_push@plt>
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x0,-0x2c(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    120a <cod_base64+0x7a>
jmp    1255 <cod_base64+0xc5>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1080 <BIO_write@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jg     1249 <cod_base64+0xb9>
mov    -0x20(%rbp),%rdi
call   1070 <BIO_should_retry@plt>
cmp    $0x0,%rax
je     123f <cod_base64+0xaf>
jmp    11f4 <cod_base64+0x64>
jmp    1244 <cod_base64+0xb4>
jmp    1250 <cod_base64+0xc0>
movl   $0x1,-0x2c(%rbp)
jmp    11f4 <cod_base64+0x64>
mov    -0x20(%rbp),%rdi
call   10b0 <BIO_flush@plt>
mov    -0x28(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   10a0 <BIO_get_mem_data@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cod_base64>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <BIO_f_base64@plt>
mov    %eax,%edi
call   1060 <BIO_new@plt>
mov    %rax,%rbp
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1050 <BIO_set_flags@plt>
xor    %eax,%eax
call   1090 <BIO_s_mem@plt>
mov    %eax,%edi
call   1060 <BIO_new@plt>
mov    %rax,%r12
mov    %rbp,%rdi
mov    %rax,%rsi
call   1030 <BIO_push@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1080 <BIO_write@plt>
test   %eax,%eax
jg     120c <cod_base64+0x7c>
mov    %rbp,%rdi
call   1070 <BIO_should_retry@plt>
jmp    11f0 <cod_base64+0x60>
mov    %rbp,%rdi
call   10b0 <BIO_flush@plt>
lea    0x8(%rsp),%rsi
mov    %r12,%rdi
call   10a0 <BIO_get_mem_data@plt>
mov    %eax,(%r14)
mov    0x8(%rsp),%rax
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 i8* @cod_base64(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%12 = call i32 (...) @BIO_f_base64()
%13 = call i32* @BIO_new(i32 %12)
store i32* %13, i32** %7
%14 = load i32*, i32** %7
%15 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%16 = call i32 @BIO_set_flags(i32* %14, i32 %15)
%17 = call i32 (...) @BIO_s_mem()
%18 = call i32* @BIO_new(i32 %17)
store i32* %18, i32** %8
%19 = load i32*, i32** %7
%20 = load i32*, i32** %8
%21 = call i32 @BIO_push(i32* %19, i32* %20)
store i32 0, i32* %9
store i32 0, i32* %10
br label %22
22: ; preds = %41, %37, %3
%23 = load i32, i32* %9
%24 = icmp ne i32 %23, 0
%25 = xor i1 %24, true
br i1 %25, label %26, label %42
26: ; preds = %22
%27 = load i32*, i32** %7
%28 = load i8*, i8** %4
%29 = load i32, i32* %5
%30 = call i32 @BIO_write(i32* %27, i8* %28, i32 %29)
store i32 %30, i32* %10
%31 = load i32, i32* %10
%32 = icmp sle i32 %31, 0
br i1 %32, label %33, label %40
33: ; preds = %26
%34 = load i32*, i32** %7
%35 = call i64 @BIO_should_retry(i32* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %33
br label %22
38: ; preds = %33
br label %39
39: ; preds = %38
br label %41
40: ; preds = %26
store i32 1, i32* %9
br label %41
41: ; preds = %40, %39
br label %22
42: ; preds = %22
%43 = load i32*, i32** %7
%44 = call i32 @BIO_flush(i32* %43)
%45 = load i32*, i32** %8
%46 = call i32 @BIO_get_mem_data(i32* %45, i8** %11)
%47 = load i32*, i32** %6
store i32 %46, i32* %47
%48 = load i8*, i8** %11
ret i8* %48
}

LLVM IR (-O2):
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define i8* @cod_base64(i8* %0, i32 %1, i32* nocapture writeonly %2) {
%4 = alloca i8*
%5 = tail call i32 (...) @BIO_f_base64()
%6 = tail call i32* @BIO_new(i32 %5)
%7 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%8 = tail call i32 @BIO_set_flags(i32* %6, i32 %7)
%9 = tail call i32 (...) @BIO_s_mem()
%10 = tail call i32* @BIO_new(i32 %9)
%11 = tail call i32 @BIO_push(i32* %6, i32* %10)
%12 = tail call i32 @BIO_write(i32* %6, i8* %0, i32 %1)
%13 = icmp slt i32 %12, 1
br i1 %13, label %14, label %18
14: ; preds = %3, %14
%15 = tail call i64 @BIO_should_retry(i32* %6)
%16 = tail call i32 @BIO_write(i32* %6, i8* %0, i32 %1)
%17 = icmp slt i32 %16, 1
br i1 %17, label %14, label %18
18: ; preds = %14, %3
%19 = tail call i32 @BIO_flush(i32* %6)
%20 = bitcast i8** %4 to i8*
%21 = call i32 @BIO_get_mem_data(i32* %10, i8** %4)
store i32 %21, i32* %2
%22 = load i8*, i8** %4
ret i8* %22
}