#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 *, size_t);
int /*<<< orphan*/ *BIO_push(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int BIO_read(int /*<<< orphan*/ *, unsigned char *, size_t);
int /*<<< orphan*/ BIO_set_flags(int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ malloc(size_t);
size_t strlen(char const *);
unsigned char *base64_decode(const char *base64data, int *len) {
  BIO *b64, *bmem;
  size_t length = strlen(base64data);
  unsigned char *buffer = (unsigned char *)malloc(length);
  b64 = BIO_new(BIO_f_base64());
  BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
  bmem = BIO_new_mem_buf((void *)base64data, length);
  bmem = BIO_push(b64, bmem);
  *len = BIO_read(bmem, buffer, length);
  BIO_free_all(bmem);
  return buffer;
}


x86 assembly (clang, -O0):
<base64_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1060 <BIO_f_base64@plt>
mov    %eax,%edi
call   10a0 <BIO_new@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
call   1070 <BIO_set_flags@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <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    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <BIO_read@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rdi
call   10b0 <BIO_free_all@plt>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64_decode>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
call   1050 <strlen@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   1090 <malloc@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1060 <BIO_f_base64@plt>
mov    %eax,%edi
call   10a0 <BIO_new@plt>
mov    %rax,%rbx
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <BIO_set_flags@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1080 <BIO_new_mem_buf@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <BIO_push@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1040 <BIO_read@plt>
mov    %eax,(%r14)
mov    %rbx,%rdi
call   10b0 <BIO_free_all@plt>
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define i8* @base64_decode(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i8*
store i8* %0, i8** %3
store i32* %1, i32** %4
%9 = load i8*, i8** %3
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %7
%11 = load i64, i64* %7
%12 = call i64 @malloc(i64 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %8
%14 = call i32 (...) @BIO_f_base64()
%15 = call i32* @BIO_new(i32 %14)
store i32* %15, i32** %5
%16 = load i32*, i32** %5
%17 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%18 = call i32 @BIO_set_flags(i32* %16, i32 %17)
%19 = load i8*, i8** %3
%20 = load i64, i64* %7
%21 = call i32* @BIO_new_mem_buf(i8* %19, i64 %20)
store i32* %21, i32** %6
%22 = load i32*, i32** %5
%23 = load i32*, i32** %6
%24 = call i32* @BIO_push(i32* %22, i32* %23)
store i32* %24, i32** %6
%25 = load i32*, i32** %6
%26 = load i8*, i8** %8
%27 = load i64, i64* %7
%28 = call i32 @BIO_read(i32* %25, i8* %26, i64 %27)
%29 = load i32*, i32** %4
store i32 %28, i32* %29
%30 = load i32*, i32** %6
%31 = call i32 @BIO_free_all(i32* %30)
%32 = load i8*, i8** %8
ret i8* %32
}

LLVM IR (-O2):
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define i8* @base64_decode(i8* %0, i32* nocapture writeonly %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @malloc(i64 %3)
%5 = inttoptr i64 %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_new_mem_buf(i8* %0, i64 %3)
%11 = tail call i32* @BIO_push(i32* %7, i32* %10)
%12 = tail call i32 @BIO_read(i32* %11, i8* %5, i64 %3)
store i32 %12, i32* %1
%13 = tail call i32 @BIO_free_all(i32* %11)
ret i8* %5
}