#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 base64_to_binary(unsigned char);
unsigned int decode_base64_length(unsigned char *);
unsigned int decode_base64(unsigned char input[], unsigned char output[]) {
  unsigned int output_length = decode_base64_length(input);
  for (unsigned int i = 2; i < output_length; i += 3) {
    output[0] =
        base64_to_binary(input[0]) << 2 | base64_to_binary(input[1]) >> 4;
    output[1] =
        base64_to_binary(input[1]) << 4 | base64_to_binary(input[2]) >> 2;
    output[2] = base64_to_binary(input[2]) << 6 | base64_to_binary(input[3]);
    input += 4;
    output += 3;
  }
  switch (output_length % 3) {
  case 1:
    output[0] =
        base64_to_binary(input[0]) << 2 | base64_to_binary(input[1]) >> 4;
    break;
  case 2:
    output[0] =
        base64_to_binary(input[0]) << 2 | base64_to_binary(input[1]) >> 4;
    output[1] =
        base64_to_binary(input[1]) << 4 | base64_to_binary(input[2]) >> 2;
    break;
  }
  return output_length;
}


x86 assembly (clang, -O0):
<decode_base64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <decode_base64_length@plt>
mov    %eax,-0x14(%rbp)
movl   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1209 <decode_base64+0xe9>
mov    -0x8(%rbp),%rax
movzbl (%rax),%edi
call   1030 <base64_to_binary@plt>
shl    $0x2,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%edi
call   1030 <base64_to_binary@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
sar    $0x4,%ecx
or     %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%edi
call   1030 <base64_to_binary@plt>
shl    $0x4,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movzbl 0x2(%rax),%edi
call   1030 <base64_to_binary@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
sar    $0x2,%ecx
or     %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x8(%rbp),%rax
movzbl 0x2(%rax),%edi
call   1030 <base64_to_binary@plt>
shl    $0x6,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movzbl 0x3(%rax),%edi
call   1030 <base64_to_binary@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
or     %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x18(%rbp)
jmp    1143 <decode_base64+0x23>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
mov    %ecx,%eax
mov    $0xaaaaaaab,%edx
imul   %rdx,%rcx
shr    $0x21,%rcx
mov    %ecx,%edx
mov    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
mov    %eax,-0x28(%rbp)
sub    $0x1,%eax
je     1248 <decode_base64+0x128>
jmp    1237 <decode_base64+0x117>
mov    -0x28(%rbp),%eax
sub    $0x2,%eax
je     127e <decode_base64+0x15e>
jmp    12e2 <decode_base64+0x1c2>
mov    -0x8(%rbp),%rax
movzbl (%rax),%edi
call   1030 <base64_to_binary@plt>
shl    $0x2,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%edi
call   1030 <base64_to_binary@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
sar    $0x4,%ecx
or     %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
jmp    12e2 <decode_base64+0x1c2>
mov    -0x8(%rbp),%rax
movzbl (%rax),%edi
call   1030 <base64_to_binary@plt>
shl    $0x2,%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%edi
call   1030 <base64_to_binary@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
sar    $0x4,%ecx
or     %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%edi
call   1030 <base64_to_binary@plt>
shl    $0x4,%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movzbl 0x2(%rax),%edi
call   1030 <base64_to_binary@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
sar    $0x2,%ecx
or     %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x14(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_base64>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r12
call   1040 <decode_base64_length@plt>
mov    %eax,%r14d
cmp    $0x3,%eax
jb     11b7 <decode_base64+0x97>
mov    $0x2,%ebp
movzbl (%r12),%edi
call   1030 <base64_to_binary@plt>
mov    %eax,%ebx
shl    $0x2,%ebx
movzbl 0x1(%r12),%edi
call   1030 <base64_to_binary@plt>
shr    $0x4,%eax
or     %ebx,%eax
mov    %al,(%r15)
movzbl 0x1(%r12),%edi
call   1030 <base64_to_binary@plt>
mov    %eax,%ebx
shl    $0x4,%ebx
movzbl 0x2(%r12),%edi
call   1030 <base64_to_binary@plt>
shr    $0x2,%eax
or     %ebx,%eax
mov    %al,0x1(%r15)
movzbl 0x2(%r12),%edi
call   1030 <base64_to_binary@plt>
mov    %eax,%ebx
shl    $0x6,%ebx
movzbl 0x3(%r12),%edi
call   1030 <base64_to_binary@plt>
or     %ebx,%eax
mov    %al,0x2(%r15)
add    $0x4,%r12
add    $0x3,%r15
add    $0x3,%ebp
cmp    %r14d,%ebp
jb     1140 <decode_base64+0x20>
mov    %r14d,%eax
mov    $0xaaaaaaab,%ecx
imul   %rax,%rcx
shr    $0x21,%rcx
lea    (%rcx,%rcx,2),%ecx
mov    %r14d,%eax
sub    %ecx,%eax
cmp    $0x1,%eax
je     1221 <decode_base64+0x101>
cmp    $0x2,%eax
jne    1243 <decode_base64+0x123>
movzbl (%r12),%edi
call   1030 <base64_to_binary@plt>
mov    %eax,%ebx
shl    $0x2,%ebx
movzbl 0x1(%r12),%edi
call   1030 <base64_to_binary@plt>
shr    $0x4,%eax
or     %ebx,%eax
mov    %al,(%r15)
movzbl 0x1(%r12),%edi
call   1030 <base64_to_binary@plt>
mov    %eax,%ebx
shl    $0x4,%ebx
movzbl 0x2(%r12),%edi
call   1030 <base64_to_binary@plt>
shr    $0x2,%eax
or     %ebx,%eax
mov    %al,0x1(%r15)
jmp    1243 <decode_base64+0x123>
movzbl (%r12),%edi
call   1030 <base64_to_binary@plt>
mov    %eax,%ebx
shl    $0x2,%ebx
movzbl 0x1(%r12),%edi
call   1030 <base64_to_binary@plt>
shr    $0x4,%eax
or     %ebx,%eax
mov    %al,(%r15)
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @decode_base64(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i32 @decode_base64_length(i8* %7)
store i32 %8, i32* %5
store i32 2, i32* %6
br label %9
9: ; preds = %59, %2
%10 = load i32, i32* %6
%11 = load i32, i32* %5
%12 = icmp ult i32 %10, %11
br i1 %12, label %13, label %62
13: ; preds = %9
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 0
%16 = load i8, i8* %15
%17 = call i32 @base64_to_binary(i8 zeroext %16)
%18 = shl i32 %17, 2
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = load i8, i8* %20
%22 = call i32 @base64_to_binary(i8 zeroext %21)
%23 = ashr i32 %22, 4
%24 = or i32 %18, %23
%25 = trunc i32 %24 to i8
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i64 0
store i8 %25, i8* %27
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = load i8, i8* %29
%31 = call i32 @base64_to_binary(i8 zeroext %30)
%32 = shl i32 %31, 4
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i64 2
%35 = load i8, i8* %34
%36 = call i32 @base64_to_binary(i8 zeroext %35)
%37 = ashr i32 %36, 2
%38 = or i32 %32, %37
%39 = trunc i32 %38 to i8
%40 = load i8*, i8** %4
%41 = getelementptr inbounds i8, i8* %40, i64 1
store i8 %39, i8* %41
%42 = load i8*, i8** %3
%43 = getelementptr inbounds i8, i8* %42, i64 2
%44 = load i8, i8* %43
%45 = call i32 @base64_to_binary(i8 zeroext %44)
%46 = shl i32 %45, 6
%47 = load i8*, i8** %3
%48 = getelementptr inbounds i8, i8* %47, i64 3
%49 = load i8, i8* %48
%50 = call i32 @base64_to_binary(i8 zeroext %49)
%51 = or i32 %46, %50
%52 = trunc i32 %51 to i8
%53 = load i8*, i8** %4
%54 = getelementptr inbounds i8, i8* %53, i64 2
store i8 %52, i8* %54
%55 = load i8*, i8** %3
%56 = getelementptr inbounds i8, i8* %55, i64 4
store i8* %56, i8** %3
%57 = load i8*, i8** %4
%58 = getelementptr inbounds i8, i8* %57, i64 3
store i8* %58, i8** %4
br label %59
59: ; preds = %13
%60 = load i32, i32* %6
%61 = add i32 %60, 3
store i32 %61, i32* %6
br label %9
62: ; preds = %9
%63 = load i32, i32* %5
%64 = urem i32 %63, 3
switch i32 %64, label %109 [
i32 1, label %65
i32 2, label %80
]
65: ; preds = %62
%66 = load i8*, i8** %3
%67 = getelementptr inbounds i8, i8* %66, i64 0
%68 = load i8, i8* %67
%69 = call i32 @base64_to_binary(i8 zeroext %68)
%70 = shl i32 %69, 2
%71 = load i8*, i8** %3
%72 = getelementptr inbounds i8, i8* %71, i64 1
%73 = load i8, i8* %72
%74 = call i32 @base64_to_binary(i8 zeroext %73)
%75 = ashr i32 %74, 4
%76 = or i32 %70, %75
%77 = trunc i32 %76 to i8
%78 = load i8*, i8** %4
%79 = getelementptr inbounds i8, i8* %78, i64 0
store i8 %77, i8* %79
br label %109
80: ; preds = %62
%81 = load i8*, i8** %3
%82 = getelementptr inbounds i8, i8* %81, i64 0
%83 = load i8, i8* %82
%84 = call i32 @base64_to_binary(i8 zeroext %83)
%85 = shl i32 %84, 2
%86 = load i8*, i8** %3
%87 = getelementptr inbounds i8, i8* %86, i64 1
%88 = load i8, i8* %87
%89 = call i32 @base64_to_binary(i8 zeroext %88)
%90 = ashr i32 %89, 4
%91 = or i32 %85, %90
%92 = trunc i32 %91 to i8
%93 = load i8*, i8** %4
%94 = getelementptr inbounds i8, i8* %93, i64 0
store i8 %92, i8* %94
%95 = load i8*, i8** %3
%96 = getelementptr inbounds i8, i8* %95, i64 1
%97 = load i8, i8* %96
%98 = call i32 @base64_to_binary(i8 zeroext %97)
%99 = shl i32 %98, 4
%100 = load i8*, i8** %3
%101 = getelementptr inbounds i8, i8* %100, i64 2
%102 = load i8, i8* %101
%103 = call i32 @base64_to_binary(i8 zeroext %102)
%104 = ashr i32 %103, 2
%105 = or i32 %99, %104
%106 = trunc i32 %105 to i8
%107 = load i8*, i8** %4
%108 = getelementptr inbounds i8, i8* %107, i64 1
store i8 %106, i8* %108
br label %109
109: ; preds = %62, %80, %65
%110 = load i32, i32* %5
ret i32 %110
}

LLVM IR (-O2):
define i32 @decode_base64(i8* %0, i8* nocapture writeonly %1) {
%3 = tail call i32 @decode_base64_length(i8* %0)
%4 = icmp ugt i32 %3, 2
br i1 %4, label %9, label %5
5: ; preds = %9, %2
%6 = phi i8* [ %1, %2 ], [ %42, %9 ]
%7 = phi i8* [ %0, %2 ], [ %41, %9 ]
%8 = urem i32 %3, 3
switch i32 %8, label %75 [
i32 1, label %45
i32 2, label %55
]
9: ; preds = %2, %9
%10 = phi i32 [ %43, %9 ], [ 2, %2 ]
%11 = phi i8* [ %41, %9 ], [ %0, %2 ]
%12 = phi i8* [ %42, %9 ], [ %1, %2 ]
%13 = load i8, i8* %11
%14 = tail call i32 @base64_to_binary(i8 zeroext %13)
%15 = shl i32 %14, 2
%16 = getelementptr inbounds i8, i8* %11, i64 1
%17 = load i8, i8* %16
%18 = tail call i32 @base64_to_binary(i8 zeroext %17)
%19 = lshr i32 %18, 4
%20 = or i32 %19, %15
%21 = trunc i32 %20 to i8
store i8 %21, i8* %12
%22 = load i8, i8* %16
%23 = tail call i32 @base64_to_binary(i8 zeroext %22)
%24 = shl i32 %23, 4
%25 = getelementptr inbounds i8, i8* %11, i64 2
%26 = load i8, i8* %25
%27 = tail call i32 @base64_to_binary(i8 zeroext %26)
%28 = lshr i32 %27, 2
%29 = or i32 %28, %24
%30 = trunc i32 %29 to i8
%31 = getelementptr inbounds i8, i8* %12, i64 1
store i8 %30, i8* %31
%32 = load i8, i8* %25
%33 = tail call i32 @base64_to_binary(i8 zeroext %32)
%34 = shl i32 %33, 6
%35 = getelementptr inbounds i8, i8* %11, i64 3
%36 = load i8, i8* %35
%37 = tail call i32 @base64_to_binary(i8 zeroext %36)
%38 = or i32 %37, %34
%39 = trunc i32 %38 to i8
%40 = getelementptr inbounds i8, i8* %12, i64 2
store i8 %39, i8* %40
%41 = getelementptr inbounds i8, i8* %11, i64 4
%42 = getelementptr inbounds i8, i8* %12, i64 3
%43 = add i32 %10, 3
%44 = icmp ult i32 %43, %3
br i1 %44, label %9, label %5
45: ; preds = %5
%46 = load i8, i8* %7
%47 = tail call i32 @base64_to_binary(i8 zeroext %46)
%48 = shl i32 %47, 2
%49 = getelementptr inbounds i8, i8* %7, i64 1
%50 = load i8, i8* %49
%51 = tail call i32 @base64_to_binary(i8 zeroext %50)
%52 = lshr i32 %51, 4
%53 = or i32 %52, %48
%54 = trunc i32 %53 to i8
store i8 %54, i8* %6
br label %75
55: ; preds = %5
%56 = load i8, i8* %7
%57 = tail call i32 @base64_to_binary(i8 zeroext %56)
%58 = shl i32 %57, 2
%59 = getelementptr inbounds i8, i8* %7, i64 1
%60 = load i8, i8* %59
%61 = tail call i32 @base64_to_binary(i8 zeroext %60)
%62 = lshr i32 %61, 4
%63 = or i32 %62, %58
%64 = trunc i32 %63 to i8
store i8 %64, i8* %6
%65 = load i8, i8* %59
%66 = tail call i32 @base64_to_binary(i8 zeroext %65)
%67 = shl i32 %66, 4
%68 = getelementptr inbounds i8, i8* %7, i64 2
%69 = load i8, i8* %68
%70 = tail call i32 @base64_to_binary(i8 zeroext %69)
%71 = lshr i32 %70, 2
%72 = or i32 %71, %67
%73 = trunc i32 %72 to i8
%74 = getelementptr inbounds i8, i8* %6, i64 1
store i8 %73, i8* %74
br label %75
75: ; preds = %5, %55, %45
ret i32 %3
}