#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 BIO_read(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
unsigned char *malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
unsigned char *_decode_m64(unsigned char *m64_ptr, int m64_len) {
  unsigned char *orig_ptr = NULL;
  int orig_len = 0;
  BIO *b64bio, *mbio, *bio;
  char *ptr = NULL;
  if (m64_len == 0)
    return NULL;
  ptr = (char *)malloc(sizeof(char) * m64_len);
  memset(ptr, '\0', m64_len);
  b64bio = BIO_new(BIO_f_base64());
  mbio = BIO_new_mem_buf(m64_ptr, m64_len);
  bio = BIO_push(b64bio, mbio);
  orig_len = BIO_read(bio, ptr, m64_len);
  if (orig_len) {
    orig_ptr = malloc(orig_len + 1);
    if (orig_ptr)
      strcpy((char *)orig_ptr, ptr);
    else
      fprintf(stderr, "ERROR: malloc failed..\n");
  }
  BIO_free_all(bio);
  return orig_ptr;
}


x86 assembly (clang, -O0):
<_decode_m64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x48(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11dd <_decode_m64+0x3d>
movq   $0x0,-0x8(%rbp)
jmp    12a5 <_decode_m64+0x105>
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    $0x0,%al
call   1060 <BIO_f_base64@plt>
mov    %eax,%edi
call   10b0 <BIO_new@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1090 <BIO_new_mem_buf@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1040 <BIO_push@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <BIO_read@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1294 <_decode_m64+0xf4>
mov    -0x24(%rbp),%edi
add    $0x1,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     127a <_decode_m64+0xda>
mov    -0x20(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    128f <_decode_m64+0xef>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
lea    0xd76(%rip),%rsi
call   1080 <fprintf@plt>
jmp    1294 <_decode_m64+0xf4>
mov    -0x40(%rbp),%rdi
call   10c0 <BIO_free_all@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_decode_m64>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %esi,%esi
je     1223 <_decode_m64+0x83>
mov    %esi,%ebp
mov    %rdi,%r15
mov    %esi,%edi
call   10a0 <malloc@plt>
mov    %rax,%r14
xor    %r12d,%r12d
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1070 <memset@plt>
xor    %eax,%eax
call   1060 <BIO_f_base64@plt>
mov    %eax,%edi
call   10b0 <BIO_new@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %ebp,%esi
call   1090 <BIO_new_mem_buf@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <BIO_push@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1050 <BIO_read@plt>
test   %eax,%eax
je     1240 <_decode_m64+0xa0>
add    $0x1,%eax
mov    %eax,%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     1228 <_decode_m64+0x88>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
jmp    1240 <_decode_m64+0xa0>
xor    %r12d,%r12d
jmp    1248 <_decode_m64+0xa8>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
lea    0xdc8(%rip),%rsi
call   1080 <fprintf@plt>
xor    %r12d,%r12d
mov    %r15,%rdi
call   10c0 <BIO_free_all@plt>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"ERROR: malloc failed..\0A\00"
define i8* @_decode_m64(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* null, i8** %6
store i32 0, i32* %7
store i8* null, i8** %11
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i8* null, i8** %3
br label %56
15: ; preds = %2
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = mul i64 1, %17
%19 = trunc i64 %18 to i32
%20 = call i8* @malloc(i32 %19)
store i8* %20, i8** %11
%21 = load i8*, i8** %11
%22 = load i32, i32* %5
%23 = call i32 @memset(i8* %21, i8 signext 0, i32 %22)
%24 = call i32 (...) @BIO_f_base64()
%25 = call i32* @BIO_new(i32 %24)
store i32* %25, i32** %8
%26 = load i8*, i8** %4
%27 = load i32, i32* %5
%28 = call i32* @BIO_new_mem_buf(i8* %26, i32 %27)
store i32* %28, i32** %9
%29 = load i32*, i32** %8
%30 = load i32*, i32** %9
%31 = call i32* @BIO_push(i32* %29, i32* %30)
store i32* %31, i32** %10
%32 = load i32*, i32** %10
%33 = load i8*, i8** %11
%34 = load i32, i32* %5
%35 = call i32 @BIO_read(i32* %32, i8* %33, i32 %34)
store i32 %35, i32* %7
%36 = load i32, i32* %7
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %52
38: ; preds = %15
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
%41 = call i8* @malloc(i32 %40)
store i8* %41, i8** %6
%42 = load i8*, i8** %6
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %48
44: ; preds = %38
%45 = load i8*, i8** %6
%46 = load i8*, i8** %11
%47 = call i32 @strcpy(i8* %45, i8* %46)
br label %51
48: ; preds = %38
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %51
51: ; preds = %48, %44
br label %52
52: ; preds = %51, %15
%53 = load i32*, i32** %10
%54 = call i32 @BIO_free_all(i32* %53)
%55 = load i8*, i8** %6
store i8* %55, i8** %3
br label %56
56: ; preds = %52, %14
%57 = load i8*, i8** %3
ret i8* %57
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"ERROR: malloc failed..\0A\00"
define i8* @_decode_m64(i8* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %25, label %4
4: ; preds = %2
%5 = tail call i8* @malloc(i32 %1)
%6 = tail call i32 @memset(i8* %5, i8 signext 0, i32 %1)
%7 = tail call i32 (...) @BIO_f_base64()
%8 = tail call i32* @BIO_new(i32 %7)
%9 = tail call i32* @BIO_new_mem_buf(i8* %0, i32 %1)
%10 = tail call i32* @BIO_push(i32* %8, i32* %9)
%11 = tail call i32 @BIO_read(i32* %10, i8* %5, i32 %1)
%12 = icmp eq i32 %11, 0
br i1 %12, label %22, label %13
13: ; preds = %4
%14 = add nsw i32 %11, 1
%15 = tail call i8* @malloc(i32 %14)
%16 = icmp eq i8* %15, null
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = tail call i32 @strcpy(i8* %15, i8* %5)
br label %22
19: ; preds = %13
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %17, %19, %4
%23 = phi i8* [ %15, %17 ], [ null, %19 ], [ null, %4 ]
%24 = tail call i32 @BIO_free_all(i32* %10)
br label %25
25: ; preds = %2, %22
%26 = phi i8* [ %23, %22 ], [ null, %2 ]
ret i8* %26
}