#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, unsigned long, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
unsigned long ftell(int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ system(char *);
char *readFile(char *filename) {
  char *buffer;
  unsigned long length;
  FILE *f = fopen(filename, "rb");
  if (!f) {
    printf("\n\n%s\n\n", "Não foi possível abrir o arquivo.");
    system("PAUSE");
    exit(0);
    return 0;
  }
  fseek(f, 0, SEEK_END);
  length = ftell(f);
  rewind(f);
  buffer = malloc(sizeof(char) * (length + 1));
  if (buffer)
    fread(buffer, sizeof(char), length, f);
  fclose(f);
  buffer[length] = '\0';
  return buffer;
}


x86 assembly (clang, -O0):
<readFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f1 <readFile+0x51>
lea    0xe31(%rip),%rdi
lea    0xe31(%rip),%rsi
call   1060 <printf@plt>
lea    0xe49(%rip),%rdi
call   1050 <system@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    0x2dec(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <rewind@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1253 <readFile+0xb3>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFile>:
push   %r15
push   %r14
push   %rbx
lea    0xe54(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     121b <readFile+0x7b>
mov    %rax,%r15
mov    0x2e28(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r15,%rdi
call   1080 <ftell@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1070 <rewind@plt>
mov    %r14d,%edi
add    $0x1,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1205 <readFile+0x65>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   1030 <fread@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
movb   $0x0,(%rbx,%r14,1)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xde1(%rip),%rdi
lea    0xde1(%rip),%rsi
call   1060 <printf@plt>
lea    0xdf9(%rip),%rdi
call   1050 <system@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [7 x i8] c"\0A\0A%s\0A\0A\00"
@.str.2 = [36 x i8] c"N\C3\A3o foi poss\C3\ADvel abrir o arquivo.\00"
@.str.3 = [6 x i8] c"PAUSE\00"
@SEEK_END = global i32 0
define i8* @readFile(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %5
%8 = load i32*, i32** %5
%9 = icmp ne i32* %8, null
br i1 %9, label %14, label %10
10: ; preds = %1
%11 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @exit(i32 0)
unreachable
14: ; preds = %1
%15 = load i32*, i32** %5
%16 = load i32, i32* @SEEK_END
%17 = call i32 @fseek(i32* %15, i32 0, i32 %16)
%18 = load i32*, i32** %5
%19 = call i64 @ftell(i32* %18)
store i64 %19, i64* %4
%20 = load i32*, i32** %5
%21 = call i32 @rewind(i32* %20)
%22 = load i64, i64* %4
%23 = add i64 %22, 1
%24 = mul i64 1, %23
%25 = trunc i64 %24 to i32
%26 = call i8* @malloc(i32 %25)
store i8* %26, i8** %3
%27 = load i8*, i8** %3
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %34
29: ; preds = %14
%30 = load i8*, i8** %3
%31 = load i64, i64* %4
%32 = load i32*, i32** %5
%33 = call i32 @fread(i8* %30, i32 1, i64 %31, i32* %32)
br label %34
34: ; preds = %29, %14
%35 = load i32*, i32** %5
%36 = call i32 @fclose(i32* %35)
%37 = load i8*, i8** %3
%38 = load i64, i64* %4
%39 = getelementptr inbounds i8, i8* %37, i64 %38
store i8 0, i8* %39
%40 = load i8*, i8** %3
ret i8* %40
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [7 x i8] c"\0A\0A%s\0A\0A\00"
@.str.2 = [36 x i8] c"N\C3\A3o foi poss\C3\ADvel abrir o arquivo.\00"
@.str.3 = [6 x i8] c"PAUSE\00"
@SEEK_END = global i32 0
define noalias i8* @readFile(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 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 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%7 = tail call i32 @exit(i32 0)
unreachable
8: ; preds = %1
%9 = load i32, i32* @SEEK_END
%10 = tail call i32 @fseek(i32* %2, i32 0, i32 %9)
%11 = tail call i64 @ftell(i32* %2)
%12 = tail call i32 @rewind(i32* %2)
%13 = trunc i64 %11 to i32
%14 = add i32 %13, 1
%15 = tail call i8* @malloc(i32 %14)
%16 = icmp eq i8* %15, null
br i1 %16, label %19, label %17
17: ; preds = %8
%18 = tail call i32 @fread(i8* %15, i32 1, i64 %11, i32* %2)
br label %19
19: ; preds = %17, %8
%20 = tail call i32 @fclose(i32* %2)
%21 = getelementptr inbounds i8, i8* %15, i64 %11
store i8 0, i8* %21
ret i8* %15
}