#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*/ free(unsigned char *);
scalar_t__ malloc(int);
size_t raw_base64_decode(unsigned char *, unsigned char *, int, int *);
int strlen(unsigned char *);
unsigned char *spc_base64_decode(unsigned char *buf, size_t *len, int strict,
                                 int *err) {
  unsigned char *outbuf;
  outbuf = (unsigned char *)malloc(3 * (strlen(buf) / 4 + 1));
  if (!outbuf) {
    *err = -3;
    *len = 0;
    return 0;
  }
  *len = raw_base64_decode(buf, outbuf, strict, err);
  if (*err) {
    free(outbuf);
    *len = 0;
    outbuf = 0;
  }
  return outbuf;
}


x86 assembly (clang, -O0):
<spc_base64_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    $0x4,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
imul   $0x3,%eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11a4 <spc_base64_decode+0x64>
mov    -0x28(%rbp),%rax
movl   $0xfffffffd,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    11f3 <spc_base64_decode+0xb3>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
call   1050 <raw_base64_decode@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
cmpl   $0x0,(%rax)
je     11eb <spc_base64_decode+0xab>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spc_base64_decode>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r12
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0x2,%ecx
lea    (%rcx,%rcx,2),%edi
add    $0x3,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     119c <spc_base64_decode+0x5c>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %r15d,%edx
mov    %r12,%rcx
call   1050 <raw_base64_decode@plt>
mov    %rax,(%r14)
cmpl   $0x0,(%r12)
je     11ad <spc_base64_decode+0x6d>
mov    %rbp,%rdi
call   1030 <free@plt>
jmp    11a4 <spc_base64_decode+0x64>
movl   $0xfffffffd,(%r12)
ff
movq   $0x0,(%r14)
xor    %ebp,%ebp
mov    %rbp,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @spc_base64_decode(i8* %0, i64* %1, i32 %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i8*
store i8* %0, i8** %6
store i64* %1, i64** %7
store i32 %2, i32* %8
store i32* %3, i32** %9
%11 = load i8*, i8** %6
%12 = call i32 @strlen(i8* %11)
%13 = sdiv i32 %12, 4
%14 = add nsw i32 %13, 1
%15 = mul nsw i32 3, %14
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %10
%18 = load i8*, i8** %10
%19 = icmp ne i8* %18, null
br i1 %19, label %23, label %20
20: ; preds = %4
%21 = load i32*, i32** %9
store i32 -3, i32* %21
%22 = load i64*, i64** %7
store i64 0, i64* %22
store i8* null, i8** %5
br label %39
23: ; preds = %4
%24 = load i8*, i8** %6
%25 = load i8*, i8** %10
%26 = load i32, i32* %8
%27 = load i32*, i32** %9
%28 = call i64 @raw_base64_decode(i8* %24, i8* %25, i32 %26, i32* %27)
%29 = load i64*, i64** %7
store i64 %28, i64* %29
%30 = load i32*, i32** %9
%31 = load i32, i32* %30
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %23
%34 = load i8*, i8** %10
%35 = call i32 @free(i8* %34)
%36 = load i64*, i64** %7
store i64 0, i64* %36
store i8* null, i8** %10
br label %37
37: ; preds = %33, %23
%38 = load i8*, i8** %10
store i8* %38, i8** %5
br label %39
39: ; preds = %37, %20
%40 = load i8*, i8** %5
ret i8* %40
}

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