#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 */
scalar_t__ EOF;
char *Memory(int, int);
int /*<<< orphan*/ exit(int);
scalar_t__ fclose(int /*<<< orphan*/ *);
int filelength(int /*<<< orphan*/);
int /*<<< orphan*/ fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
char *Load(char *filename, int *length, int min, int max) {
  FILE *fp;
  int fs;
  char *fb;
  if ((fp = fopen(filename, "rb")) == NULL) {
    printf("\nFile open error\n");
    exit(-1);
  };
  fs = filelength(fileno(fp));
  if ((fs < min) || (fs > max)) {
    printf("\nFile size error\n");
    exit(-1);
  };
  fb = Memory(fs + 3, sizeof(char));
  if (fread(fb, 1, fs, fp) != fs) {
    printf("\nFile read error\n");
    exit(-1);
  };
  if (fclose(fp) == EOF) {
    printf("\nFile close error\n");
    exit(-1);
  };
  *length = fs;
  return (fb);
}


x86 assembly (clang, -O0):
<Load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe5f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11ca <Load+0x4a>
lea    0xe48(%rip),%rdi
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1070 <fileno@plt>
mov    %eax,%edi
call   1030 <filelength@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     11f5 <Load+0x75>
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    120b <Load+0x8b>
lea    0xe19(%rip),%rdi
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x24(%rbp),%edi
add    $0x3,%edi
mov    $0x1,%esi
call   10a0 <Memory@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
cmp    -0x24(%rbp),%eax
je     1253 <Load+0xd3>
lea    0xde3(%rip),%rdi
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    0x2d85(%rip),%rcx
cmp    (%rcx),%rax
jne    1282 <Load+0x102>
lea    0xdc6(%rip),%rdi
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x24(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Load>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r12d
mov    %edx,%ebp
mov    %rsi,%r14
lea    0xe69(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1207 <Load+0x87>
mov    %rax,%r15
mov    %rax,%rdi
call   1070 <fileno@plt>
mov    %eax,%edi
call   1030 <filelength@plt>
cmp    %ebp,%eax
jl     1210 <Load+0x90>
mov    %eax,%ebx
cmp    %r12d,%eax
jg     1210 <Load+0x90>
lea    0x3(%rbx),%edi
mov    $0x1,%esi
call   10a0 <Memory@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %r15,%rcx
call   1050 <fread@plt>
cmp    %ebx,%eax
jne    1219 <Load+0x99>
mov    %r15,%rdi
call   1060 <fclose@plt>
mov    0x2df5(%rip),%rcx
cmp    (%rcx),%rax
je     1222 <Load+0xa2>
mov    %ebx,(%r14)
mov    %rbp,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe29(%rip),%rdi
jmp    1229 <Load+0xa9>
lea    0xe0f(%rip),%rdi
jmp    1229 <Load+0xa9>
lea    0xdf5(%rip),%rdi
jmp    1229 <Load+0xa9>
lea    0xdda(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [18 x i8] c"\0AFile open error\0A\00"
@.str.2 = [18 x i8] c"\0AFile size error\0A\00"
@.str.3 = [18 x i8] c"\0AFile read error\0A\00"
@EOF = global i64 0
@.str.4 = [19 x i8] c"\0AFile close error\0A\00"
define i8* @Load(i8* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i8*, i8** %5
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %9
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %4
%16 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %4
%19 = load i32*, i32** %9
%20 = call i32 @fileno(i32* %19)
%21 = call i32 @filelength(i32 %20)
store i32 %21, i32* %10
%22 = load i32, i32* %10
%23 = load i32, i32* %7
%24 = icmp slt i32 %22, %23
br i1 %24, label %29, label %25
25: ; preds = %18
%26 = load i32, i32* %10
%27 = load i32, i32* %8
%28 = icmp sgt i32 %26, %27
br i1 %28, label %29, label %32
29: ; preds = %25, %18
%30 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @exit(i32 -1)
unreachable
32: ; preds = %25
%33 = load i32, i32* %10
%34 = add nsw i32 %33, 3
%35 = call i8* @Memory(i32 %34, i32 1)
store i8* %35, i8** %11
%36 = load i8*, i8** %11
%37 = load i32, i32* %10
%38 = load i32*, i32** %9
%39 = call i32 @fread(i8* %36, i32 1, i32 %37, i32* %38)
%40 = load i32, i32* %10
%41 = icmp ne i32 %39, %40
br i1 %41, label %42, label %45
42: ; preds = %32
%43 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%44 = call i32 @exit(i32 -1)
unreachable
45: ; preds = %32
%46 = load i32*, i32** %9
%47 = call i64 @fclose(i32* %46)
%48 = load i64, i64* @EOF
%49 = icmp eq i64 %47, %48
br i1 %49, label %50, label %53
50: ; preds = %45
%51 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%52 = call i32 @exit(i32 -1)
unreachable
53: ; preds = %45
%54 = load i32, i32* %10
%55 = load i32*, i32** %6
store i32 %54, i32* %55
%56 = load i8*, i8** %11
ret i8* %56
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@EOF = global i64 0
@str = [18 x i8] c"\0AFile close error\00"
@str.5 = [17 x i8] c"\0AFile read error\00"
@str.6 = [17 x i8] c"\0AFile size error\00"
@str.7 = [17 x i8] c"\0AFile open error\00"
define i8* @Load(i8* nocapture %0, i32* nocapture writeonly %1, i32 %2, i32 %3) {
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.7, i64 0, i64 0))
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %4
%11 = tail call i32 @fileno(i32* %5)
%12 = tail call i32 @filelength(i32 %11)
%13 = icmp slt i32 %12, %2
%14 = icmp sgt i32 %12, %3
%15 = or i1 %13, %14
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.6, i64 0, i64 0))
%18 = tail call i32 @exit(i32 -1)
unreachable
19: ; preds = %10
%20 = add nsw i32 %12, 3
%21 = tail call i8* @Memory(i32 %20, i32 1)
%22 = tail call i32 @fread(i8* %21, i32 1, i32 %12, i32* %5)
%23 = icmp eq i32 %22, %12
br i1 %23, label %27, label %24
24: ; preds = %19
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.5, i64 0, i64 0))
%26 = tail call i32 @exit(i32 -1)
unreachable
27: ; preds = %19
%28 = tail call i64 @fclose(i32* %5)
%29 = load i64, i64* @EOF
%30 = icmp eq i64 %28, %29
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%33 = tail call i32 @exit(i32 -1)
unreachable
34: ; preds = %27
store i32 %12, i32* %1
ret i8* %21
}