#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_free_all(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ *BIO_new_mem_buf(void *, int);
int /*<<< orphan*/ *BIO_push(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
unsigned int BIO_read(int /*<<< orphan*/ *, unsigned char *, int);
int /*<<< orphan*/ BIO_set_flags(int /*<<< orphan*/ *, int /*<<< orphan*/);
unsigned int base64decode(void *input, int length, unsigned char *output) {
  BIO *b64_bio, *mem_bio;
  unsigned int len = 0;
  b64_bio = BIO_new(BIO_f_base64());
  mem_bio = BIO_new_mem_buf(input, length);
  mem_bio = BIO_push(b64_bio, mem_bio);
  BIO_set_flags(b64_bio, BIO_FLAGS_BASE64_NO_NL);
  len = BIO_read(mem_bio, output, length);
  output[len] = '\0';
  BIO_free_all(mem_bio);
  return len;
}


x86 assembly (clang, -O0):
<base64decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    $0x0,%al
call   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1070 <BIO_new_mem_buf@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <BIO_push@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
call   1060 <BIO_set_flags@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1040 <BIO_read@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
call   1090 <BIO_free_all@plt>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64decode>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %r15d,%esi
call   1070 <BIO_new_mem_buf@plt>
mov    %rbp,%rdi
mov    %rax,%rsi
call   1030 <BIO_push@plt>
mov    %rax,%rbx
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1060 <BIO_set_flags@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1040 <BIO_read@plt>
mov    %eax,%ebp
mov    %eax,%eax
movb   $0x0,(%r14,%rax,1)
mov    %rbx,%rdi
call   1090 <BIO_free_all@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define i32 @base64decode(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
store i32 0, i32* %9
%10 = call i32 (...) @BIO_f_base64()
%11 = call i32* @BIO_new(i32 %10)
store i32* %11, i32** %7
%12 = load i8*, i8** %4
%13 = load i32, i32* %5
%14 = call i32* @BIO_new_mem_buf(i8* %12, 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)
store i32* %17, i32** %8
%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** %8
%22 = load i8*, i8** %6
%23 = load i32, i32* %5
%24 = call i32 @BIO_read(i32* %21, i8* %22, i32 %23)
store i32 %24, i32* %9
%25 = load i8*, i8** %6
%26 = load i32, i32* %9
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8 0, i8* %28
%29 = load i32*, i32** %8
%30 = call i32 @BIO_free_all(i32* %29)
%31 = load i32, i32* %9
ret i32 %31
}

LLVM IR (-O2):
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define i32 @base64decode(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_new_mem_buf(i8* %0, i32 %1)
%7 = tail call i32* @BIO_push(i32* %5, i32* %6)
%8 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%9 = tail call i32 @BIO_set_flags(i32* %5, i32 %8)
%10 = tail call i32 @BIO_read(i32* %7, i8* %2, i32 %1)
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %2, i64 %11
store i8 0, i8* %12
%13 = tail call i32 @BIO_free_all(i32* %7)
ret i32 %10
}