#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*/ conteudo;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
char *lerArquivo(char nomeDoArquivo[1024]) {
  FILE *arquivo;
  char conteudo[4000];
  size_t bytes_lidos;
  if ((arquivo = fopen(nomeDoArquivo, "r")) != NULL) {
    bytes_lidos = fread(conteudo, 1, sizeof(conteudo), arquivo);
    fclose(arquivo);
    conteudo[bytes_lidos] = '\0';
  }
  return conteudo;
}


x86 assembly (clang, -O0):
<lerArquivo>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1196 <lerArquivo+0x66>
lea    -0xfb0(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0xfa0,%edx
call   1030 <fread@plt>
mov    %rax,-0xfb8(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0xfb8(%rbp),%rax
movb   $0x0,-0xfb0(%rbp,%rax,1)
lea    -0xfb0(%rbp),%rax
add    $0xfc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lerArquivo>:
push   %r14
push   %rbx
sub    $0xfa8,%rsp
lea    0xebf(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1173 <lerArquivo+0x43>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0xfa0,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <fclose@plt>
movb   $0x0,(%rsp,%r14,1)
mov    %rsp,%rax
add    $0xfa8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i8* @lerArquivo(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [4000 x 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 = icmp ne i32* %7, null
br i1 %8, label %9, label %17
9: ; preds = %1
%10 = getelementptr inbounds [4000 x i8], [4000 x i8]* %4, i64 0, i64 0
%11 = load i32*, i32** %3
%12 = call i64 @fread(i8* %10, i32 1, i32 4000, i32* %11)
store i64 %12, i64* %5
%13 = load i32*, i32** %3
%14 = call i32 @fclose(i32* %13)
%15 = load i64, i64* %5
%16 = getelementptr inbounds [4000 x i8], [4000 x i8]* %4, i64 0, i64 %15
store i8 0, i8* %16
br label %17
17: ; preds = %9, %1
%18 = getelementptr inbounds [4000 x i8], [4000 x i8]* %4, i64 0, i64 0
ret i8* %18
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define noalias i8* @lerArquivo(i8* nocapture %0) {
%2 = alloca [4000 x i8]
%3 = getelementptr inbounds [4000 x i8], [4000 x i8]* %2, i64 0, i64 0
%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 %10, label %6
6: ; preds = %1
%7 = call i64 @fread(i8* %3, i32 1, i32 4000, i32* %4)
%8 = tail call i32 @fclose(i32* %4)
%9 = getelementptr inbounds [4000 x i8], [4000 x i8]* %2, i64 0, i64 %7
store i8 0, i8* %9
br label %10
10: ; preds = %6, %1
ret i8* %3
}