#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);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
size_t strlen(char *);
void nome_arquivo(char *nome, int numero) {
  FILE *alocacao;
  printf("Digite o nome do %dº documento: ", numero);
  do {
    scanf("%[^\n]", nome);
    getchar();
    alocacao = abre_arquivo(nome, 'r');
    if (alocacao == NULL)
      printf("Digite o nome do documento novamente: ");
  } while (alocacao == NULL);
  nome[strlen(nome)] = '\0';
  fclose(alocacao);
}


x86 assembly (clang, -O0):
<nome_arquivo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%rsi
lea    0xe97(%rip),%rdi
call   1080 <scanf@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    -0x8(%rbp),%rdi
mov    $0x72,%esi
call   1030 <abre_arquivo@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c2 <nome_arquivo+0x62>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    11c7 <nome_arquivo+0x67>
cmpq   $0x0,-0x18(%rbp)
je     1180 <nome_arquivo+0x20>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nome_arquivo>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
lea    0xe8e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xea2(%rip),%rdi
mov    %r12,%rsi
call   1080 <scanf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %r12,%rdi
mov    $0x72,%esi
call   1030 <abre_arquivo@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11f1 <nome_arquivo+0x91>
lea    0xe7d(%rip),%r14
lea    0xe70(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1080 <scanf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %r12,%rdi
mov    $0x72,%esi
call   1030 <abre_arquivo@plt>
test   %rax,%rax
je     11c0 <nome_arquivo+0x60>
mov    %rax,%rbx
mov    %r12,%rdi
call   1050 <strlen@plt>
movb   $0x0,(%r12,%rax,1)
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <fclose@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"Digite o nome do %d\C2\BA documento: \00"
@.str.1 = [6 x i8] c"%[^\0A]\00"
@.str.2 = [39 x i8] c"Digite o nome do documento novamente: \00"
define void @nome_arquivo(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %6)
br label %8
8: ; preds = %19, %2
%9 = load i8*, i8** %3
%10 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = call i32 (...) @getchar()
%12 = load i8*, i8** %3
%13 = call i32* @abre_arquivo(i8* %12, i8 signext 114)
store i32* %13, i32** %5
%14 = load i32*, i32** %5
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %8
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %8
br label %19
19: ; preds = %18
%20 = load i32*, i32** %5
%21 = icmp eq i32* %20, null
br i1 %21, label %8, label %22
22: ; preds = %19
%23 = load i8*, i8** %3
%24 = load i8*, i8** %3
%25 = call i64 @strlen(i8* %24)
%26 = getelementptr inbounds i8, i8* %23, i64 %25
store i8 0, i8* %26
%27 = load i32*, i32** %5
%28 = call i32 @fclose(i32* %27)
ret void
}

LLVM IR (-O2):
@.str = [34 x i8] c"Digite o nome do %d\C2\BA documento: \00"
@.str.1 = [6 x i8] c"%[^\0A]\00"
@.str.2 = [39 x i8] c"Digite o nome do documento novamente: \00"
define void @nome_arquivo(i8* %0, i32 %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %1)
%4 = tail call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%5 = tail call i32 (...) @getchar()
%6 = tail call i32* @abre_arquivo(i8* %0, i8 signext 114)
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %14
8: ; preds = %2, %8
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%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 = tail call i32* @abre_arquivo(i8* %0, i8 signext 114)
%13 = icmp eq i32* %12, null
br i1 %13, label %8, label %14
14: ; preds = %8, %2
%15 = phi i32* [ %6, %2 ], [ %12, %8 ]
%16 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%17 = getelementptr inbounds i8, i8* %0, i64 %16
store i8 0, i8* %17
%18 = tail call i32 @fclose(i32* %15)
ret void
}