#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 */
struct stat {
  int st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fstat(int /*<<< orphan*/, struct stat *);
int /*<<< orphan*/ my_err(char *, char *, int, char *);
scalar_t__ my_malloc(int);
char *util_read_entire_file(char *filename) {
  FILE *fh;
  struct stat fs;
  char *buf;
  fh = fopen(filename, "r");
  if (fh == NULL) {
    my_err("%s:%d: Could not open tree file '%s'",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/bmvdgeijn/WASP/refs/heads/master/snp2h5/"
           "util.c",
           48, filename);
  }
  fstat(fileno(fh), &fs);
  buf = ((char *)my_malloc(sizeof(char) * fs.st_size + 1));
  if (fread(buf, fs.st_size, 1, fh) == 0) {
    my_err("%s:%d: Could not read entire file '%s'",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/bmvdgeijn/WASP/refs/heads/master/snp2h5/"
           "util.c",
           58, filename);
  }
  buf[fs.st_size] = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<util_read_entire_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a7 <util_read_entire_file+0x47>
mov    -0x8(%rbp),%rcx
lea    0xe6c(%rip),%rdi
lea    0xe8a(%rip),%rsi
mov    $0x30,%edx
call   1070 <my_err@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fileno@plt>
mov    %eax,%edi
lea    -0x18(%rbp),%rsi
call   1080 <fstat@plt>
movslq -0x18(%rbp),%rax
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x0,%rax
jne    120d <util_read_entire_file+0xad>
mov    -0x8(%rbp),%rcx
lea    0xeb4(%rip),%rdi
lea    0xe24(%rip),%rsi
mov    $0x3a,%edx
call   1070 <my_err@plt>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_read_entire_file>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe8e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
jne    119a <util_read_entire_file+0x3a>
lea    0xe7c(%rip),%rdi
lea    0xe9a(%rip),%rsi
mov    $0x30,%edx
mov    %r14,%rcx
call   1070 <my_err@plt>
mov    %r15,%rdi
call   1050 <fileno@plt>
mov    %rsp,%rsi
mov    %eax,%edi
call   1080 <fstat@plt>
mov    (%rsp),%eax
movslq %eax,%r12
lea    0x1(%r12),%edi
call   1030 <my_malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12d,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
test   %rax,%rax
jne    11f2 <util_read_entire_file+0x92>
lea    0xed2(%rip),%rdi
lea    0xe42(%rip),%rsi
mov    $0x3a,%edx
mov    %r14,%rcx
call   1070 <my_err@plt>
movb   $0x0,(%rbx,%r12,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [2 x i8] c"r\00"
@.str.1 = [37 x i8] c"%s:%d: Could not open tree file '%s'\00"
@.str.2 = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/bmvdgeijn/WASP/refs/heads/master/snp2h5/util.c\00"
@.str.3 = [39 x i8] c"%s:%d: Could not read entire file '%s'\00"
define i8* @util_read_entire_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.stat
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %3
%8 = load i32*, i32** %3
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = call i32 @my_err(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.2, i64 0, i64 0), i32 48, i8* %11)
br label %13
13: ; preds = %10, %1
%14 = load i32*, i32** %3
%15 = call i32 @fileno(i32* %14)
%16 = call i32 @fstat(i32 %15, %struct.stat* %4)
%17 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%18 = load i32, i32* %17
%19 = sext i32 %18 to i64
%20 = mul i64 1, %19
%21 = add i64 %20, 1
%22 = trunc i64 %21 to i32
%23 = call i64 @my_malloc(i32 %22)
%24 = inttoptr i64 %23 to i8*
store i8* %24, i8** %5
%25 = load i8*, i8** %5
%26 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%27 = load i32, i32* %26
%28 = load i32*, i32** %3
%29 = call i64 @fread(i8* %25, i32 %27, i32 1, i32* %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %13
%32 = load i8*, i8** %2
%33 = call i32 @my_err(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.2, i64 0, i64 0), i32 58, i8* %32)
br label %34
34: ; preds = %31, %13
%35 = load i8*, i8** %5
%36 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%37 = load i32, i32* %36
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
store i8 0, i8* %39
%40 = load i8*, i8** %5
ret i8* %40
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [2 x i8] c"r\00"
@.str.1 = [37 x i8] c"%s:%d: Could not open tree file '%s'\00"
@.str.2 = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/bmvdgeijn/WASP/refs/heads/master/snp2h5/util.c\00"
@.str.3 = [39 x i8] c"%s:%d: Could not read entire file '%s'\00"
define i8* @util_read_entire_file(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @my_err(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.2, i64 0, i64 0), i32 48, i8* %0)
br label %8
8: ; preds = %6, %1
%9 = tail call i32 @fileno(i32* %4)
%10 = call i32 @fstat(i32 %9, %struct.stat* %2)
%11 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%12 = load i32, i32* %11
%13 = add i32 %12, 1
%14 = tail call i64 @my_malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
%16 = tail call i64 @fread(i8* %15, i32 %12, i32 1, i32* %4)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %8
%19 = tail call i32 @my_err(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.2, i64 0, i64 0), i32 58, i8* %0)
br label %20
20: ; preds = %18, %8
%21 = sext i32 %12 to i64
%22 = getelementptr inbounds i8, i8* %15, i64 %21
store i8 0, i8* %22
ret i8* %15
}