#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(void *, size_t);
int /*<<< orphan*/ *BIO_push(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int BIO_read(int /*<<< orphan*/ *, unsigned char *, size_t);
int /*<<< orphan*/ BIO_set_flags(int /*<<< orphan*/ *, int /*<<< orphan*/);
int base64_decode(unsigned char *out, size_t out_len, const char *in,
                  size_t in_len) {
  BIO *b64 = BIO_new(BIO_f_base64());
  BIO *bmem = BIO_new_mem_buf((void *)in, in_len);
  bmem = BIO_push(b64, bmem);
  BIO_set_flags(bmem, BIO_FLAGS_BASE64_NO_NL);
  int ret = BIO_read(bmem, out, out_len);
  BIO_free_all(bmem);
  return ret;
}


x86 assembly (clang, -O0):
<base64_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    $0x0,%al
call   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <BIO_new_mem_buf@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <BIO_push@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
call   1060 <BIO_set_flags@plt>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <BIO_read@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
call   1090 <BIO_free_all@plt>
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64_decode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,%rbx
mov    %r13,%rdi
mov    %r12,%rsi
call   1070 <BIO_new_mem_buf@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <BIO_push@plt>
mov    %rax,%rbx
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <BIO_set_flags@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <BIO_read@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1090 <BIO_free_all@plt>
mov    %ebp,%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 @base64_decode(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%12 = call i32 (...) @BIO_f_base64()
%13 = call i32* @BIO_new(i32 %12)
store i32* %13, i32** %9
%14 = load i8*, i8** %7
%15 = load i64, i64* %8
%16 = call i32* @BIO_new_mem_buf(i8* %14, i64 %15)
store i32* %16, i32** %10
%17 = load i32*, i32** %9
%18 = load i32*, i32** %10
%19 = call i32* @BIO_push(i32* %17, i32* %18)
store i32* %19, i32** %10
%20 = load i32*, i32** %10
%21 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%22 = call i32 @BIO_set_flags(i32* %20, i32 %21)
%23 = load i32*, i32** %10
%24 = load i8*, i8** %5
%25 = load i64, i64* %6
%26 = call i32 @BIO_read(i32* %23, i8* %24, i64 %25)
store i32 %26, i32* %11
%27 = load i32*, i32** %10
%28 = call i32 @BIO_free_all(i32* %27)
%29 = load i32, i32* %11
ret i32 %29
}

LLVM IR (-O2):
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define i32 @base64_decode(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = tail call i32 (...) @BIO_f_base64()
%6 = tail call i32* @BIO_new(i32 %5)
%7 = tail call i32* @BIO_new_mem_buf(i8* %2, i64 %3)
%8 = tail call i32* @BIO_push(i32* %6, i32* %7)
%9 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%10 = tail call i32 @BIO_set_flags(i32* %8, i32 %9)
%11 = tail call i32 @BIO_read(i32* %8, i8* %0, i64 %1)
%12 = tail call i32 @BIO_free_all(i32* %8)
ret i32 %11
}