#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(unsigned char *, int);
int /*<<< orphan*/ *BIO_push(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_read(int /*<<< orphan*/ *, char *, int);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *smtp_unbase64(unsigned char *input, int length) {
  BIO *b64, *bmem;
  char *buffer = malloc(sizeof(char) * length);
  memset(buffer, 0, length);
  b64 = BIO_new(BIO_f_base64());
  bmem = BIO_new_mem_buf(input, length);
  bmem = BIO_push(b64, bmem);
  BIO_read(bmem, buffer, length);
  BIO_free_all(bmem);
  return buffer;
}


x86 assembly (clang, -O0):
<smtp_unbase64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0xc(%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,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1070 <BIO_new_mem_buf@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <BIO_push@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1040 <BIO_read@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <BIO_free_all@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smtp_unbase64>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
mov    %esi,%edi
call   1080 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1060 <memset@plt>
xor    %eax,%eax
call   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1090 <BIO_new@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %ebp,%esi
call   1070 <BIO_new_mem_buf@plt>
mov    %r15,%rdi
mov    %rax,%rsi
call   1030 <BIO_push@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1040 <BIO_read@plt>
mov    %rbx,%rdi
call   10a0 <BIO_free_all@plt>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @smtp_unbase64(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = sext i32 %8 to i64
%10 = mul i64 1, %9
%11 = trunc i64 %10 to i32
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %7
%13 = load i8*, i8** %7
%14 = load i32, i32* %4
%15 = call i32 @memset(i8* %13, i32 0, i32 %14)
%16 = call i32 (...) @BIO_f_base64()
%17 = call i32* @BIO_new(i32 %16)
store i32* %17, i32** %5
%18 = load i8*, i8** %3
%19 = load i32, i32* %4
%20 = call i32* @BIO_new_mem_buf(i8* %18, i32 %19)
store i32* %20, i32** %6
%21 = load i32*, i32** %5
%22 = load i32*, i32** %6
%23 = call i32* @BIO_push(i32* %21, i32* %22)
store i32* %23, i32** %6
%24 = load i32*, i32** %6
%25 = load i8*, i8** %7
%26 = load i32, i32* %4
%27 = call i32 @BIO_read(i32* %24, i8* %25, i32 %26)
%28 = load i32*, i32** %6
%29 = call i32 @BIO_free_all(i32* %28)
%30 = load i8*, i8** %7
ret i8* %30
}

LLVM IR (-O2):
define i8* @smtp_unbase64(i8* %0, i32 %1) {
%3 = tail call i8* @malloc(i32 %1)
%4 = tail call i32 @memset(i8* %3, i32 0, i32 %1)
%5 = tail call i32 (...) @BIO_f_base64()
%6 = tail call i32* @BIO_new(i32 %5)
%7 = tail call i32* @BIO_new_mem_buf(i8* %0, i32 %1)
%8 = tail call i32* @BIO_push(i32* %6, i32* %7)
%9 = tail call i32 @BIO_read(i32* %8, i8* %3, i32 %1)
%10 = tail call i32 @BIO_free_all(i32* %8)
ret i8* %3
}