#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 char FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(char *);
char *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
char *ler_string();
char *ler_string_arquivo(char *);
int /*<<< orphan*/ printf(char *);
void ler_arquivo(char **preordem, char **mensagem) {
  char *nome_arquivo = NULL;
  printf("\tNome do arquivo: ");
  nome_arquivo = ler_string();
  FILE *arquivo = fopen(nome_arquivo, "r");
  if (arquivo == NULL) {
    printf("\tO arquivo não pôde ser aberto.\n");
    free(nome_arquivo);
    free(arquivo);
    exit(0);
  }
  *(preordem) = ler_string_arquivo(arquivo);
  *(mensagem) = ler_string_arquivo(arquivo);
  fclose(arquivo);
  free(nome_arquivo);
}


x86 assembly (clang, -O0):
<ler_arquivo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe71(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1090 <ler_string@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e3 <ler_arquivo+0x73>
lea    0xe50(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1080 <ler_string_arquivo@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rdi
call   1080 <ler_string_arquivo@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ler_arquivo>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe6b(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
call   10a0 <ler_string@plt>
mov    %rax,%r12
lea    0xe68(%rip),%rsi
mov    %rax,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ec <ler_arquivo+0x6c>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <ler_string_arquivo@plt>
mov    %rax,(%r15)
mov    %rbx,%rdi
call   1090 <ler_string_arquivo@plt>
mov    %rax,(%r14)
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>
lea    0xe22(%rip),%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   1030 <free@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"\09Nome do arquivo: \00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [35 x i8] c"\09O arquivo n\C3\A3o p\C3\B4de ser aberto.\0A\00"
define void @ler_arquivo(i8** %0, i8** %1) {
%3 = alloca i8**
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
store i8** %0, i8*** %3
store i8** %1, i8*** %4
store i8* null, i8** %5
%7 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%8 = call i8* (...) @ler_string()
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = call i8* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%15 = load i8*, i8** %5
%16 = call i32 @free(i8* %15)
%17 = load i8*, i8** %6
%18 = call i32 @free(i8* %17)
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %2
%21 = load i8*, i8** %6
%22 = call i8* @ler_string_arquivo(i8* %21)
%23 = load i8**, i8*** %3
store i8* %22, i8** %23
%24 = load i8*, i8** %6
%25 = call i8* @ler_string_arquivo(i8* %24)
%26 = load i8**, i8*** %4
store i8* %25, i8** %26
%27 = load i8*, i8** %6
%28 = call i32 @fclose(i8* %27)
%29 = load i8*, i8** %5
%30 = call i32 @free(i8* %29)
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"\09Nome do arquivo: \00"
@.str.1 = [2 x i8] c"r\00"
@str = [34 x i8] c"\09O arquivo n\C3\A3o p\C3\B4de ser aberto.\00"
define void @ler_arquivo(i8** nocapture writeonly %0, i8** nocapture writeonly %1) {
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%4 = tail call i8* (...) @ler_string()
%5 = tail call i8* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @free(i8* %4)
%10 = tail call i32 @free(i8* null)
%11 = tail call i32 @exit(i32 0)
unreachable
12: ; preds = %2
%13 = tail call i8* @ler_string_arquivo(i8* %5)
store i8* %13, i8** %0
%14 = tail call i8* @ler_string_arquivo(i8* %5)
store i8* %14, i8** %1
%15 = tail call i32 @fclose(i8* %5)
%16 = tail call i32 @free(i8* %4)
ret void
}