#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 decodeblock(char *, char *, int);
char *strchr(char *, int);
int strlen(char *);
int Base64Decode(char *input, char *output, int oplen) {
  char *charval = 0;
  char decoderinput[4 + 1] = "";
  char encodingtabe[63 + 1] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                              "abcdefghijklmnopqrstuvwxyz"
                              "0123456789";
  ;
  int index = 0, asciival = 0, computeval = 0, iplen = 0, rc = 0;
  iplen = strlen(input);
  while (index < iplen) {
    asciival = (int)input[index];
    if (asciival == '$') {
      rc = decodeblock(decoderinput, output, oplen);
      break;
    } else {
      charval = strchr(encodingtabe, asciival);
      if (charval) {
        decoderinput[computeval] = charval - encodingtabe;
        computeval = (computeval + 1) % 4;
        if (computeval == 0) {
          rc = decodeblock(decoderinput, output, oplen);
          decoderinput[0] = decoderinput[1] = decoderinput[2] =
              decoderinput[3] = 0;
        }
      }
    }
    index++;
  }
  return (rc);
}


x86 assembly (clang, -O0):
<Base64Decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x25(%rbp),%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1050 <memset@plt>
lea    -0x70(%rbp),%rdi
lea    0xe77(%rip),%rsi
mov    $0x40,%edx
call   1060 <memcpy@plt>
movl   $0x0,-0x74(%rbp)
movl   $0x0,-0x78(%rbp)
movl   $0x0,-0x7c(%rbp)
movl   $0x0,-0x80(%rbp)
movl   $0x0,-0x84(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x80(%rbp)
mov    -0x74(%rbp),%eax
cmp    -0x80(%rbp),%eax
jge    128e <Base64Decode+0x13e>
mov    -0x8(%rbp),%rax
movslq -0x74(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x78(%rbp)
cmpl   $0x24,-0x78(%rbp)
jne    1205 <Base64Decode+0xb5>
lea    -0x25(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1070 <decodeblock@plt>
mov    %eax,-0x84(%rbp)
jmp    128e <Base64Decode+0x13e>
lea    -0x70(%rbp),%rdi
mov    -0x78(%rbp),%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     127b <Base64Decode+0x12b>
mov    -0x20(%rbp),%rax
lea    -0x70(%rbp),%rcx
sub    %rcx,%rax
mov    %al,%cl
movslq -0x7c(%rbp),%rax
mov    %cl,-0x25(%rbp,%rax,1)
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,-0x7c(%rbp)
cmpl   $0x0,-0x7c(%rbp)
jne    1276 <Base64Decode+0x126>
lea    -0x25(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1070 <decodeblock@plt>
mov    %eax,-0x84(%rbp)
movb   $0x0,-0x22(%rbp)
movb   $0x0,-0x23(%rbp)
movb   $0x0,-0x24(%rbp)
movb   $0x0,-0x25(%rbp)
jmp    127b <Base64Decode+0x12b>
jmp    1280 <Base64Decode+0x130>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    11c5 <Base64Decode+0x75>
mov    -0x84(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Base64Decode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %edx,0x14(%rsp)
mov    %rsi,0x18(%rsp)
mov    %rdi,%rbp
movb   $0x0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
movaps 0xed2(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xeb6(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe9a(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe7e(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
call   1030 <strlen@plt>
test   %eax,%eax
jle    1213 <Base64Decode+0xe3>
mov    %eax,%r12d
xor    %r14d,%r14d
lea    0x20(%rsp),%rbx
xor    %r13d,%r13d
xor    %r15d,%r15d
jmp    11b9 <Base64Decode+0x89>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r14
cmp    %r14,%r12
je     122e <Base64Decode+0xfe>
movsbl 0x0(%rbp,%r14,1),%esi
cmp    $0x24,%esi
je     1218 <Base64Decode+0xe8>
mov    %rbx,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
je     11b0 <Base64Decode+0x80>
sub    %ebx,%eax
movslq %r15d,%rcx
mov    %al,0xc(%rsp,%rcx,1)
lea    0x1(%rcx),%r15d
add    $0x4,%ecx
test   %r15d,%r15d
cmovns %r15d,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%r15d
jne    11b0 <Base64Decode+0x80>
lea    0xc(%rsp),%rdi
mov    0x18(%rsp),%rsi
mov    0x14(%rsp),%edx
call   1050 <decodeblock@plt>
mov    %eax,%r13d
movl   $0x0,0xc(%rsp)
xor    %r15d,%r15d
jmp    11b0 <Base64Decode+0x80>
xor    %r13d,%r13d
jmp    122e <Base64Decode+0xfe>
lea    0xc(%rsp),%rdi
mov    0x18(%rsp),%rsi
mov    0x14(%rsp),%edx
call   1050 <decodeblock@plt>
mov    %eax,%r13d
mov    %r13d,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@__const.Base64Decode.encodingtabe = [64 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\00\00"
define i32 @Base64Decode(i8* %0, i8* %1, i32 %2) {
%4 = alloca [5 x i8]
%5 = alloca [64 x i8]
%6 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%8 = tail call i32 @strlen(i8* %0)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %43
10: ; preds = %3
%11 = ptrtoint [64 x i8]* %5 to i64
%12 = zext i32 %8 to i64
%13 = bitcast [5 x i8]* %4 to i32*
br label %14
14: ; preds = %10, %38
%15 = phi i64 [ 0, %10 ], [ %41, %38 ]
%16 = phi i32 [ 0, %10 ], [ %40, %38 ]
%17 = phi i32 [ 0, %10 ], [ %39, %38 ]
%18 = getelementptr inbounds i8, i8* %0, i64 %15
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 36
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = call i32 @decodeblock(i8* %6, i8* %1, i32 %2)
br label %43
23: ; preds = %14
%24 = sext i8 %19 to i32
%25 = call i8* @strchr(i8* %7, i32 %24)
%26 = icmp eq i8* %25, null
br i1 %26, label %38, label %27
27: ; preds = %23
%28 = ptrtoint i8* %25 to i64
%29 = sub i64 %28, %11
%30 = trunc i64 %29 to i8
%31 = sext i32 %17 to i64
%32 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 %31
store i8 %30, i8* %32
%33 = add nsw i32 %17, 1
%34 = srem i32 %33, 4
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %27
%37 = call i32 @decodeblock(i8* %6, i8* %1, i32 %2)
store i32 0, i32* %13
br label %38
38: ; preds = %23, %36, %27
%39 = phi i32 [ 0, %36 ], [ %34, %27 ], [ %17, %23 ]
%40 = phi i32 [ %37, %36 ], [ %16, %27 ], [ %16, %23 ]
%41 = add nuw nsw i64 %15, 1
%42 = icmp eq i64 %41, %12
br i1 %42, label %43, label %14
43: ; preds = %38, %3, %21
%44 = phi i32 [ %22, %21 ], [ 0, %3 ], [ %40, %38 ]
ret i32 %44
}