#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);
unsigned int base64_is_well_formed_imp(char *string,
                                       unsigned int string_length) {
  unsigned int string_length_mod, scan_length;
  if (string_length == 0)
    return 0;
  string_length_mod = string_length % 4;
  if (string_length_mod == 0) {
    if (string[string_length - 1] == '=') {
      if (string[string_length - 2] == '=')
        scan_length = string_length - 2;
      else
        scan_length = string_length - 1;
    } else
      scan_length = string_length;
  } else if (string_length_mod == 1)
    return 0;
  else
    scan_length = string_length;
  for (unsigned int k = 0; k < scan_length; k++) {
    if (!base64_is_valid_char(string[k]))
      return 0;
  }
  return scan_length;
}


x86 assembly (clang, -O0):
<base64_is_well_formed_imp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1135 <base64_is_well_formed_imp+0x25>
movl   $0x0,-0x4(%rbp)
jmp    1213 <base64_is_well_formed_imp+0x103>
mov    -0x14(%rbp),%eax
and    $0x3,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11a1 <base64_is_well_formed_imp+0x91>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3d,%eax
jne    1196 <base64_is_well_formed_imp+0x86>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x2,%ecx
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3d,%eax
jne    1188 <base64_is_well_formed_imp+0x78>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x1c(%rbp)
jmp    1191 <base64_is_well_formed_imp+0x81>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    119c <base64_is_well_formed_imp+0x8c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11c2 <base64_is_well_formed_imp+0xb2>
cmpl   $0x1,-0x18(%rbp)
jne    11b7 <base64_is_well_formed_imp+0xa7>
movl   $0x0,-0x4(%rbp)
jmp    1213 <base64_is_well_formed_imp+0x103>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11c2 <base64_is_well_formed_imp+0xb2>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    120d <base64_is_well_formed_imp+0xfd>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1030 <base64_is_valid_char@plt>
cmp    $0x0,%eax
jne    11fa <base64_is_well_formed_imp+0xea>
movl   $0x0,-0x4(%rbp)
jmp    1213 <base64_is_well_formed_imp+0x103>
jmp    11ff <base64_is_well_formed_imp+0xef>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11c9 <base64_is_well_formed_imp+0xb9>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64_is_well_formed_imp>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
xor    %r14d,%r14d
test   %esi,%esi
je     117a <base64_is_well_formed_imp+0x6a>
mov    %esi,%r15d
mov    %esi,%eax
and    $0x3,%eax
cmp    $0x1,%eax
je     117a <base64_is_well_formed_imp+0x6a>
mov    %rdi,%r12
test   %eax,%eax
jne    1153 <base64_is_well_formed_imp+0x43>
lea    -0x1(%r15),%eax
cmpb   $0x3d,(%r12,%rax,1)
jne    1153 <base64_is_well_formed_imp+0x43>
add    $0xfffffffe,%r15d
cmpb   $0x3d,(%r12,%r15,1)
cmove  %r15d,%eax
mov    %eax,%r15d
test   %eax,%eax
je     117a <base64_is_well_formed_imp+0x6a>
mov    %r15d,%r13d
xor    %r14d,%r14d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsbl (%r12,%rbx,1),%edi
call   1030 <base64_is_valid_char@plt>
test   %eax,%eax
je     117a <base64_is_well_formed_imp+0x6a>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1160 <base64_is_well_formed_imp+0x50>
mov    %r15d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @base64_is_well_formed_imp(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i32, i32* %5
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 0, i32* %3
br label %72
12: ; preds = %2
%13 = load i32, i32* %5
%14 = urem i32 %13, 4
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %45
17: ; preds = %12
%18 = load i8*, i8** %4
%19 = load i32, i32* %5
%20 = sub i32 %19, 1
%21 = zext i32 %20 to i64
%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 %42
26: ; preds = %17
%27 = load i8*, i8** %4
%28 = load i32, i32* %5
%29 = sub i32 %28, 2
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 61
br i1 %34, label %35, label %38
35: ; preds = %26
%36 = load i32, i32* %5
%37 = sub i32 %36, 2
store i32 %37, i32* %7
br label %41
38: ; preds = %26
%39 = load i32, i32* %5
%40 = sub i32 %39, 1
store i32 %40, i32* %7
br label %41
41: ; preds = %38, %35
br label %44
42: ; preds = %17
%43 = load i32, i32* %5
store i32 %43, i32* %7
br label %44
44: ; preds = %42, %41
br label %52
45: ; preds = %12
%46 = load i32, i32* %6
%47 = icmp eq i32 %46, 1
br i1 %47, label %48, label %49
48: ; preds = %45
store i32 0, i32* %3
br label %72
49: ; preds = %45
%50 = load i32, i32* %5
store i32 %50, i32* %7
br label %51
51: ; preds = %49
br label %52
52: ; preds = %51, %44
store i32 0, i32* %8
br label %53
53: ; preds = %67, %52
%54 = load i32, i32* %8
%55 = load i32, i32* %7
%56 = icmp ult i32 %54, %55
br i1 %56, label %57, label %70
57: ; preds = %53
%58 = load i8*, i8** %4
%59 = load i32, i32* %8
%60 = zext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
%62 = load i8, i8* %61
%63 = call i32 @base64_is_valid_char(i8 signext %62)
%64 = icmp ne i32 %63, 0
br i1 %64, label %66, label %65
65: ; preds = %57
store i32 0, i32* %3
br label %72
66: ; preds = %57
br label %67
67: ; preds = %66
%68 = load i32, i32* %8
%69 = add i32 %68, 1
store i32 %69, i32* %8
br label %53
70: ; preds = %53
%71 = load i32, i32* %7
store i32 %71, i32* %3
br label %72
72: ; preds = %70, %65, %48, %11
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
define i32 @base64_is_well_formed_imp(i8* nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %32, label %4
4: ; preds = %2
%5 = and i32 %1, 3
switch i32 %5, label %20 [
i32 0, label %6
i32 1, label %32
]
6: ; preds = %4
%7 = add i32 %1, -1
%8 = zext i32 %7 to i64
%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 %20
12: ; preds = %6
%13 = add i32 %1, -2
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 61
%18 = select i1 %17, i32 %13, i32 %7
%19 = icmp eq i32 %18, 0
br i1 %19, label %32, label %20
20: ; preds = %4, %6, %12
%21 = phi i32 [ %18, %12 ], [ %1, %6 ], [ %1, %4 ]
%22 = zext i32 %21 to i64
br label %25
23: ; preds = %25
%24 = icmp eq i64 %31, %22
br i1 %24, label %32, label %25
25: ; preds = %20, %23
%26 = phi i64 [ 0, %20 ], [ %31, %23 ]
%27 = getelementptr inbounds i8, i8* %0, i64 %26
%28 = load i8, i8* %27
%29 = tail call i32 @base64_is_valid_char(i8 signext %28)
%30 = icmp eq i32 %29, 0
%31 = add nuw nsw i64 %26, 1
br i1 %30, label %32, label %23
32: ; preds = %25, %23, %12, %4, %2
%33 = phi i32 [ 0, %2 ], [ 0, %4 ], [ 0, %12 ], [ 0, %25 ], [ %21, %23 ]
ret i32 %33
}