#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 /*<<< orphan*/ _explicit_bzero(char *, size_t);
int b64_pton(char const *, unsigned char *, size_t);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(size_t);
int decode_base64(const char *src, size_t src_len, char **dst,
                  size_t *dst_len) {
  int sz;
  *dst = NULL;
  if ((*dst = (char *)malloc(src_len + 1)) == NULL)
    return 0;
  if ((sz = b64_pton(src, (unsigned char *)*dst, src_len)) <= 0) {
    _explicit_bzero(*dst, src_len);
    free(*dst);
    *dst = NULL;
    return 0;
  }
  (*dst)[sz] = 0;
  *dst_len = (size_t)sz;
  return 1;
}


x86 assembly (clang, -O0):
<decode_base64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    -0x20(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    118d <decode_base64+0x4d>
movl   $0x0,-0x4(%rbp)
jmp    1201 <decode_base64+0xc1>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <b64_pton@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jg     11e0 <decode_base64+0xa0>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <_explicit_bzero@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1201 <decode_base64+0xc1>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movslq -0x2c(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_base64>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %rdi,%r12
movq   $0x0,(%rdx)
lea    0x1(%rsi),%rdi
call   1060 <malloc@plt>
mov    %rax,(%rbx)
xor    %r15d,%r15d
test   %rax,%rax
je     11ac <decode_base64+0x6c>
mov    %r12,%rdi
mov    %rax,%rsi
mov    %rbp,%rdx
call   1050 <b64_pton@plt>
mov    (%rbx),%rdi
test   %eax,%eax
jle    1195 <decode_base64+0x55>
mov    %eax,%eax
movb   $0x0,(%rdi,%rax,1)
mov    %rax,(%r14)
mov    $0x1,%r15d
jmp    11ac <decode_base64+0x6c>
mov    %rbp,%rsi
call   1040 <_explicit_bzero@plt>
mov    (%rbx),%rdi
call   1030 <free@plt>
movq   $0x0,(%rbx)
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @decode_base64(i8* %0, i64 %1, i8** %2, i64* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8**
%9 = alloca i64*
%10 = alloca i32
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8** %2, i8*** %8
store i64* %3, i64** %9
%11 = load i8**, i8*** %8
store i8* null, i8** %11
%12 = load i64, i64* %7
%13 = add i64 %12, 1
%14 = call i64 @malloc(i64 %13)
%15 = inttoptr i64 %14 to i8*
%16 = load i8**, i8*** %8
store i8* %15, i8** %16
%17 = icmp eq i8* %15, null
br i1 %17, label %18, label %19
18: ; preds = %4
store i32 0, i32* %5
br label %44
19: ; preds = %4
%20 = load i8*, i8** %6
%21 = load i8**, i8*** %8
%22 = load i8*, i8** %21
%23 = load i64, i64* %7
%24 = call i32 @b64_pton(i8* %20, i8* %22, i64 %23)
store i32 %24, i32* %10
%25 = icmp sle i32 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %19
%27 = load i8**, i8*** %8
%28 = load i8*, i8** %27
%29 = load i64, i64* %7
%30 = call i32 @_explicit_bzero(i8* %28, i64 %29)
%31 = load i8**, i8*** %8
%32 = load i8*, i8** %31
%33 = call i32 @free(i8* %32)
%34 = load i8**, i8*** %8
store i8* null, i8** %34
store i32 0, i32* %5
br label %44
35: ; preds = %19
%36 = load i8**, i8*** %8
%37 = load i8*, i8** %36
%38 = load i32, i32* %10
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 0, i8* %40
%41 = load i32, i32* %10
%42 = sext i32 %41 to i64
%43 = load i64*, i64** %9
store i64 %42, i64* %43
store i32 1, i32* %5
br label %44
44: ; preds = %35, %26, %18
%45 = load i32, i32* %5
ret i32 %45
}

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