#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 get_next_char();
int base64_get_next_byte(void) {
  static int buffer;
  static int buffer_pos = 0;
  int ret = -1;
  int next = get_next_char();
  if (next < 0)
    return -1;
  if (buffer_pos == 0) {
    ret = (next << 2) & 0xfc;
    if ((next = get_next_char()) < 0)
      return -1;
    ret |= (next >> 4) & 0x03;
    buffer = (next << 4) & 0xf0;
    buffer_pos = 1;
  } else if (buffer_pos == 1) {
    ret = buffer | ((next >> 2) & 0x0f);
    buffer = (next << 6) & 0xc0;
    buffer_pos = 2;
  } else if (buffer_pos == 2) {
    ret = buffer | (next & 0x3f);
    buffer_pos = 0;
  }
  return ret;
}


x86 assembly (clang, -O0):
<base64_get_next_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0xffffffff,-0x8(%rbp)
mov    $0x0,%al
call   1030 <get_next_char@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    113f <base64_get_next_byte+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1221 <base64_get_next_byte+0x111>
cmpl   $0x0,0x2eea(%rip)
jne    11a8 <base64_get_next_byte+0x98>
mov    -0xc(%rbp),%eax
shl    $0x2,%eax
and    $0xfc,%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <get_next_char@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1179 <base64_get_next_byte+0x69>
movl   $0xffffffff,-0x4(%rbp)
jmp    1221 <base64_get_next_byte+0x111>
mov    -0xc(%rbp),%eax
sar    $0x4,%eax
and    $0x3,%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x4,%eax
and    $0xf0,%eax
mov    %eax,0x2e93(%rip)
movl   $0x1,0x2e8d(%rip)
jmp    121b <base64_get_next_byte+0x10b>
cmpl   $0x1,0x2e81(%rip)
jne    11e9 <base64_get_next_byte+0xd9>
mov    0x2e71(%rip),%eax
mov    -0xc(%rbp),%ecx
sar    $0x2,%ecx
and    $0xf,%ecx
or     %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x6,%eax
and    $0xc0,%eax
mov    %eax,0x2e52(%rip)
movl   $0x2,0x2e4c(%rip)
jmp    1216 <base64_get_next_byte+0x106>
cmpl   $0x2,0x2e40(%rip)
jne    1211 <base64_get_next_byte+0x101>
mov    0x2e30(%rip),%eax
mov    -0xc(%rbp),%ecx
and    $0x3f,%ecx
or     %ecx,%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,0x2e1f(%rip)
jmp    1216 <base64_get_next_byte+0x106>
jmp    121b <base64_get_next_byte+0x10b>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64_get_next_byte>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <get_next_char@plt>
mov    $0xffffffff,%ebp
test   %eax,%eax
js     1194 <base64_get_next_byte+0x84>
mov    %eax,%ebx
mov    0x2f05(%rip),%eax
cmp    $0x1,%eax
je     1160 <base64_get_next_byte+0x50>
test   %eax,%eax
jne    1181 <base64_get_next_byte+0x71>
xor    %eax,%eax
call   1030 <get_next_char@plt>
test   %eax,%eax
js     1194 <base64_get_next_byte+0x84>
and    $0x3f,%ebx
mov    %eax,%ecx
shr    $0x4,%ecx
and    $0x3,%ecx
lea    (%rcx,%rbx,4),%ebp
shl    $0x4,%eax
movzbl %al,%eax
mov    %eax,0x2ed3(%rip)
mov    $0x1,%eax
jmp    118e <base64_get_next_byte+0x7e>
mov    %ebx,%ebp
shr    $0x2,%ebp
and    $0xf,%ebp
or     0x2ebe(%rip),%ebp
shl    $0x6,%ebx
movzbl %bl,%eax
mov    %eax,0x2eb2(%rip)
mov    $0x2,%eax
jmp    118e <base64_get_next_byte+0x7e>
and    $0x3f,%ebx
or     0x2ea2(%rip),%ebx
xor    %eax,%eax
mov    %ebx,%ebp
mov    %eax,0x2e9c(%rip)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@base64_get_next_byte.buffer = internal global i32 0
@base64_get_next_byte.buffer_pos = internal global i32 0
define i32 @base64_get_next_byte() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 -1, i32* %2
%4 = call i32 (...) @get_next_char()
store i32 %4, i32* %3
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %0
store i32 -1, i32* %1
br label %51
8: ; preds = %0
%9 = load i32, i32* @base64_get_next_byte.buffer_pos
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %8
%12 = load i32, i32* %3
%13 = shl i32 %12, 2
%14 = and i32 %13, 252
store i32 %14, i32* %2
%15 = call i32 (...) @get_next_char()
store i32 %15, i32* %3
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %11
store i32 -1, i32* %1
br label %51
18: ; preds = %11
%19 = load i32, i32* %3
%20 = ashr i32 %19, 4
%21 = and i32 %20, 3
%22 = load i32, i32* %2
%23 = or i32 %22, %21
store i32 %23, i32* %2
%24 = load i32, i32* %3
%25 = shl i32 %24, 4
%26 = and i32 %25, 240
store i32 %26, i32* @base64_get_next_byte.buffer
store i32 1, i32* @base64_get_next_byte.buffer_pos
br label %49
27: ; preds = %8
%28 = load i32, i32* @base64_get_next_byte.buffer_pos
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %39
30: ; preds = %27
%31 = load i32, i32* @base64_get_next_byte.buffer
%32 = load i32, i32* %3
%33 = ashr i32 %32, 2
%34 = and i32 %33, 15
%35 = or i32 %31, %34
store i32 %35, i32* %2
%36 = load i32, i32* %3
%37 = shl i32 %36, 6
%38 = and i32 %37, 192
store i32 %38, i32* @base64_get_next_byte.buffer
store i32 2, i32* @base64_get_next_byte.buffer_pos
br label %48
39: ; preds = %27
%40 = load i32, i32* @base64_get_next_byte.buffer_pos
%41 = icmp eq i32 %40, 2
br i1 %41, label %42, label %47
42: ; preds = %39
%43 = load i32, i32* @base64_get_next_byte.buffer
%44 = load i32, i32* %3
%45 = and i32 %44, 63
%46 = or i32 %43, %45
store i32 %46, i32* %2
store i32 0, i32* @base64_get_next_byte.buffer_pos
br label %47
47: ; preds = %42, %39
br label %48
48: ; preds = %47, %30
br label %49
49: ; preds = %48, %18
%50 = load i32, i32* %2
store i32 %50, i32* %1
br label %51
51: ; preds = %49, %17, %7
%52 = load i32, i32* %1
ret i32 %52
}

LLVM IR (-O2):
@base64_get_next_byte.buffer = internal unnamed_addr global i32 0
@base64_get_next_byte.buffer_pos = internal unnamed_addr global i32 0
define i32 @base64_get_next_byte() {
%1 = tail call i32 (...) @get_next_char()
%2 = icmp slt i32 %1, 0
br i1 %2, label %30, label %3
3: ; preds = %0
%4 = load i32, i32* @base64_get_next_byte.buffer_pos
switch i32 %4, label %23 [
i32 0, label %5
i32 1, label %16
]
5: ; preds = %3
%6 = tail call i32 (...) @get_next_char()
%7 = icmp slt i32 %6, 0
br i1 %7, label %30, label %8
8: ; preds = %5
%9 = shl i32 %1, 2
%10 = and i32 %9, 252
%11 = lshr i32 %6, 4
%12 = and i32 %11, 3
%13 = or i32 %12, %10
%14 = shl i32 %6, 4
%15 = and i32 %14, 240
store i32 %15, i32* @base64_get_next_byte.buffer
br label %27
16: ; preds = %3
%17 = load i32, i32* @base64_get_next_byte.buffer
%18 = lshr i32 %1, 2
%19 = and i32 %18, 15
%20 = or i32 %17, %19
%21 = shl i32 %1, 6
%22 = and i32 %21, 192
store i32 %22, i32* @base64_get_next_byte.buffer
br label %27
23: ; preds = %3
%24 = load i32, i32* @base64_get_next_byte.buffer
%25 = and i32 %1, 63
%26 = or i32 %24, %25
br label %27
27: ; preds = %16, %23, %8
%28 = phi i32 [ 1, %8 ], [ 0, %23 ], [ 2, %16 ]
%29 = phi i32 [ %13, %8 ], [ %26, %23 ], [ %20, %16 ]
store i32 %28, i32* @base64_get_next_byte.buffer_pos
br label %30
30: ; preds = %27, %5, %0
%31 = phi i32 [ -1, %0 ], [ -1, %5 ], [ %29, %27 ]
ret i32 %31
}