#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*/ fprintf(int /*<<< orphan*/, char *, int, int);
int fread(void *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int read_bytes(void *target, size_t length, FILE *file, int x, int y) {
  int bytesIn = fread(target, 1, length, file);
  if (bytesIn < length) {
    fprintf(stderr, "Short read on record %d field %d\n", y, x);
    return -1;
  }
  return bytesIn;
}


x86 assembly (clang, -O0):
<read_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1189 <read_bytes+0x69>
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
lea    0xe88(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    118f <read_bytes+0x6f>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_bytes>:
push   %rbp
push   %r14
push   %rbx
mov    %r8d,%ebp
mov    %ecx,%r14d
mov    %rdx,%rcx
mov    %rsi,%rbx
mov    $0x1,%esi
mov    %rbx,%rdx
call   1030 <fread@plt>
movslq %eax,%rcx
cmp    %rbx,%rcx
jae    1164 <read_bytes+0x44>
mov    0x2e94(%rip),%rax
mov    (%rax),%edi
lea    0xeab(%rip),%rsi
mov    %ebp,%edx
mov    %r14d,%ecx
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"Short read on record %d field %d\0A\00"
define i32 @read_bytes(i8* %0, i64 %1, i32* %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %7
store i64 %1, i64* %8
store i32* %2, i32** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%13 = load i8*, i8** %7
%14 = load i64, i64* %8
%15 = load i32*, i32** %9
%16 = call i32 @fread(i8* %13, i32 1, i64 %14, i32* %15)
store i32 %16, i32* %12
%17 = load i32, i32* %12
%18 = sext i32 %17 to i64
%19 = load i64, i64* %8
%20 = icmp ult i64 %18, %19
br i1 %20, label %21, label %26
21: ; preds = %5
%22 = load i32, i32* @stderr
%23 = load i32, i32* %11
%24 = load i32, i32* %10
%25 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %23, i32 %24)
store i32 -1, i32* %6
br label %28
26: ; preds = %5
%27 = load i32, i32* %12
store i32 %27, i32* %6
br label %28
28: ; preds = %26, %21
%29 = load i32, i32* %6
ret i32 %29
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"Short read on record %d field %d\0A\00"
define i32 @read_bytes(i8* nocapture %0, i64 %1, i32* nocapture %2, i32 %3, i32 %4) {
%6 = tail call i32 @fread(i8* %0, i32 1, i64 %1, i32* %2)
%7 = sext i32 %6 to i64
%8 = icmp ult i64 %7, %1
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %3)
br label %12
12: ; preds = %5, %9
%13 = phi i32 [ -1, %9 ], [ %6, %5 ]
ret i32 %13
}