#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 */
scalar_t__ strlen(char const *);
int data_length_for_base64(const char *base64) {
  int len = (int)strlen(base64);
  int numBlocks = len / 4;
  int numPaddingChars = 0;
  if (numBlocks == 0) {
    return 0;
  } else {
    if (base64[len - 1] == '=') {
      numPaddingChars++;
    };
    if (base64[len - 2] == '=') {
      numPaddingChars++;
    };
    return (3 * numBlocks) - numPaddingChars;
  }
}


x86 assembly (clang, -O0):
<data_length_for_base64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1153 <data_length_for_base64+0x43>
movl   $0x0,-0x4(%rbp)
jmp    11a3 <data_length_for_base64+0x93>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3d,%eax
jne    1176 <data_length_for_base64+0x66>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3d,%eax
jne    1199 <data_length_for_base64+0x89>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
imul   $0x3,-0x18(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<data_length_for_base64>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    0x3(%rax),%edx
xor    %ecx,%ecx
cmp    $0x7,%edx
jb     116d <data_length_for_base64+0x5d>
test   %eax,%eax
cmovns %eax,%edx
sar    $0x2,%edx
shl    $0x20,%rax
movabs $0xffffffff00000000,%rcx
ff ff ff
add    %rax,%rcx
sar    $0x20,%rcx
xor    %esi,%esi
cmpb   $0x3d,(%rbx,%rcx,1)
sete   %sil
mov    %esi,%ecx
neg    %ecx
movabs $0xfffffffe00000000,%rdi
ff ff ff
add    %rax,%rdi
sar    $0x20,%rdi
cmpb   $0x3d,(%rbx,%rdi,1)
not    %esi
cmovne %ecx,%esi
lea    (%rdx,%rdx,2),%ecx
add    %esi,%ecx
mov    %ecx,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @data_length_for_base64(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = trunc i64 %2 to i32
%4 = add i32 %3, 3
%5 = icmp ult i32 %4, 7
br i1 %5, label %24, label %6
6: ; preds = %1
%7 = sdiv i32 %3, 4
%8 = shl i64 %2, 32
%9 = add i64 %8, -4294967296
%10 = ashr exact i64 %9, 32
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 61
%14 = sext i1 %13 to i32
%15 = add i64 %8, -8589934592
%16 = ashr exact i64 %15, 32
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 61
%20 = select i1 %13, i32 -2, i32 -1
%21 = select i1 %19, i32 %20, i32 %14
%22 = mul nsw i32 %7, 3
%23 = add nsw i32 %21, %22
br label %24
24: ; preds = %1, %6
%25 = phi i32 [ %23, %6 ], [ 0, %1 ]
ret i32 %25
}