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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
unsigned int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
unsigned char get(FILE *f) {
  static unsigned char buf[8192];
  static unsigned high = 0, next = 0;
  if (next >= high) {
    next = 0;
    high = fread(buf, 1, sizeof(buf), f);
    if (high < 0) {
      perror("fread() failed");
      exit(1);
    } else if (high == 0)
      return (0);
  }
  return buf[next++];
}


x86 assembly (clang, -O0):
<get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x4f12(%rip),%eax
cmp    0x4f08(%rip),%eax
jb     11bb <get+0x8b>
movl   $0x0,0x4efc(%rip)
mov    -0x10(%rbp),%rcx
lea    0x2eed(%rip),%rdi
mov    $0x1,%esi
mov    $0x2000,%edx
call   1030 <fread@plt>
mov    %eax,0x4ed8(%rip)
cmpl   $0x0,0x4ed1(%rip)
jae    119b <get+0x6b>
lea    0xe74(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
cmpl   $0x0,0x4eae(%rip)
jne    11b1 <get+0x81>
movb   $0x0,-0x1(%rbp)
jmp    11dd <get+0xad>
jmp    11b6 <get+0x86>
jmp    11bb <get+0x8b>
mov    0x4e93(%rip),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,0x4e88(%rip)
mov    %eax,%eax
mov    %eax,%ecx
lea    0x2e79(%rip),%rax
mov    (%rax,%rcx,1),%al
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get>:
push   %rax
mov    0x4f2d(%rip),%eax
cmp    0x4f23(%rip),%eax
jb     1152 <get+0x42>
mov    %rdi,%rcx
movl   $0x0,0x4f18(%rip)
lea    0x2f0d(%rip),%rdi
mov    $0x1,%esi
mov    $0x2000,%edx
call   1030 <fread@plt>
mov    %eax,0x4ef8(%rip)
test   %eax,%eax
je     1169 <get+0x59>
mov    0x4ef2(%rip),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x4ee9(%rip)
mov    %eax,%eax
lea    0x2edc(%rip),%rcx
mov    (%rax,%rcx,1),%al
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@get.buf = internal global [8192 x i8] zeroinitializer
@get.high = internal global i32 0
@get.next = internal global i32 0
@.str = [15 x i8] c"fread() failed\00"
define zeroext i8 @get(i32* %0) {
%2 = alloca i8
%3 = alloca i32*
store i32* %0, i32** %3
%4 = load i32, i32* @get.next
%5 = load i32, i32* @get.high
%6 = icmp uge i32 %4, %5
br i1 %6, label %7, label %21
7: ; preds = %1
store i32 0, i32* @get.next
%8 = load i32*, i32** %3
%9 = call i32 @fread(i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @get.buf, i64 0, i64 0), i32 1, i32 8192, i32* %8)
store i32 %9, i32* @get.high
%10 = load i32, i32* @get.high
%11 = icmp ult i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %7
%16 = load i32, i32* @get.high
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %15
store i8 0, i8* %2
br label %27
19: ; preds = %15
br label %20
20: ; preds = %19
br label %21
21: ; preds = %20, %1
%22 = load i32, i32* @get.next
%23 = add i32 %22, 1
store i32 %23, i32* @get.next
%24 = zext i32 %22 to i64
%25 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get.buf, i64 0, i64 %24
%26 = load i8, i8* %25
store i8 %26, i8* %2
br label %27
27: ; preds = %21, %18
%28 = load i8, i8* %2
ret i8 %28
}

LLVM IR (-O2):
@get.buf = internal global [8192 x i8] zeroinitializer
@get.high = internal unnamed_addr global i32 0
@get.next = internal unnamed_addr global i32 0
define zeroext i8 @get(i32* nocapture %0) {
%2 = load i32, i32* @get.next
%3 = load i32, i32* @get.high
%4 = icmp ult i32 %2, %3
br i1 %4, label %10, label %5
5: ; preds = %1
store i32 0, i32* @get.next
%6 = tail call i32 @fread(i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @get.buf, i64 0, i64 0), i32 1, i32 8192, i32* %0)
store i32 %6, i32* @get.high
%7 = icmp eq i32 %6, 0
br i1 %7, label %16, label %8
8: ; preds = %5
%9 = load i32, i32* @get.next
br label %10
10: ; preds = %8, %1
%11 = phi i32 [ %9, %8 ], [ %2, %1 ]
%12 = add i32 %11, 1
store i32 %12, i32* @get.next
%13 = zext i32 %11 to i64
%14 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get.buf, i64 0, i64 %13
%15 = load i8, i8* %14
br label %16
16: ; preds = %5, %10
%17 = phi i8 [ %15, %10 ], [ 0, %5 ]
ret i8 %17
}