#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
unsigned long fread(unsigned char *, int, unsigned long, int /*<<< orphan*/ *);
long _readEntireFile(const char *pszFileName, unsigned char *pBytes,
                     unsigned long iLen) {
  FILE *fp = fopen(pszFileName, "rb");
  if (!fp) {
    return -1;
  }
  if (iLen != fread(pBytes, 1, iLen, fp)) {
    fclose(fp);
    return -1;
  }
  fclose(fp);
  return iLen;
}


x86 assembly (clang, -O0):
<_readEntireFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1170 <_readEntireFile+0x40>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11c5 <_readEntireFile+0x95>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
je     11b4 <_readEntireFile+0x84>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11c5 <_readEntireFile+0x95>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_readEntireFile>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
lea    0xebe(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     117d <_readEntireFile+0x4d>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <fclose@plt>
cmp    %r15,%r14
mov    $0xffffffffffffffff,%rax
cmove  %r15,%rax
jmp    1184 <_readEntireFile+0x54>
mov    $0xffffffffffffffff,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
define i64 @_readEntireFile(i8* %0, i8* %1, i64 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%9 = load i8*, i8** %5
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %8
%11 = load i32*, i32** %8
%12 = icmp ne i32* %11, null
br i1 %12, label %14, label %13
13: ; preds = %3
store i64 -1, i64* %4
br label %28
14: ; preds = %3
%15 = load i64, i64* %7
%16 = load i8*, i8** %6
%17 = load i64, i64* %7
%18 = load i32*, i32** %8
%19 = call i64 @fread(i8* %16, i32 1, i64 %17, i32* %18)
%20 = icmp ne i64 %15, %19
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = load i32*, i32** %8
%23 = call i32 @fclose(i32* %22)
store i64 -1, i64* %4
br label %28
24: ; preds = %14
%25 = load i32*, i32** %8
%26 = call i32 @fclose(i32* %25)
%27 = load i64, i64* %7
store i64 %27, i64* %4
br label %28
28: ; preds = %24, %21, %13
%29 = load i64, i64* %4
ret i64 %29
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
define i64 @_readEntireFile(i8* nocapture %0, i8* nocapture %1, i64 %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = tail call i64 @fread(i8* %1, i32 1, i64 %2, i32* %4)
%8 = icmp eq i64 %7, %2
%9 = tail call i32 @fclose(i32* %4)
%10 = select i1 %8, i64 %2, i64 -1
br label %11
11: ; preds = %6, %3
%12 = phi i64 [ -1, %3 ], [ %10, %6 ]
ret i64 %12
}