#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*/ FILE;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int B64_decoded_l(char *, int);
int /*<<< orphan*/ BIO_FLAGS_BASE64_NO_NL;
int /*<<< orphan*/ BIO_NOCLOSE;
int /*<<< orphan*/ BIO_f_base64();
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ *BIO_new_fp(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ *BIO_push(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int BIO_read(int /*<<< orphan*/ *, unsigned char *, int);
int /*<<< orphan*/ BIO_set_flags(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ *fmemopen(unsigned char *, int, char *);
int B64_decode(unsigned char *in, int inl, unsigned char *out) {
  BIO *bio, *b64;
  int outl;
  FILE *stream;
  outl = B64_decoded_l((char *)in, inl);
  stream = fmemopen(in, inl, "r");
  b64 = BIO_new(BIO_f_base64());
  bio = BIO_new_fp(stream, BIO_NOCLOSE);
  bio = BIO_push(b64, bio);
  BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL);
  outl = BIO_read(bio, out, outl);
  return outl;
}


x86 assembly (clang, -O0):
<B64_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <B64_decoded_l@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    0xe50(%rip),%rdx
call   1050 <fmemopen@plt>
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1080 <BIO_f_base64@plt>
mov    %eax,%edi
call   10a0 <BIO_new@plt>
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rdi
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
call   1040 <BIO_new_fp@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <BIO_push@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
call   1090 <BIO_set_flags@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1070 <BIO_read@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<B64_decode>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%ebx
mov    %rdi,%rbp
call   1030 <B64_decoded_l@plt>
mov    %eax,%r15d
lea    0xe62(%rip),%rdx
mov    %rbp,%rdi
mov    %ebx,%esi
call   1050 <fmemopen@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1080 <BIO_f_base64@plt>
mov    %eax,%edi
call   10a0 <BIO_new@plt>
mov    %rax,%rbp
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <BIO_new_fp@plt>
mov    %rbp,%rdi
mov    %rax,%rsi
call   1060 <BIO_push@plt>
mov    %rax,%rbx
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1090 <BIO_set_flags@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <BIO_read@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@BIO_NOCLOSE = global i32 0
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define i32 @B64_decode(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%11 = load i8*, i8** %4
%12 = load i32, i32* %5
%13 = call i32 @B64_decoded_l(i8* %11, i32 %12)
store i32 %13, i32* %9
%14 = load i8*, i8** %4
%15 = load i32, i32* %5
%16 = call i32* @fmemopen(i8* %14, i32 %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %10
%17 = call i32 (...) @BIO_f_base64()
%18 = call i32* @BIO_new(i32 %17)
store i32* %18, i32** %8
%19 = load i32*, i32** %10
%20 = load i32, i32* @BIO_NOCLOSE
%21 = call i32* @BIO_new_fp(i32* %19, i32 %20)
store i32* %21, i32** %7
%22 = load i32*, i32** %8
%23 = load i32*, i32** %7
%24 = call i32* @BIO_push(i32* %22, i32* %23)
store i32* %24, i32** %7
%25 = load i32*, i32** %7
%26 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%27 = call i32 @BIO_set_flags(i32* %25, i32 %26)
%28 = load i32*, i32** %7
%29 = load i8*, i8** %6
%30 = load i32, i32* %9
%31 = call i32 @BIO_read(i32* %28, i8* %29, i32 %30)
store i32 %31, i32* %9
%32 = load i32, i32* %9
ret i32 %32
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@BIO_NOCLOSE = global i32 0
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define i32 @B64_decode(i8* %0, i32 %1, i8* %2) {
%4 = tail call i32 @B64_decoded_l(i8* %0, i32 %1)
%5 = tail call i32* @fmemopen(i8* %0, i32 %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 (...) @BIO_f_base64()
%7 = tail call i32* @BIO_new(i32 %6)
%8 = load i32, i32* @BIO_NOCLOSE
%9 = tail call i32* @BIO_new_fp(i32* %5, i32 %8)
%10 = tail call i32* @BIO_push(i32* %7, i32* %9)
%11 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%12 = tail call i32 @BIO_set_flags(i32* %10, i32 %11)
%13 = tail call i32 @BIO_read(i32* %10, i8* %2, i32 %4)
ret i32 %13
}