#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 */
size_t strlen(char const *);
size_t CalcDecodeLength(const char *b64input) {
  size_t len = strlen(b64input), padding = 0;
  if (b64input[len - 1] == '=' && b64input[len - 2] == '=')
    padding = 2;
  else if (b64input[len - 1] == '=')
    padding = 1;
  return (len * 3) / 4 - padding;
}


x86 assembly (clang, -O0):
<CalcDecodeLength>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3d,%eax
jne    1170 <CalcDecodeLength+0x60>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x2,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3d,%eax
jne    1170 <CalcDecodeLength+0x60>
movq   $0x2,-0x18(%rbp)
jmp    1196 <CalcDecodeLength+0x86>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3d,%eax
jne    1191 <CalcDecodeLength+0x81>
movq   $0x1,-0x18(%rbp)
jmp    1196 <CalcDecodeLength+0x86>
imul   $0x3,-0x10(%rbp),%rax
shr    $0x2,%rax
sub    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CalcDecodeLength>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    -0x1(%rax,%rbx,1),%dl
cmp    $0x3d,%dl
jne    1130 <CalcDecodeLength+0x20>
mov    $0xfffffffffffffffe,%rcx
cmpb   $0x3d,-0x2(%rax,%rbx,1)
je     113b <CalcDecodeLength+0x2b>
xor    %ecx,%ecx
cmp    $0x3d,%dl
sete   %cl
neg    %rcx
lea    (%rax,%rax,2),%rax
shr    $0x2,%rax
add    %rcx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
define i64 @CalcDecodeLength(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add i64 %2, -1
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 61
br i1 %6, label %7, label %12
7: ; preds = %1
%8 = add i64 %2, -2
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 61
br i1 %11, label %14, label %12
12: ; preds = %7, %1
%13 = sext i1 %6 to i64
br label %14
14: ; preds = %12, %7
%15 = phi i64 [ -2, %7 ], [ %13, %12 ]
%16 = mul i64 %2, 3
%17 = lshr i64 %16, 2
%18 = add nsw i64 %15, %17
ret i64 %18
}