#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ limpaVetor(char *);
scalar_t__ malloc(int);
scalar_t__ realloc(char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
char *openFile(char caminho[]) {
  char *arquivo = NULL, temp[1024] = {};
  FILE *file;
  arquivo = (char *)malloc(sizeof(char) * 1024);
  limpaVetor(arquivo);
  if ((file = fopen(caminho, "r")) == NULL) {
    fprintf(stderr, "Erro: Arquivo Invalido!\r\nEndereco: %s\r\n", caminho);
    return NULL;
  }
  while ((fgets(temp, 1024, file)) != NULL) {
    strcat(arquivo, temp);
    arquivo = (char *)realloc(arquivo, sizeof(char) * 1024);
  }
  fclose(file);
  file = NULL;
  return arquivo;
}


x86 assembly (clang, -O0):
<openFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   10b0 <limpaVetor@plt>
mov    -0x10(%rbp),%rdi
lea    0xe24(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x428(%rbp)
cmp    $0x0,%rax
jne    1218 <openFile+0x88>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdfc(%rip),%rsi
call   1060 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1285 <openFile+0xf5>
jmp    121d <openFile+0x8d>
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1266 <openFile+0xd6>
mov    -0x18(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    $0x400,%esi
call   1080 <realloc@plt>
mov    %rax,-0x18(%rbp)
jmp    121d <openFile+0x8d>
mov    -0x428(%rbp),%rdi
call   1030 <fclose@plt>
movq   $0x0,-0x428(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openFile>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%r15
mov    %rsp,%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   10b0 <limpaVetor@plt>
lea    0xe36(%rip),%rsi
mov    %r15,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     123a <openFile+0xaa>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1230 <openFile+0xa0>
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
call   10a0 <strcat@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
call   1080 <realloc@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    1200 <openFile+0x70>
mov    %r14,%rdi
call   1030 <fclose@plt>
jmp    1254 <openFile+0xc4>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
lea    0xdb8(%rip),%rsi
mov    %r15,%rdx
call   1060 <fprintf@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [40 x i8] c"Erro: Arquivo Invalido!\0D\0AEndereco: %s\0D\0A\00"
define i8* @openFile(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [1024 x i8]
%6 = alloca i32*
store i8* %0, i8** %3
store i8* null, i8** %4
%7 = bitcast [1024 x i8]* %5 to i8*
%8 = call i64 @malloc(i32 1024)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = call i32 @limpaVetor(i8* %10)
%12 = load i8*, i8** %3
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %6
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %1
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %3
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %17)
store i8* null, i8** %2
br label %36
19: ; preds = %1
br label %20
20: ; preds = %25, %19
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%22 = load i32*, i32** %6
%23 = call i32* @fgets(i8* %21, i32 1024, i32* %22)
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %32
25: ; preds = %20
%26 = load i8*, i8** %4
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%28 = call i32 @strcat(i8* %26, i8* %27)
%29 = load i8*, i8** %4
%30 = call i64 @realloc(i8* %29, i32 1024)
%31 = inttoptr i64 %30 to i8*
store i8* %31, i8** %4
br label %20
32: ; preds = %20
%33 = load i32*, i32** %6
%34 = call i32 @fclose(i32* %33)
store i32* null, i32** %6
%35 = load i8*, i8** %4
store i8* %35, i8** %2
br label %36
36: ; preds = %32, %15
%37 = load i8*, i8** %2
ret i8* %37
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [40 x i8] c"Erro: Arquivo Invalido!\0D\0AEndereco: %s\0D\0A\00"
define i8* @openFile(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = tail call i64 @malloc(i32 1024)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @limpaVetor(i8* %5)
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = call i32* @fgets(i8* %3, i32 1024, i32* %7)
%11 = icmp eq i32* %10, null
br i1 %11, label %24, label %15
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %27
15: ; preds = %9, %15
%16 = phi i8* [ %19, %15 ], [ %5, %9 ]
%17 = call i32 @strcat(i8* %16, i8* %3)
%18 = call i64 @realloc(i8* %16, i32 1024)
%19 = inttoptr i64 %18 to i8*
%20 = call i32* @fgets(i8* %3, i32 1024, i32* %7)
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %15
22: ; preds = %15
%23 = inttoptr i64 %18 to i8*
br label %24
24: ; preds = %22, %9
%25 = phi i8* [ %5, %9 ], [ %23, %22 ]
%26 = call i32 @fclose(i32* %7)
br label %27
27: ; preds = %24, %12
%28 = phi i8* [ null, %12 ], [ %25, %24 ]
ret i8* %28
}