#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*/ *abre_arquivo(char *, char, char);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
char *ler_palavra();
char ler_simounao();
int /*<<< orphan*/ printf(char *, ...);
char *ler_nome_doc(int doc, int tot, char cond) {
  FILE *alocacao;
  char *nome, resp = 'S';
  do {
    if (cond == 'l')
      printf("\nDigite o nome do %dº documento, dentre o(s) %d,\na ser "
             "analisado, com a extensao .txt:\n",
             doc, tot);
    else
      printf("\nDigite o nome do documento a ser armazenados os dados, com a "
             "extensao .txt:\n");
    nome = ler_palavra();
    while (nome[0] == 0) {
      printf("\nNome invalido! Digite novamente!\n");
      nome = ler_palavra();
    }
    alocacao = abre_arquivo(nome, 'r', cond);
    if (cond == 'l') {
      if (alocacao == NULL)
        printf("\nO arquivo fornecido nao existe neste diretorio! Digite o "
               "nome novamente!\n");
    } else {
      if (alocacao != NULL) {
        printf("\nO arquivo ja existe! Deseja sobrescrever? S/N ou s/n\n");
        resp = ler_simounao();
        if (resp == 'N' || resp == 'n')
          printf("\nEntao digite um nome novamente!\n");
        else
          printf("\nEntao, prosseguindo...\n");
      }
    }
  } while ((cond == 'l' && alocacao == NULL) ||
           (cond == 'e' && (resp != 'S' && resp != 's')));
  free(alocacao);
  return nome;
}


x86 assembly (clang, -O0):
<ler_nome_doc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movb   $0x53,-0x21(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x6c,%eax
jne    118d <ler_nome_doc+0x3d>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    119b <ler_nome_doc+0x4b>
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <ler_palavra@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11d4 <ler_nome_doc+0x84>
lea    0xeea(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <ler_palavra@plt>
mov    %rax,-0x20(%rbp)
jmp    11a6 <ler_nome_doc+0x56>
mov    -0x20(%rbp),%rdi
mov    $0x72,%esi
movsbl -0x9(%rbp),%edx
call   1040 <abre_arquivo@plt>
mov    %rax,-0x18(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x6c,%eax
jne    1215 <ler_nome_doc+0xc5>
cmpq   $0x0,-0x18(%rbp)
jne    1210 <ler_nome_doc+0xc0>
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    127d <ler_nome_doc+0x12d>
cmpq   $0x0,-0x18(%rbp)
je     1278 <ler_nome_doc+0x128>
lea    0xeee(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <ler_simounao@plt>
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
cmp    $0x4e,%eax
je     1252 <ler_nome_doc+0x102>
movsbl -0x21(%rbp),%eax
cmp    $0x6e,%eax
jne    1265 <ler_nome_doc+0x115>
lea    0xef3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1273 <ler_nome_doc+0x123>
lea    0xf02(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1278 <ler_nome_doc+0x128>
jmp    127d <ler_nome_doc+0x12d>
jmp    1282 <ler_nome_doc+0x132>
movsbl -0x9(%rbp),%eax
cmp    $0x6c,%eax
jne    129f <ler_nome_doc+0x14f>
mov    $0x1,%al
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x22(%rbp)
je     12dc <ler_nome_doc+0x18c>
movsbl -0x9(%rbp),%ecx
xor    %eax,%eax
cmp    $0x65,%ecx
mov    %al,-0x23(%rbp)
jne    12d6 <ler_nome_doc+0x186>
movsbl -0x21(%rbp),%ecx
xor    %eax,%eax
cmp    $0x53,%ecx
mov    %al,-0x24(%rbp)
je     12d0 <ler_nome_doc+0x180>
movsbl -0x21(%rbp),%eax
cmp    $0x73,%eax
setne  %al
mov    %al,-0x24(%rbp)
mov    -0x24(%rbp),%al
mov    %al,-0x23(%rbp)
mov    -0x23(%rbp),%al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
test   $0x1,%al
jne    1167 <ler_nome_doc+0x17>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ler_nome_doc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,0x4(%rsp)
mov    %edi,%r12d
movb   $0x53,0x2(%rsp)
lea    0xfdf(%rip),%rbp
movsbl %bl,%r13d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x6c,%bl
jne    11b0 <ler_nome_doc+0x50>
lea    0xe64(%rip),%rdi
mov    %r12d,%esi
mov    0x4(%rsp),%edx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11bc <ler_nome_doc+0x5c>
nopl   0x0(%rax)
lea    0xea2(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1070 <ler_palavra@plt>
mov    %rax,%r15
cmpb   $0x0,(%rax)
jne    11e7 <ler_nome_doc+0x87>
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1070 <ler_palavra@plt>
cmpb   $0x0,(%rax)
je     11d0 <ler_nome_doc+0x70>
mov    %rax,%r15
mov    %r15,%rdi
mov    $0x72,%esi
mov    %r13d,%edx
call   1040 <abre_arquivo@plt>
mov    %rax,%r14
cmp    $0x6c,%bl
jne    1215 <ler_nome_doc+0xb5>
test   %r14,%r14
jne    127a <ler_nome_doc+0x11a>
lea    0xf0a(%rip),%rdi
call   1050 <puts@plt>
jmp    1190 <ler_nome_doc+0x30>
test   %r14,%r14
je     124c <ler_nome_doc+0xec>
lea    0xe85(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1080 <ler_simounao@plt>
mov    %al,0x2(%rsp)
and    $0xdf,%al
cmp    $0x4e,%al
jne    1259 <ler_nome_doc+0xf9>
lea    0xeb6(%rip),%rdi
call   1050 <puts@plt>
mov    $0x4e,%al
cmp    $0x65,%bl
je     1272 <ler_nome_doc+0x112>
jmp    127a <ler_nome_doc+0x11a>
mov    0x2(%rsp),%al
and    $0xdf,%al
cmp    $0x65,%bl
je     1272 <ler_nome_doc+0x112>
jmp    127a <ler_nome_doc+0x11a>
lea    0xe7c(%rip),%rdi
mov    %al,0x3(%rsp)
call   1050 <puts@plt>
mov    0x3(%rsp),%al
cmp    $0x65,%bl
jne    127a <ler_nome_doc+0x11a>
cmp    $0x53,%al
jne    1190 <ler_nome_doc+0x30>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [89 x i8] c"\0ADigite o nome do %d\C2\BA documento, dentre o(s) %d,\0Aa ser analisado, com a extensao .txt:\0A\00"
@.str.1 = [78 x i8] c"\0ADigite o nome do documento a ser armazenados os dados, com a extensao .txt:\0A\00"
@.str.2 = [35 x i8] c"\0ANome invalido! Digite novamente!\0A\00"
@.str.3 = [75 x i8] c"\0AO arquivo fornecido nao existe neste diretorio! Digite o nome novamente!\0A\00"
@.str.4 = [55 x i8] c"\0AO arquivo ja existe! Deseja sobrescrever? S/N ou s/n\0A\00"
@.str.5 = [34 x i8] c"\0AEntao digite um nome novamente!\0A\00"
@.str.6 = [25 x i8] c"\0AEntao, prosseguindo...\0A\00"
define i8* @ler_nome_doc(i32 %0, i32 %1, i8 signext %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8 %2, i8* %6
store i8 83, i8* %9
br label %10
10: ; preds = %87, %3
%11 = load i8, i8* %6
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 108
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i32, i32* %4
%16 = load i32, i32* %5
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %16)
br label %20
18: ; preds = %10
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
%21 = call i8* (...) @ler_palavra()
store i8* %21, i8** %8
br label %22
22: ; preds = %28, %20
%23 = load i8*, i8** %8
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%30 = call i8* (...) @ler_palavra()
store i8* %30, i8** %8
br label %22
31: ; preds = %22
%32 = load i8*, i8** %8
%33 = load i8, i8* %6
%34 = call i32* @abre_arquivo(i8* %32, i8 signext 114, i8 signext %33)
store i32* %34, i32** %7
%35 = load i8, i8* %6
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 108
br i1 %37, label %38, label %44
38: ; preds = %31
%39 = load i32*, i32** %7
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.3, i64 0, i64 0))
br label %43
43: ; preds = %41, %38
br label %63
44: ; preds = %31
%45 = load i32*, i32** %7
%46 = icmp ne i32* %45, null
br i1 %46, label %47, label %62
47: ; preds = %44
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0))
%49 = call signext i8 (...) @ler_simounao()
store i8 %49, i8* %9
%50 = load i8, i8* %9
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 78
br i1 %52, label %57, label %53
53: ; preds = %47
%54 = load i8, i8* %9
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 110
br i1 %56, label %57, label %59
57: ; preds = %53, %47
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
br label %61
59: ; preds = %53
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
br label %61
61: ; preds = %59, %57
br label %62
62: ; preds = %61, %44
br label %63
63: ; preds = %62, %43
br label %64
64: ; preds = %63
%65 = load i8, i8* %6
%66 = sext i8 %65 to i32
%67 = icmp eq i32 %66, 108
br i1 %67, label %68, label %71
68: ; preds = %64
%69 = load i32*, i32** %7
%70 = icmp eq i32* %69, null
br i1 %70, label %87, label %71
71: ; preds = %68, %64
%72 = load i8, i8* %6
%73 = sext i8 %72 to i32
%74 = icmp eq i32 %73, 101
br i1 %74, label %75, label %85
75: ; preds = %71
%76 = load i8, i8* %9
%77 = sext i8 %76 to i32
%78 = icmp ne i32 %77, 83
br i1 %78, label %79, label %83
79: ; preds = %75
%80 = load i8, i8* %9
%81 = sext i8 %80 to i32
%82 = icmp ne i32 %81, 115
br label %83
83: ; preds = %79, %75
%84 = phi i1 [ false, %75 ], [ %82, %79 ]
br label %85
85: ; preds = %83, %71
%86 = phi i1 [ false, %71 ], [ %84, %83 ]
br label %87
87: ; preds = %85, %68
%88 = phi i1 [ true, %68 ], [ %86, %85 ]
br i1 %88, label %10, label %89
89: ; preds = %87
%90 = load i32*, i32** %7
%91 = call i32 @free(i32* %90)
%92 = load i8*, i8** %8
ret i8* %92
}

LLVM IR (-O2):
@.str = [89 x i8] c"\0ADigite o nome do %d\C2\BA documento, dentre o(s) %d,\0Aa ser analisado, com a extensao .txt:\0A\00"
@str = [77 x i8] c"\0ADigite o nome do documento a ser armazenados os dados, com a extensao .txt:\00"
@str.7 = [54 x i8] c"\0AO arquivo ja existe! Deseja sobrescrever? S/N ou s/n\00"
@str.8 = [24 x i8] c"\0AEntao, prosseguindo...\00"
@str.9 = [33 x i8] c"\0AEntao digite um nome novamente!\00"
@str.10 = [74 x i8] c"\0AO arquivo fornecido nao existe neste diretorio! Digite o nome novamente!\00"
@str.11 = [34 x i8] c"\0ANome invalido! Digite novamente!\00"
define i8* @ler_nome_doc(i32 %0, i32 %1, i8 signext %2) {
%4 = icmp eq i8 %2, 108
%5 = icmp ne i8 %2, 101
br label %6
6: ; preds = %41, %3
%7 = phi i8 [ %43, %41 ], [ 83, %3 ]
br label %8
8: ; preds = %6, %39
br i1 %4, label %9, label %11
9: ; preds = %8
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([89 x i8], [89 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1)
br label %13
11: ; preds = %8
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([77 x i8], [77 x i8]* @str, i64 0, i64 0))
br label %13
13: ; preds = %11, %9
%14 = tail call i8* (...) @ler_palavra()
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %13, %17
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.11, i64 0, i64 0))
%19 = tail call i8* (...) @ler_palavra()
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %17, label %22
22: ; preds = %17, %13
%23 = phi i8* [ %14, %13 ], [ %19, %17 ]
%24 = tail call i32* @abre_arquivo(i8* %23, i8 signext 114, i8 signext %2)
%25 = icmp eq i32* %24, null
br i1 %4, label %26, label %27
26: ; preds = %22
br i1 %25, label %39, label %46
27: ; preds = %22
br i1 %25, label %28, label %30
28: ; preds = %27
%29 = and i8 %7, -33
br label %41
30: ; preds = %27
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str.7, i64 0, i64 0))
%32 = tail call signext i8 (...) @ler_simounao()
%33 = and i8 %32, -33
%34 = icmp eq i8 %33, 78
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.9, i64 0, i64 0))
br label %41
37: ; preds = %30
%38 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.8, i64 0, i64 0))
br label %41
39: ; preds = %26
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @str.10, i64 0, i64 0))
br label %8
41: ; preds = %28, %35, %37
%42 = phi i8 [ %29, %28 ], [ 78, %35 ], [ %33, %37 ]
%43 = phi i8 [ %7, %28 ], [ %32, %35 ], [ %32, %37 ]
%44 = icmp eq i8 %42, 83
%45 = select i1 %5, i1 true, i1 %44
br i1 %45, label %46, label %6
46: ; preds = %41, %26
%47 = tail call i32 @free(i32* %24)
ret i8* %23
}