#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;
size_t fread(char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
char *malloc(size_t);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, size_t, size_t);
int /*<<< orphan*/ puts(char *);
char *ic_read_slurp_file(FILE *file) {
  long fsize;
  size_t ufsize;
  size_t read;
  char *buffer;
  if (fseek(file, 0, SEEK_END)) {
    puts("ERROR: fseek SEEK_END failed in read_slurp_file");
    perror("read_slurp_file::fseek SEEK_END");
    return 0;
  }
  fsize = ftell(file);
  ufsize = fsize;
  if (fsize < 0) {
    puts("ERROR: fstell failed in read_slurp_file");
    perror("read_slurp_file::ftell");
    return 0;
  }
  if (fseek(file, 0, SEEK_SET)) {
    puts("ERROR: fseek SEEK_SET failed in read_slurp_file");
    perror("read_slurp_file::fseek SEEK_SET");
    return 0;
  }
  buffer = malloc(ufsize + 1);
  if (!buffer) {
    puts("ERROR: malloc failed in read_slurp_file");
    return 0;
  }
  buffer[fsize] = '\0';
  read = fread(buffer, 1, fsize, file);
  if (read != ufsize) {
    printf("ERROR: read_slurp_file::fread read '%zd' when we expected '%lu'\n",
           read, ufsize);
    free(buffer);
    return 0;
  }
  return buffer;
}


x86 assembly (clang, -O0):
<ic_read_slurp_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e51(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
cmp    $0x0,%rax
je     11cf <ic_read_slurp_file+0x4f>
lea    0xe4f(%rip),%rdi
call   1040 <puts@plt>
lea    0xe73(%rip),%rdi
call   10a0 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    12f2 <ic_read_slurp_file+0x172>
mov    -0x10(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1214 <ic_read_slurp_file+0x94>
lea    0xe5a(%rip),%rdi
call   1040 <puts@plt>
lea    0xe76(%rip),%rdi
call   10a0 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    12f2 <ic_read_slurp_file+0x172>
mov    -0x10(%rbp),%rdi
mov    0x2db9(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
cmp    $0x0,%rax
je     1257 <ic_read_slurp_file+0xd7>
lea    0xe56(%rip),%rdi
call   1040 <puts@plt>
lea    0xe7a(%rip),%rdi
call   10a0 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    12f2 <ic_read_slurp_file+0x172>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    128c <ic_read_slurp_file+0x10c>
lea    0xe65(%rip),%rdi
call   1040 <puts@plt>
movq   $0x0,-0x8(%rbp)
jmp    12f2 <ic_read_slurp_file+0x172>
mov    -0x30(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     12ea <ic_read_slurp_file+0x16a>
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe38(%rip),%rdi
call   1060 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    12f2 <ic_read_slurp_file+0x172>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ic_read_slurp_file>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2e59(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
test   %rax,%rax
jne    1232 <ic_read_slurp_file+0xb2>
mov    %r14,%rdi
call   1070 <ftell@plt>
test   %rax,%rax
js     124c <ic_read_slurp_file+0xcc>
mov    %rax,%rbx
mov    0x2e1c(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
test   %rax,%rax
jne    1266 <ic_read_slurp_file+0xe6>
lea    0x1(%rbx),%rdi
call   1080 <malloc@plt>
test   %rax,%rax
je     121a <ic_read_slurp_file+0x9a>
mov    %rax,%r15
movb   $0x0,(%rax,%rbx,1)
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1050 <fread@plt>
cmp    %rbx,%rax
je     1229 <ic_read_slurp_file+0xa9>
lea    0xf02(%rip),%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1060 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    1226 <ic_read_slurp_file+0xa6>
lea    0xebe(%rip),%rdi
call   1040 <puts@plt>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdc7(%rip),%rdi
call   1040 <puts@plt>
lea    0xdeb(%rip),%rdi
call   10a0 <perror@plt>
jmp    1226 <ic_read_slurp_file+0xa6>
lea    0xdfd(%rip),%rdi
call   1040 <puts@plt>
lea    0xe19(%rip),%rdi
call   10a0 <perror@plt>
jmp    1226 <ic_read_slurp_file+0xa6>
lea    0xe22(%rip),%rdi
call   1040 <puts@plt>
lea    0xe46(%rip),%rdi
call   10a0 <perror@plt>
jmp    1226 <ic_read_slurp_file+0xa6>

LLVM IR (-O0):
@SEEK_END = global i32 0
@.str = [48 x i8] c"ERROR: fseek SEEK_END failed in read_slurp_file\00"
@.str.1 = [32 x i8] c"read_slurp_file::fseek SEEK_END\00"
@.str.2 = [40 x i8] c"ERROR: fstell failed in read_slurp_file\00"
@.str.3 = [23 x i8] c"read_slurp_file::ftell\00"
@SEEK_SET = global i32 0
@.str.4 = [48 x i8] c"ERROR: fseek SEEK_SET failed in read_slurp_file\00"
@.str.5 = [32 x i8] c"read_slurp_file::fseek SEEK_SET\00"
@.str.6 = [40 x i8] c"ERROR: malloc failed in read_slurp_file\00"
@.str.7 = [65 x i8] c"ERROR: read_slurp_file::fread read '%zd' when we expected '%lu'\0A\00"
define i8* @ic_read_slurp_file(i32* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
store i32* %0, i32** %3
%8 = load i32*, i32** %3
%9 = load i32, i32* @SEEK_END
%10 = call i64 @fseek(i32* %8, i32 0, i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = call i32 @puts(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %2
br label %59
15: ; preds = %1
%16 = load i32*, i32** %3
%17 = call i64 @ftell(i32* %16)
store i64 %17, i64* %4
%18 = load i64, i64* %4
store i64 %18, i64* %5
%19 = load i64, i64* %4
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = call i32 @puts(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
store i8* null, i8** %2
br label %59
24: ; preds = %15
%25 = load i32*, i32** %3
%26 = load i32, i32* @SEEK_SET
%27 = call i64 @fseek(i32* %25, i32 0, i32 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = call i32 @puts(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0))
%31 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
store i8* null, i8** %2
br label %59
32: ; preds = %24
%33 = load i64, i64* %5
%34 = add i64 %33, 1
%35 = call i8* @malloc(i64 %34)
store i8* %35, i8** %7
%36 = load i8*, i8** %7
%37 = icmp ne i8* %36, null
br i1 %37, label %40, label %38
38: ; preds = %32
%39 = call i32 @puts(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0))
store i8* null, i8** %2
br label %59
40: ; preds = %32
%41 = load i8*, i8** %7
%42 = load i64, i64* %4
%43 = getelementptr inbounds i8, i8* %41, i64 %42
store i8 0, i8* %43
%44 = load i8*, i8** %7
%45 = load i64, i64* %4
%46 = load i32*, i32** %3
%47 = call i64 @fread(i8* %44, i32 1, i64 %45, i32* %46)
store i64 %47, i64* %6
%48 = load i64, i64* %6
%49 = load i64, i64* %5
%50 = icmp ne i64 %48, %49
br i1 %50, label %51, label %57
51: ; preds = %40
%52 = load i64, i64* %6
%53 = load i64, i64* %5
%54 = call i32 @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.7, i64 0, i64 0), i64 %52, i64 %53)
%55 = load i8*, i8** %7
%56 = call i32 @free(i8* %55)
store i8* null, i8** %2
br label %59
57: ; preds = %40
%58 = load i8*, i8** %7
store i8* %58, i8** %2
br label %59
59: ; preds = %57, %51, %38, %29, %21, %12
%60 = load i8*, i8** %2
ret i8* %60
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@.str = [48 x i8] c"ERROR: fseek SEEK_END failed in read_slurp_file\00"
@.str.1 = [32 x i8] c"read_slurp_file::fseek SEEK_END\00"
@.str.2 = [40 x i8] c"ERROR: fstell failed in read_slurp_file\00"
@.str.3 = [23 x i8] c"read_slurp_file::ftell\00"
@SEEK_SET = global i32 0
@.str.4 = [48 x i8] c"ERROR: fseek SEEK_SET failed in read_slurp_file\00"
@.str.5 = [32 x i8] c"read_slurp_file::fseek SEEK_SET\00"
@.str.6 = [40 x i8] c"ERROR: malloc failed in read_slurp_file\00"
@.str.7 = [65 x i8] c"ERROR: read_slurp_file::fread read '%zd' when we expected '%lu'\0A\00"
define noalias i8* @ic_read_slurp_file(i32* nocapture %0) {
%2 = load i32, i32* @SEEK_END
%3 = tail call i64 @fseek(i32* %0, i32 0, i32 %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %34
8: ; preds = %1
%9 = tail call i64 @ftell(i32* %0)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %34
14: ; preds = %8
%15 = load i32, i32* @SEEK_SET
%16 = tail call i64 @fseek(i32* %0, i32 0, i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0))
%20 = tail call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
br label %34
21: ; preds = %14
%22 = add nuw i64 %9, 1
%23 = tail call i8* @malloc(i64 %22)
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0))
br label %34
27: ; preds = %21
%28 = getelementptr inbounds i8, i8* %23, i64 %9
store i8 0, i8* %28
%29 = tail call i64 @fread(i8* %23, i32 1, i64 %9, i32* %0)
%30 = icmp eq i64 %29, %9
br i1 %30, label %34, label %31
31: ; preds = %27
%32 = tail call i32 @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.7, i64 0, i64 0), i64 %29, i64 %9)
%33 = tail call i32 @free(i8* %23)
br label %34
34: ; preds = %27, %31, %25, %18, %11, %5
%35 = phi i8* [ null, %5 ], [ null, %11 ], [ null, %18 ], [ null, %31 ], [ null, %25 ], [ %23, %27 ]
ret i8* %35
}