#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 base64_decode_length(const char *in, size_t len) {
  size_t result = len / 4 * 3;
  for (size_t i = 1; i <= 2; i++) {
    if (len >= i && in[len - i] == '=')
      result--;
    else
      break;
  }
  return result;
}


x86 assembly (clang, -O0):
<base64_decode_length>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
shr    $0x2,%rax
imul   $0x3,%rax,%rax
mov    %rax,-0x18(%rbp)
movq   $0x1,-0x20(%rbp)
cmpq   $0x2,-0x20(%rbp)
ja     1182 <base64_decode_length+0x82>
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
jb     1167 <base64_decode_length+0x67>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3d,%eax
jne    1167 <base64_decode_length+0x67>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    116c <base64_decode_length+0x6c>
jmp    1182 <base64_decode_length+0x82>
jmp    1171 <base64_decode_length+0x71>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1124 <base64_decode_length+0x24>
mov    -0x18(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64_decode_length>:
mov    %rsi,%rax
shr    $0x2,%rax
lea    (%rax,%rax,2),%rax
test   %rsi,%rsi
je     1132 <base64_decode_length+0x32>
cmpb   $0x3d,-0x1(%rsi,%rdi,1)
jne    1132 <base64_decode_length+0x32>
lea    -0x1(%rax),%rcx
cmp    $0x1,%rsi
jne    1125 <base64_decode_length+0x25>
mov    %rcx,%rax
ret
add    $0xfffffffffffffffe,%rax
cmpb   $0x3d,-0x2(%rsi,%rdi,1)
cmovne %rcx,%rax
ret

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

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