#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int b64read(unsigned char *inbuf, char mode, size_t max_count, FILE *fp) {
  int count = 0;
  int temp = 0;
  while (count < max_count) {
    temp = fgetc(fp);
    inbuf[count] = temp;
    switch (mode) {
    case 'e':
      if (temp >= 0) {
        count++;
      } else {
        inbuf[count] = 0;
        return count;
      }
      break;
    case 'd':
      if (temp == 0xA) {
        inbuf[count] = 0;
        break;
      } else if ((temp == 61) || (temp == 43) || (temp >= 47 && temp <= 57) ||
                 (temp >= 65 && temp <= 90) || (temp >= 97 && temp <= 122)) {
        count++;
      } else if (temp == -1) {
        inbuf[count] = 0;
        return count;
      } else {
        return -1;
      }
      break;
    default:
      fprintf(stderr, "ERR: b64read invalid mode\n");
      fclose(fp);
      exit(-1);
    }
  }
  return count;
}


x86 assembly (clang, -O0):
<b64read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movslq -0x2c(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    12c7 <b64read+0x187>
mov    -0x28(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
movsbl -0x11(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x64,%eax
je     11ea <b64read+0xaa>
jmp    11a5 <b64read+0x65>
mov    -0x34(%rbp),%eax
sub    $0x65,%eax
jne    129a <b64read+0x15a>
jmp    11b6 <b64read+0x76>
cmpl   $0x0,-0x30(%rbp)
jl     11ce <b64read+0x8e>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11e5 <b64read+0xa5>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12cd <b64read+0x18d>
jmp    12c2 <b64read+0x182>
cmpl   $0xa,-0x30(%rbp)
jne    1205 <b64read+0xc5>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    12c2 <b64read+0x182>
cmpl   $0x3d,-0x30(%rbp)
je     1255 <b64read+0x115>
cmpl   $0x2b,-0x30(%rbp)
je     1255 <b64read+0x115>
cmpl   $0x2f,-0x30(%rbp)
jl     122d <b64read+0xed>
cmpl   $0x39,-0x30(%rbp)
jle    1255 <b64read+0x115>
cmpl   $0x41,-0x30(%rbp)
jl     1241 <b64read+0x101>
cmpl   $0x5a,-0x30(%rbp)
jle    1255 <b64read+0x115>
cmpl   $0x61,-0x30(%rbp)
jl     1263 <b64read+0x123>
cmpl   $0x7a,-0x30(%rbp)
jg     1263 <b64read+0x123>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1290 <b64read+0x150>
cmpl   $0xffffffff,-0x30(%rbp)
jne    1284 <b64read+0x144>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12cd <b64read+0x18d>
movl   $0xffffffff,-0x4(%rbp)
jmp    12cd <b64read+0x18d>
jmp    1295 <b64read+0x155>
jmp    12c2 <b64read+0x182>
mov    0x2d3f(%rip),%rax
mov    (%rax),%edi
lea    0xd56(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
jmp    1168 <b64read+0x28>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<b64read>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdx,%rdx
je     11de <b64read+0x9e>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rdi,%r12
movsbl %sil,%r13d
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    117d <b64read+0x3d>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
movslq %ebp,%rbx
mov    %ebp,%ecx
cmp    %r15,%rbx
jae    11e0 <b64read+0xa0>
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    %al,(%r12,%rbx,1)
cmp    $0x64,%r13d
je     11a0 <b64read+0x60>
cmp    $0x65,%r13d
jne    11f1 <b64read+0xb1>
test   %eax,%eax
jns    1170 <b64read+0x30>
jmp    11d5 <b64read+0x95>
nopl   0x0(%rax,%rax,1)
cmp    $0x3d,%eax
je     1170 <b64read+0x30>
cmp    $0x2b,%eax
je     1170 <b64read+0x30>
cmp    $0xa,%eax
jne    11b6 <b64read+0x76>
movb   $0x0,(%r12,%rbx,1)
jmp    1173 <b64read+0x33>
lea    -0x2f(%rax),%ecx
cmp    $0xb,%ecx
jb     1170 <b64read+0x30>
mov    %eax,%ecx
and    $0xffffffdf,%ecx
add    $0xffffffbf,%ecx
cmp    $0x19,%ecx
jbe    1170 <b64read+0x30>
mov    $0xffffffff,%ecx
cmp    $0xffffffff,%eax
jne    11e0 <b64read+0xa0>
movb   $0x0,(%r12,%rbx,1)
mov    %ebp,%ecx
jmp    11e0 <b64read+0xa0>
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
lea    0xdff(%rip),%rsi
call   1050 <fprintf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"ERR: b64read invalid mode\0A\00"
define i32 @b64read(i8* %0, i8 signext %1, i64 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i64
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %6
store i8 %1, i8* %7
store i64 %2, i64* %8
store i32* %3, i32** %9
store i32 0, i32* %10
store i32 0, i32* %11
br label %12
12: ; preds = %94, %4
%13 = load i32, i32* %10
%14 = sext i32 %13 to i64
%15 = load i64, i64* %8
%16 = icmp ult i64 %14, %15
br i1 %16, label %17, label %95
17: ; preds = %12
%18 = load i32*, i32** %9
%19 = call i32 @fgetc(i32* %18)
store i32 %19, i32* %11
%20 = load i32, i32* %11
%21 = trunc i32 %20 to i8
%22 = load i8*, i8** %6
%23 = load i32, i32* %10
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
store i8 %21, i8* %25
%26 = load i8, i8* %7
%27 = sext i8 %26 to i32
switch i32 %27, label %88 [
i32 101, label %28
i32 100, label %41
]
28: ; preds = %17
%29 = load i32, i32* %11
%30 = icmp sge i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32, i32* %10
%33 = add nsw i32 %32, 1
store i32 %33, i32* %10
br label %40
34: ; preds = %28
%35 = load i8*, i8** %6
%36 = load i32, i32* %10
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 0, i8* %38
%39 = load i32, i32* %10
store i32 %39, i32* %5
br label %97
40: ; preds = %31
br label %94
41: ; preds = %17
%42 = load i32, i32* %11
%43 = icmp eq i32 %42, 10
br i1 %43, label %44, label %49
44: ; preds = %41
%45 = load i8*, i8** %6
%46 = load i32, i32* %10
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
store i8 0, i8* %48
br label %94
49: ; preds = %41
%50 = load i32, i32* %11
%51 = icmp eq i32 %50, 61
br i1 %51, label %73, label %52
52: ; preds = %49
%53 = load i32, i32* %11
%54 = icmp eq i32 %53, 43
br i1 %54, label %73, label %55
55: ; preds = %52
%56 = load i32, i32* %11
%57 = icmp sge i32 %56, 47
br i1 %57, label %58, label %61
58: ; preds = %55
%59 = load i32, i32* %11
%60 = icmp sle i32 %59, 57
br i1 %60, label %73, label %61
61: ; preds = %58, %55
%62 = load i32, i32* %11
%63 = icmp sge i32 %62, 65
br i1 %63, label %64, label %67
64: ; preds = %61
%65 = load i32, i32* %11
%66 = icmp sle i32 %65, 90
br i1 %66, label %73, label %67
67: ; preds = %64, %61
%68 = load i32, i32* %11
%69 = icmp sge i32 %68, 97
br i1 %69, label %70, label %76
70: ; preds = %67
%71 = load i32, i32* %11
%72 = icmp sle i32 %71, 122
br i1 %72, label %73, label %76
73: ; preds = %70, %64, %58, %52, %49
%74 = load i32, i32* %10
%75 = add nsw i32 %74, 1
store i32 %75, i32* %10
br label %86
76: ; preds = %70, %67
%77 = load i32, i32* %11
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %85
79: ; preds = %76
%80 = load i8*, i8** %6
%81 = load i32, i32* %10
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %80, i64 %82
store i8 0, i8* %83
%84 = load i32, i32* %10
store i32 %84, i32* %5
br label %97
85: ; preds = %76
store i32 -1, i32* %5
br label %97
86: ; preds = %73
br label %87
87: ; preds = %86
br label %94
88: ; preds = %17
%89 = load i32, i32* @stderr
%90 = call i32 @fprintf(i32 %89, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%91 = load i32*, i32** %9
%92 = call i32 @fclose(i32* %91)
%93 = call i32 @exit(i32 -1)
unreachable
94: ; preds = %87, %44, %40
br label %12
95: ; preds = %12
%96 = load i32, i32* %10
store i32 %96, i32* %5
br label %97
97: ; preds = %95, %85, %79, %34
%98 = load i32, i32* %5
ret i32 %98
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"ERR: b64read invalid mode\0A\00"
define i32 @b64read(i8* nocapture writeonly %0, i8 signext %1, i64 %2, i32* nocapture %3) {
%5 = icmp eq i64 %2, 0
br i1 %5, label %41, label %6
6: ; preds = %4
%7 = sext i8 %1 to i32
br label %8
8: ; preds = %6, %36
%9 = phi i64 [ 0, %6 ], [ %38, %36 ]
%10 = phi i32 [ 0, %6 ], [ %37, %36 ]
%11 = tail call i32 @fgetc(i32* %3)
%12 = trunc i32 %11 to i8
%13 = getelementptr inbounds i8, i8* %0, i64 %9
store i8 %12, i8* %13
switch i32 %7, label %31 [
i32 101, label %14
i32 100, label %18
]
14: ; preds = %8
%15 = icmp sgt i32 %11, -1
br i1 %15, label %16, label %40
16: ; preds = %14
%17 = add nsw i32 %10, 1
br label %36
18: ; preds = %8
switch i32 %11, label %20 [
i32 10, label %19
i32 61, label %27
i32 43, label %27
]
19: ; preds = %18
store i8 0, i8* %13
br label %36
20: ; preds = %18
%21 = add i32 %11, -47
%22 = icmp ult i32 %21, 11
%23 = and i32 %11, -33
%24 = add i32 %23, -65
%25 = icmp ult i32 %24, 26
%26 = or i1 %22, %25
br i1 %26, label %27, label %29
27: ; preds = %18, %18, %20
%28 = add nsw i32 %10, 1
br label %36
29: ; preds = %20
%30 = icmp eq i32 %11, -1
br i1 %30, label %40, label %41
31: ; preds = %8
%32 = load i32, i32* @stderr
%33 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%34 = tail call i32 @fclose(i32* %3)
%35 = tail call i32 @exit(i32 -1)
unreachable
36: ; preds = %27, %19, %16
%37 = phi i32 [ %10, %19 ], [ %28, %27 ], [ %17, %16 ]
%38 = sext i32 %37 to i64
%39 = icmp ult i64 %38, %2
br i1 %39, label %8, label %41
40: ; preds = %14, %29
store i8 0, i8* %13
br label %41
41: ; preds = %36, %40, %4, %29
%42 = phi i32 [ -1, %29 ], [ 0, %4 ], [ %10, %40 ], [ %37, %36 ]
ret i32 %42
}