#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*/ *);
size_t BIO_get_mem_data(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ *BIO_new_mem_buf(void *, int);
int /*<<< orphan*/ *BIO_push(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
size_t BIO_read(int /*<<< orphan*/ *, unsigned char *, size_t);
int /*<<< orphan*/ BIO_set_flags(int /*<<< orphan*/ *, int /*<<< orphan*/);
unsigned char *malloc(size_t);
void openssl_base64_decode(char *encoded_bytes, unsigned char **decoded_bytes,
                           size_t *decoded_length) {
  BIO *bioMem, *b64;
  size_t buffer_length;
  bioMem = BIO_new_mem_buf((void *)encoded_bytes, -1);
  b64 = BIO_new(BIO_f_base64());
  BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
  bioMem = BIO_push(b64, bioMem);
  buffer_length = BIO_get_mem_data(bioMem, NULL);
  *decoded_bytes = malloc(buffer_length);
  if (decoded_bytes == NULL) {
    BIO_free_all(bioMem);
    *decoded_length = 0;
    return;
  }
  *decoded_length = BIO_read(bioMem, *decoded_bytes, buffer_length);
  BIO_free_all(bioMem);
}


x86 assembly (clang, -O0):
<openssl_base64_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0xffffffff,%esi
call   1070 <BIO_new_mem_buf@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1090 <BIO_new@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
call   1060 <BIO_set_flags@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <BIO_push@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   10b0 <BIO_get_mem_data@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x10(%rbp)
jne    1233 <openssl_base64_decode+0xa3>
mov    -0x20(%rbp),%rdi
call   10a0 <BIO_free_all@plt>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
jmp    125a <openssl_base64_decode+0xca>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x30(%rbp),%rdx
call   1040 <BIO_read@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rdi
call   10a0 <BIO_free_all@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openssl_base64_decode>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    $0xffffffff,%esi
call   1070 <BIO_new_mem_buf@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1090 <BIO_new@plt>
mov    %rax,%rbx
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <BIO_set_flags@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <BIO_push@plt>
mov    %rax,%r12
mov    %rax,%rdi
xor    %esi,%esi
call   10b0 <BIO_get_mem_data@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <malloc@plt>
mov    %rax,(%r15)
mov    %r12,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1040 <BIO_read@plt>
mov    %rax,(%r14)
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    10a0 <BIO_free_all@plt>

LLVM IR (-O0):
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define void @openssl_base64_decode(i8* %0, i8** %1, i64* %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i64*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i64
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i64* %2, i64** %6
%10 = load i8*, i8** %4
%11 = call i32* @BIO_new_mem_buf(i8* %10, i32 -1)
store i32* %11, i32** %7
%12 = call i32 (...) @BIO_f_base64()
%13 = call i32* @BIO_new(i32 %12)
store i32* %13, i32** %8
%14 = load i32*, i32** %8
%15 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%16 = call i32 @BIO_set_flags(i32* %14, i32 %15)
%17 = load i32*, i32** %8
%18 = load i32*, i32** %7
%19 = call i32* @BIO_push(i32* %17, i32* %18)
store i32* %19, i32** %7
%20 = load i32*, i32** %7
%21 = call i64 @BIO_get_mem_data(i32* %20, i32* null)
store i64 %21, i64* %9
%22 = load i64, i64* %9
%23 = call i8* @malloc(i64 %22)
%24 = load i8**, i8*** %5
store i8* %23, i8** %24
%25 = load i8**, i8*** %5
%26 = icmp eq i8** %25, null
br i1 %26, label %27, label %31
27: ; preds = %3
%28 = load i32*, i32** %7
%29 = call i32 @BIO_free_all(i32* %28)
%30 = load i64*, i64** %6
store i64 0, i64* %30
br label %40
31: ; preds = %3
%32 = load i32*, i32** %7
%33 = load i8**, i8*** %5
%34 = load i8*, i8** %33
%35 = load i64, i64* %9
%36 = call i64 @BIO_read(i32* %32, i8* %34, i64 %35)
%37 = load i64*, i64** %6
store i64 %36, i64* %37
%38 = load i32*, i32** %7
%39 = call i32 @BIO_free_all(i32* %38)
br label %40
40: ; preds = %31, %27
ret void
}

LLVM IR (-O2):
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define void @openssl_base64_decode(i8* %0, i8** nocapture writeonly %1, i64* nocapture writeonly %2) {
%4 = tail call i32* @BIO_new_mem_buf(i8* %0, i32 -1)
%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_push(i32* %6, i32* %4)
%10 = tail call i64 @BIO_get_mem_data(i32* %9, i32* null)
%11 = tail call i8* @malloc(i64 %10)
store i8* %11, i8** %1
%12 = tail call i64 @BIO_read(i32* %9, i8* %11, i64 %10)
store i64 %12, i64* %2
%13 = tail call i32 @BIO_free_all(i32* %9)
ret void
}