#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_binary(unsigned char *, unsigned char *);
size_t base64_decoded_size(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ strlen(unsigned char *);
char *base64_decode(unsigned char *in) {
  char *out;
  size_t outlen;
  int numbytes;
  outlen = base64_decoded_size(strlen(in));
  if ((out = (char *)malloc(sizeof(char) * (outlen + 1))) == NULL)
    return (NULL);
  if ((numbytes = base64_decode_binary((unsigned char *)out, in)) < 0) {
    free(out);
    return (NULL);
  }
  *(out + numbytes) = '\0';
  return (out);
}


x86 assembly (clang, -O0):
<base64_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
call   1030 <base64_decoded_size@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    119e <base64_decode+0x4e>
movq   $0x0,-0x8(%rbp)
jmp    11e1 <base64_decode+0x91>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <base64_decode_binary@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    11cd <base64_decode+0x7d>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11e1 <base64_decode+0x91>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64_decode>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <strlen@plt>
mov    %eax,%edi
call   1030 <base64_decoded_size@plt>
lea    0x1(%rax),%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1192 <base64_decode+0x42>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1070 <base64_decode_binary@plt>
test   %eax,%eax
js     118a <base64_decode+0x3a>
mov    %eax,%eax
movb   $0x0,(%rbx,%rax,1)
jmp    1194 <base64_decode+0x44>
mov    %rbx,%rdi
call   1040 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @base64_decode(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
%9 = call i64 @base64_decoded_size(i32 %8)
store i64 %9, i64* %5
%10 = load i64, i64* %5
%11 = add i64 %10, 1
%12 = mul i64 1, %11
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %4
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %1
store i8* null, i8** %2
br label %32
18: ; preds = %1
%19 = load i8*, i8** %4
%20 = load i8*, i8** %3
%21 = call i32 @base64_decode_binary(i8* %19, i8* %20)
store i32 %21, i32* %6
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i8*, i8** %4
%25 = call i32 @free(i8* %24)
store i8* null, i8** %2
br label %32
26: ; preds = %18
%27 = load i8*, i8** %4
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 0, i8* %30
%31 = load i8*, i8** %4
store i8* %31, i8** %2
br label %32
32: ; preds = %26, %23, %17
%33 = load i8*, i8** %2
ret i8* %33
}

LLVM IR (-O2):
define i8* @base64_decode(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i64 @base64_decoded_size(i32 %2)
%4 = trunc i64 %3 to i32
%5 = add i32 %4, 1
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = icmp eq i64 %6, 0
br i1 %8, label %17, label %9
9: ; preds = %1
%10 = tail call i32 @base64_decode_binary(i8* %7, i8* %0)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @free(i8* %7)
br label %17
14: ; preds = %9
%15 = zext i32 %10 to i64
%16 = getelementptr inbounds i8, i8* %7, i64 %15
store i8 0, i8* %16
br label %17
17: ; preds = %1, %14, %12
%18 = phi i8* [ null, %12 ], [ %7, %14 ], [ null, %1 ]
ret i8* %18
}