#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 Base64decode_len(const char *encodedString) {
  size_t result;
  size_t sourceLength = strlen(encodedString);
  if (sourceLength == 0) {
    result = 0;
  } else {
    result = sourceLength / 4 * 3;
    if (encodedString[sourceLength - 1] == '=') {
      if (encodedString[sourceLength - 2] == '=') {
        result--;
      }
      result--;
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<Base64decode_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1141 <Base64decode_len+0x31>
movq   $0x0,-0x10(%rbp)
jmp    11a0 <Base64decode_len+0x90>
mov    -0x18(%rbp),%rax
shr    $0x2,%rax
imul   $0x3,%rax,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3d,%eax
jne    119b <Base64decode_len+0x8b>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x2,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3d,%eax
jne    118f <Base64decode_len+0x7f>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    11a0 <Base64decode_len+0x90>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Base64decode_len>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %rax,%rax
je     1142 <Base64decode_len+0x32>
mov    %rax,%rcx
shr    $0x2,%rax
lea    (%rax,%rax,2),%rax
cmpb   $0x3d,-0x1(%rcx,%rbx,1)
jne    1140 <Base64decode_len+0x30>
xor    %edx,%edx
cmpb   $0x3d,-0x2(%rcx,%rbx,1)
sete   %dl
not    %rdx
add    %rdx,%rax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

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

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