#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*/);
size_t BIO_read(int /*<<< orphan*/ *, unsigned char *, int /*<<< orphan*/);
int /*<<< orphan*/ BIO_set_flags(int /*<<< orphan*/ *, int /*<<< orphan*/);
int CalcDecodeLength(char *);
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ strlen(char *);
bool Base64Decode(char *b64message, unsigned char **buffer, size_t *length) {
  int decodeLen = CalcDecodeLength(b64message);
  *buffer = (unsigned char *)malloc(decodeLen + 1);
  (*buffer)[decodeLen] = '\0';
  BIO *bio = BIO_push(BIO_new(BIO_f_base64()), BIO_new_mem_buf(b64message, -1));
  BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL);
  *length = BIO_read(bio, *buffer, strlen(b64message));
  if (*length != decodeLen) {
    free(*buffer);
    return false;
  }
  BIO_free_all(bio);
  return true;
}


x86 assembly (clang, -O0):
<Base64Decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <CalcDecodeLength@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
add    $0x1,%edi
call   10b0 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    $0x0,%al
call   1070 <BIO_f_base64@plt>
mov    %eax,%edi
call   10c0 <BIO_new@plt>
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0xffffffff,%esi
call   10a0 <BIO_new_mem_buf@plt>
mov    -0x44(%rbp),%edi
mov    %eax,%esi
call   1040 <BIO_push@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    0x2db4(%rip),%rax
mov    (%rax),%esi
call   1080 <BIO_set_flags@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1050 <BIO_read@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
cmp    %rcx,%rax
je     1294 <Base64Decode+0xe4>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a4 <Base64Decode+0xf4>
mov    -0x30(%rbp),%rdi
call   10d0 <BIO_free_all@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%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    %rsi,%r12
mov    %rdi,%r13
call   1090 <CalcDecodeLength@plt>
mov    %eax,%ebx
lea    0x1(%rbx),%edi
call   10b0 <malloc@plt>
mov    %rax,(%r12)
movslq %ebx,%r14
movb   $0x0,(%rax,%r14,1)
xor    %r15d,%r15d
xor    %eax,%eax
call   1070 <BIO_f_base64@plt>
mov    %eax,%edi
call   10c0 <BIO_new@plt>
mov    %eax,%ebx
mov    %r13,%rdi
mov    $0xffffffff,%esi
call   10a0 <BIO_new_mem_buf@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1040 <BIO_push@plt>
mov    %rax,%rbx
mov    0x2dcd(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <BIO_set_flags@plt>
mov    (%r12),%rbp
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1050 <BIO_read@plt>
mov    (%rsp),%rcx
mov    %rax,(%rcx)
cmp    %r14,%rax
jne    1252 <Base64Decode+0xa2>
mov    %rbx,%rdi
call   10d0 <BIO_free_all@plt>
mov    $0x1,%r15d
jmp    125b <Base64Decode+0xab>
mov    (%r12),%rdi
call   1030 <free@plt>
mov    %r15d,%eax
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 i32 @Base64Decode(i8* %0, i8** %1, i64* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i64*
%8 = alloca i32
%9 = alloca i32*
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i64* %2, i64** %7
%10 = load i8*, i8** %5
%11 = call i32 @CalcDecodeLength(i8* %10)
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = add nsw i32 %12, 1
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
%16 = load i8**, i8*** %6
store i8* %15, i8** %16
%17 = load i8**, i8*** %6
%18 = load i8*, i8** %17
%19 = load i32, i32* %8
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
store i8 0, i8* %21
%22 = call i32 (...) @BIO_f_base64()
%23 = call i32 @BIO_new(i32 %22)
%24 = load i8*, i8** %5
%25 = call i32 @BIO_new_mem_buf(i8* %24, i32 -1)
%26 = call i32* @BIO_push(i32 %23, i32 %25)
store i32* %26, i32** %9
%27 = load i32*, i32** %9
%28 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%29 = call i32 @BIO_set_flags(i32* %27, i32 %28)
%30 = load i32*, i32** %9
%31 = load i8**, i8*** %6
%32 = load i8*, i8** %31
%33 = load i8*, i8** %5
%34 = call i32 @strlen(i8* %33)
%35 = call i64 @BIO_read(i32* %30, i8* %32, i32 %34)
%36 = load i64*, i64** %7
store i64 %35, i64* %36
%37 = load i64*, i64** %7
%38 = load i64, i64* %37
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = icmp ne i64 %38, %40
br i1 %41, label %42, label %46
42: ; preds = %3
%43 = load i8**, i8*** %6
%44 = load i8*, i8** %43
%45 = call i32 @free(i8* %44)
store i32 0, i32* %4
br label %49
46: ; preds = %3
%47 = load i32*, i32** %9
%48 = call i32 @BIO_free_all(i32* %47)
store i32 1, i32* %4
br label %49
49: ; preds = %46, %42
%50 = load i32, i32* %4
ret i32 %50
}

LLVM IR (-O2):
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define i32 @Base64Decode(i8* %0, i8** nocapture %1, i64* nocapture writeonly %2) {
%4 = tail call i32 @CalcDecodeLength(i8* %0)
%5 = add nsw i32 %4, 1
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %1
%8 = sext i32 %4 to i64
%9 = getelementptr inbounds i8, i8* %7, i64 %8
store i8 0, i8* %9
%10 = tail call i32 (...) @BIO_f_base64()
%11 = tail call i32 @BIO_new(i32 %10)
%12 = tail call i32 @BIO_new_mem_buf(i8* %0, i32 -1)
%13 = tail call i32* @BIO_push(i32 %11, i32 %12)
%14 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%15 = tail call i32 @BIO_set_flags(i32* %13, i32 %14)
%16 = load i8*, i8** %1
%17 = tail call i32 @strlen(i8* %0)
%18 = tail call i64 @BIO_read(i32* %13, i8* %16, i32 %17)
store i64 %18, i64* %2
%19 = icmp eq i64 %18, %8
br i1 %19, label %23, label %20
20: ; preds = %3
%21 = load i8*, i8** %1
%22 = tail call i32 @free(i8* %21)
br label %25
23: ; preds = %3
%24 = tail call i32 @BIO_free_all(i32* %13)
br label %25
25: ; preds = %23, %20
%26 = phi i32 [ 0, %20 ], [ 1, %23 ]
ret i32 %26
}