#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned long,
                           unsigned long, unsigned long);
size_t fread(void *, size_t, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void xfread(void *ptr, size_t size, size_t nmemb, FILE *stream) {
  size_t r = fread(ptr, size, nmemb, stream);
  if (r != nmemb) {
    fprintf(
        stderr,
        "error: expected to read %lu elements of size %lu but received %lu\n",
        (unsigned long)nmemb, (unsigned long)size, (unsigned long)r);
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<xfread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1030 <fread@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     119e <xfread+0x6e>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xe75(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xfread>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
call   1030 <fread@plt>
cmp    %rbx,%rax
jne    114c <xfread+0x1c>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e8d(%rip),%rcx
mov    (%rcx),%edi
lea    0xea4(%rip),%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
mov    %rax,%r8
call   1040 <fprintf@plt>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [67 x i8] c"error: expected to read %lu elements of size %lu but received %lu\0A\00"
@EXIT_FAILURE = global i32 0
define void @xfread(i8* %0, i64 %1, i64 %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i32* %3, i32** %8
%10 = load i8*, i8** %5
%11 = load i64, i64* %6
%12 = load i64, i64* %7
%13 = load i32*, i32** %8
%14 = call i64 @fread(i8* %10, i64 %11, i64 %12, i32* %13)
store i64 %14, i64* %9
%15 = load i64, i64* %9
%16 = load i64, i64* %7
%17 = icmp ne i64 %15, %16
br i1 %17, label %18, label %26
18: ; preds = %4
%19 = load i32, i32* @stderr
%20 = load i64, i64* %7
%21 = load i64, i64* %6
%22 = load i64, i64* %9
%23 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i64 %20, i64 %21, i64 %22)
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %4
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [67 x i8] c"error: expected to read %lu elements of size %lu but received %lu\0A\00"
@EXIT_FAILURE = global i32 0
define void @xfread(i8* nocapture %0, i64 %1, i64 %2, i32* nocapture %3) {
%5 = tail call i64 @fread(i8* %0, i64 %1, i64 %2, i32* %3)
%6 = icmp eq i64 %5, %2
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i64 %2, i64 %1, i64 %5)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %4
ret void
}