#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 strlen(char const *);
int base64_decode_len(const char *data) {
  int i, j;
  j = 0;
  for (i = strlen(data) - 1; i >= 0; i--) {
    if (data[i] == '=')
      j++;
    if (data[i] != '=')
      break;
  }
  return strlen(data) / 4 * 3 - j;
}


x86 assembly (clang, -O0):
<base64_decode_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1187 <base64_decode_len+0x77>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3d,%eax
jne    115a <base64_decode_len+0x4a>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3d,%eax
je     1174 <base64_decode_len+0x64>
jmp    1187 <base64_decode_len+0x77>
jmp    1179 <base64_decode_len+0x69>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1132 <base64_decode_len+0x22>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    $0x4,%ecx
cltd
idiv   %ecx
imul   $0x3,%eax,%eax
sub    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64_decode_len>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ecx
xor    %edx,%edx
test   %eax,%eax
cmovs  %eax,%edx
sub    %edx,%eax
mov    $0xffffffff,%ebp
nopl   0x0(%rax,%rax,1)
cmp    %ecx,%edx
je     1144 <base64_decode_len+0x34>
add    $0x1,%ebp
cmpb   $0x3d,-0x1(%rbx,%rcx,1)
lea    -0x1(%rcx),%rcx
je     1130 <base64_decode_len+0x20>
jmp    1146 <base64_decode_len+0x36>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0x2,%ecx
lea    (%rcx,%rcx,2),%eax
sub    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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