#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*/ error(char *);
size_t fread(unsigned char *, int, int, int /*<<< orphan*/ *);
unsigned char getByte(FILE *in) {
  static unsigned char readBuffer[4 * 1024];
  static size_t pos = 0;
  static size_t available = 0;
  if (pos == available) {
    pos = 0;
    available = fread(readBuffer, 1, 4 * 1024, in);
    if (available == 0)
      error("out of data");
  }
  return readBuffer[pos++];
}


x86 assembly (clang, -O0):
<getByte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x3f0d(%rip),%rax
cmp    0x3f0e(%rip),%rax
jne    118b <getByte+0x6b>
movq   $0x0,0x3ef5(%rip)
mov    -0x8(%rbp),%rcx
lea    0x2eea(%rip),%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
mov    %rax,0x3edc(%rip)
cmpq   $0x0,0x3ed4(%rip)
jne    1186 <getByte+0x66>
lea    0xe7f(%rip),%rdi
call   1040 <error@plt>
jmp    118b <getByte+0x6b>
mov    0x3eae(%rip),%rcx
mov    %rcx,%rax
add    $0x1,%rax
mov    %rax,0x3ea0(%rip)
lea    0x2e99(%rip),%rax
movzbl (%rax,%rcx,1),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getByte>:
push   %rax
mov    0x3f18(%rip),%rax
cmp    0x3f19(%rip),%rax
jne    116d <getByte+0x4d>
mov    %rdi,%rcx
movq   $0x0,0x3f01(%rip)
lea    0x2efa(%rip),%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
mov    %rax,0x3eec(%rip)
test   %rax,%rax
jne    116d <getByte+0x4d>
lea    0xe98(%rip),%rdi
call   1040 <error@plt>
mov    0x3ecc(%rip),%rax
lea    0x1(%rax),%rcx
mov    %rcx,0x3ec1(%rip)
lea    0x2eba(%rip),%rcx
mov    (%rax,%rcx,1),%al
pop    %rcx
ret

LLVM IR (-O0):
@getByte.readBuffer = internal global [4096 x i8] zeroinitializer
@getByte.pos = internal global i64 0
@getByte.available = internal global i64 0
@.str = [12 x i8] c"out of data\00"
define zeroext i8 @getByte(i32* %0) {
%2 = alloca i32*
store i32* %0, i32** %2
%3 = load i64, i64* @getByte.pos
%4 = load i64, i64* @getByte.available
%5 = icmp eq i64 %3, %4
br i1 %5, label %6, label %14
6: ; preds = %1
store i64 0, i64* @getByte.pos
%7 = load i32*, i32** %2
%8 = call i64 @fread(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @getByte.readBuffer, i64 0, i64 0), i32 1, i32 4096, i32* %7)
store i64 %8, i64* @getByte.available
%9 = load i64, i64* @getByte.available
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = call i32 @error(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %6
br label %14
14: ; preds = %13, %1
%15 = load i64, i64* @getByte.pos
%16 = add i64 %15, 1
store i64 %16, i64* @getByte.pos
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* @getByte.readBuffer, i64 0, i64 %15
%18 = load i8, i8* %17
ret i8 %18
}

LLVM IR (-O2):
@getByte.readBuffer = internal global [4096 x i8] zeroinitializer
@getByte.pos = internal unnamed_addr global i64 0
@getByte.available = internal unnamed_addr global i64 0
@.str = [12 x i8] c"out of data\00"
define zeroext i8 @getByte(i32* nocapture %0) {
%2 = load i64, i64* @getByte.pos
%3 = load i64, i64* @getByte.available
%4 = icmp eq i64 %2, %3
br i1 %4, label %5, label %10
5: ; preds = %1
store i64 0, i64* @getByte.pos
%6 = tail call i64 @fread(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @getByte.readBuffer, i64 0, i64 0), i32 1, i32 4096, i32* %0)
store i64 %6, i64* @getByte.available
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @error(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %5, %8, %1
%11 = load i64, i64* @getByte.pos
%12 = add i64 %11, 1
store i64 %12, i64* @getByte.pos
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* @getByte.readBuffer, i64 0, i64 %11
%14 = load i8, i8* %13
ret i8 %14
}