#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 */

/* Variables and functions */
int base64_decode(unsigned char *, int, char *);
int base64_decsize(char *);
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ malloc(int);
unsigned char *base64_dec_malloc(char *src) {
  int size;
  unsigned char *buffer;
  size = base64_decsize(src) + 1;
  buffer = (unsigned char *)malloc(size);
  if (buffer == NULL) {
    return NULL;
  }
  size = base64_decode(buffer, size, src);
  if (size == -1) {
    free(buffer);
    return NULL;
  }
  return buffer;
}


x86 assembly (clang, -O0):
<base64_dec_malloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <base64_decsize@plt>
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117f <base64_dec_malloc+0x3f>
movq   $0x0,-0x8(%rbp)
jmp    11ba <base64_dec_malloc+0x7a>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1060 <base64_decode@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11b2 <base64_dec_malloc+0x72>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ba <base64_dec_malloc+0x7a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64_dec_malloc>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <base64_decsize@plt>
mov    %eax,%ebp
add    $0x1,%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     117a <base64_dec_malloc+0x3a>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
call   1060 <base64_decode@plt>
cmp    $0xffffffff,%eax
jne    117c <base64_dec_malloc+0x3c>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @base64_dec_malloc(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @base64_decsize(i8* %6)
%8 = add nsw i32 %7, 1
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %5
%12 = load i8*, i8** %5
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %1
store i8* null, i8** %2
br label %27
15: ; preds = %1
%16 = load i8*, i8** %5
%17 = load i32, i32* %4
%18 = load i8*, i8** %3
%19 = call i32 @base64_decode(i8* %16, i32 %17, i8* %18)
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = load i8*, i8** %5
%24 = call i32 @free(i8* %23)
store i8* null, i8** %2
br label %27
25: ; preds = %15
%26 = load i8*, i8** %5
store i8* %26, i8** %2
br label %27
27: ; preds = %25, %22, %14
%28 = load i8*, i8** %2
ret i8* %28
}

LLVM IR (-O2):
define i8* @base64_dec_malloc(i8* %0) {
%2 = tail call i32 @base64_decsize(i8* %0)
%3 = add nsw i32 %2, 1
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to i8*
%6 = icmp eq i64 %4, 0
br i1 %6, label %12, label %7
7: ; preds = %1
%8 = tail call i32 @base64_decode(i8* %5, i32 %3, i8* %0)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @free(i8* %5)
br label %12
12: ; preds = %7, %1, %10
%13 = phi i8* [ null, %10 ], [ null, %1 ], [ %5, %7 ]
ret i8* %13
}