#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*/ err_fatal_simple_core(char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
size_t fread(void *, size_t, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
size_t err_fread(void *ptr, size_t size, size_t nmemb, FILE *stream) {
  size_t ret = fread(ptr, size, nmemb, stream);
  if (ret != nmemb) {
    err_fatal_simple_core("fread", strerror(errno));
  }
  return ret;
}


x86 assembly (clang, -O0):
<err_fread>:
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     118b <err_fread+0x5b>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %eax,%esi
lea    0xe7a(%rip),%rdi
call   1040 <err_fatal_simple_core@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<err_fread>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
call   1030 <fread@plt>
mov    %rax,%r14
cmp    %rbx,%rax
je     1160 <err_fread+0x30>
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xea7(%rip),%rdi
mov    %eax,%esi
call   1040 <err_fatal_simple_core@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"fread\00"
@errno = global i32 0
define i64 @err_fread(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 %22
18: ; preds = %4
%19 = load i32, i32* @errno
%20 = call i32 @strerror(i32 %19)
%21 = call i32 @err_fatal_simple_core(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %18, %4
%23 = load i64, i64* %9
ret i64 %23
}

LLVM IR (-O2):
@.str = [6 x i8] c"fread\00"
@errno = global i32 0
define i64 @err_fread(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 %11, label %7
7: ; preds = %4
%8 = load i32, i32* @errno
%9 = tail call i32 @strerror(i32 %8)
%10 = tail call i32 @err_fatal_simple_core(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %7, %4
ret i64 %5
}