#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_free_all(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ *BIO_new_mem_buf(char const *, int);
int /*<<< orphan*/ BIO_push(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
long BIO_read(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ BIO_set_close(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ BIO_set_flags(int /*<<< orphan*/ *, int /*<<< orphan*/);
char *malloc(int);
char *unbase64(const char *in, int in_len, int *out_len) {
  BIO *buf, *b64;
  char *out;
  long len;
  buf = BIO_new_mem_buf(in, in_len);
  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);
  out = malloc((in_len + 1) * sizeof(char));
  len = BIO_read(b64, out, in_len);
  out[len] = '\0';
  *out_len = len;
  BIO_free_all(b64);
  return out;
}


x86 assembly (clang, -O0):
<unbase64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1080 <BIO_new_mem_buf@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
call   1030 <BIO_set_close@plt>
mov    $0x0,%al
call   1060 <BIO_f_base64@plt>
mov    %eax,%edi
call   10a0 <BIO_new@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
call   1070 <BIO_set_flags@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <BIO_push@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1050 <BIO_read@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x38(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x38(%rbp),%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rdi
call   10b0 <BIO_free_all@plt>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unbase64>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %esi,%r15d
call   1080 <BIO_new_mem_buf@plt>
mov    %rax,%r12
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
mov    %r12,%rdi
call   1030 <BIO_set_close@plt>
xor    %eax,%eax
call   1060 <BIO_f_base64@plt>
mov    %eax,%edi
call   10a0 <BIO_new@plt>
mov    %rax,%r13
mov    0x2e10(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdi
call   1070 <BIO_set_flags@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   1040 <BIO_push@plt>
lea    0x1(%r15),%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %r13,%rdi
mov    %rax,%rsi
mov    %r15d,%edx
call   1050 <BIO_read@plt>
movb   $0x0,(%rbx,%rax,1)
mov    %eax,(%r14)
mov    %r13,%rdi
call   10b0 <BIO_free_all@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@BIO_CLOSE = global i32 0
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define i8* @unbase64(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 i64
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%11 = load i8*, i8** %4
%12 = load i32, i32* %5
%13 = call i32* @BIO_new_mem_buf(i8* %11, 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* %5
%26 = add nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = mul i64 %27, 1
%29 = trunc i64 %28 to i32
%30 = call i8* @malloc(i32 %29)
store i8* %30, i8** %9
%31 = load i32*, i32** %8
%32 = load i8*, i8** %9
%33 = load i32, i32* %5
%34 = call i64 @BIO_read(i32* %31, i8* %32, i32 %33)
store i64 %34, i64* %10
%35 = load i8*, i8** %9
%36 = load i64, i64* %10
%37 = getelementptr inbounds i8, i8* %35, i64 %36
store i8 0, i8* %37
%38 = load i64, i64* %10
%39 = trunc i64 %38 to i32
%40 = load i32*, i32** %6
store i32 %39, i32* %40
%41 = load i32*, i32** %8
%42 = call i32 @BIO_free_all(i32* %41)
%43 = load i8*, i8** %9
ret i8* %43
}

LLVM IR (-O2):
@BIO_CLOSE = global i32 0
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define i8* @unbase64(i8* %0, i32 %1, i32* nocapture writeonly %2) {
%4 = tail call i32* @BIO_new_mem_buf(i8* %0, i32 %1)
%5 = load i32, i32* @BIO_CLOSE
%6 = tail call i32 @BIO_set_close(i32* %4, i32 %5)
%7 = tail call i32 (...) @BIO_f_base64()
%8 = tail call i32* @BIO_new(i32 %7)
%9 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%10 = tail call i32 @BIO_set_flags(i32* %8, i32 %9)
%11 = tail call i32 @BIO_push(i32* %8, i32* %4)
%12 = add nsw i32 %1, 1
%13 = tail call i8* @malloc(i32 %12)
%14 = tail call i64 @BIO_read(i32* %8, i8* %13, i32 %1)
%15 = getelementptr inbounds i8, i8* %13, i64 %14
store i8 0, i8* %15
%16 = trunc i64 %14 to i32
store i32 %16, i32* %2
%17 = tail call i32 @BIO_free_all(i32* %8)
ret i8* %13
}