#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_f_base64();
int /*<<< orphan*/ BIO_free_all(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ *BIO_new_mem_buf(unsigned char *, int);
int /*<<< orphan*/ *BIO_push(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_read(int /*<<< orphan*/ *, char *, int);
char *malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
char *unbase64(unsigned char *input, int length) {
  BIO *b64, *bmem;
  char *buf;
  buf = malloc(length);
  memset(buf, '\0', length);
  b64 = BIO_new(BIO_f_base64());
  bmem = BIO_new_mem_buf(input, length);
  bmem = BIO_push(b64, bmem);
  BIO_read(bmem, buf, length);
  BIO_free_all(bmem);
  return buf;
}


x86 assembly (clang, -O0):
<unbase64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    $0x0,%al
call   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1090 <BIO_new@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1070 <BIO_new_mem_buf@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <BIO_push@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1040 <BIO_read@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <BIO_free_all@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unbase64>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
mov    %esi,%edi
call   1080 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1060 <memset@plt>
xor    %eax,%eax
call   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1090 <BIO_new@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %ebp,%esi
call   1070 <BIO_new_mem_buf@plt>
mov    %r15,%rdi
mov    %rax,%rsi
call   1030 <BIO_push@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1040 <BIO_read@plt>
mov    %rbx,%rdi
call   10a0 <BIO_free_all@plt>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @unbase64(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = call i8* @malloc(i32 %8)
store i8* %9, i8** %7
%10 = load i8*, i8** %7
%11 = load i32, i32* %4
%12 = call i32 @memset(i8* %10, i8 signext 0, i32 %11)
%13 = call i32 (...) @BIO_f_base64()
%14 = call i32* @BIO_new(i32 %13)
store i32* %14, i32** %5
%15 = load i8*, i8** %3
%16 = load i32, i32* %4
%17 = call i32* @BIO_new_mem_buf(i8* %15, i32 %16)
store i32* %17, i32** %6
%18 = load i32*, i32** %5
%19 = load i32*, i32** %6
%20 = call i32* @BIO_push(i32* %18, i32* %19)
store i32* %20, i32** %6
%21 = load i32*, i32** %6
%22 = load i8*, i8** %7
%23 = load i32, i32* %4
%24 = call i32 @BIO_read(i32* %21, i8* %22, i32 %23)
%25 = load i32*, i32** %6
%26 = call i32 @BIO_free_all(i32* %25)
%27 = load i8*, i8** %7
ret i8* %27
}

LLVM IR (-O2):
define i8* @unbase64(i8* %0, i32 %1) {
%3 = tail call i8* @malloc(i32 %1)
%4 = tail call i32 @memset(i8* %3, i8 signext 0, i32 %1)
%5 = tail call i32 (...) @BIO_f_base64()
%6 = tail call i32* @BIO_new(i32 %5)
%7 = tail call i32* @BIO_new_mem_buf(i8* %0, i32 %1)
%8 = tail call i32* @BIO_push(i32* %6, i32* %7)
%9 = tail call i32 @BIO_read(i32* %8, i8* %3, i32 %1)
%10 = tail call i32 @BIO_free_all(i32* %8)
ret i8* %3
}