#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 */

/* Variables and functions */
int /*<<< orphan*/ apaga(char *);
int /*<<< orphan*/ copia(char *, char *);
int /*<<< orphan*/ cria_agenda_arquivo(char const *);
int /*<<< orphan*/ edita(char *);
int /*<<< orphan*/ limpa_arquivo(char *);
int /*<<< orphan*/ lista(char *);
int /*<<< orphan*/ pesquisa(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ saida(int, int /*<<< orphan*/);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
int main(int argc, const char *argv[]) {
  int op = 0, op2 = 0;
  char arquivo[1000], origem[1000], file[1000] = "", nome_agenda[1000];
  strcat(arquivo, "Agenda.txt");
  strcat(origem, arquivo);
  strcat(origem, ".editado");
  while (op != 9) {
    saida(10, 0);
    scanf("%d", &op);
    switch (op) {
    case 1:
      if (argc == 2)
        cria_agenda_arquivo(argv[1]);
      else {
        puts("Informe o nome do arquivo:");
        scanf("%s", file);
        cria_agenda_arquivo(file);
      }
      break;
    case 2:
      lista(arquivo);
      break;
    case 3:
      edita(arquivo);
      copia(arquivo, origem);
      break;
    case 4:
      apaga(arquivo);
      copia(arquivo, origem);
      break;
    case 5:
      pesquisa(arquivo);
      break;
    case 6:
      limpa_arquivo(arquivo);
      break;
    case 9:
      break;
    default:
      saida(9, 0);
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfe0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    -0xbe0(%rbp),%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1080 <memset@plt>
lea    -0x400(%rbp),%rdi
lea    0xe1c(%rip),%rsi
call   10e0 <strcat@plt>
lea    -0x7f0(%rbp),%rdi
lea    -0x400(%rbp),%rsi
call   10e0 <strcat@plt>
lea    -0x7f0(%rbp),%rdi
lea    0xe01(%rip),%rsi
call   10e0 <strcat@plt>
cmpl   $0x9,-0x14(%rbp)
je     1373 <main+0x1b3>
mov    $0xa,%edi
xor    %esi,%esi
mov    %esi,-0xfdc(%rbp)
call   1040 <saida@plt>
mov    -0xfdc(%rbp),%eax
lea    0xddc(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   10b0 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0xfd8(%rbp)
sub    $0x8,%eax
ja     1362 <main+0x1a2>
mov    -0xfd8(%rbp),%rax
lea    0xd75(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
cmpl   $0x2,-0x8(%rbp)
jne    12b0 <main+0xf0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <cria_agenda_arquivo@plt>
jmp    12dd <main+0x11d>
lea    0xd84(%rip),%rdi
call   1050 <puts@plt>
lea    -0xbe0(%rbp),%rsi
lea    0xd8c(%rip),%rdi
mov    $0x0,%al
call   10b0 <scanf@plt>
lea    -0xbe0(%rbp),%rdi
call   1030 <cria_agenda_arquivo@plt>
jmp    136e <main+0x1ae>
lea    -0x400(%rbp),%rdi
call   1060 <lista@plt>
jmp    136e <main+0x1ae>
lea    -0x400(%rbp),%rdi
call   10a0 <edita@plt>
lea    -0x400(%rbp),%rdi
lea    -0x7f0(%rbp),%rsi
call   1070 <copia@plt>
jmp    136e <main+0x1ae>
lea    -0x400(%rbp),%rdi
call   10c0 <apaga@plt>
lea    -0x400(%rbp),%rdi
lea    -0x7f0(%rbp),%rsi
call   1070 <copia@plt>
jmp    136e <main+0x1ae>
lea    -0x400(%rbp),%rdi
call   10d0 <pesquisa@plt>
jmp    136e <main+0x1ae>
lea    -0x400(%rbp),%rdi
call   1090 <limpa_arquivo@plt>
jmp    136e <main+0x1ae>
jmp    136e <main+0x1ae>
mov    $0x9,%edi
xor    %esi,%esi
call   1040 <saida@plt>
jmp    1233 <main+0x73>
xor    %eax,%eax
add    $0xfe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xbd8,%rsp
mov    %rsi,0x8(%rsp)
mov    %edi,%r12d
movl   $0x0,0x4(%rsp)
lea    0x10(%rsp),%rdi
mov    $0x3e8,%edx
xor    %esi,%esi
call   1080 <memset@plt>
lea    0xe2b(%rip),%rsi
lea    0x7f0(%rsp),%rbp
mov    %rbp,%rdi
call   10e0 <strcat@plt>
lea    0x400(%rsp),%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10e0 <strcat@plt>
lea    0xe0c(%rip),%rsi
mov    %rbx,%rdi
call   10e0 <strcat@plt>
lea    0xe06(%rip),%r13
lea    0x4(%rsp),%r14
lea    0xdc2(%rip),%r15
jmp    125e <main+0x9e>
mov    %rbp,%rdi
call   10a0 <edita@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1070 <copia@plt>
cmpl   $0x9,0x4(%rsp)
je     131e <main+0x15e>
mov    $0xa,%edi
xor    %esi,%esi
call   1040 <saida@plt>
mov    %r13,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   10b0 <scanf@plt>
mov    0x4(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0x8,%eax
ja     12ca <main+0x10a>
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
cmp    $0x2,%r12d
jne    12db <main+0x11b>
mov    0x8(%rsp),%rax
mov    0x8(%rax),%rdi
call   1030 <cria_agenda_arquivo@plt>
jmp    1253 <main+0x93>
mov    %rbp,%rdi
call   1060 <lista@plt>
jmp    1253 <main+0x93>
mov    %rbp,%rdi
call   10c0 <apaga@plt>
jmp    1248 <main+0x88>
mov    %rbp,%rdi
call   10d0 <pesquisa@plt>
jmp    1253 <main+0x93>
mov    %rbp,%rdi
call   1090 <limpa_arquivo@plt>
jmp    1253 <main+0x93>
mov    $0x9,%edi
xor    %esi,%esi
call   1040 <saida@plt>
jmp    1253 <main+0x93>
lea    0xd59(%rip),%rdi
call   1050 <puts@plt>
lea    0xd68(%rip),%rdi
mov    %r14,%rbx
mov    %r12d,%r14d
lea    0x10(%rsp),%r12
mov    %r12,%rsi
xor    %eax,%eax
call   10b0 <scanf@plt>
mov    %r12,%rdi
mov    %r14d,%r12d
mov    %rbx,%r14
lea    0x400(%rsp),%rbx
call   1030 <cria_agenda_arquivo@plt>
jmp    1253 <main+0x93>
xor    %eax,%eax
add    $0xbd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"Agenda.txt\00"
@.str.1 = [9 x i8] c".editado\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [27 x i8] c"Informe o nome do arquivo:\00"
@.str.4 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1000 x i8]
%9 = alloca [1000 x i8]
%10 = alloca [1000 x i8]
%11 = alloca [1000 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
%12 = bitcast [1000 x i8]* %10 to i8*
%13 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%14 = call i32 @strcat(i8* %13, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%16 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%17 = call i32 @strcat(i8* %15, i8* %16)
%18 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%19 = call i32 @strcat(i8* %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %66, %2
%21 = load i32, i32* %6
%22 = icmp ne i32 %21, 9
br i1 %22, label %23, label %67
23: ; preds = %20
%24 = call i32 @saida(i32 10, i32 0)
%25 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%26 = load i32, i32* %6
switch i32 %26, label %64 [
i32 1, label %27
i32 2, label %42
i32 3, label %45
i32 4, label %51
i32 5, label %57
i32 6, label %60
i32 9, label %63
]
27: ; preds = %23
%28 = load i32, i32* %4
%29 = icmp eq i32 %28, 2
br i1 %29, label %30, label %35
30: ; preds = %27
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @cria_agenda_arquivo(i8* %33)
br label %41
35: ; preds = %27
%36 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%37 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%38 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %37)
%39 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%40 = call i32 @cria_agenda_arquivo(i8* %39)
br label %41
41: ; preds = %35, %30
br label %66
42: ; preds = %23
%43 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%44 = call i32 @lista(i8* %43)
br label %66
45: ; preds = %23
%46 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%47 = call i32 @edita(i8* %46)
%48 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%49 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%50 = call i32 @copia(i8* %48, i8* %49)
br label %66
51: ; preds = %23
%52 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%53 = call i32 @apaga(i8* %52)
%54 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%55 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%56 = call i32 @copia(i8* %54, i8* %55)
br label %66
57: ; preds = %23
%58 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%59 = call i32 @pesquisa(i8* %58)
br label %66
60: ; preds = %23
%61 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%62 = call i32 @limpa_arquivo(i8* %61)
br label %66
63: ; preds = %23
br label %66
64: ; preds = %23
%65 = call i32 @saida(i32 9, i32 0)
br label %66
66: ; preds = %64, %63, %60, %57, %51, %45, %42, %41
br label %20
67: ; preds = %20
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"Agenda.txt\00"
@.str.1 = [9 x i8] c".editado\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [27 x i8] c"Informe o nome do arquivo:\00"
@.str.4 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [1000 x i8]
%5 = alloca [1000 x i8]
%6 = alloca [1000 x i8]
%7 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%8 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%11 = call i32 @strcat(i8* %8, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @strcat(i8* %9, i8* %8)
%13 = call i32 @strcat(i8* %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32 %0, 2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
br label %16
16: ; preds = %2, %42
%17 = call i32 @saida(i32 10, i32 0)
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%19 = load i32, i32* %3
switch i32 %19, label %40 [
i32 1, label %20
i32 2, label %28
i32 3, label %30
i32 4, label %33
i32 5, label %36
i32 6, label %38
i32 9, label %45
]
20: ; preds = %16
br i1 %14, label %21, label %24
21: ; preds = %20
%22 = load i8*, i8** %15
%23 = call i32 @cria_agenda_arquivo(i8* %22)
br label %42
24: ; preds = %20
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%26 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %10)
%27 = call i32 @cria_agenda_arquivo(i8* %10)
br label %42
28: ; preds = %16
%29 = call i32 @lista(i8* %8)
br label %42
30: ; preds = %16
%31 = call i32 @edita(i8* %8)
%32 = call i32 @copia(i8* %8, i8* %9)
br label %42
33: ; preds = %16
%34 = call i32 @apaga(i8* %8)
%35 = call i32 @copia(i8* %8, i8* %9)
br label %42
36: ; preds = %16
%37 = call i32 @pesquisa(i8* %8)
br label %42
38: ; preds = %16
%39 = call i32 @limpa_arquivo(i8* %8)
br label %42
40: ; preds = %16
%41 = call i32 @saida(i32 9, i32 0)
br label %42
42: ; preds = %21, %24, %40, %38, %36, %33, %30, %28
%43 = load i32, i32* %3
%44 = icmp eq i32 %43, 9
br i1 %44, label %45, label %16
45: ; preds = %16, %42
ret i32 0
}