#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_push(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ BIO_read(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ BIO_s_mem();
int /*<<< orphan*/ BIO_set_flags(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ BIO_write(int /*<<< orphan*/ *, void const *, int);
char *calloc(int, int);
char *base64decode(const void *b64_decode_this, int decode_this_many_bytes,
                   int *decodedLength) {
  BIO *b64_bio, *mem_bio;
  char *base64_decoded =
      calloc((decode_this_many_bytes * 3) / 4 + 1, sizeof(char));
  b64_bio = BIO_new(BIO_f_base64());
  mem_bio = BIO_new(BIO_s_mem());
  BIO_write(mem_bio, b64_decode_this, decode_this_many_bytes);
  BIO_push(b64_bio, mem_bio);
  BIO_set_flags(b64_bio, BIO_FLAGS_BASE64_NO_NL);
  int decoded_byte_index = 0;
  while (0 < BIO_read(b64_bio, base64_decoded + decoded_byte_index, 1)) {
    decoded_byte_index++;
  }
  BIO_free_all(b64_bio);
  *decodedLength = decoded_byte_index;
  return base64_decoded;
}


x86 assembly (clang, -O0):
<base64decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
imul   $0x3,-0xc(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   10b0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   10a0 <BIO_write@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <BIO_push@plt>
mov    -0x20(%rbp),%rdi
mov    0x2dd2(%rip),%rax
mov    (%rax),%esi
call   1070 <BIO_set_flags@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
movslq -0x34(%rbp),%rax
add    %rax,%rsi
mov    $0x1,%edx
call   1040 <BIO_read@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jge    1251 <base64decode+0xc1>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    121c <base64decode+0x8c>
mov    -0x20(%rbp),%rdi
call   1090 <BIO_free_all@plt>
mov    -0x34(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64decode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,(%rsp)
mov    %esi,%r12d
mov    %rdi,%r13
lea    (%r12,%r12,2),%eax
lea    (%r12,%r12,2),%edi
add    $0x3,%edi
test   %eax,%eax
cmovns %eax,%edi
sar    $0x2,%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,%r14
xor    %eax,%eax
call   10b0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r13,%rsi
mov    %r12d,%edx
call   10a0 <BIO_write@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <BIO_push@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1070 <BIO_set_flags@plt>
mov    $0xffffffff,%ebp
mov    %r15,%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <BIO_read@plt>
add    $0x1,%ebp
add    $0x1,%rbx
test   %rax,%rax
jg     1220 <base64decode+0x90>
mov    %r14,%rdi
call   1090 <BIO_free_all@plt>
mov    (%rsp),%rax
mov    %ebp,(%rax)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define i8* @base64decode(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%11 = load i32, i32* %5
%12 = mul nsw i32 %11, 3
%13 = sdiv i32 %12, 4
%14 = add nsw i32 %13, 1
%15 = call i8* @calloc(i32 %14, i32 1)
store i8* %15, i8** %9
%16 = call i32 (...) @BIO_f_base64()
%17 = call i32* @BIO_new(i32 %16)
store i32* %17, i32** %7
%18 = call i32 (...) @BIO_s_mem()
%19 = call i32* @BIO_new(i32 %18)
store i32* %19, i32** %8
%20 = load i32*, i32** %8
%21 = load i8*, i8** %4
%22 = load i32, i32* %5
%23 = call i32 @BIO_write(i32* %20, i8* %21, i32 %22)
%24 = load i32*, i32** %7
%25 = load i32*, i32** %8
%26 = call i32 @BIO_push(i32* %24, i32* %25)
%27 = load i32*, i32** %7
%28 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%29 = call i32 @BIO_set_flags(i32* %27, i32 %28)
store i32 0, i32* %10
br label %30
30: ; preds = %38, %3
%31 = load i32*, i32** %7
%32 = load i8*, i8** %9
%33 = load i32, i32* %10
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = call i64 @BIO_read(i32* %31, i8* %35, i32 1)
%37 = icmp slt i64 0, %36
br i1 %37, label %38, label %41
38: ; preds = %30
%39 = load i32, i32* %10
%40 = add nsw i32 %39, 1
store i32 %40, i32* %10
br label %30
41: ; preds = %30
%42 = load i32*, i32** %7
%43 = call i32 @BIO_free_all(i32* %42)
%44 = load i32, i32* %10
%45 = load i32*, i32** %6
store i32 %44, i32* %45
%46 = load i8*, i8** %9
ret i8* %46
}

LLVM IR (-O2):
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define i8* @base64decode(i8* %0, i32 %1, i32* nocapture writeonly %2) {
%4 = mul nsw i32 %1, 3
%5 = sdiv i32 %4, 4
%6 = add nsw i32 %5, 1
%7 = tail call i8* @calloc(i32 %6, i32 1)
%8 = tail call i32 (...) @BIO_f_base64()
%9 = tail call i32* @BIO_new(i32 %8)
%10 = tail call i32 (...) @BIO_s_mem()
%11 = tail call i32* @BIO_new(i32 %10)
%12 = tail call i32 @BIO_write(i32* %11, i8* %0, i32 %1)
%13 = tail call i32 @BIO_push(i32* %9, i32* %11)
%14 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%15 = tail call i32 @BIO_set_flags(i32* %9, i32 %14)
br label %16
16: ; preds = %16, %3
%17 = phi i64 [ %21, %16 ], [ 0, %3 ]
%18 = getelementptr inbounds i8, i8* %7, i64 %17
%19 = tail call i64 @BIO_read(i32* %9, i8* %18, i32 1)
%20 = icmp sgt i64 %19, 0
%21 = add nuw i64 %17, 1
br i1 %20, label %16, label %22
22: ; preds = %16
%23 = trunc i64 %17 to i32
%24 = tail call i32 @BIO_free_all(i32* %9)
store i32 %23, i32* %2
ret i8* %7
}