#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 EOF;
int /*<<< orphan*/ errno;
scalar_t__ ferror(int /*<<< orphan*/ *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ panic(char *);
char *strerror(int /*<<< orphan*/);
unsigned read8(FILE *f) {
  int result = getc(f);
  if (EOF == result)
    panic(ferror(f) ? strerror(errno) : "Premature EOF in read8");
  return 0xFF & result;
}


x86 assembly (clang, -O0):
<read8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <getc@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e89(%rip),%rax
mov    (%rax),%eax
cmp    -0xc(%rbp),%eax
jne    11ad <read8+0x6d>
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1194 <read8+0x54>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,-0x18(%rbp)
jmp    11a4 <read8+0x64>
lea    0xe65(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11a4 <read8+0x64>
mov    -0x18(%rbp),%rdi
call   1040 <panic@plt>
mov    -0xc(%rbp),%eax
and    $0xff,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read8>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1060 <getc@plt>
mov    %eax,%ebp
mov    0x2e94(%rip),%rax
cmp    %ebp,(%rax)
jne    1184 <read8+0x44>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     1178 <read8+0x38>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,%rdi
jmp    117f <read8+0x3f>
lea    0xe81(%rip),%rdi
call   1040 <panic@plt>
movzbl %bpl,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
@errno = global i32 0
@.str = [23 x i8] c"Premature EOF in read8\00"
define i32 @read8(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
store i32* %0, i32** %2
%4 = load i32*, i32** %2
%5 = call i32 @getc(i32* %4)
store i32 %5, i32* %3
%6 = load i32, i32* @EOF
%7 = load i32, i32* %3
%8 = icmp eq i32 %6, %7
br i1 %8, label %9, label %20
9: ; preds = %1
%10 = load i32*, i32** %2
%11 = call i64 @ferror(i32* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
br label %17
16: ; preds = %9
br label %17
17: ; preds = %16, %13
%18 = phi i8* [ %15, %13 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), %16 ]
%19 = call i32 @panic(i8* %18)
br label %20
20: ; preds = %17, %1
%21 = load i32, i32* %3
%22 = and i32 255, %21
ret i32 %22
}

LLVM IR (-O2):
@EOF = global i32 0
@errno = global i32 0
@.str = [23 x i8] c"Premature EOF in read8\00"
define i32 @read8(i32* nocapture %0) {
%2 = tail call i32 @getc(i32* %0)
%3 = load i32, i32* @EOF
%4 = icmp eq i32 %3, %2
br i1 %4, label %5, label %14
5: ; preds = %1
%6 = tail call i64 @ferror(i32* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
br label %11
11: ; preds = %5, %8
%12 = phi i8* [ %10, %8 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), %5 ]
%13 = tail call i32 @panic(i8* %12)
br label %14
14: ; preds = %11, %1
%15 = and i32 %2, 255
ret i32 %15
}