#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(char *, int);
int /*<<< orphan*/ *BIO_push(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_read(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ BIO_set_flags(int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, size_t);
char *base64decode(char *base64encoded, size_t length) {
  BIO *b64, *bmem;
  char *buffer = (char *)malloc(length);
  memset(buffer, 0, length);
  b64 = BIO_new(BIO_f_base64());
  BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
  bmem = BIO_new_mem_buf(base64encoded, (int)length);
  bmem = BIO_push(b64, bmem);
  BIO_read(bmem, buffer, (int)length);
  BIO_free_all(bmem);
  b64 = NULL;
  return buffer;
}


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

x86 assembly (clang, -O2):
<base64decode>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r15
mov    %rsi,%rdi
call   1090 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
mov    %r12,%rdx
call   1060 <memset@plt>
xor    %eax,%eax
call   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   10a0 <BIO_new@plt>
mov    %rax,%rbx
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <BIO_set_flags@plt>
mov    %r15,%rdi
mov    %r12d,%esi
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    %r14,%rsi
mov    %r12d,%edx
call   1040 <BIO_read@plt>
mov    %rbx,%rdi
call   10b0 <BIO_free_all@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define i8* @base64decode(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%8 = load i64, i64* %4
%9 = call i64 @malloc(i64 %8)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = load i64, i64* %4
%13 = call i32 @memset(i8* %11, i32 0, i64 %12)
%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* %4
%21 = trunc i64 %20 to i32
%22 = call i32* @BIO_new_mem_buf(i8* %19, i32 %21)
store i32* %22, i32** %6
%23 = load i32*, i32** %5
%24 = load i32*, i32** %6
%25 = call i32* @BIO_push(i32* %23, i32* %24)
store i32* %25, i32** %6
%26 = load i32*, i32** %6
%27 = load i8*, i8** %7
%28 = load i64, i64* %4
%29 = trunc i64 %28 to i32
%30 = call i32 @BIO_read(i32* %26, i8* %27, i32 %29)
%31 = load i32*, i32** %6
%32 = call i32 @BIO_free_all(i32* %31)
store i32* null, i32** %5
%33 = load i8*, i8** %7
ret i8* %33
}

LLVM IR (-O2):
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define i8* @base64decode(i8* %0, i64 %1) {
%3 = tail call i64 @malloc(i64 %1)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @memset(i8* %4, i32 0, i64 %1)
%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 = trunc i64 %1 to i32
%11 = tail call i32* @BIO_new_mem_buf(i8* %0, i32 %10)
%12 = tail call i32* @BIO_push(i32* %7, i32* %11)
%13 = tail call i32 @BIO_read(i32* %12, i8* %4, i32 %10)
%14 = tail call i32 @BIO_free_all(i32* %12)
ret i8* %4
}