#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*/ base64_is_valid_char(char const);
unsigned base64_valid(const char *data, size_t len) {
  for (size_t i = 0; i < len; i++)
    if (!base64_is_valid_char(data[i]))
      return i;
  return len;
}


x86 assembly (clang, -O0):
<base64_valid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1172 <base64_valid+0x62>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <base64_is_valid_char@plt>
cmp    $0x0,%eax
jne    115c <base64_valid+0x4c>
mov    -0x20(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    1179 <base64_valid+0x69>
jmp    1161 <base64_valid+0x51>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1128 <base64_valid+0x18>
mov    -0x18(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64_valid>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rsi,%rsi
je     1162 <base64_valid+0x52>
mov    %rsi,%r14
mov    %rdi,%r15
movsbl (%rdi),%edi
call   1030 <base64_is_valid_char@plt>
test   %eax,%eax
je     1162 <base64_valid+0x52>
lea    -0x1(%r14),%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
cmp    %rbp,%rbx
je     115f <base64_valid+0x4f>
movsbl 0x1(%r15,%rbp,1),%edi
call   1030 <base64_is_valid_char@plt>
add    $0x1,%rbp
test   %eax,%eax
jne    1140 <base64_valid+0x30>
cmp    %r14,%rbp
cmovb  %ebp,%r14d
mov    %r14d,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @base64_valid(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 0, i64* %6
br label %7
7: ; preds = %22, %2
%8 = load i64, i64* %6
%9 = load i64, i64* %5
%10 = icmp ult i64 %8, %9
br i1 %10, label %11, label %25
11: ; preds = %7
%12 = load i8*, i8** %4
%13 = load i64, i64* %6
%14 = getelementptr inbounds i8, i8* %12, i64 %13
%15 = load i8, i8* %14
%16 = call i32 @base64_is_valid_char(i8 signext %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %11
%19 = load i64, i64* %6
%20 = trunc i64 %19 to i32
store i32 %20, i32* %3
br label %28
21: ; preds = %11
br label %22
22: ; preds = %21
%23 = load i64, i64* %6
%24 = add i64 %23, 1
store i64 %24, i64* %6
br label %7
25: ; preds = %7
%26 = load i64, i64* %5
%27 = trunc i64 %26 to i32
store i32 %27, i32* %3
br label %28
28: ; preds = %25, %18
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
define i32 @base64_valid(i8* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %23, label %4
4: ; preds = %2
%5 = load i8, i8* %0
%6 = tail call i32 @base64_is_valid_char(i8 signext %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %23, label %17
8: ; preds = %17
%9 = getelementptr inbounds i8, i8* %0, i64 %19
%10 = load i8, i8* %9
%11 = tail call i32 @base64_is_valid_char(i8 signext %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = icmp ult i64 %19, %1
%15 = select i1 %14, i64 %19, i64 %1
%16 = trunc i64 %15 to i32
br label %23
17: ; preds = %4, %8
%18 = phi i64 [ %19, %8 ], [ 0, %4 ]
%19 = add nuw i64 %18, 1
%20 = icmp eq i64 %19, %1
br i1 %20, label %21, label %8
21: ; preds = %17
%22 = trunc i64 %1 to i32
br label %23
23: ; preds = %4, %13, %21, %2
%24 = phi i32 [ %22, %21 ], [ 0, %2 ], [ %16, %13 ], [ 0, %4 ]
ret i32 %24
}