#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(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, void *, int, int, int);
int fread(void *, size_t, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
void read_from_file_or_die(void *ptr, size_t size, size_t nmemb, FILE *fp) {
  int rv = fread(ptr, size, nmemb, fp);
  if (rv != nmemb) {
    perror("fread");
    fprintf(stderr, "ptr=%p size=%d nmemb=%d rv=%d\n", ptr, (int)size,
            (int)nmemb, (int)rv);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<read_from_file_or_die>:
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    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     11be <read_from_file_or_die+0x7e>
lea    0xe7b(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %eax,%r8d
mov    -0x24(%rbp),%r9d
lea    0xe57(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_from_file_or_die>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <fread@plt>
mov    %eax,%ebp
cltq
cmp    %rbx,%rax
jne    1169 <read_from_file_or_die+0x29>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe90(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    0xe81(%rip),%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
mov    %ebx,%r8d
mov    %ebp,%r9d
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"fread\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"ptr=%p size=%d nmemb=%d rv=%d\0A\00"
define void @read_from_file_or_die(i8* %0, i64 %1, i64 %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i32
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 i32 @fread(i8* %10, i64 %11, i64 %12, i32* %13)
store i32 %14, i32* %9
%15 = load i32, i32* %9
%16 = sext i32 %15 to i64
%17 = load i64, i64* %7
%18 = icmp ne i64 %16, %17
br i1 %18, label %19, label %30
19: ; preds = %4
%20 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %5
%23 = load i64, i64* %6
%24 = trunc i64 %23 to i32
%25 = load i64, i64* %7
%26 = trunc i64 %25 to i32
%27 = load i32, i32* %9
%28 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %22, i32 %24, i32 %26, i32 %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %4
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"fread\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"ptr=%p size=%d nmemb=%d rv=%d\0A\00"
define void @read_from_file_or_die(i8* %0, i64 %1, i64 %2, i32* nocapture %3) {
%5 = tail call i32 @fread(i8* %0, i64 %1, i64 %2, i32* %3)
%6 = sext i32 %5 to i64
%7 = icmp eq i64 %6, %2
br i1 %7, label %15, label %8
8: ; preds = %4
%9 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @stderr
%11 = trunc i64 %1 to i32
%12 = trunc i64 %2 to i32
%13 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %11, i32 %12, i32 %5)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %4
ret void
}