#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 strlen(char const *);
scalar_t__ strtok(char *, 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);
  unsigned char *line;
  int p = 0;
  line = (unsigned char *)strtok((char *)buf, "\r\n\t ");
  while (line) {
    p += base64decode_block(outbuf + p, (const char *)line,
                            strlen((char *)line));
    line = (unsigned char *)strtok(NULL, "\r\n\t ");
  }
  outbuf[p] = 0;
  *size = p;
  return outbuf;
}


x86 assembly (clang, -O0):
<base64decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1168 <base64decode+0x28>
movq   $0x0,-0x8(%rbp)
jmp    1241 <base64decode+0x101>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
ja     118d <base64decode+0x4d>
movq   $0x0,-0x8(%rbp)
jmp    1241 <base64decode+0x101>
mov    -0x20(%rbp),%rax
shr    $0x2,%rax
imul   $0x3,%rax,%rdi
add    $0x3,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1222 <base64decode+0xe2>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    %rax,%rdx
call   1030 <base64decode_block@plt>
mov    %rax,%rcx
movslq -0x34(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x34(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdec(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x30(%rbp)
jmp    11c1 <base64decode+0x81>
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    $0x50,%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     11d3 <base64decode+0x93>
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
test   %rax,%rax
je     11d3 <base64decode+0x93>
shr    $0x2,%rax
lea    (%rax,%rax,2),%rdi
add    $0x3,%rdi
call   1050 <malloc@plt>
mov    %rax,%r12
lea    0xe81(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strtok@plt>
test   %rax,%rax
je     11d8 <base64decode+0x98>
mov    %rax,%rbx
xor    %ebp,%ebp
lea    0xe68(%rip),%r15
nopl   0x0(%rax,%rax,1)
lea    (%r12,%rbp,1),%r13
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <base64decode_block@plt>
add    %eax,%ebp
xor    %edi,%edi
mov    %r15,%rsi
call   1060 <strtok@plt>
mov    %rax,%rbx
movslq %ebp,%rbp
test   %rax,%rax
jne    11a0 <base64decode+0x60>
jmp    11da <base64decode+0x9a>
xor    %r12d,%r12d
jmp    11e2 <base64decode+0xa2>
xor    %ebp,%ebp
movb   $0x0,(%r12,%rbp,1)
mov    %rbp,(%r14)
mov    %r12,%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 %56
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 %56
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
store i32 0, i32* %9
%26 = load i8*, i8** %4
%27 = call i64 @strtok(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%28 = inttoptr i64 %27 to i8*
store i8* %28, i8** %8
br label %29
29: ; preds = %32, %19
%30 = load i8*, i8** %8
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %47
32: ; preds = %29
%33 = load i8*, i8** %7
%34 = load i32, i32* %9
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8*, i8** %8
%38 = load i8*, i8** %8
%39 = call i64 @strlen(i8* %38)
%40 = call i64 @base64decode_block(i8* %36, i8* %37, i64 %39)
%41 = load i32, i32* %9
%42 = sext i32 %41 to i64
%43 = add nsw i64 %42, %40
%44 = trunc i64 %43 to i32
store i32 %44, i32* %9
%45 = call i64 @strtok(i8* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%46 = inttoptr i64 %45 to i8*
store i8* %46, i8** %8
br label %29
47: ; preds = %29
%48 = load i8*, i8** %7
%49 = load i32, i32* %9
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
store i8 0, i8* %51
%52 = load i32, i32* %9
%53 = sext i32 %52 to i64
%54 = load i64*, i64** %5
store i64 %53, i64* %54
%55 = load i8*, i8** %7
store i8* %55, i8** %3
br label %56
56: ; preds = %47, %18, %12
%57 = load i8*, i8** %3
ret i8* %57
}

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 %30, label %4
4: ; preds = %2
%5 = tail call i64 @strlen(i8* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %30, 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 i64 @strtok(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %27, label %15
15: ; preds = %7, %15
%16 = phi i64 [ %23, %15 ], [ %13, %7 ]
%17 = phi i64 [ %25, %15 ], [ 0, %7 ]
%18 = inttoptr i64 %16 to i8*
%19 = getelementptr inbounds i8, i8* %12, i64 %17
%20 = tail call i64 @strlen(i8* %18)
%21 = tail call i64 @base64decode_block(i8* %19, i8* %18, i64 %20)
%22 = add nsw i64 %21, %17
%23 = tail call i64 @strtok(i8* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%24 = shl i64 %22, 32
%25 = ashr exact i64 %24, 32
%26 = icmp eq i64 %23, 0
br i1 %26, label %27, label %15
27: ; preds = %15, %7
%28 = phi i64 [ 0, %7 ], [ %25, %15 ]
%29 = getelementptr inbounds i8, i8* %12, i64 %28
store i8 0, i8* %29
store i64 %28, i64* %1
br label %30
30: ; preds = %27, %4, %2
%31 = phi i8* [ null, %2 ], [ %12, %27 ], [ null, %4 ]
ret i8* %31
}