#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_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*/ *);
int BIO_read(int /*<<< orphan*/ *, unsigned char *, int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int Base64Decode(const char *input, int inLen, unsigned char *output,
                 int outLen) {
  if (!input || !output) {
    return -1;
  }
  char tmp[256];
  tmp[255] = '\n';
  memcpy(&tmp[0], input, inLen);
  memset(output, 0, outLen);
  BIO *b642 = BIO_new(BIO_f_base64());
  BIO *bmem2 = BIO_new_mem_buf(&tmp[0], inLen + 1);
  bmem2 = BIO_push(b642, bmem2);
  outLen = BIO_read(bmem2, output, outLen);
  BIO_free_all(bmem2);
  return 0;
}


x86 assembly (clang, -O0):
<Base64Decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11af <Base64Decode+0x2f>
cmpq   $0x0,-0x20(%rbp)
jne    11bb <Base64Decode+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1251 <Base64Decode+0xd1>
movb   $0xa,-0x31(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1070 <memcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    $0x0,%al
call   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1090 <BIO_new@plt>
mov    %rax,-0x138(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
call   1080 <BIO_new_mem_buf@plt>
mov    %rax,-0x140(%rbp)
mov    -0x138(%rbp),%rdi
mov    -0x140(%rbp),%rsi
call   1030 <BIO_push@plt>
mov    %rax,-0x140(%rbp)
mov    -0x140(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <BIO_read@plt>
mov    %eax,-0x24(%rbp)
mov    -0x140(%rbp),%rdi
call   10a0 <BIO_free_all@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Base64Decode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    $0xffffffff,%r15d
test   %rdi,%rdi
je     1213 <Base64Decode+0x93>
mov    %rdx,%rbx
test   %rdx,%rdx
je     1213 <Base64Decode+0x93>
mov    %ecx,%r14d
mov    %esi,%ebp
mov    %rdi,%rsi
movb   $0xa,0xff(%rsp)
0a
mov    %rsp,%r12
mov    %r12,%rdi
mov    %ebp,%edx
call   1070 <memcpy@plt>
xor    %r15d,%r15d
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14d,%edx
call   1060 <memset@plt>
xor    %eax,%eax
call   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1090 <BIO_new@plt>
mov    %rax,%r13
add    $0x1,%ebp
mov    %r12,%rdi
mov    %ebp,%esi
call   1080 <BIO_new_mem_buf@plt>
mov    %r13,%rdi
mov    %rax,%rsi
call   1030 <BIO_push@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1040 <BIO_read@plt>
mov    %rbp,%rdi
call   10a0 <BIO_free_all@plt>
mov    %r15d,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @Base64Decode(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca [256 x i8]
%11 = alloca i32*
%12 = alloca i32*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%13 = load i8*, i8** %6
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %4
%16 = load i8*, i8** %8
%17 = icmp ne i8* %16, null
br i1 %17, label %19, label %18
18: ; preds = %15, %4
store i32 -1, i32* %5
br label %43
19: ; preds = %15
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 255
store i8 10, i8* %20
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%22 = load i8*, i8** %6
%23 = load i32, i32* %7
%24 = call i32 @memcpy(i8* %21, i8* %22, i32 %23)
%25 = load i8*, i8** %8
%26 = load i32, i32* %9
%27 = call i32 @memset(i8* %25, i32 0, i32 %26)
%28 = call i32 (...) @BIO_f_base64()
%29 = call i32* @BIO_new(i32 %28)
store i32* %29, i32** %11
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
%33 = call i32* @BIO_new_mem_buf(i8* %30, i32 %32)
store i32* %33, i32** %12
%34 = load i32*, i32** %11
%35 = load i32*, i32** %12
%36 = call i32* @BIO_push(i32* %34, i32* %35)
store i32* %36, i32** %12
%37 = load i32*, i32** %12
%38 = load i8*, i8** %8
%39 = load i32, i32* %9
%40 = call i32 @BIO_read(i32* %37, i8* %38, i32 %39)
store i32 %40, i32* %9
%41 = load i32*, i32** %12
%42 = call i32 @BIO_free_all(i32* %41)
store i32 0, i32* %5
br label %43
43: ; preds = %19, %18
%44 = load i32, i32* %5
ret i32 %44
}

LLVM IR (-O2):
define i32 @Base64Decode(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca [256 x i8]
%6 = icmp ne i8* %0, null
%7 = icmp ne i8* %2, null
%8 = and i1 %6, %7
br i1 %8, label %9, label %21
9: ; preds = %4
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 255
store i8 10, i8* %11
%12 = call i32 @memcpy(i8* %10, i8* %0, i32 %1)
%13 = call i32 @memset(i8* %2, i32 0, i32 %3)
%14 = call i32 (...) @BIO_f_base64()
%15 = call i32* @BIO_new(i32 %14)
%16 = add nsw i32 %1, 1
%17 = call i32* @BIO_new_mem_buf(i8* %10, i32 %16)
%18 = call i32* @BIO_push(i32* %15, i32* %17)
%19 = call i32 @BIO_read(i32* %18, i8* %2, i32 %3)
%20 = call i32 @BIO_free_all(i32* %18)
br label %21
21: ; preds = %4, %9
%22 = phi i32 [ 0, %9 ], [ -1, %4 ]
ret i32 %22
}