#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*/ carregarVetorAgenda();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
char getch();
int /*<<< orphan*/ gets(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
scalar_t__ realloc(char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ system(char *);
void cadastrar() {
  char *nome = NULL;
  char *telefone = NULL;
  nome = (char *)malloc(sizeof(char));
  telefone = (char *)malloc(sizeof(char));
  int flag = 1;
  char F;
  while (flag) {
    system("cls");
    printf("==================================================================="
           "=============\n");
    printf("||                     INSERIR CONTATOS - AGENDA APS               "
           "           ||\n");
    printf("==================================================================="
           "=============\n\n");
    nome = (char *)realloc(nome, sizeof(char));
    telefone = (char *)realloc(nome, sizeof(char));
    if (nome == NULL || telefone == NULL) {
      printf("\nErro nos ponteiros\n");
      exit(0);
    }
    FILE *arquivoNome = fopen("nome.txt", "a");
    if (arquivoNome == 0) {
      printf("\nErro ao acessar arquivo NOME\n");
      exit(0);
    }
    printf("Insira o Nome: ");
    gets(nome);
    strcat(nome, "\n");
    fputs(nome, arquivoNome);
    fclose(arquivoNome);
    FILE *arquivoTelefone = fopen("telefone.txt", "a");
    if (arquivoTelefone == 0) {
      printf("\nErro ao acessar arquivo TELEFONE\n");
      exit(0);
    }
    printf("Insira o Telefone: ");
    gets(telefone);
    strcat(telefone, "\n");
    fputs(telefone, arquivoTelefone);
    fclose(arquivoTelefone);
    printf("\n\nPressione F para fechar ou qualquer tecla para continuar ...");
    F = getch();
    switch (F) {
    case ('F'):
    case ('f'):
      carregarVetorAgenda();
      flag = 0;
      break;
    }
  }
}


x86 assembly (clang, -O0):
<cadastrar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     13a0 <cadastrar+0x1e0>
lea    0xdf4(%rip),%rdi
call   1040 <system@plt>
lea    0xdec(%rip),%rdi
call   1050 <printf@plt>
lea    0xe32(%rip),%rdi
call   1050 <printf@plt>
lea    0xe78(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   10a0 <realloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   10a0 <realloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     126f <cadastrar+0xaf>
cmpq   $0x0,-0x10(%rbp)
jne    1282 <cadastrar+0xc2>
lea    0xe85(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
lea    0xe87(%rip),%rdi
lea    0xe89(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12b7 <cadastrar+0xf7>
lea    0xe70(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
lea    0xe7c(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1070 <gets@plt>
mov    -0x8(%rbp),%rdi
lea    0xe22(%rip),%rsi
call   10d0 <strcat@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <fputs@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe51(%rip),%rdi
lea    0xe19(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1327 <cadastrar+0x167>
lea    0xe3c(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
lea    0xe4c(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1070 <gets@plt>
mov    -0x10(%rbp),%rdi
lea    0xdb2(%rip),%rsi
call   10d0 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <fputs@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe25(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
call   10b0 <getch@plt>
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%eax
or     $0x20,%eax
sub    $0x66,%eax
je     138d <cadastrar+0x1cd>
jmp    139b <cadastrar+0x1db>
mov    $0x0,%al
call   1090 <carregarVetorAgenda@plt>
movl   $0x0,-0x14(%rbp)
jmp    11fb <cadastrar+0x3b>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cadastrar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    $0x1,%edi
call   1090 <malloc@plt>
lea    0xe14(%rip),%r14
lea    0xf71(%rip),%r12
lea    0xe39(%rip),%r15
nopw   0x0(%rax,%rax,1)
lea    0xde9(%rip),%rdi
call   1050 <system@plt>
lea    0xe5c(%rip),%rdi
call   1030 <puts@plt>
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
lea    0xee6(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   10b0 <realloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1,%esi
call   10b0 <realloc@plt>
test   %rbx,%rbx
je     133b <cadastrar+0x16b>
mov    %rax,%r13
test   %rax,%rax
je     133b <cadastrar+0x16b>
lea    0xd8b(%rip),%rdi
mov    %r14,%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1344 <cadastrar+0x174>
mov    %rax,%rbp
lea    0xd7b(%rip),%rdi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1080 <gets@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10e0 <strcat@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1070 <fputs@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
lea    0xd59(%rip),%rdi
mov    %r14,%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     134d <cadastrar+0x17d>
mov    %rax,%rbp
lea    0xd4f(%rip),%rdi
call   1060 <printf@plt>
mov    %r13,%rdi
call   1080 <gets@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   10e0 <strcat@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   1070 <fputs@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1060 <printf@plt>
xor    %eax,%eax
call   10c0 <getch@plt>
movsbl %al,%eax
or     $0x20,%eax
cmp    $0x66,%eax
jne    1210 <cadastrar+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10a0 <carregarVetorAgenda@plt>
lea    0xe71(%rip),%rdi
jmp    1354 <cadastrar+0x184>
lea    0xe4a(%rip),%rdi
jmp    1354 <cadastrar+0x184>
lea    0xe1f(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"cls\00"
@.str.1 = [82 x i8] c"================================================================================\0A\00"
@.str.2 = [82 x i8] c"|| INSERIR CONTATOS - AGENDA APS ||\0A\00"
@.str.3 = [83 x i8] c"================================================================================\0A\0A\00"
@.str.4 = [21 x i8] c"\0AErro nos ponteiros\0A\00"
@.str.5 = [9 x i8] c"nome.txt\00"
@.str.6 = [2 x i8] c"a\00"
@.str.7 = [31 x i8] c"\0AErro ao acessar arquivo NOME\0A\00"
@.str.8 = [16 x i8] c"Insira o Nome: \00"
@.str.9 = [2 x i8] c"\0A\00"
@.str.10 = [13 x i8] c"telefone.txt\00"
@.str.11 = [35 x i8] c"\0AErro ao acessar arquivo TELEFONE\0A\00"
@.str.12 = [20 x i8] c"Insira o Telefone: \00"
@.str.13 = [63 x i8] c"\0A\0APressione F para fechar ou qualquer tecla para continuar ...\00"
define void @cadastrar() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32*
%6 = alloca i32*
store i8* null, i8** %1
store i8* null, i8** %2
%7 = call i64 @malloc(i32 1)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %1
%9 = call i64 @malloc(i32 1)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %2
store i32 1, i32* %3
br label %11
11: ; preds = %74, %0
%12 = load i32, i32* %3
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %75
14: ; preds = %11
%15 = call i32 @system(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @printf(i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str.3, i64 0, i64 0))
%19 = load i8*, i8** %1
%20 = call i64 @realloc(i8* %19, i32 1)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %1
%22 = load i8*, i8** %1
%23 = call i64 @realloc(i8* %22, i32 1)
%24 = inttoptr i64 %23 to i8*
store i8* %24, i8** %2
%25 = load i8*, i8** %1
%26 = icmp eq i8* %25, null
br i1 %26, label %30, label %27
27: ; preds = %14
%28 = load i8*, i8** %2
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %33
30: ; preds = %27, %14
%31 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %27
%34 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %34, i32** %5
%35 = load i32*, i32** %5
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
%39 = call i32 @exit(i32 0)
unreachable
40: ; preds = %33
%41 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
%42 = load i8*, i8** %1
%43 = call i32 @gets(i8* %42)
%44 = load i8*, i8** %1
%45 = call i32 @strcat(i8* %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%46 = load i8*, i8** %1
%47 = load i32*, i32** %5
%48 = call i32 @fputs(i8* %46, i32* %47)
%49 = load i32*, i32** %5
%50 = call i32 @fclose(i32* %49)
%51 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %51, i32** %6
%52 = load i32*, i32** %6
%53 = icmp eq i32* %52, null
br i1 %53, label %54, label %57
54: ; preds = %40
%55 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0))
%56 = call i32 @exit(i32 0)
unreachable
57: ; preds = %40
%58 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i64 0, i64 0))
%59 = load i8*, i8** %2
%60 = call i32 @gets(i8* %59)
%61 = load i8*, i8** %2
%62 = call i32 @strcat(i8* %61, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%63 = load i8*, i8** %2
%64 = load i32*, i32** %6
%65 = call i32 @fputs(i8* %63, i32* %64)
%66 = load i32*, i32** %6
%67 = call i32 @fclose(i32* %66)
%68 = call i32 @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.13, i64 0, i64 0))
%69 = call signext i8 (...) @getch()
store i8 %69, i8* %4
%70 = load i8, i8* %4
%71 = sext i8 %70 to i32
switch i32 %71, label %74 [
i32 70, label %72
i32 102, label %72
]
72: ; preds = %57, %57
%73 = call i32 (...) @carregarVetorAgenda()
store i32 0, i32* %3
br label %74
74: ; preds = %57, %72
br label %11
75: ; preds = %11
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"cls\00"
@.str.5 = [9 x i8] c"nome.txt\00"
@.str.6 = [2 x i8] c"a\00"
@.str.8 = [16 x i8] c"Insira o Nome: \00"
@.str.9 = [2 x i8] c"\0A\00"
@.str.10 = [13 x i8] c"telefone.txt\00"
@.str.12 = [20 x i8] c"Insira o Telefone: \00"
@.str.13 = [63 x i8] c"\0A\0APressione F para fechar ou qualquer tecla para continuar ...\00"
@str = [81 x i8] c"================================================================================\00"
@str.14 = [81 x i8] c"|| INSERIR CONTATOS - AGENDA APS ||\00"
@str.15 = [82 x i8] c"================================================================================\0A\00"
@str.16 = [34 x i8] c"\0AErro ao acessar arquivo TELEFONE\00"
@str.17 = [30 x i8] c"\0AErro ao acessar arquivo NOME\00"
@str.18 = [20 x i8] c"\0AErro nos ponteiros\00"
define void @cadastrar() {
%1 = tail call i64 @malloc(i32 1)
%2 = inttoptr i64 %1 to i8*
%3 = tail call i64 @malloc(i32 1)
br label %4
4: ; preds = %37, %0
%5 = phi i8* [ %2, %0 ], [ %11, %37 ]
%6 = tail call i32 @system(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @str.14, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([82 x i8], [82 x i8]* @str.15, i64 0, i64 0))
%10 = tail call i64 @realloc(i8* %5, i32 1)
%11 = inttoptr i64 %10 to i8*
%12 = tail call i64 @realloc(i8* %11, i32 1)
%13 = inttoptr i64 %12 to i8*
%14 = icmp eq i64 %10, 0
%15 = icmp eq i64 %12, 0
%16 = select i1 %14, i1 true, i1 %15
br i1 %16, label %17, label %20
17: ; preds = %4
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.18, i64 0, i64 0))
%19 = tail call i32 @exit(i32 0)
unreachable
20: ; preds = %4
%21 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.17, i64 0, i64 0))
%25 = tail call i32 @exit(i32 0)
unreachable
26: ; preds = %20
%27 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
%28 = tail call i32 @gets(i8* %11)
%29 = tail call i32 @strcat(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%30 = tail call i32 @fputs(i8* %11, i32* %21)
%31 = tail call i32 @fclose(i32* %21)
%32 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %37
34: ; preds = %26
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.16, i64 0, i64 0))
%36 = tail call i32 @exit(i32 0)
unreachable
37: ; preds = %26
%38 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i64 0, i64 0))
%39 = tail call i32 @gets(i8* %13)
%40 = tail call i32 @strcat(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%41 = tail call i32 @fputs(i8* %13, i32* %32)
%42 = tail call i32 @fclose(i32* %32)
%43 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str.13, i64 0, i64 0))
%44 = tail call signext i8 (...) @getch()
%45 = sext i8 %44 to i32
switch i32 %45, label %4 [
i32 70, label %46
i32 102, label %46
]
46: ; preds = %37, %37
%47 = tail call i32 (...) @carregarVetorAgenda()
ret void
}