#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
size_t fread(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ netl_die(int, char *, char *, int);
int /*<<< orphan*/ stderr;
unsigned char *readentire(char *fn, size_t *size, size_t max, char *prog) {
  FILE *fp;
  char *buff, *ptr;
  size_t br, left;
  if ((fp = fopen(fn, "r")) == NULL) {
    fprintf(stderr, "%s: warning: could not open %s, skipping\n", prog, fn);
    return NULL;
  }
  fseek(fp, 0, SEEK_END);
  *size = ftell(fp);
  fseek(fp, 0, SEEK_SET);
  if (max != 0 && *size > max) {
    fprintf(stderr, "%s: warning: file %s is to big skipping\n", prog, fn);
    return NULL;
  }
  buff = (char *)malloc(*size);
  if (buff == NULL) {
    netl_die(47, "%s: could not allocate %d bytes, die!", prog, (int)*size);
  }
  ptr = buff;
  left = *size;
  while (left > 0 && !feof(fp)) {
    if ((br = fread(ptr, 1, left, fp)) == 0) {
      fprintf(stderr, "%s: warning: error reading %s, skipping\n", prog, fn);
      fprintf(stderr, "culd not read %d bytes while not at EOF!\n", (int)left);
      return NULL;
    }
    ptr += br;
    left -= br;
  }
  fclose(fp);
  return buff;
}


x86 assembly (clang, -O0):
<readentire>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe4d(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11f2 <readentire+0x62>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe24(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1393 <readentire+0x203>
mov    -0x30(%rbp),%rdi
mov    0x2deb(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x30(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rdi
mov    0x2dac(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
cmpq   $0x0,-0x20(%rbp)
je     1275 <readentire+0xe5>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
cmp    -0x20(%rbp),%rax
jbe    1275 <readentire+0xe5>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xdcb(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1393 <readentire+0x203>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    12ae <readentire+0x11e>
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %eax,%ecx
mov    $0x2f,%edi
lea    0xdac(%rip),%rsi
call   1080 <netl_die@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x50(%rbp)
mov    %al,-0x51(%rbp)
jbe    12e5 <readentire+0x155>
mov    -0x30(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
test   $0x1,%al
jne    12f5 <readentire+0x165>
jmp    1382 <readentire+0x1f2>
mov    -0x40(%rbp),%rdi
mov    -0x50(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    1362 <readentire+0x1d2>
mov    0x2cb8(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xd4a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2c99(%rip),%rax
mov    (%rax),%edi
mov    -0x50(%rbp),%rax
mov    %eax,%edx
lea    0xd56(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1393 <readentire+0x203>
mov    -0x48(%rbp),%rax
add    -0x40(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x48(%rbp),%rcx
mov    -0x50(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x50(%rbp)
jmp    12c1 <readentire+0x131>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readentire>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rbp
mov    %rdx,%rbx
mov    %rsi,%r13
mov    %rdi,%r15
lea    0xe52(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     120d <readentire+0x7d>
mov    %rax,%r14
mov    0x2e26(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r14,%rdi
call   1060 <ftell@plt>
mov    %rax,0x0(%r13)
mov    0x2def(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    0x0(%r13),%rdi
test   %rbx,%rbx
je     1232 <readentire+0xa2>
cmp    %rbx,%rdi
jbe    1232 <readentire+0xa2>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
lea    0xe21(%rip),%rsi
jmp    121d <readentire+0x8d>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
lea    0xde5(%rip),%rsi
xor    %r12d,%r12d
mov    %rbp,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    12db <readentire+0x14b>
call   1090 <malloc@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1257 <readentire+0xc7>
mov    0x0(%r13),%ecx
lea    0xe0b(%rip),%rsi
mov    $0x2f,%edi
mov    %rbp,%rdx
call   1080 <netl_die@plt>
mov    %rbp,(%rsp)
mov    0x0(%r13),%rbx
test   %rbx,%rbx
je     129c <readentire+0x10c>
mov    %r12,%rbp
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    129c <readentire+0x10c>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     12a6 <readentire+0x116>
add    %rax,%rbp
sub    %rax,%rbx
jne    1270 <readentire+0xe0>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    12db <readentire+0x14b>
mov    0x2d2b(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xdc4(%rip),%rsi
xor    %r12d,%r12d
mov    (%rsp),%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xdd2(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [42 x i8] c"%s: warning: could not open %s, skipping\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [41 x i8] c"%s: warning: file %s is to big skipping\0A\00"
@.str.3 = [38 x i8] c"%s: could not allocate %d bytes, die!\00"
@.str.4 = [41 x i8] c"%s: warning: error reading %s, skipping\0A\00"
@.str.5 = [42 x i8] c"culd not read %d bytes while not at EOF!\0A\00"
define i8* @readentire(i8* %0, i64* %1, i64 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i64
store i8* %0, i8** %6
store i64* %1, i64** %7
store i64 %2, i64* %8
store i8* %3, i8** %9
%15 = load i8*, i8** %6
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %10
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %23
18: ; preds = %4
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %9
%21 = load i8*, i8** %6
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %20, i8* %21)
store i8* null, i8** %5
br label %98
23: ; preds = %4
%24 = load i32*, i32** %10
%25 = load i32, i32* @SEEK_END
%26 = call i32 @fseek(i32* %24, i32 0, i32 %25)
%27 = load i32*, i32** %10
%28 = call i64 @ftell(i32* %27)
%29 = load i64*, i64** %7
store i64 %28, i64* %29
%30 = load i32*, i32** %10
%31 = load i32, i32* @SEEK_SET
%32 = call i32 @fseek(i32* %30, i32 0, i32 %31)
%33 = load i64, i64* %8
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %45
35: ; preds = %23
%36 = load i64*, i64** %7
%37 = load i64, i64* %36
%38 = load i64, i64* %8
%39 = icmp ugt i64 %37, %38
br i1 %39, label %40, label %45
40: ; preds = %35
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %9
%43 = load i8*, i8** %6
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %42, i8* %43)
store i8* null, i8** %5
br label %98
45: ; preds = %35, %23
%46 = load i64*, i64** %7
%47 = load i64, i64* %46
%48 = call i64 @malloc(i64 %47)
%49 = inttoptr i64 %48 to i8*
store i8* %49, i8** %11
%50 = load i8*, i8** %11
%51 = icmp eq i8* %50, null
br i1 %51, label %52, label %58
52: ; preds = %45
%53 = load i8*, i8** %9
%54 = load i64*, i64** %7
%55 = load i64, i64* %54
%56 = trunc i64 %55 to i32
%57 = call i32 @netl_die(i32 47, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %53, i32 %56)
br label %58
58: ; preds = %52, %45
%59 = load i8*, i8** %11
store i8* %59, i8** %12
%60 = load i64*, i64** %7
%61 = load i64, i64* %60
store i64 %61, i64* %14
br label %62
62: ; preds = %87, %58
%63 = load i64, i64* %14
%64 = icmp ugt i64 %63, 0
br i1 %64, label %65, label %70
65: ; preds = %62
%66 = load i32*, i32** %10
%67 = call i32 @feof(i32* %66)
%68 = icmp ne i32 %67, 0
%69 = xor i1 %68, true
br label %70
70: ; preds = %65, %62
%71 = phi i1 [ false, %62 ], [ %69, %65 ]
br i1 %71, label %72, label %94
72: ; preds = %70
%73 = load i8*, i8** %12
%74 = load i64, i64* %14
%75 = load i32*, i32** %10
%76 = call i64 @fread(i8* %73, i32 1, i64 %74, i32* %75)
store i64 %76, i64* %13
%77 = icmp eq i64 %76, 0
br i1 %77, label %78, label %87
78: ; preds = %72
%79 = load i32, i32* @stderr
%80 = load i8*, i8** %9
%81 = load i8*, i8** %6
%82 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i8* %80, i8* %81)
%83 = load i32, i32* @stderr
%84 = load i64, i64* %14
%85 = trunc i64 %84 to i32
%86 = call i32 (i32, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i32 %85)
store i8* null, i8** %5
br label %98
87: ; preds = %72
%88 = load i64, i64* %13
%89 = load i8*, i8** %12
%90 = getelementptr inbounds i8, i8* %89, i64 %88
store i8* %90, i8** %12
%91 = load i64, i64* %13
%92 = load i64, i64* %14
%93 = sub i64 %92, %91
store i64 %93, i64* %14
br label %62
94: ; preds = %70
%95 = load i32*, i32** %10
%96 = call i32 @fclose(i32* %95)
%97 = load i8*, i8** %11
store i8* %97, i8** %5
br label %98
98: ; preds = %94, %78, %40, %18
%99 = load i8*, i8** %5
ret i8* %99
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [42 x i8] c"%s: warning: could not open %s, skipping\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [41 x i8] c"%s: warning: file %s is to big skipping\0A\00"
@.str.3 = [38 x i8] c"%s: could not allocate %d bytes, die!\00"
@.str.4 = [41 x i8] c"%s: warning: error reading %s, skipping\0A\00"
@.str.5 = [42 x i8] c"culd not read %d bytes while not at EOF!\0A\00"
define i8* @readentire(i8* %0, i64* nocapture %1, i64 %2, i8* %3) {
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %3, i8* %0)
br label %54
10: ; preds = %4
%11 = load i32, i32* @SEEK_END
%12 = tail call i32 @fseek(i32* %5, i32 0, i32 %11)
%13 = tail call i64 @ftell(i32* %5)
store i64 %13, i64* %1
%14 = load i32, i32* @SEEK_SET
%15 = tail call i32 @fseek(i32* %5, i32 0, i32 %14)
%16 = icmp ne i64 %2, 0
%17 = load i64, i64* %1
%18 = icmp ugt i64 %17, %2
%19 = select i1 %16, i1 %18, i1 false
br i1 %19, label %20, label %23
20: ; preds = %10
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %3, i8* %0)
br label %54
23: ; preds = %10
%24 = tail call i64 @malloc(i64 %17)
%25 = inttoptr i64 %24 to i8*
%26 = icmp eq i64 %24, 0
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i64, i64* %1
%29 = trunc i64 %28 to i32
%30 = tail call i32 @netl_die(i32 47, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %3, i32 %29)
br label %31
31: ; preds = %27, %23
%32 = load i64, i64* %1
%33 = icmp eq i64 %32, 0
br i1 %33, label %52, label %34
34: ; preds = %31, %48
%35 = phi i64 [ %50, %48 ], [ %32, %31 ]
%36 = phi i8* [ %49, %48 ], [ %25, %31 ]
%37 = tail call i32 @feof(i32* %5)
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %52
39: ; preds = %34
%40 = tail call i64 @fread(i8* %36, i32 1, i64 %35, i32* %5)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %39
%43 = load i32, i32* @stderr
%44 = tail call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i8* %3, i8* %0)
%45 = load i32, i32* @stderr
%46 = trunc i64 %35 to i32
%47 = tail call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i32 %46)
br label %54
48: ; preds = %39
%49 = getelementptr inbounds i8, i8* %36, i64 %40
%50 = sub i64 %35, %40
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %34
52: ; preds = %34, %48, %31
%53 = tail call i32 @fclose(i32* %5)
br label %54
54: ; preds = %52, %42, %20, %7
%55 = phi i8* [ null, %7 ], [ null, %20 ], [ null, %42 ], [ %25, %52 ]
ret i8* %55
}