#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 input[]) {
  unsigned char *start = input;
  while (base64_to_binary(input[0]) < 64) {
    ++input;
  }
  unsigned int input_length = input - start;
  unsigned int output_length = input_length / 4 * 3;
  switch (input_length % 4) {
  default:
    return output_length;
  case 2:
    return output_length + 1;
  case 3:
    return output_length + 2;
  }
}


x86 assembly (clang, -O0):
<decode_base64_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1030 <base64_to_binary@plt>
cmp    $0x40,%eax
jge    114a <decode_base64_length+0x3a>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1124 <decode_base64_length+0x14>
mov    -0x10(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
shr    $0x2,%ecx
mov    %ecx,%eax
lea    (%rax,%rax,2),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
and    $0x3,%eax
mov    %eax,-0x24(%rbp)
sub    $0x2,%eax
je     1196 <decode_base64_length+0x86>
jmp    117a <decode_base64_length+0x6a>
mov    -0x24(%rbp),%eax
sub    $0x3,%eax
je     11a4 <decode_base64_length+0x94>
jmp    118b <decode_base64_length+0x7b>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ad <decode_base64_length+0x9d>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11ad <decode_base64_length+0x9d>
mov    -0x20(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_base64_length>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0xffffffff,%ebp
nopl   0x0(%rax,%rax,1)
movzbl (%rbx),%edi
call   1030 <base64_to_binary@plt>
add    $0x1,%rbx
add    $0x1,%ebp
cmp    $0x40,%eax
jl     1120 <decode_base64_length+0x10>
mov    %ebp,%eax
shr    $0x2,%eax
lea    (%rax,%rax,2),%eax
and    $0x3,%ebp
cmp    $0x3,%ebp
je     114e <decode_base64_length+0x3e>
cmp    $0x2,%ebp
jne    1151 <decode_base64_length+0x41>
add    $0x1,%eax
jmp    1151 <decode_base64_length+0x41>
add    $0x2,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @decode_base64_length(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
store i8* %7, i8** %4
br label %8
8: ; preds = %14, %1
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = call i32 @base64_to_binary(i8 zeroext %11)
%13 = icmp slt i32 %12, 64
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %3
br label %8
17: ; preds = %8
%18 = load i8*, i8** %3
%19 = load i8*, i8** %4
%20 = ptrtoint i8* %18 to i64
%21 = ptrtoint i8* %19 to i64
%22 = sub i64 %20, %21
%23 = trunc i64 %22 to i32
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = udiv i32 %24, 4
%26 = mul i32 %25, 3
store i32 %26, i32* %6
%27 = load i32, i32* %5
%28 = urem i32 %27, 4
switch i32 %28, label %29 [
i32 2, label %31
i32 3, label %34
]
29: ; preds = %17
%30 = load i32, i32* %6
store i32 %30, i32* %2
br label %37
31: ; preds = %17
%32 = load i32, i32* %6
%33 = add i32 %32, 1
store i32 %33, i32* %2
br label %37
34: ; preds = %17
%35 = load i32, i32* %6
%36 = add i32 %35, 2
store i32 %36, i32* %2
br label %37
37: ; preds = %34, %31, %29
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
define i32 @decode_base64_length(i8* %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i8* [ %0, %1 ], [ %7, %2 ]
%4 = load i8, i8* %3
%5 = tail call i32 @base64_to_binary(i8 zeroext %4)
%6 = icmp slt i32 %5, 64
%7 = getelementptr inbounds i8, i8* %3, i64 1
br i1 %6, label %2, label %8
8: ; preds = %2
%9 = ptrtoint i8* %3 to i64
%10 = ptrtoint i8* %0 to i64
%11 = sub i64 %9, %10
%12 = trunc i64 %11 to i32
%13 = lshr i32 %12, 2
%14 = mul nuw i32 %13, 3
%15 = and i32 %12, 3
switch i32 %15, label %20 [
i32 2, label %16
i32 3, label %18
]
16: ; preds = %8
%17 = add nuw i32 %14, 1
br label %20
18: ; preds = %8
%19 = add nuw i32 %14, 2
br label %20
20: ; preds = %8, %18, %16
%21 = phi i32 [ %19, %18 ], [ %17, %16 ], [ %14, %8 ]
ret i32 %21
}