// File: nataly-enne[P]pet-fera/pet_fera_remover.cpp
// Function: remover(std::map<int, MAMIFERO_NATIVO, std::less<int>, std::allocator<std::pair<int const, MAMIFERO_NATIVO>>>&, std::map<int, MAMIFERO_EXOTICO, std::less<int>, std::allocator<std::pair<int const, MAMIFERO_EXOTICO>>>&)
void remover(map <int, MAMIFERO_NATIVO> &mamiferos_nat, map <int, MAMIFERO_EXOTICO> &mamiferos_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 = mamiferos_nat.find(id_buscado);
					
				if(result != mamiferos_nat.end()){
					cout << "ID existe!" << endl;
					mamiferos_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("mamiferos_nat.txt");
					for(auto it = mamiferos_nat.begin(); it != mamiferos_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 = mamiferos_ex.find(id_buscado);
					
				if(result != mamiferos_ex.end()){
					cout << "ID existe!" << endl;
					mamiferos_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("mamiferos_ex.txt");
					for(auto it = mamiferos_ex.begin(); it != mamiferos_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 0x393a5
leaq -0x458(%rbp), %rdi
callq 0x33b0
jmp 0x393b3
jmp 0x393b5
movq 0x17bfc(%rip), %rdi     # 0x50fb8
leaq 0x8e34(%rip), %rsi      # 0x421f7
callq 0x3240
movq %rax, -0x660(%rbp)
jmp 0x393d1
movq -0x660(%rbp), %rdi
movq 0x17bc1(%rip), %rsi     # 0x50fa0
callq 0x3280
jmp 0x393e6
movq 0x17beb(%rip), %rdi     # 0x50fd8
leaq -0x12(%rbp), %rsi
callq 0x32e0
jmp 0x393f8
movsbl -0x12(%rbp), %eax
cmpl $0x6e, %eax
je 0x394f3
movsbl -0x12(%rbp), %eax
cmpl $0x65, %eax
je 0x394f3
movq 0x17b9f(%rip), %rdi     # 0x50fb8
leaq 0x8db1(%rip), %rsi      # 0x421d1
callq 0x3240
movq %rax, -0x668(%rbp)
jmp 0x3942e
movq -0x668(%rbp), %rdi
movq 0x17b64(%rip), %rsi     # 0x50fa0
callq 0x3280
jmp 0x39443
movq 0x17b6e(%rip), %rdi     # 0x50fb8
movq 0x17b4f(%rip), %rsi     # 0x50fa0
callq 0x3280
jmp 0x39458
movq 0x17b59(%rip), %rdi     # 0x50fb8
leaq 0x8172(%rip), %rsi      # 0x415d8
callq 0x3240
movq %rax, -0x670(%rbp)
jmp 0x39474
movq -0x670(%rbp), %rdi
movq 0x17b1e(%rip), %rsi     # 0x50fa0
callq 0x3280
jmp 0x39489
movq 0x17b48(%rip), %rdi     # 0x50fd8
leaq -0x13(%rbp), %rsi
callq 0x32e0
jmp 0x3949b
movsbl -0x13(%rbp), %eax
cmpl $0x73, %eax
jne 0x394ee
jmp 0x39a9b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
jmp 0x39add
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
jmp 0x39ad1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
jmp 0x39ac5
jmp 0x39a8c
movsbl -0x12(%rbp), %eax
cmpl $0x6e, %eax
jne 0x3987c
jmp 0x39502
movq 0x17aaf(%rip), %rdi     # 0x50fb8
leaq 0x8d17(%rip), %rsi      # 0x42227
callq 0x3240
movq %rax, -0x678(%rbp)
jmp 0x3951e
movq -0x678(%rbp), %rdi
movq 0x17a74(%rip), %rsi     # 0x50fa0
callq 0x3280
jmp 0x39533
cmpl $0x0, -0x44(%rbp)
jne 0x39550
movq 0x17a98(%rip), %rdi     # 0x50fd8
callq 0x33f0
jmp 0x39547
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movq 0x17a81(%rip), %rdi     # 0x50fd8
leaq -0x38(%rbp), %rsi
callq 0x3070
jmp 0x39562
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 0x395d0
movslq -0x45c(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x3430
movq %rax, -0x688(%rbp)
jmp 0x395a7
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 0x3956c
cmpl $0x0, -0x40(%rbp)
jne 0x39629
movq 0x179db(%rip), %rdi     # 0x50fb8
leaq 0x8e25(%rip), %rsi      # 0x42409
callq 0x3240
movq %rax, -0x690(%rbp)
jmp 0x395f2
movq -0x690(%rbp), %rdi
movq 0x179a0(%rip), %rsi     # 0x50fa0
callq 0x3280
movq %rax, -0x698(%rbp)
jmp 0x3960e
movq -0x698(%rbp), %rdi
movq 0x17984(%rip), %rsi     # 0x50fa0
callq 0x3280
jmp 0x39623
movb $0x6e, -0x15(%rbp)
jmp 0x3969f
movl $0x10, %edi
movl $0x8, %esi
callq 0x13c90
movl %eax, -0x69c(%rbp)
jmp 0x39640
movl -0x69c(%rbp), %edx
leaq -0x5e8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x3370
jmp 0x39658
leaq -0x5e8(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x3170
jmp 0x3966a
movb $0x73, -0x15(%rbp)
leaq -0x5e8(%rbp), %rdi
callq 0x31b0
jmp 0x3969f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
leaq -0x5e8(%rbp), %rdi
callq 0x31b0
jmp 0x39ac5
jmp 0x396a1
movsbl -0x15(%rbp), %eax
cmpl $0x6e, %eax
je 0x39502
movq -0x8(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x37690
movq %rax, -0x6a8(%rbp)
jmp 0x396c4
movq -0x6a8(%rbp), %rax
movq %rax, -0x5f0(%rbp)
movq -0x8(%rbp), %rdi
callq 0x13f10
movq %rax, -0x5f8(%rbp)
leaq -0x5f0(%rbp), %rdi
leaq -0x5f8(%rbp), %rsi
callq 0x13ee0
testb $0x1, %al
jne 0x396fe
jmp 0x39801
movq 0x178b3(%rip), %rdi     # 0x50fb8
leaq 0x8b31(%rip), %rsi      # 0x4223d
callq 0x3240
movq %rax, -0x6b0(%rbp)
jmp 0x3971a
movq -0x6b0(%rbp), %rdi
movq 0x17878(%rip), %rsi     # 0x50fa0
callq 0x3280
jmp 0x3972f
movq -0x8(%rbp), %rdi
movq -0x5f0(%rbp), %rax
movq %rax, -0x600(%rbp)
movq -0x600(%rbp), %rsi
callq 0x3b460
movq %rax, -0x6b8(%rbp)
jmp 0x39756
movq -0x6b8(%rbp), %rax
movq %rax, -0x608(%rbp)
leaq 0x884e(%rip), %rsi      # 0x41fb9
leaq -0x248(%rbp), %rdi
movl $0x10, %edx
callq 0x3050
jmp 0x3977e
movq -0x8(%rbp), %rdi
callq 0x13eb0
movq %rax, -0x610(%rbp)
movq -0x8(%rbp), %rdi
callq 0x13f10
movq %rax, -0x618(%rbp)
leaq -0x610(%rbp), %rdi
leaq -0x618(%rbp), %rsi
callq 0x13ee0
testb $0x1, %al
jne 0x397b7
jmp 0x397f1
leaq -0x610(%rbp), %rdi
callq 0x1fd80
movq %rax, %rsi
addq $0x8, %rsi
leaq -0x248(%rbp), %rdi
callq 0xe2a0
jmp 0x397d8
jmp 0x397da
leaq -0x610(%rbp), %rdi
xorl %esi, %esi
callq 0x13f70
movq %rax, -0x620(%rbp)
jmp 0x3978e
leaq -0x248(%rbp), %rdi
callq 0x3310
jmp 0x397ff
jmp 0x39834
movq 0x177b0(%rip), %rdi     # 0x50fb8
leaq 0x8c33(%rip), %rsi      # 0x42442
callq 0x3240
movq %rax, -0x6c0(%rbp)
jmp 0x3981d
movq -0x6c0(%rbp), %rdi
movq 0x17775(%rip), %rsi     # 0x50fa0
callq 0x3280
jmp 0x39832
jmp 0x39834
movq 0x1777d(%rip), %rdi     # 0x50fb8
leaq 0x8c18(%rip), %rsi      # 0x4245a
callq 0x3240
movq %rax, -0x6c8(%rbp)
jmp 0x39850
movq -0x6c8(%rbp), %rdi
movq 0x17742(%rip), %rsi     # 0x50fa0
callq 0x3280
jmp 0x39865
movq 0x1776c(%rip), %rdi     # 0x50fd8
leaq -0x11(%rbp), %rsi
callq 0x32e0
jmp 0x39877
jmp 0x39a8a
movq 0x17735(%rip), %rdi     # 0x50fb8
leaq 0x899d(%rip), %rsi      # 0x42227
callq 0x3240
movq %rax, -0x6d0(%rbp)
jmp 0x39898
movq -0x6d0(%rbp), %rdi
movq 0x176fa(%rip), %rsi     # 0x50fa0
callq 0x3280
jmp 0x398ad
movq 0x17724(%rip), %rdi     # 0x50fd8
leaq -0x3c(%rbp), %rsi
callq 0x3170
jmp 0x398bf
movq -0x10(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x37710
movq %rax, -0x6d8(%rbp)
jmp 0x398d5
movq -0x6d8(%rbp), %rax
movq %rax, -0x628(%rbp)
movq -0x10(%rbp), %rdi
callq 0x14010
movq %rax, -0x630(%rbp)
leaq -0x628(%rbp), %rdi
leaq -0x630(%rbp), %rsi
callq 0x13fe0
testb $0x1, %al
jne 0x3990f
jmp 0x39a12
movq 0x176a2(%rip), %rdi     # 0x50fb8
leaq 0x8920(%rip), %rsi      # 0x4223d
callq 0x3240
movq %rax, -0x6e0(%rbp)
jmp 0x3992b
movq -0x6e0(%rbp), %rdi
movq 0x17667(%rip), %rsi     # 0x50fa0
callq 0x3280
jmp 0x39940
movq -0x10(%rbp), %rdi
movq -0x628(%rbp), %rax
movq %rax, -0x638(%rbp)
movq -0x638(%rbp), %rsi
callq 0x3b4a0
movq %rax, -0x6e8(%rbp)
jmp 0x39967
movq -0x6e8(%rbp), %rax
movq %rax, -0x640(%rbp)
leaq 0x864f(%rip), %rsi      # 0x41fcb
leaq -0x458(%rbp), %rdi
movl $0x10, %edx
callq 0x3050
jmp 0x3998f
movq -0x10(%rbp), %rdi
callq 0x13fb0
movq %rax, -0x648(%rbp)
movq -0x10(%rbp), %rdi
callq 0x14010
movq %rax, -0x650(%rbp)
leaq -0x648(%rbp), %rdi
leaq -0x650(%rbp), %rsi
callq 0x13fe0
testb $0x1, %al
jne 0x399c8
jmp 0x39a02
leaq -0x648(%rbp), %rdi
callq 0x1fdc0
movq %rax, %rsi
addq $0x8, %rsi
leaq -0x458(%rbp), %rdi
callq 0xe860
jmp 0x399e9
jmp 0x399eb
leaq -0x648(%rbp), %rdi
xorl %esi, %esi
callq 0x14070
movq %rax, -0x658(%rbp)
jmp 0x3999f
leaq -0x458(%rbp), %rdi
callq 0x3310
jmp 0x39a10
jmp 0x39a45
movq 0x1759f(%rip), %rdi     # 0x50fb8
leaq 0x8a22(%rip), %rsi      # 0x42442
callq 0x3240
movq %rax, -0x6f0(%rbp)
jmp 0x39a2e
movq -0x6f0(%rbp), %rdi
movq 0x17564(%rip), %rsi     # 0x50fa0
callq 0x3280
jmp 0x39a43
jmp 0x39a45
movq 0x1756c(%rip), %rdi     # 0x50fb8
leaq 0x8a07(%rip), %rsi      # 0x4245a
callq 0x3240
movq %rax, -0x6f8(%rbp)
jmp 0x39a61
movq -0x6f8(%rbp), %rdi
movq 0x17531(%rip), %rsi     # 0x50fa0
callq 0x3280
jmp 0x39a76
movq 0x1755b(%rip), %rdi     # 0x50fd8
leaq -0x11(%rbp), %rsi
callq 0x32e0
jmp 0x39a88
jmp 0x39a8a
jmp 0x39a8c
jmp 0x39a8e
movsbl -0x11(%rbp), %eax
cmpl $0x73, %eax
je 0x393b5
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)