// File: nataly-enne[P]pet-fera/pet_fera_remover.cpp
// Function: remover(std::map<int, REPTIL_NATIVO, std::less<int>, std::allocator<std::pair<int const, REPTIL_NATIVO>>>&, std::map<int, REPTIL_EXOTICO, std::less<int>, std::allocator<std::pair<int const, REPTIL_EXOTICO>>>&)
void remover(map <int, REPTIL_NATIVO> &repteis_nat, map <int, REPTIL_EXOTICO> &repteis_ex){
	char op, opcao, resp, c, sucesso = 'n';
	string id_buscado_string;
	int id_buscado, verificacao, cont = 0;
	ofstream nativos;
	ofstream exoticos;	

	do{
		cout << "É nativo ou exotico? \n n - NATIVO\n e - EXOTICO" << endl;
		cin >> opcao;
		if(opcao != 'n' && opcao != 'e'){
			cout << "Opção inválida!! Tente novamente!\n" << endl;
			cout << endl;
			cout << "Deseja sair? s/n" << endl;
			cin >> resp;
			if(resp == 's'){
				break;
			}	
		}
		else{ 
			if(opcao == 'n'){
				do{
					cout << "Insira o ID buscado: " << endl;
					if(!cont){
						cin.ignore();
						cont++;
					}
					getline(cin, id_buscado_string);
					for(int i=0; i<(int)id_buscado_string.size(); i++){
						c = id_buscado_string[i];
						verificacao = isdigit(c);
					}
					if(!verificacao){
						cout << "ERRO: apenas numeros inteiros positivos são permitidos!"<< endl << endl;
						sucesso = 'n';
					}else{
						stringstream ss(id_buscado_string);
						ss >> id_buscado;
						sucesso = 's';
					}
				}while(sucesso == 'n');

				auto result = repteis_nat.find(id_buscado);
					
				if(result != repteis_nat.end()){
					cout << "ID existe!" << endl;
					repteis_nat.erase(result);

					/* A condição do map não ser vazio para escrever no arquivo foi removido, para que mesmo quando o map estiver vazio escreva no arquivo
					senão, quando o arquivo só tiver uma linha e o usuário for apagar essa linha, mesmo assim o arquivo permacerá com essa linha. */
					nativos.open("repteis_nat.txt");
					for(auto it = repteis_nat.begin(); it != repteis_nat.end(); it++){
						nativos << (*it).second;
					}
						nativos.close();
					//sucesso = 's';
				}
				else{
					cout << "Animal não cadastrado!" << endl;
				}
				cout << "Deseja remover outro? s/n" << endl;
				cin >> op;

			}
			else{
				cout << "Insira o ID buscado: " << endl;
				cin >> id_buscado;

				auto result = repteis_ex.find(id_buscado);
					
				if(result != repteis_ex.end()){
					cout << "ID existe!" << endl;
					repteis_ex.erase(result);

					/* A condição do map não ser vazio para escrever no arquivo foi removido, para que mesmo quando o map estiver vazio escreva no arquivo
					senão, quando o arquivo só tiver uma linha e o usuário for apagar essa linha, mesmo assim o arquivo permacerá com essa linha. */
					exoticos.open("repteis_ex.txt");
					for(auto it = repteis_ex.begin(); it != repteis_ex.end(); it++){
						exoticos << (*it).second;
					}
					exoticos.close();
					//sucesso = 's';
				}
				else{
					cout << "Animal não cadastrado!" << endl;
				}
				cout << "Deseja remover outro? s/n" << endl;
				cin >> op;
			}
		} // Primeiro else.
	}while(op == 's');
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x700, %rsp            # imm = 0x700
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb $0x6e, -0x15(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x3300
movl $0x0, -0x44(%rbp)
leaq -0x248(%rbp), %rdi
callq 0x33b0
jmp 0x39b35
leaq -0x458(%rbp), %rdi
callq 0x33b0
jmp 0x39b43
jmp 0x39b45
movq 0x1746c(%rip), %rdi     # 0x50fb8
leaq 0x86a4(%rip), %rsi      # 0x421f7
callq 0x3240
movq %rax, -0x660(%rbp)
jmp 0x39b61
movq -0x660(%rbp), %rdi
movq 0x17431(%rip), %rsi     # 0x50fa0
callq 0x3280
jmp 0x39b76
movq 0x1745b(%rip), %rdi     # 0x50fd8
leaq -0x12(%rbp), %rsi
callq 0x32e0
jmp 0x39b88
movsbl -0x12(%rbp), %eax
cmpl $0x6e, %eax
je 0x39c83
movsbl -0x12(%rbp), %eax
cmpl $0x65, %eax
je 0x39c83
movq 0x1740f(%rip), %rdi     # 0x50fb8
leaq 0x8621(%rip), %rsi      # 0x421d1
callq 0x3240
movq %rax, -0x668(%rbp)
jmp 0x39bbe
movq -0x668(%rbp), %rdi
movq 0x173d4(%rip), %rsi     # 0x50fa0
callq 0x3280
jmp 0x39bd3
movq 0x173de(%rip), %rdi     # 0x50fb8
movq 0x173bf(%rip), %rsi     # 0x50fa0
callq 0x3280
jmp 0x39be8
movq 0x173c9(%rip), %rdi     # 0x50fb8
leaq 0x79e2(%rip), %rsi      # 0x415d8
callq 0x3240
movq %rax, -0x670(%rbp)
jmp 0x39c04
movq -0x670(%rbp), %rdi
movq 0x1738e(%rip), %rsi     # 0x50fa0
callq 0x3280
jmp 0x39c19
movq 0x173b8(%rip), %rdi     # 0x50fd8
leaq -0x13(%rbp), %rsi
callq 0x32e0
jmp 0x39c2b
movsbl -0x13(%rbp), %eax
cmpl $0x73, %eax
jne 0x39c7e
jmp 0x3a22b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
jmp 0x3a26d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
jmp 0x3a261
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
jmp 0x3a255
jmp 0x3a21c
movsbl -0x12(%rbp), %eax
cmpl $0x6e, %eax
jne 0x3a00c
jmp 0x39c92
movq 0x1731f(%rip), %rdi     # 0x50fb8
leaq 0x8587(%rip), %rsi      # 0x42227
callq 0x3240
movq %rax, -0x678(%rbp)
jmp 0x39cae
movq -0x678(%rbp), %rdi
movq 0x172e4(%rip), %rsi     # 0x50fa0
callq 0x3280
jmp 0x39cc3
cmpl $0x0, -0x44(%rbp)
jne 0x39ce0
movq 0x17308(%rip), %rdi     # 0x50fd8
callq 0x33f0
jmp 0x39cd7
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movq 0x172f1(%rip), %rdi     # 0x50fd8
leaq -0x38(%rbp), %rsi
callq 0x3070
jmp 0x39cf2
movl $0x0, -0x45c(%rbp)
movl -0x45c(%rbp), %eax
movl %eax, -0x67c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x31a0
movq %rax, %rcx
movl -0x67c(%rbp), %eax
cmpl %ecx, %eax
jge 0x39d60
movslq -0x45c(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x3430
movq %rax, -0x688(%rbp)
jmp 0x39d37
movq -0x688(%rbp), %rax
movb (%rax), %al
movb %al, -0x14(%rbp)
movsbl -0x14(%rbp), %edi
callq 0x3220
movl %eax, -0x40(%rbp)
movl -0x45c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x45c(%rbp)
jmp 0x39cfc
cmpl $0x0, -0x40(%rbp)
jne 0x39db9
movq 0x1724b(%rip), %rdi     # 0x50fb8
leaq 0x8695(%rip), %rsi      # 0x42409
callq 0x3240
movq %rax, -0x690(%rbp)
jmp 0x39d82
movq -0x690(%rbp), %rdi
movq 0x17210(%rip), %rsi     # 0x50fa0
callq 0x3280
movq %rax, -0x698(%rbp)
jmp 0x39d9e
movq -0x698(%rbp), %rdi
movq 0x171f4(%rip), %rsi     # 0x50fa0
callq 0x3280
jmp 0x39db3
movb $0x6e, -0x15(%rbp)
jmp 0x39e2f
movl $0x10, %edi
movl $0x8, %esi
callq 0x13c90
movl %eax, -0x69c(%rbp)
jmp 0x39dd0
movl -0x69c(%rbp), %edx
leaq -0x5e8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x3370
jmp 0x39de8
leaq -0x5e8(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x3170
jmp 0x39dfa
movb $0x73, -0x15(%rbp)
leaq -0x5e8(%rbp), %rdi
callq 0x31b0
jmp 0x39e2f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
leaq -0x5e8(%rbp), %rdi
callq 0x31b0
jmp 0x3a255
jmp 0x39e31
movsbl -0x15(%rbp), %eax
cmpl $0x6e, %eax
je 0x39c92
movq -0x8(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x37790
movq %rax, -0x6a8(%rbp)
jmp 0x39e54
movq -0x6a8(%rbp), %rax
movq %rax, -0x5f0(%rbp)
movq -0x8(%rbp), %rdi
callq 0x14110
movq %rax, -0x5f8(%rbp)
leaq -0x5f0(%rbp), %rdi
leaq -0x5f8(%rbp), %rsi
callq 0x140e0
testb $0x1, %al
jne 0x39e8e
jmp 0x39f91
movq 0x17123(%rip), %rdi     # 0x50fb8
leaq 0x83a1(%rip), %rsi      # 0x4223d
callq 0x3240
movq %rax, -0x6b0(%rbp)
jmp 0x39eaa
movq -0x6b0(%rbp), %rdi
movq 0x170e8(%rip), %rsi     # 0x50fa0
callq 0x3280
jmp 0x39ebf
movq -0x8(%rbp), %rdi
movq -0x5f0(%rbp), %rax
movq %rax, -0x600(%rbp)
movq -0x600(%rbp), %rsi
callq 0x3b4e0
movq %rax, -0x6b8(%rbp)
jmp 0x39ee6
movq -0x6b8(%rbp), %rax
movq %rax, -0x608(%rbp)
leaq 0x81bc(%rip), %rsi      # 0x420b7
leaq -0x248(%rbp), %rdi
movl $0x10, %edx
callq 0x3050
jmp 0x39f0e
movq -0x8(%rbp), %rdi
callq 0x140b0
movq %rax, -0x610(%rbp)
movq -0x8(%rbp), %rdi
callq 0x14110
movq %rax, -0x618(%rbp)
leaq -0x610(%rbp), %rdi
leaq -0x618(%rbp), %rsi
callq 0x140e0
testb $0x1, %al
jne 0x39f47
jmp 0x39f81
leaq -0x610(%rbp), %rdi
callq 0x1ff80
movq %rax, %rsi
addq $0x8, %rsi
leaq -0x248(%rbp), %rdi
callq 0xfd10
jmp 0x39f68
jmp 0x39f6a
leaq -0x610(%rbp), %rdi
xorl %esi, %esi
callq 0x14170
movq %rax, -0x620(%rbp)
jmp 0x39f1e
leaq -0x248(%rbp), %rdi
callq 0x3310
jmp 0x39f8f
jmp 0x39fc4
movq 0x17020(%rip), %rdi     # 0x50fb8
leaq 0x84a3(%rip), %rsi      # 0x42442
callq 0x3240
movq %rax, -0x6c0(%rbp)
jmp 0x39fad
movq -0x6c0(%rbp), %rdi
movq 0x16fe5(%rip), %rsi     # 0x50fa0
callq 0x3280
jmp 0x39fc2
jmp 0x39fc4
movq 0x16fed(%rip), %rdi     # 0x50fb8
leaq 0x8488(%rip), %rsi      # 0x4245a
callq 0x3240
movq %rax, -0x6c8(%rbp)
jmp 0x39fe0
movq -0x6c8(%rbp), %rdi
movq 0x16fb2(%rip), %rsi     # 0x50fa0
callq 0x3280
jmp 0x39ff5
movq 0x16fdc(%rip), %rdi     # 0x50fd8
leaq -0x11(%rbp), %rsi
callq 0x32e0
jmp 0x3a007
jmp 0x3a21a
movq 0x16fa5(%rip), %rdi     # 0x50fb8
leaq 0x820d(%rip), %rsi      # 0x42227
callq 0x3240
movq %rax, -0x6d0(%rbp)
jmp 0x3a028
movq -0x6d0(%rbp), %rdi
movq 0x16f6a(%rip), %rsi     # 0x50fa0
callq 0x3280
jmp 0x3a03d
movq 0x16f94(%rip), %rdi     # 0x50fd8
leaq -0x3c(%rbp), %rsi
callq 0x3170
jmp 0x3a04f
movq -0x10(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x37810
movq %rax, -0x6d8(%rbp)
jmp 0x3a065
movq -0x6d8(%rbp), %rax
movq %rax, -0x628(%rbp)
movq -0x10(%rbp), %rdi
callq 0x14210
movq %rax, -0x630(%rbp)
leaq -0x628(%rbp), %rdi
leaq -0x630(%rbp), %rsi
callq 0x141e0
testb $0x1, %al
jne 0x3a09f
jmp 0x3a1a2
movq 0x16f12(%rip), %rdi     # 0x50fb8
leaq 0x8190(%rip), %rsi      # 0x4223d
callq 0x3240
movq %rax, -0x6e0(%rbp)
jmp 0x3a0bb
movq -0x6e0(%rbp), %rdi
movq 0x16ed7(%rip), %rsi     # 0x50fa0
callq 0x3280
jmp 0x3a0d0
movq -0x10(%rbp), %rdi
movq -0x628(%rbp), %rax
movq %rax, -0x638(%rbp)
movq -0x638(%rbp), %rsi
callq 0x3b520
movq %rax, -0x6e8(%rbp)
jmp 0x3a0f7
movq -0x6e8(%rbp), %rax
movq %rax, -0x640(%rbp)
leaq 0x7fbb(%rip), %rsi      # 0x420c7
leaq -0x458(%rbp), %rdi
movl $0x10, %edx
callq 0x3050
jmp 0x3a11f
movq -0x10(%rbp), %rdi
callq 0x141b0
movq %rax, -0x648(%rbp)
movq -0x10(%rbp), %rdi
callq 0x14210
movq %rax, -0x650(%rbp)
leaq -0x648(%rbp), %rdi
leaq -0x650(%rbp), %rsi
callq 0x141e0
testb $0x1, %al
jne 0x3a158
jmp 0x3a192
leaq -0x648(%rbp), %rdi
callq 0x1ffc0
movq %rax, %rsi
addq $0x8, %rsi
leaq -0x458(%rbp), %rdi
callq 0x10320
jmp 0x3a179
jmp 0x3a17b
leaq -0x648(%rbp), %rdi
xorl %esi, %esi
callq 0x14270
movq %rax, -0x658(%rbp)
jmp 0x3a12f
leaq -0x458(%rbp), %rdi
callq 0x3310
jmp 0x3a1a0
jmp 0x3a1d5
movq 0x16e0f(%rip), %rdi     # 0x50fb8
leaq 0x8292(%rip), %rsi      # 0x42442
callq 0x3240
movq %rax, -0x6f0(%rbp)
jmp 0x3a1be
movq -0x6f0(%rbp), %rdi
movq 0x16dd4(%rip), %rsi     # 0x50fa0
callq 0x3280
jmp 0x3a1d3
jmp 0x3a1d5
movq 0x16ddc(%rip), %rdi     # 0x50fb8
leaq 0x8277(%rip), %rsi      # 0x4245a
callq 0x3240
movq %rax, -0x6f8(%rbp)
jmp 0x3a1f1
movq -0x6f8(%rbp), %rdi
movq 0x16da1(%rip), %rsi     # 0x50fa0
callq 0x3280
jmp 0x3a206
movq 0x16dcb(%rip), %rdi     # 0x50fd8
leaq -0x11(%rbp), %rsi
callq 0x32e0
jmp 0x3a218
jmp 0x3a21a
jmp 0x3a21c
jmp 0x3a21e
movsbl -0x11(%rbp), %eax
cmpl $0x73, %eax
je 0x39b45
leaq -0x458(%rbp), %rdi
callq 0x3340
leaq -0x248(%rbp), %rdi
callq 0x3340
leaq -0x38(%rbp), %rdi
callq 0x3180
addq $0x700, %rsp            # imm = 0x700
popq %rbp
retq
leaq -0x458(%rbp), %rdi
callq 0x3340
leaq -0x248(%rbp), %rdi
callq 0x3340
leaq -0x38(%rbp), %rdi
callq 0x3180
movq -0x250(%rbp), %rdi
callq 0x33d0
nopw %cs:(%rax,%rax)