#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 /*<<< orphan*/ BIO_FLAGS_BASE64_NO_NL;
int /*<<< orphan*/ BIO_NOCLOSE;
int /*<<< orphan*/ BIO_f_base64();
int /*<<< orphan*/ BIO_free_all(int /*<<< orphan*/ *);
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*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ BIO_set_flags(int /*<<< orphan*/ *, int /*<<< orphan*/);
size_t decDataLength(char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fmemopen(void *, int /*<<< orphan*/, char *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ strlen(char const *);
char *wksxmpp_b64decode(const char *encdata, char **decdata, size_t *dlen) {
  BIO *bio, *b64;
  FILE *stream;
  int len;
  *dlen = decDataLength(encdata);
  *decdata = (char *)malloc((*dlen) + 1);
  stream = fmemopen((void *)encdata, strlen(encdata), "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);
  len = BIO_read(bio, *decdata, strlen(encdata));
  (*decdata)[len] = '\0';
  BIO_free_all(bio);
  fclose(stream);
  return *decdata;
}


x86 assembly (clang, -O0):
<wksxmpp_b64decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   10d0 <decDataLength@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
add    $0x1,%rdi
call   10b0 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%esi
lea    0xde1(%rip),%rdx
call   1040 <fmemopen@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1090 <BIO_f_base64@plt>
mov    %eax,%edi
call   10c0 <BIO_new@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
mov    0x2da3(%rip),%rax
mov    (%rax),%esi
call   1030 <BIO_new_fp@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <BIO_push@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2d6c(%rip),%rax
mov    (%rax),%esi
call   10a0 <BIO_set_flags@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
call   1070 <BIO_read@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x34(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
call   10e0 <BIO_free_all@plt>
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wksxmpp_b64decode>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r12
call   10d0 <decDataLength@plt>
mov    %rax,(%rbx)
lea    0x1(%rax),%rdi
call   10b0 <malloc@plt>
mov    %rax,(%r14)
mov    %r12,%rdi
call   1080 <strlen@plt>
lea    0xe0b(%rip),%rdx
mov    %r12,%rdi
mov    %eax,%esi
call   1040 <fmemopen@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1090 <BIO_f_base64@plt>
mov    %eax,%edi
call   10c0 <BIO_new@plt>
mov    %rax,%rbx
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   1030 <BIO_new_fp@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <BIO_push@plt>
mov    %rax,%rbx
mov    0x2d9f(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10a0 <BIO_set_flags@plt>
mov    (%r14),%r13
mov    %r12,%rdi
call   1080 <strlen@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %eax,%edx
call   1070 <BIO_read@plt>
mov    (%r14),%rcx
cltq
movb   $0x0,(%rcx,%rax,1)
mov    %rbx,%rdi
call   10e0 <BIO_free_all@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
mov    (%r14),%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@BIO_NOCLOSE = global i32 0
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define i8* @wksxmpp_b64decode(i8* %0, i8** %1, i64* %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i64*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i64* %2, i64** %6
%11 = load i8*, i8** %4
%12 = call i64 @decDataLength(i8* %11)
%13 = load i64*, i64** %6
store i64 %12, i64* %13
%14 = load i64*, i64** %6
%15 = load i64, i64* %14
%16 = add i64 %15, 1
%17 = call i64 @malloc(i64 %16)
%18 = inttoptr i64 %17 to i8*
%19 = load i8**, i8*** %5
store i8* %18, i8** %19
%20 = load i8*, i8** %4
%21 = load i8*, i8** %4
%22 = call i32 @strlen(i8* %21)
%23 = call i32* @fmemopen(i8* %20, i32 %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %23, i32** %9
%24 = call i32 (...) @BIO_f_base64()
%25 = call i32* @BIO_new(i32 %24)
store i32* %25, i32** %8
%26 = load i32*, i32** %9
%27 = load i32, i32* @BIO_NOCLOSE
%28 = call i32* @BIO_new_fp(i32* %26, i32 %27)
store i32* %28, i32** %7
%29 = load i32*, i32** %8
%30 = load i32*, i32** %7
%31 = call i32* @BIO_push(i32* %29, i32* %30)
store i32* %31, i32** %7
%32 = load i32*, i32** %7
%33 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%34 = call i32 @BIO_set_flags(i32* %32, i32 %33)
%35 = load i32*, i32** %7
%36 = load i8**, i8*** %5
%37 = load i8*, i8** %36
%38 = load i8*, i8** %4
%39 = call i32 @strlen(i8* %38)
%40 = call i32 @BIO_read(i32* %35, i8* %37, i32 %39)
store i32 %40, i32* %10
%41 = load i8**, i8*** %5
%42 = load i8*, i8** %41
%43 = load i32, i32* %10
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
store i8 0, i8* %45
%46 = load i32*, i32** %7
%47 = call i32 @BIO_free_all(i32* %46)
%48 = load i32*, i32** %9
%49 = call i32 @fclose(i32* %48)
%50 = load i8**, i8*** %5
%51 = load i8*, i8** %50
ret i8* %51
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@BIO_NOCLOSE = global i32 0
@BIO_FLAGS_BASE64_NO_NL = global i32 0
define i8* @wksxmpp_b64decode(i8* %0, i8** nocapture %1, i64* nocapture writeonly %2) {
%4 = tail call i64 @decDataLength(i8* %0)
store i64 %4, i64* %2
%5 = add i64 %4, 1
%6 = tail call i64 @malloc(i64 %5)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %1
%8 = tail call i32 @strlen(i8* %0)
%9 = tail call i32* @fmemopen(i8* %0, i32 %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 (...) @BIO_f_base64()
%11 = tail call i32* @BIO_new(i32 %10)
%12 = load i32, i32* @BIO_NOCLOSE
%13 = tail call i32* @BIO_new_fp(i32* %9, i32 %12)
%14 = tail call i32* @BIO_push(i32* %11, i32* %13)
%15 = load i32, i32* @BIO_FLAGS_BASE64_NO_NL
%16 = tail call i32 @BIO_set_flags(i32* %14, i32 %15)
%17 = load i8*, i8** %1
%18 = tail call i32 @strlen(i8* %0)
%19 = tail call i32 @BIO_read(i32* %14, i8* %17, i32 %18)
%20 = load i8*, i8** %1
%21 = sext i32 %19 to i64
%22 = getelementptr inbounds i8, i8* %20, i64 %21
store i8 0, i8* %22
%23 = tail call i32 @BIO_free_all(i32* %14)
%24 = tail call i32 @fclose(i32* %9)
%25 = load i8*, i8** %1
ret i8* %25
}