#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*/ errno;
scalar_t__ ferror(int /*<<< orphan*/ *);
size_t fread(unsigned char *, int, unsigned int, int /*<<< orphan*/ *);
int /*<<< orphan*/ panic(char *);
char *strerror(int /*<<< orphan*/);
void read_block(unsigned char *dest, unsigned size, FILE *f) {
  while (0 < size) {
    size_t n = fread(dest, 1, size, f);
    if (0 == n)
      panic(ferror(f) ? strerror(errno) : "Premature EOF in read_block");
    dest += n, size -= n;
  }
}


x86 assembly (clang, -O0):
<read_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
jae    11e4 <read_block+0xa4>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    11c6 <read_block+0x86>
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11ad <read_block+0x6d>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,-0x28(%rbp)
jmp    11bd <read_block+0x7d>
lea    0xe4c(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11bd <read_block+0x7d>
mov    -0x28(%rbp),%rdi
call   1050 <panic@plt>
mov    -0x20(%rbp),%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0xc(%rbp),%eax
sub    %rcx,%rax
mov    %eax,-0xc(%rbp)
jmp    1153 <read_block+0x13>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_block>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     11b5 <read_block+0x75>
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xea2(%rip),%r12
mov    0x2e7b(%rip),%r13
jmp    117d <read_block+0x3d>
nopw   0x0(%rax,%rax,1)
call   1050 <panic@plt>
add    %r15,%rbx
sub    %r15d,%ebp
je     11b5 <read_block+0x75>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1175 <read_block+0x35>
mov    %r14,%rdi
call   1030 <ferror@plt>
mov    %r12,%rdi
test   %rax,%rax
je     1170 <read_block+0x30>
mov    0x0(%r13),%edi
call   1060 <strerror@plt>
mov    %rax,%rdi
jmp    1170 <read_block+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@.str = [28 x i8] c"Premature EOF in read_block\00"
define void @read_block(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i64
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
br label %8
8: ; preds = %29, %3
%9 = load i32, i32* %5
%10 = icmp ult i32 0, %9
br i1 %10, label %11, label %38
11: ; preds = %8
%12 = load i8*, i8** %4
%13 = load i32, i32* %5
%14 = load i32*, i32** %6
%15 = call i64 @fread(i8* %12, i32 1, i32 %13, i32* %14)
store i64 %15, i64* %7
%16 = load i64, i64* %7
%17 = icmp eq i64 0, %16
br i1 %17, label %18, label %29
18: ; preds = %11
%19 = load i32*, i32** %6
%20 = call i64 @ferror(i32* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
br label %26
25: ; preds = %18
br label %26
26: ; preds = %25, %22
%27 = phi i8* [ %24, %22 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), %25 ]
%28 = call i32 @panic(i8* %27)
br label %29
29: ; preds = %26, %11
%30 = load i64, i64* %7
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i64 %30
store i8* %32, i8** %4
%33 = load i64, i64* %7
%34 = load i32, i32* %5
%35 = zext i32 %34 to i64
%36 = sub i64 %35, %33
%37 = trunc i64 %36 to i32
store i32 %37, i32* %5
br label %8
38: ; preds = %8
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [28 x i8] c"Premature EOF in read_block\00"
define void @read_block(i8* nocapture %0, i32 %1, i32* nocapture %2) {
%4 = icmp eq i32 %1, 0
br i1 %4, label %24, label %5
5: ; preds = %3, %19
%6 = phi i8* [ %20, %19 ], [ %0, %3 ]
%7 = phi i32 [ %22, %19 ], [ %1, %3 ]
%8 = tail call i64 @fread(i8* %6, i32 1, i32 %7, i32* %2)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %5
%11 = tail call i64 @ferror(i32* %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = load i32, i32* @errno
%15 = tail call i8* @strerror(i32 %14)
br label %16
16: ; preds = %10, %13
%17 = phi i8* [ %15, %13 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), %10 ]
%18 = tail call i32 @panic(i8* %17)
br label %19
19: ; preds = %16, %5
%20 = getelementptr inbounds i8, i8* %6, i64 %8
%21 = trunc i64 %8 to i32
%22 = sub i32 %7, %21
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %5
24: ; preds = %19, %3
ret void
}