#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 *decode64(const void *b64_decode_this, int decode_this_many_bytes) {
  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);
  return base64_decoded;
}


x86 assembly (clang, -O0):
<decode64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%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,-0x28(%rbp)
mov    $0x0,%al
call   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   10b0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   10a0 <BIO_write@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <BIO_push@plt>
mov    -0x18(%rbp),%rdi
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
call   1070 <BIO_set_flags@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
movslq -0x2c(%rbp),%rax
add    %rax,%rsi
mov    $0x1,%edx
call   1040 <BIO_read@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jge    124d <decode64+0xbd>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1218 <decode64+0x88>
mov    -0x18(%rbp),%rdi
call   1090 <BIO_free_all@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode64>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %rdi,%r12
lea    (%r15,%r15,2),%eax
lea    (%r15,%r15,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,%r14
xor    %eax,%eax
call   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,%r13
xor    %eax,%eax
call   10b0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
call   10a0 <BIO_write@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1030 <BIO_push@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdi
call   1070 <BIO_set_flags@plt>
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <BIO_read@plt>
add    $0x1,%rbx
test   %rax,%rax
jg     1220 <decode64+0x90>
mov    %r13,%rdi
call   1090 <BIO_free_all@plt>
mov    %r14,%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* @decode64(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = load i32, i32* %4
%10 = mul nsw i32 %9, 3
%11 = sdiv i32 %10, 4
%12 = add nsw i32 %11, 1
%13 = call i8* @calloc(i32 %12, i32 1)
store i8* %13, i8** %7
%14 = call i32 (...) @BIO_f_base64()
%15 = call i32* @BIO_new(i32 %14)
store i32* %15, i32** %5
%16 = call i32 (...) @BIO_s_mem()
%17 = call i32* @BIO_new(i32 %16)
store i32* %17, i32** %6
%18 = load i32*, i32** %6
%19 = load i8*, i8** %3
%20 = load i32, i32* %4
%21 = call i32 @BIO_write(i32* %18, i8* %19, i32 %20)
%22 = load i32*, i32** %5
%23 = load i32*, i32** %6
%24 = call i32 @BIO_push(i32* %22, i32* %23)
%25 = load i32*, i32** %5
%26 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%27 = call i32 @BIO_set_flags(i32* %25, i32 %26)
store i32 0, i32* %8
br label %28
28: ; preds = %36, %2
%29 = load i32*, i32** %5
%30 = load i8*, i8** %7
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = call i64 @BIO_read(i32* %29, i8* %33, i32 1)
%35 = icmp slt i64 0, %34
br i1 %35, label %36, label %39
36: ; preds = %28
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %28
39: ; preds = %28
%40 = load i32*, i32** %5
%41 = call i32 @BIO_free_all(i32* %40)
%42 = load i8*, i8** %7
ret i8* %42
}

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