#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*/ EXIT_FAILURE;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ calloc(unsigned long long, int);
int /*<<< orphan*/ erralloc();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, unsigned long long, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
unsigned long long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
char *readFile(char *filename) {
  FILE *fp;
  char *buffer;
  unsigned long long int n;
  fp = fopen(filename, "r");
  if (!fp) {
    printf("Error: file not found or it isn't acessible.\n");
    exit(EXIT_FAILURE);
  }
  fseek(fp, 0L, SEEK_END);
  n = ftell(fp);
  fseek(fp, 0L, SEEK_SET);
  buffer = (char *)calloc(n + 1, sizeof(char));
  if (!buffer)
    erralloc();
  fread(buffer, sizeof(char), n, fp);
  fclose(fp);
  return buffer;
}


x86 assembly (clang, -O0):
<readFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d5 <readFile+0x45>
lea    0xe40(%rip),%rdi
call   1060 <printf@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e08(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1090 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2dd5(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1090 <fseek@plt>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1236 <readFile+0xa6>
mov    $0x0,%al
call   1040 <erralloc@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFile>:
push   %r15
push   %r14
push   %rbx
lea    0xe64(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     121e <readFile+0x8e>
mov    %rax,%rbx
mov    0x2e38(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbx,%rdi
call   1080 <ftell@plt>
mov    %rax,%r14
mov    0x2e0a(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r14,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11fa <readFile+0x6a>
xor    %eax,%eax
call   1050 <erralloc@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xddd(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [46 x i8] c"Error: file not found or it isn't acessible.\0A\00"
@EXIT_FAILURE = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i8* @readFile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
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 ne i32* %8, null
br i1 %9, label %14, label %10
10: ; preds = %1
%11 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %1
%15 = load i32*, i32** %3
%16 = load i32, i32* @SEEK_END
%17 = call i32 @fseek(i32* %15, i64 0, i32 %16)
%18 = load i32*, i32** %3
%19 = call i64 @ftell(i32* %18)
store i64 %19, i64* %5
%20 = load i32*, i32** %3
%21 = load i32, i32* @SEEK_SET
%22 = call i32 @fseek(i32* %20, i64 0, i32 %21)
%23 = load i64, i64* %5
%24 = add i64 %23, 1
%25 = call i64 @calloc(i64 %24, i32 1)
%26 = inttoptr i64 %25 to i8*
store i8* %26, i8** %4
%27 = load i8*, i8** %4
%28 = icmp ne i8* %27, null
br i1 %28, label %31, label %29
29: ; preds = %14
%30 = call i32 (...) @erralloc()
br label %31
31: ; preds = %29, %14
%32 = load i8*, i8** %4
%33 = load i64, i64* %5
%34 = load i32*, i32** %3
%35 = call i32 @fread(i8* %32, i32 1, i64 %33, i32* %34)
%36 = load i32*, i32** %3
%37 = call i32 @fclose(i32* %36)
%38 = load i8*, i8** %4
ret i8* %38
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@str = [45 x i8] c"Error: file not found or it isn't acessible.\00"
define i8* @readFile(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %1
%9 = load i32, i32* @SEEK_END
%10 = tail call i32 @fseek(i32* %2, i64 0, i32 %9)
%11 = tail call i64 @ftell(i32* %2)
%12 = load i32, i32* @SEEK_SET
%13 = tail call i32 @fseek(i32* %2, i64 0, i32 %12)
%14 = add i64 %11, 1
%15 = tail call i64 @calloc(i64 %14, i32 1)
%16 = inttoptr i64 %15 to i8*
%17 = icmp eq i64 %15, 0
br i1 %17, label %18, label %20
18: ; preds = %8
%19 = tail call i32 (...) @erralloc()
br label %20
20: ; preds = %18, %8
%21 = tail call i32 @fread(i8* %16, i32 1, i64 %11, i32* %2)
%22 = tail call i32 @fclose(i32* %2)
ret i8* %16
}