#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 */
scalar_t__ base64decode_block(unsigned char *, char const *, size_t);
scalar_t__ malloc(size_t);
size_t strcspn(char const *, char *);
size_t strlen(char const *);
int /*<<< orphan*/ strspn(char const *, char *);
unsigned char *base64decode(const char *buf, size_t *size) {
  if (!buf)
    return NULL;
  size_t len = strlen(buf);
  if (len <= 0)
    return NULL;
  unsigned char *outbuf = (unsigned char *)malloc((len / 4) * 3 + 3);
  const char *ptr = buf;
  int p = 0;
  do {
    ptr += strspn(ptr, "\r\n\t ");
    if (*ptr == '\0') {
      break;
    }
    len = strcspn(ptr, "\r\n\t ");
    if (len > 0) {
      p += base64decode_block(outbuf + p, ptr, len);
      ptr += len;
    } else {
      break;
    }
  } while (1);
  outbuf[p] = 0;
  *size = p;
  return outbuf;
}


x86 assembly (clang, -O0):
<base64decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1178 <base64decode+0x28>
movq   $0x0,-0x8(%rbp)
jmp    1287 <base64decode+0x137>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
ja     119d <base64decode+0x4d>
movq   $0x0,-0x8(%rbp)
jmp    1287 <base64decode+0x137>
mov    -0x20(%rbp),%rax
shr    $0x2,%rax
imul   $0x3,%rax,%rdi
add    $0x3,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe30(%rip),%rsi
call   1050 <strspn@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11fa <base64decode+0xaa>
jmp    1268 <base64decode+0x118>
mov    -0x30(%rbp),%rdi
lea    0xdfb(%rip),%rsi
call   1060 <strcspn@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jbe    124f <base64decode+0xff>
mov    -0x28(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <base64decode_block@plt>
mov    %rax,%rcx
movslq -0x34(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1254 <base64decode+0x104>
jmp    1268 <base64decode+0x118>
jmp    1259 <base64decode+0x109>
mov    $0x1,%al
test   $0x1,%al
jne    11c5 <base64decode+0x75>
jmp    1268 <base64decode+0x118>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movslq -0x34(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64decode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11f3 <base64decode+0xa3>
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
test   %rax,%rax
je     11f3 <base64decode+0xa3>
shr    $0x2,%rax
lea    (%rax,%rax,2),%rdi
add    $0x3,%rdi
call   1070 <malloc@plt>
mov    %rax,%r15
lea    0xe6d(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strspn@plt>
cltq
cmpb   $0x0,(%rbx,%rax,1)
je     11f8 <base64decode+0xa8>
add    %rax,%rbx
xor    %ebp,%ebp
lea    0xe51(%rip),%r12
nop
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <strcspn@plt>
test   %rax,%rax
je     11fa <base64decode+0xaa>
mov    %rax,%r13
lea    (%r15,%rbp,1),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <base64decode_block@plt>
add    %eax,%ebp
add    %r13,%rbx
movslq %ebp,%rbp
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <strspn@plt>
cltq
cmpb   $0x0,(%rax,%rbx,1)
lea    (%rbx,%rax,1),%rbx
jne    11b0 <base64decode+0x60>
jmp    11fa <base64decode+0xaa>
xor    %r15d,%r15d
jmp    1202 <base64decode+0xb2>
xor    %ebp,%ebp
movb   $0x0,(%r15,%rbp,1)
mov    %rbp,(%r14)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"\0D\0A\09 \00"
define i8* @base64decode(i8* %0, i64* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %4
store i64* %1, i64** %5
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %2
store i8* null, i8** %3
br label %70
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i64 @strlen(i8* %14)
store i64 %15, i64* %6
%16 = load i64, i64* %6
%17 = icmp ule i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %13
store i8* null, i8** %3
br label %70
19: ; preds = %13
%20 = load i64, i64* %6
%21 = udiv i64 %20, 4
%22 = mul i64 %21, 3
%23 = add i64 %22, 3
%24 = call i64 @malloc(i64 %23)
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %7
%26 = load i8*, i8** %4
store i8* %26, i8** %8
store i32 0, i32* %9
br label %27
27: ; preds = %60, %19
%28 = load i8*, i8** %8
%29 = call i32 @strspn(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%30 = load i8*, i8** %8
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds i8, i8* %30, i64 %31
store i8* %32, i8** %8
%33 = load i8*, i8** %8
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %27
br label %61
38: ; preds = %27
%39 = load i8*, i8** %8
%40 = call i64 @strcspn(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i64 %40, i64* %6
%41 = load i64, i64* %6
%42 = icmp ugt i64 %41, 0
br i1 %42, label %43, label %58
43: ; preds = %38
%44 = load i8*, i8** %7
%45 = load i32, i32* %9
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8*, i8** %8
%49 = load i64, i64* %6
%50 = call i64 @base64decode_block(i8* %47, i8* %48, i64 %49)
%51 = load i32, i32* %9
%52 = sext i32 %51 to i64
%53 = add nsw i64 %52, %50
%54 = trunc i64 %53 to i32
store i32 %54, i32* %9
%55 = load i64, i64* %6
%56 = load i8*, i8** %8
%57 = getelementptr inbounds i8, i8* %56, i64 %55
store i8* %57, i8** %8
br label %59
58: ; preds = %38
br label %61
59: ; preds = %43
br label %60
60: ; preds = %59
br i1 true, label %27, label %61
61: ; preds = %60, %58, %37
%62 = load i8*, i8** %7
%63 = load i32, i32* %9
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %62, i64 %64
store i8 0, i8* %65
%66 = load i32, i32* %9
%67 = sext i32 %66 to i64
%68 = load i64*, i64** %5
store i64 %67, i64* %68
%69 = load i8*, i8** %7
store i8* %69, i8** %3
br label %70
70: ; preds = %61, %18, %12
%71 = load i8*, i8** %3
ret i8* %71
}

LLVM IR (-O2):
@.str = [5 x i8] c"\0D\0A\09 \00"
define i8* @base64decode(i8* %0, i64* nocapture writeonly %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %38, label %4
4: ; preds = %2
%5 = tail call i64 @strlen(i8* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %38, label %7
7: ; preds = %4
%8 = lshr i64 %5, 2
%9 = mul nuw i64 %8, 3
%10 = add nuw i64 %9, 3
%11 = tail call i64 @malloc(i64 %10)
%12 = inttoptr i64 %11 to i8*
%13 = tail call i32 @strspn(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %35, label %18
18: ; preds = %7, %23
%19 = phi i8* [ %32, %23 ], [ %15, %7 ]
%20 = phi i64 [ %29, %23 ], [ 0, %7 ]
%21 = tail call i64 @strcspn(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %35, label %23
23: ; preds = %18
%24 = getelementptr inbounds i8, i8* %12, i64 %20
%25 = tail call i64 @base64decode_block(i8* %24, i8* %19, i64 %21)
%26 = add nsw i64 %25, %20
%27 = getelementptr inbounds i8, i8* %19, i64 %21
%28 = shl i64 %26, 32
%29 = ashr exact i64 %28, 32
%30 = tail call i32 @strspn(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %27, i64 %31
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 0
br i1 %34, label %35, label %18
35: ; preds = %23, %18, %7
%36 = phi i64 [ 0, %7 ], [ %20, %18 ], [ %29, %23 ]
%37 = getelementptr inbounds i8, i8* %12, i64 %36
store i8 0, i8* %37
store i64 %36, i64* %1
br label %38
38: ; preds = %35, %4, %2
%39 = phi i8* [ null, %2 ], [ %12, %35 ], [ null, %4 ]
ret i8* %39
}