#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 /*<<< orphan*/ assert(int);
int strlen(char *);
int util_base64_decoded_size(char *in) {
  int length = strlen(in);
  if (!length)
    return 0;
  assert(length % 4 == 0);
  int l = 3 * length / 4;
  if (in[length - 1] == '=')
    l -= 1;
  if (in[length - 2] == '=')
    l -= 1;
  return l;
}


x86 assembly (clang, -O0):
<util_base64_decoded_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    114e <util_base64_decoded_size+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    11c4 <util_base64_decoded_size+0xa4>
mov    -0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
imul   $0x3,-0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3d,%eax
jne    119b <util_base64_decoded_size+0x7b>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3d,%eax
jne    11be <util_base64_decoded_size+0x9e>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_base64_decoded_size>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
je     1170 <util_base64_decoded_size+0x50>
mov    %eax,%ebx
xor    %edi,%edi
test   $0x3,%bl
sete   %dil
call   1040 <assert@plt>
lea    (%rbx,%rbx,2),%ecx
lea    (%rbx,%rbx,2),%eax
add    $0x3,%eax
test   %ecx,%ecx
cmovns %ecx,%eax
sar    $0x2,%eax
movslq %ebx,%rcx
xor    %edx,%edx
cmpb   $0x3d,-0x1(%rcx,%r14,1)
sete   %dl
sub    %edx,%eax
xor    %edx,%edx
cmpb   $0x3d,-0x2(%rcx,%r14,1)
sete   %dl
sub    %edx,%eax
jmp    1172 <util_base64_decoded_size+0x52>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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