#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int ftell(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);
  };
  fseek(fp, 0L, SEEK_END);
  fs = ftell(fp);
  fseek(fp, 0L, SEEK_SET);
  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   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    0x2e13(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1070 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2dd9(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1070 <fseek@plt>
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     121a <Load+0x9a>
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    1230 <Load+0xb0>
lea    0xdf4(%rip),%rdi
call   1050 <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   1030 <fread@plt>
cmp    -0x24(%rbp),%eax
je     1278 <Load+0xf8>
lea    0xdbe(%rip),%rdi
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2d58(%rip),%rcx
cmp    (%rcx),%rax
jne    12a7 <Load+0x127>
lea    0xda1(%rip),%rdi
call   1050 <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     122a <Load+0xaa>
mov    %rax,%r15
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %r15,%rdi
call   1060 <ftell@plt>
mov    %eax,%ebx
mov    0x2e04(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
cmp    %ebp,%ebx
jl     1233 <Load+0xb3>
cmp    %r12d,%ebx
jg     1233 <Load+0xb3>
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   1040 <fread@plt>
cmp    %ebx,%eax
jne    123c <Load+0xbc>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    0x2dca(%rip),%rcx
cmp    (%rcx),%rax
je     1245 <Load+0xc5>
mov    %ebx,(%r14)
mov    %rbp,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe06(%rip),%rdi
jmp    124c <Load+0xcc>
lea    0xdec(%rip),%rdi
jmp    124c <Load+0xcc>
lea    0xdd2(%rip),%rdi
jmp    124c <Load+0xcc>
lea    0xdb7(%rip),%rdi
call   1030 <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"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.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 = load i32, i32* @SEEK_END
%21 = call i32 @fseek(i32* %19, i64 0, i32 %20)
%22 = load i32*, i32** %9
%23 = call i32 @ftell(i32* %22)
store i32 %23, i32* %10
%24 = load i32*, i32** %9
%25 = load i32, i32* @SEEK_SET
%26 = call i32 @fseek(i32* %24, i64 0, i32 %25)
%27 = load i32, i32* %10
%28 = load i32, i32* %7
%29 = icmp slt i32 %27, %28
br i1 %29, label %34, label %30
30: ; preds = %18
%31 = load i32, i32* %10
%32 = load i32, i32* %8
%33 = icmp sgt i32 %31, %32
br i1 %33, label %34, label %37
34: ; preds = %30, %18
%35 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 @exit(i32 -1)
unreachable
37: ; preds = %30
%38 = load i32, i32* %10
%39 = add nsw i32 %38, 3
%40 = call i8* @Memory(i32 %39, i32 1)
store i8* %40, i8** %11
%41 = load i8*, i8** %11
%42 = load i32, i32* %10
%43 = load i32*, i32** %9
%44 = call i32 @fread(i8* %41, i32 1, i32 %42, i32* %43)
%45 = load i32, i32* %10
%46 = icmp ne i32 %44, %45
br i1 %46, label %47, label %50
47: ; preds = %37
%48 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%49 = call i32 @exit(i32 -1)
unreachable
50: ; preds = %37
%51 = load i32*, i32** %9
%52 = call i64 @fclose(i32* %51)
%53 = load i64, i64* @EOF
%54 = icmp eq i64 %52, %53
br i1 %54, label %55, label %58
55: ; preds = %50
%56 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%57 = call i32 @exit(i32 -1)
unreachable
58: ; preds = %50
%59 = load i32, i32* %10
%60 = load i32*, i32** %6
store i32 %59, i32* %60
%61 = load i8*, i8** %11
ret i8* %61
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@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 = load i32, i32* @SEEK_END
%12 = tail call i32 @fseek(i32* %5, i64 0, i32 %11)
%13 = tail call i32 @ftell(i32* %5)
%14 = load i32, i32* @SEEK_SET
%15 = tail call i32 @fseek(i32* %5, i64 0, i32 %14)
%16 = icmp slt i32 %13, %2
%17 = icmp sgt i32 %13, %3
%18 = or i1 %16, %17
br i1 %18, label %19, label %22
19: ; preds = %10
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.6, i64 0, i64 0))
%21 = tail call i32 @exit(i32 -1)
unreachable
22: ; preds = %10
%23 = add nsw i32 %13, 3
%24 = tail call i8* @Memory(i32 %23, i32 1)
%25 = tail call i32 @fread(i8* %24, i32 1, i32 %13, i32* %5)
%26 = icmp eq i32 %25, %13
br i1 %26, label %30, label %27
27: ; preds = %22
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.5, i64 0, i64 0))
%29 = tail call i32 @exit(i32 -1)
unreachable
30: ; preds = %22
%31 = tail call i64 @fclose(i32* %5)
%32 = load i64, i64* @EOF
%33 = icmp eq i64 %31, %32
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%36 = tail call i32 @exit(i32 -1)
unreachable
37: ; preds = %30
store i32 %13, i32* %1
ret i8* %24
}