#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ getchar();
char ler_simounao();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ zera_string(char *, int /*<<< orphan*/, int);
void ler_nome_doc(char *nome) {
  FILE *alocacao;
  char resp = 'S';
  do {
    printf("\nDigite o nome do documento a ser armazenados os dados, com a "
           "extensao .txt:\n");
    do {
      zera_string(nome, 0, 15 * 2);
      scanf("%[^\n]", nome);
      getchar();
      if (nome[0] == 0)
        printf(
            "\nNome invalido! Apenas ENTER foi recolhido! Digite novamente!\n");
    } while (nome[0] == 0);
    alocacao = abre_arquivo(nome, 'r', 'e');
    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");
      fclose(alocacao);
    }
  } while ((resp != 'S' && resp != 's'));
  if (alocacao != NULL)
    fclose(alocacao);
}


x86 assembly (clang, -O0):
<ler_nome_doc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x53,-0x11(%rbp)
lea    0xe79(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x1e,%edx
call   1040 <zera_string@plt>
mov    -0x8(%rbp),%rsi
lea    0xea7(%rip),%rdi
call   1090 <scanf@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11cf <ler_nome_doc+0x5f>
lea    0xe8a(%rip),%rdi
call   1060 <printf@plt>
jmp    11d4 <ler_nome_doc+0x64>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     118c <ler_nome_doc+0x1c>
mov    -0x8(%rbp),%rdi
mov    $0x72,%esi
mov    $0x65,%edx
call   1030 <abre_arquivo@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     125c <ler_nome_doc+0xec>
lea    0xe86(%rip),%rdi
call   1060 <printf@plt>
mov    $0x0,%al
call   1080 <ler_simounao@plt>
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x4e,%eax
je     1236 <ler_nome_doc+0xc6>
movsbl -0x11(%rbp),%eax
cmp    $0x6e,%eax
jne    1247 <ler_nome_doc+0xd7>
lea    0xe8d(%rip),%rdi
call   1060 <printf@plt>
jmp    1253 <ler_nome_doc+0xe3>
lea    0xe9e(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
jmp    1261 <ler_nome_doc+0xf1>
movsbl -0x11(%rbp),%ecx
xor    %eax,%eax
cmp    $0x53,%ecx
mov    %al,-0x12(%rbp)
je     1280 <ler_nome_doc+0x110>
movsbl -0x11(%rbp),%eax
cmp    $0x73,%eax
setne  %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
test   $0x1,%al
jne    1180 <ler_nome_doc+0x10>
cmpq   $0x0,-0x10(%rbp)
je     129f <ler_nome_doc+0x12f>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x20,%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    %rdi,%rbx
mov    $0x53,%bpl
lea    0xe7e(%rip),%r14
lea    0xe71(%rip),%r15
lea    0xf2c(%rip),%r12
and    $0xdf,%bpl
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <puts@plt>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1e,%edx
call   1050 <zera_string@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <scanf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
cmpb   $0x0,(%rbx)
jne    11e3 <ler_nome_doc+0x73>
mov    %r12,%rdi
call   1040 <puts@plt>
cmpb   $0x0,(%rbx)
je     11b0 <ler_nome_doc+0x40>
mov    %rbx,%rdi
mov    $0x72,%esi
mov    $0x65,%edx
call   1030 <abre_arquivo@plt>
test   %rax,%rax
jne    1210 <ler_nome_doc+0xa0>
cmp    $0x53,%bpl
jne    11a0 <ler_nome_doc+0x30>
jmp    1270 <ler_nome_doc+0x100>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rax,%r13
lea    0xe39(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1080 <ler_simounao@plt>
mov    %eax,%ebp
and    $0xdf,%al
mov    %al,0x7(%rsp)
cmp    $0x4e,%al
lea    0xe52(%rip),%rdi
lea    0xe63(%rip),%rax
cmove  %rax,%rdi
call   1040 <puts@plt>
mov    %r13,%rdi
call   1060 <fclose@plt>
cmpb   $0x53,0x7(%rsp)
jne    1196 <ler_nome_doc+0x26>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [78 x i8] c"\0ADigite o nome do documento a ser armazenados os dados, com a extensao .txt:\0A\00"
@.str.1 = [6 x i8] c"%[^\0A]\00"
@.str.2 = [63 x i8] c"\0ANome invalido! Apenas ENTER foi recolhido! Digite novamente!\0A\00"
@.str.3 = [55 x i8] c"\0AO arquivo ja existe! Deseja sobrescrever? S/N ou s/n\0A\00"
@.str.4 = [34 x i8] c"\0AEntao digite um nome novamente!\0A\00"
@.str.5 = [25 x i8] c"\0AEntao, prosseguindo...\0A\00"
define void @ler_nome_doc(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8
store i8* %0, i8** %2
store i8 83, i8* %4
br label %5
5: ; preds = %58, %1
%6 = call i32 @printf(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %21, %5
%8 = load i8*, i8** %2
%9 = call i32 @zera_string(i8* %8, i32 0, i32 30)
%10 = load i8*, i8** %2
%11 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = call i32 (...) @getchar()
%13 = load i8*, i8** %2
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %7
%19 = call i32 @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %7
br label %21
21: ; preds = %20
%22 = load i8*, i8** %2
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 0
br i1 %26, label %7, label %27
27: ; preds = %21
%28 = load i8*, i8** %2
%29 = call i32* @abre_arquivo(i8* %28, i8 signext 114, i8 signext 101)
store i32* %29, i32** %3
%30 = load i32*, i32** %3
%31 = icmp ne i32* %30, null
br i1 %31, label %32, label %49
32: ; preds = %27
%33 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0))
%34 = call signext i8 (...) @ler_simounao()
store i8 %34, i8* %4
%35 = load i8, i8* %4
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 78
br i1 %37, label %42, label %38
38: ; preds = %32
%39 = load i8, i8* %4
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 110
br i1 %41, label %42, label %44
42: ; preds = %38, %32
%43 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
br label %46
44: ; preds = %38
%45 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
br label %46
46: ; preds = %44, %42
%47 = load i32*, i32** %3
%48 = call i32 @fclose(i32* %47)
br label %49
49: ; preds = %46, %27
br label %50
50: ; preds = %49
%51 = load i8, i8* %4
%52 = sext i8 %51 to i32
%53 = icmp ne i32 %52, 83
br i1 %53, label %54, label %58
54: ; preds = %50
%55 = load i8, i8* %4
%56 = sext i8 %55 to i32
%57 = icmp ne i32 %56, 115
br label %58
58: ; preds = %54, %50
%59 = phi i1 [ false, %50 ], [ %57, %54 ]
br i1 %59, label %5, label %60
60: ; preds = %58
%61 = load i32*, i32** %3
%62 = icmp ne i32* %61, null
br i1 %62, label %63, label %66
63: ; preds = %60
%64 = load i32*, i32** %3
%65 = call i32 @fclose(i32* %64)
br label %66
66: ; preds = %63, %60
ret void
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c"%[^\0A]\00"
@str = [77 x i8] c"\0ADigite o nome do documento a ser armazenados os dados, com a extensao .txt:\00"
@str.6 = [54 x i8] c"\0AO arquivo ja existe! Deseja sobrescrever? S/N ou s/n\00"
@str.7 = [24 x i8] c"\0AEntao, prosseguindo...\00"
@str.8 = [33 x i8] c"\0AEntao digite um nome novamente!\00"
@str.9 = [62 x i8] c"\0ANome invalido! Apenas ENTER foi recolhido! Digite novamente!\00"
define void @ler_nome_doc(i8* %0) {
br label %2
2: ; preds = %21, %1
%3 = phi i8 [ %23, %21 ], [ 83, %1 ]
%4 = and i8 %3, -33
%5 = icmp eq i8 %4, 83
br label %6
6: ; preds = %2, %30
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([77 x i8], [77 x i8]* @str, i64 0, i64 0))
br label %8
8: ; preds = %14, %6
%9 = tail call i32 @zera_string(i8* %0, i32 0, i32 30)
%10 = tail call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%11 = tail call i32 (...) @getchar()
%12 = load i8, i8* %0
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %8
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str.9, i64 0, i64 0))
%16 = load i8, i8* %0
%17 = icmp eq i8 %16, 0
br i1 %17, label %8, label %18
18: ; preds = %8, %14
%19 = tail call i32* @abre_arquivo(i8* %0, i8 signext 114, i8 signext 101)
%20 = icmp eq i32* %19, null
br i1 %20, label %30, label %21
21: ; preds = %18
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str.6, i64 0, i64 0))
%23 = tail call signext i8 (...) @ler_simounao()
%24 = and i8 %23, -33
%25 = icmp eq i8 %24, 78
%26 = select i1 %25, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @str.8, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @str.7, i64 0, i64 0)
%27 = tail call i32 @puts(i8* dereferenceable(1) %26)
%28 = tail call i32 @fclose(i32* %19)
%29 = icmp eq i8 %24, 83
br i1 %29, label %31, label %2
30: ; preds = %18
br i1 %5, label %33, label %6
31: ; preds = %21
%32 = tail call i32 @fclose(i32* %19)
br label %33
33: ; preds = %30, %31
ret void
}