#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*/ *);
int fread(void *, int, int, int /*<<< orphan*/ *);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
char *strerror(int /*<<< orphan*/);
int sisRead(FILE *fp, void *ptr, int len, char *err, int errlen) {
  int nread;
  nread = fread(ptr, 1, len, fp);
  if (nread != len) {
    if (ferror(fp)) {
      snprintf(err, errlen, "Error reading from file: %s", strerror(errno));
      return 1;
    } else {
      int offset = ftell(fp);
      snprintf(
          err, errlen,
          "Unexpected EOF or short read (%d bytes of %d retured at offset %d)",
          nread, len, offset);
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<sisRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     121a <sisRead+0xca>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11e2 <sisRead+0x92>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%esi
mov    %rax,%rcx
lea    0xe31(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1221 <sisRead+0xd1>
mov    -0x10(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    -0x34(%rbp),%r9d
lea    0xe15(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1221 <sisRead+0xd1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sisRead>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%r14d
mov    %rcx,%r15
mov    %edx,%ebp
mov    %rdi,%rbx
mov    %rsi,%rdi
mov    $0x1,%esi
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %eax,%r12d
xor    %eax,%eax
cmp    %ebp,%r12d
je     11db <sisRead+0x8b>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     11b1 <sisRead+0x61>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe61(%rip),%rdx
mov    %r15,%rdi
mov    %r14d,%esi
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <snprintf@plt>
jmp    11d6 <sisRead+0x86>
mov    %rbx,%rdi
call   1060 <ftell@plt>
lea    0xe5c(%rip),%rdx
mov    %r15,%rdi
mov    %r14d,%esi
mov    %r12d,%ecx
mov    %ebp,%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   1050 <snprintf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Error reading from file: %s\00"
@errno = global i32 0
@.str.1 = [67 x i8] c"Unexpected EOF or short read (%d bytes of %d retured at offset %d)\00"
define i32 @sisRead(i32* %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
%14 = load i8*, i8** %8
%15 = load i32, i32* %9
%16 = load i32*, i32** %7
%17 = call i32 @fread(i8* %14, i32 1, i32 %15, i32* %16)
store i32 %17, i32* %12
%18 = load i32, i32* %12
%19 = load i32, i32* %9
%20 = icmp ne i32 %18, %19
br i1 %20, label %21, label %40
21: ; preds = %5
%22 = load i32*, i32** %7
%23 = call i64 @ferror(i32* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %21
%26 = load i8*, i8** %10
%27 = load i32, i32* %11
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
%30 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %26, i32 %27, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %29)
store i32 1, i32* %6
br label %41
31: ; preds = %21
%32 = load i32*, i32** %7
%33 = call i32 @ftell(i32* %32)
store i32 %33, i32* %13
%34 = load i8*, i8** %10
%35 = load i32, i32* %11
%36 = load i32, i32* %12
%37 = load i32, i32* %9
%38 = load i32, i32* %13
%39 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %34, i32 %35, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0), i32 %36, i32 %37, i32 %38)
store i32 1, i32* %6
br label %41
40: ; preds = %5
store i32 0, i32* %6
br label %41
41: ; preds = %40, %31, %25
%42 = load i32, i32* %6
ret i32 %42
}

LLVM IR (-O2):
@.str = [28 x i8] c"Error reading from file: %s\00"
@errno = global i32 0
@.str.1 = [67 x i8] c"Unexpected EOF or short read (%d bytes of %d retured at offset %d)\00"
define i32 @sisRead(i32* nocapture %0, i8* nocapture %1, i32 %2, i8* %3, i32 %4) {
%6 = tail call i32 @fread(i8* %1, i32 1, i32 %2, i32* %0)
%7 = icmp eq i32 %6, %2
br i1 %7, label %18, label %8
8: ; preds = %5
%9 = tail call i64 @ferror(i32* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = load i32, i32* @errno
%13 = tail call i8* @strerror(i32 %12)
%14 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %3, i32 %4, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %18
15: ; preds = %8
%16 = tail call i32 @ftell(i32* %0)
%17 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %3, i32 %4, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0), i32 %6, i32 %2, i32 %16)
br label %18
18: ; preds = %5, %15, %11
%19 = phi i32 [ 1, %11 ], [ 1, %15 ], [ 0, %5 ]
ret i32 %19
}