// File: /workspace/github_cpp_makefile_star2_O1/nataly-enne[P]pet-fera/pet_fera_remover.cpp
// Function: remover(std::map<int, TRATADOR, std::less<int>, std::allocator<std::pair<int const, TRATADOR>>>&)
void remover(map <int, TRATADOR>  &tratadores){
	char c, sucesso = 'n';
	string id_buscado_string, op;
	int id_buscado, verificacao, cont = 0;
	ofstream tratador;

	do{
		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 = tratadores.find(id_buscado);
					
		if(result != tratadores.end()){
			cout << "ID existe!" << endl;
			tratadores.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. */
			tratador.open("tratadores.txt");
			for(auto it = tratadores.begin(); it != tratadores.end(); it++){
				tratador << (*it).second;
			}
			tratador.close();
					
		}
		else{
			cout << "Funcionario não cadastrado!" << endl;
		}
		cout << "Deseja remover outro? s/n" << endl;
		getline(cin, op);
	}while(op == "s");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3d8, %rsp            # imm = 0x3D8
movq %rdi, %rbx
leaq -0x48(%rbp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0x68(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0x278(%rbp), %rdi
callq 0x3360
movq %rbx, -0x38(%rbp)
addq $0x8, %rbx
movb $0x1, %r14b
movq 0x12af7(%rip), %r15     # 0x47fd0
leaq -0x278(%rbp), %r12
movl $0x15, %edx
movq %r15, %rdi
leaq 0x5d78(%rip), %rsi      # 0x3b267
callq 0x3250
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x31f0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3130
testb $0x1, %r14b
je 0x3552d
movq 0x12ab8(%rip), %rdi     # 0x47fe0
callq 0x33a0
movq 0x12aac(%rip), %rcx     # 0x47fe0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x31f0
movsbl %al, %edx
movq 0x12a8e(%rip), %rdi     # 0x47fe0
leaq -0x58(%rbp), %rsi
callq 0x33c0
movq -0x50(%rbp), %rax
testl %eax, %eax
jle 0x3557a
decl %eax
movq -0x58(%rbp), %rcx
movsbl (%rcx,%rax), %eax
addl $-0x30, %eax
xorl %r13d, %r13d
cmpl $0xa, %eax
setb %r13b
testl %r13d, %r13d
je 0x355c0
leaq -0x400(%rbp), %r14
movq %r14, %rdi
leaq -0x58(%rbp), %rsi
movl $0x18, %edx
callq 0x3310
movq %r14, %rdi
leaq -0x2c(%rbp), %rsi
callq 0x3120
movq %r14, %rdi
movq 0x12a03(%rip), %rsi     # 0x47fb0
callq 0x3160
leaq -0x380(%rbp), %rdi
callq 0x30d0
jmp 0x35625
movl $0x38, %edx
movq %r15, %rdi
leaq 0x5e7a(%rip), %rsi      # 0x3b449
callq 0x3250
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x31f0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3130
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x31f0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3130
xorl %r14d, %r14d
testl %r13d, %r13d
je 0x354e0
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rcx
movq %rbx, %rax
testq %rcx, %rcx
je 0x3565e
movl -0x2c(%rbp), %edx
movq %rbx, %rax
xorl %esi, %esi
cmpl %edx, 0x20(%rcx)
setl %sil
cmovgeq %rcx, %rax
movq 0x10(%rcx,%rsi,8), %rcx
testq %rcx, %rcx
jne 0x35647
movq %rbx, %r14
cmpq %rbx, %rax
je 0x35673
movl -0x2c(%rbp), %ecx
cmpl 0x20(%rax), %ecx
cmovlq %rbx, %rax
movq %rax, %r14
cmpq %rbx, %r14
je 0x3570a
movl $0xa, %edx
movq %r15, %rdi
leaq 0x5bf2(%rip), %rsi      # 0x3b27d
callq 0x3250
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x31f0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3130
movq -0x38(%rbp), %rdi
movq %r14, %rsi
callq 0x35a8a
movq %r12, %rdi
leaq 0x537b(%rip), %rsi      # 0x3aa48
movl $0x10, %edx
callq 0x3050
movq -0x38(%rbp), %rax
movq 0x18(%rax), %r14
cmpq %rbx, %r14
je 0x35700
leaq 0x28(%r14), %rsi
movq %r12, %rdi
callq 0xffb4
movq %r14, %rdi
callq 0x3140
movq %rax, %r14
cmpq %rbx, %rax
jne 0x356e4
movq %r12, %rdi
callq 0x32a0
jmp 0x35745
movl $0x1c, %edx
movq %r15, %rdi
leaq 0x5ddc(%rip), %rsi      # 0x3b4f5
callq 0x3250
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x31f0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3130
movl $0x19, %edx
movq %r15, %rdi
leaq 0x5d46(%rip), %rsi      # 0x3b49a
callq 0x3250
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x31f0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3130
movq 0x12859(%rip), %rcx     # 0x47fe0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x31f0
movsbl %al, %edx
movq 0x1283b(%rip), %rdi     # 0x47fe0
leaq -0x78(%rbp), %rsi
callq 0x33c0
leaq -0x78(%rbp), %rdi
leaq 0x4e38(%rip), %rsi      # 0x3a5f1
callq 0x30c0
xorl %r14d, %r14d
testl %eax, %eax
je 0x354e0
movq 0x127f8(%rip), %rax     # 0x47fc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x270(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x278(%rbp,%rcx)
callq 0x3190
leaq -0x180(%rbp), %rdi
callq 0x30d0
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x35811
callq 0x31d0
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x35823
callq 0x31d0
addq $0x3d8, %rsp            # imm = 0x3D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x35873
jmp 0x35864
movq %rax, %rbx
movq 0x1276a(%rip), %rsi     # 0x47fb0
leaq -0x400(%rbp), %rdi
callq 0x3160
leaq -0x380(%rbp), %rdi
callq 0x30d0
jmp 0x35867
jmp 0x35864
jmp 0x35864
movq %rax, %rbx
leaq -0x278(%rbp), %rdi
callq 0x32e0
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x35885
callq 0x31d0
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x35897
callq 0x31d0
movq %rbx, %rdi
callq 0x3380
nop