// File: /workspace/github_cpp_makefile_star2_O3/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, -0x30(%rbp)
leaq 0x8(%rbx), %r12
movb $0x1, %bl
movq 0x12bfb(%rip), %r15     # 0x47fd0
movq 0x12c04(%rip), %r13     # 0x47fe0
movl $0x15, %edx
movq %r15, %rdi
leaq 0x5e7c(%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, %bl
je 0x35424
movq %r13, %rdi
callq 0x33a0
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x31f0
movsbl %al, %edx
movq %r13, %rdi
leaq -0x58(%rbp), %rsi
callq 0x33c0
movq -0x50(%rbp), %rax
testl %eax, %eax
jle 0x35467
decl %eax
movq -0x58(%rbp), %rcx
movsbl (%rcx,%rax), %eax
addl $-0x30, %eax
xorl %r14d, %r14d
cmpl $0xa, %eax
setb %r14b
testl %r14d, %r14d
je 0x3559f
leaq -0x400(%rbp), %rbx
movq %rbx, %rdi
leaq -0x58(%rbp), %rsi
movl $0x18, %edx
callq 0x3310
movq %rbx, %rdi
leaq -0x34(%rbp), %rsi
callq 0x3120
movq %rbx, %rdi
movq 0x12b12(%rip), %rsi     # 0x47fb0
callq 0x3160
leaq -0x380(%rbp), %rdi
callq 0x30d0
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rcx
testq %rcx, %rcx
je 0x354e6
movl -0x34(%rbp), %eax
movq %r12, %rbx
xorl %edx, %edx
cmpl %eax, 0x20(%rcx)
setl %dl
cmovgeq %rcx, %rbx
movq 0x10(%rcx,%rdx,8), %rcx
testq %rcx, %rcx
jne 0x354c2
cmpq %r12, %rbx
je 0x354e6
cmpl 0x20(%rbx), %eax
jge 0x3560e
movl $0x1c, %edx
movq %r15, %rdi
leaq 0x6000(%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 0x5f6a(%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 (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x31f0
movsbl %al, %edx
movq %r13, %rdi
leaq -0x78(%rbp), %rsi
callq 0x33c0
leaq -0x78(%rbp), %rdi
leaq 0x5066(%rip), %rsi      # 0x3a5f1
callq 0x30c0
xorl %ebx, %ebx
testl %eax, %eax
je 0x353dc
jmp 0x356ab
movl $0x38, %edx
movq %r15, %rdi
leaq 0x5e9b(%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, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x31f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
xorl %ebx, %ebx
movq %rax, %rdi
callq 0x3130
xorl %r14d, %r14d
jmp 0x353dc
movl $0xa, %edx
movq %r15, %rdi
leaq 0x5c60(%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 -0x30(%rbp), %rdi
movq %rbx, %rsi
callq 0x3596c
leaq -0x278(%rbp), %rdi
leaq 0x53e5(%rip), %rsi      # 0x3aa48
movl $0x10, %edx
callq 0x3050
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rbx
cmpq %r12, %rbx
je 0x3569a
leaq 0x28(%rbx), %rsi
leaq -0x278(%rbp), %rdi
callq 0xffb8
movq %rbx, %rdi
callq 0x3140
movq %rax, %rbx
cmpq %r12, %rax
jne 0x3567a
leaq -0x278(%rbp), %rdi
callq 0x32a0
jmp 0x35521
movq 0x12916(%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 0x356f3
callq 0x31d0
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x35705
callq 0x31d0
addq $0x3d8, %rsp            # imm = 0x3D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x35755
jmp 0x35746
movq %rax, %rbx
movq 0x12888(%rip), %rsi     # 0x47fb0
leaq -0x400(%rbp), %rdi
callq 0x3160
leaq -0x380(%rbp), %rdi
callq 0x30d0
jmp 0x35749
jmp 0x35746
jmp 0x35746
movq %rax, %rbx
leaq -0x278(%rbp), %rdi
callq 0x32e0
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x35767
callq 0x31d0
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x35779
callq 0x31d0
movq %rbx, %rdi
callq 0x3380
nop