#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 *, unsigned char *, int, int, int);
char *strchr(char *, int);
scalar_t__ strlen(char *);
int Base64Decode(char *input, unsigned char *output, int oplen, int debug) {
  char *charval = 0;
  char decoderinput[4 + 1] = "";
  char encodingtable[63 + 1] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                               "abcdefghijklmnopqrstuvwxyz"
                               "0123456789"
                               "-_";
  ;
  int index = 0, asciival = 0, computeval = 0, iplen = 0, rc = 0, oindex = 3;
  iplen = (int)strlen(input);
  while (index < iplen) {
    asciival = (int)input[index];
    if (asciival == '=') {
      rc = decodeblock(decoderinput, output, oplen, debug, oindex);
      break;
    } else {
      charval = strchr(encodingtable, asciival);
      if (charval) {
        decoderinput[computeval] = charval - encodingtable;
        computeval = (computeval + 1) % 4;
        if (computeval == 0) {
          rc = decodeblock(decoderinput, output, oplen, debug, oindex);
          oindex = oindex + 3;
          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)
mov    %ecx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x25(%rbp),%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1050 <memset@plt>
lea    -0x70(%rbp),%rdi
lea    0xe74(%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)
movl   $0x3,-0x88(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x80(%rbp)
mov    -0x74(%rbp),%eax
cmp    -0x80(%rbp),%eax
jge    12be <Base64Decode+0x16e>
mov    -0x8(%rbp),%rax
movslq -0x74(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x78(%rbp)
cmpl   $0x3d,-0x78(%rbp)
jne    121c <Base64Decode+0xcc>
lea    -0x25(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x88(%rbp),%r8d
call   1070 <decodeblock@plt>
mov    %eax,-0x84(%rbp)
jmp    12be <Base64Decode+0x16e>
lea    -0x70(%rbp),%rdi
mov    -0x78(%rbp),%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12ab <Base64Decode+0x15b>
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    12a6 <Base64Decode+0x156>
lea    -0x25(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x88(%rbp),%r8d
call   1070 <decodeblock@plt>
mov    %eax,-0x84(%rbp)
mov    -0x88(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x88(%rbp)
movb   $0x0,-0x22(%rbp)
movb   $0x0,-0x23(%rbp)
movb   $0x0,-0x24(%rbp)
movb   $0x0,-0x25(%rbp)
jmp    12ab <Base64Decode+0x15b>
jmp    12b0 <Base64Decode+0x160>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    11d2 <Base64Decode+0x82>
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    %ecx,0x14(%rsp)
mov    %edx,0x10(%rsp)
mov    %rsi,0x18(%rsp)
mov    %rdi,%rbp
movb   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
movaps 0xece(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xeb2(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe96(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe7a(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
call   1030 <strlen@plt>
test   %eax,%eax
jle    1233 <Base64Decode+0x103>
mov    %eax,%r15d
xor    %r12d,%r12d
mov    $0x3,%r13d
lea    0x20(%rsp),%rbx
movl   $0x0,0x4(%rsp)
xor    %r14d,%r14d
jmp    11cd <Base64Decode+0x9d>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r12
cmp    %r12,%r15
je     125b <Base64Decode+0x12b>
movsbl 0x0(%rbp,%r12,1),%esi
cmp    $0x3d,%esi
je     123d <Base64Decode+0x10d>
mov    %rbx,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
je     11c0 <Base64Decode+0x90>
sub    %ebx,%eax
movslq %r14d,%rcx
mov    %al,0x8(%rsp,%rcx,1)
lea    0x1(%rcx),%r14d
add    $0x4,%ecx
test   %r14d,%r14d
cmovns %r14d,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%r14d
jne    11c0 <Base64Decode+0x90>
lea    0x8(%rsp),%rdi
mov    0x18(%rsp),%rsi
mov    0x10(%rsp),%edx
mov    0x14(%rsp),%ecx
mov    %r13d,%r8d
call   1050 <decodeblock@plt>
mov    %eax,0x4(%rsp)
add    $0x3,%r13d
movl   $0x0,0x8(%rsp)
xor    %r14d,%r14d
jmp    11c0 <Base64Decode+0x90>
movl   $0x0,0x4(%rsp)
jmp    125b <Base64Decode+0x12b>
lea    0x8(%rsp),%rdi
mov    0x18(%rsp),%rsi
mov    0x10(%rsp),%edx
mov    0x14(%rsp),%ecx
mov    %r13d,%r8d
call   1050 <decodeblock@plt>
mov    %eax,0x4(%rsp)
mov    0x4(%rsp),%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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