// File: /workspace/github_cpp_makefile_star2_O2/brashi[P]PetFera/src/./banco_dados.cpp
// Function: BancoDados::salvarAnimais()
void BancoDados::salvarAnimais() {
    /*if(petshop->getAnimais().size() == 0) {
        throw "Nenhum animal registrado. Geração de arquivo cancelada.";;
    }*/
    ofstream arqDados(animalArq);
    if(arqDados.bad() || arqDados.fail()) {
        throw "Algo deu errado na criação do arquivo de animais.";
    }

    string classe, classificao;

    for(auto& animal : petshop->getAnimais()) {
        classe = Animal::getClasse(animal, true);
        classificao = Animal::getClassificacao(animal, true);
        arqDados << classe << ';' << classificao << ';'
                 << animal->getNome() << ';' << animal->getEspecie() << ';'
                 << animal->getAmeacadoPor() << ';' << animal->getVeterinario()->getNome() << ';'
                 << animal->getTratador()->getNome() << ';'
                 << animal->getPerigoso() << ';';


        switch(strFiltro[classificao]) {
            case 'D':
                arqDados << dynamic_pointer_cast<Domestico>(animal)->getAdestrado() << ';';                
                break;
            case 'E':
                arqDados << dynamic_pointer_cast<Exotico>(animal)->getLocal() << ';';
                break;
            case 'N':
                arqDados << dynamic_pointer_cast<Nativo>(animal)->getRegiao() << ';'
                         << dynamic_pointer_cast<Nativo>(animal)->getLicenca() << ';';
                break;
        }

        switch(strFiltro[classe]) {
            case 'A':
                arqDados << dynamic_pointer_cast<Ave>(animal)->getVoa() << endl;
                break;
            case 'F':
                arqDados << dynamic_pointer_cast<Anfibio>(animal)->getCauda() << ';'
                         << dynamic_pointer_cast<Anfibio>(animal)->getPata() << endl;
                break;
            case 'R':
                arqDados << dynamic_pointer_cast<Reptil>(animal)->getPele() << endl;
                break;
            case 'M':
                arqDados << dynamic_pointer_cast<Mamifero>(animal)->getGestacao() << endl;
                break;
        }


    }

    arqDados.close();
    if(fs::is_empty(animalArq)) {
        fs::remove(animalArq);
        return;
    }
    cout << "Arquivo de animais salvo com sucesso." << endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x358, %rsp            # imm = 0x358
movq %rdi, %r15
leaq 0x30(%rdi), %r14
leaq 0x158(%rsp), %rbx
pushq $0x10
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x54a0
movq (%rbx), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x178(%rsp,%rax)
jne 0x67c9
movq %r14, 0x48(%rsp)
leaq 0x128(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
leaq 0x108(%rsp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
xorl %edx, %edx
movb %dl, (%rax)
movb %dl, (%rcx)
movq (%r15), %rsi
leaq 0xc0(%rsp), %rdi
callq 0xe904
movq 0xc0(%rsp), %rbx
movq 0xc8(%rsp), %rax
movq %rax, 0x58(%rsp)
addq $0xa0, %r15
movq %r15, 0x50(%rsp)
pushq $0x1
popq %r15
leaq 0x118(%rsp), %rbp
leaq 0x138(%rsp), %r13
cmpq 0x58(%rsp), %rbx
je 0x6712
leaq 0xe8(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x84e2
movq %rsp, %r14
movq %r14, %rdi
movq %r12, %rsi
movl %r15d, %edx
callq 0x111ac
movq %rbp, %rdi
movq %r14, %rsi
callq 0x52f0
movq %r14, %rdi
callq 0x54c8
leaq 0xf0(%rsp), %rdi
callq 0x8466
leaq 0xd8(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x84e2
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %r12
movl %r15d, %edx
callq 0x10f5a
leaq 0xf8(%rsp), %rdi
movq %r14, %rsi
callq 0x52f0
movq %r14, %rdi
callq 0x54c8
leaq 0xe0(%rsp), %rdi
callq 0x8466
leaq 0x158(%rsp), %rdi
movq %r12, %rbp
movq %r12, %rsi
callq 0x5260
movq 0x50(%rsp), %r15
movq %rax, %rdi
pushq $0x3b
popq %rsi
callq 0x52e0
movq %rax, %rdi
leaq 0xf8(%rsp), %rsi
callq 0x5260
movq %rax, %rdi
pushq $0x3b
popq %rsi
callq 0x52e0
movq %rax, %r12
movq (%rbx), %rsi
movq %rsp, %r14
movq %r14, %rdi
callq 0x10bbc
movq %r12, %rdi
movq %r14, %rsi
callq 0x5260
movq %rax, %rdi
pushq $0x3b
popq %rsi
callq 0x52e0
movq %rax, %r12
movq (%rbx), %rsi
leaq 0x28(%rsp), %r14
movq %r14, %rdi
callq 0x10caa
movq %r12, %rdi
movq %r14, %rsi
callq 0x5260
movq %rax, %rdi
pushq $0x3b
popq %rsi
callq 0x52e0
movq %rax, %r12
movq (%rbx), %rsi
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
callq 0x10d98
movq %r12, %rdi
movq %r14, %rsi
callq 0x5260
movq %rax, %rdi
pushq $0x3b
popq %rsi
callq 0x52e0
movq %rax, %r12
movq (%rbx), %rsi
leaq 0x70(%rsp), %rdi
callq 0x10e86
movq 0x70(%rsp), %rsi
leaq 0x80(%rsp), %r14
movq %r14, %rdi
callq 0xfaa2
movq %r12, %rdi
movq %r14, %rsi
callq 0x5260
movq %rax, %rdi
pushq $0x3b
popq %rsi
callq 0x52e0
movq %rax, %r12
movq (%rbx), %rsi
leaq 0x60(%rsp), %rdi
callq 0x10ea2
movq 0x60(%rsp), %rsi
movq %r13, %r14
movq %r13, %rdi
callq 0xfaa2
movq %r12, %rdi
movq %r14, %rsi
callq 0x5260
movq %rax, %rdi
pushq $0x3b
popq %rsi
callq 0x52e0
movq %rax, %r12
movq (%rbx), %rdi
callq 0x10ebe
movzbl %al, %esi
movq %r12, %rdi
callq 0x5400
movq %rax, %rdi
pushq $0x3b
popq %rsi
callq 0x52e0
movq %r13, %rdi
callq 0x54c8
leaq 0x68(%rsp), %rdi
callq 0x8466
leaq 0x80(%rsp), %rdi
callq 0x54c8
leaq 0x78(%rsp), %rdi
callq 0x8466
leaq 0xa0(%rsp), %rdi
callq 0x54c8
leaq 0x28(%rsp), %rdi
callq 0x54c8
movq %rsp, %rdi
callq 0x54c8
movq %r15, %rdi
leaq 0xf8(%rsp), %rsi
callq 0x8c52
movzbl (%rax), %eax
cmpl $0x44, %eax
je 0x659f
cmpl $0x45, %eax
je 0x6558
cmpl $0x4e, %eax
jne 0x65d8
leaq 0xa0(%rsp), %rdi
movq %rbx, %rsi
callq 0x7e73
movq 0xa0(%rsp), %rsi
movq %rsp, %r14
movq %r14, %rdi
callq 0x14a6a
leaq 0x158(%rsp), %rdi
movq %r14, %rsi
callq 0x5260
movq %rax, %rdi
pushq $0x3b
popq %rsi
callq 0x52e0
movq %rax, %r12
leaq 0x80(%rsp), %rdi
movq %rbx, %rsi
callq 0x7e73
movq 0x80(%rsp), %rsi
leaq 0x28(%rsp), %r14
movq %r14, %rdi
callq 0x1497c
movq %r12, %rdi
movq %r14, %rsi
callq 0x5260
movq %rax, %rdi
pushq $0x3b
popq %rsi
callq 0x52e0
leaq 0x28(%rsp), %rdi
callq 0x54c8
leaq 0x88(%rsp), %rdi
callq 0x8466
movq %rsp, %rdi
callq 0x54c8
leaq 0xa8(%rsp), %rdi
jmp 0x65d3
leaq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq 0x7e1d
movq 0x28(%rsp), %rsi
movq %rsp, %r14
movq %r14, %rdi
callq 0x12076
leaq 0x158(%rsp), %rdi
movq %r14, %rsi
callq 0x5260
movq %rax, %rdi
pushq $0x3b
popq %rsi
callq 0x52e0
movq %rsp, %rdi
callq 0x54c8
leaq 0x30(%rsp), %rdi
jmp 0x65d3
movq %rsp, %rdi
movq %rbx, %rsi
callq 0x7dc7
movq (%rsp), %rdi
callq 0x11fb0
movzbl %al, %esi
leaq 0x158(%rsp), %rdi
callq 0x5400
movq %rax, %rdi
pushq $0x3b
popq %rsi
callq 0x52e0
leaq 0x8(%rsp), %rdi
callq 0x8466
movq %r15, %rdi
movq %rbp, %rsi
callq 0x8c52
movzbl (%rax), %eax
cmpl $0x52, %eax
je 0x66d0
cmpl $0x46, %eax
leaq 0x28(%rsp), %r15
je 0x663c
cmpl $0x4d, %eax
je 0x66a2
cmpl $0x41, %eax
jne 0x6705
movq %rsp, %rdi
movq %rbx, %rsi
callq 0x7ec9
movq (%rsp), %rdi
callq 0x14c94
movzbl %al, %esi
leaq 0x158(%rsp), %rdi
callq 0x5400
movq %rax, %rdi
callq 0x5160
jmp 0x66fb
movq %rsp, %rdi
movq %rbx, %rsi
callq 0x7f1e
movq (%rsp), %rdi
callq 0x163b0
movzbl %al, %esi
leaq 0x158(%rsp), %rdi
callq 0x5400
movq %rax, %rdi
pushq $0x3b
popq %rsi
callq 0x52e0
movq %rax, %r12
movq %r15, %rdi
movq %rbx, %rsi
callq 0x7f1e
movq 0x28(%rsp), %rdi
callq 0x16454
movzbl %al, %esi
movq %r12, %rdi
callq 0x5400
movq %rax, %rdi
callq 0x5160
leaq 0x30(%rsp), %rdi
callq 0x8466
jmp 0x66fb
movq %rsp, %rdi
movq %rbx, %rsi
callq 0x7fc8
movq (%rsp), %rdi
callq 0x15428
movzbl %al, %esi
leaq 0x158(%rsp), %rdi
callq 0x5400
movq %rax, %rdi
callq 0x5160
jmp 0x66fb
movq %rsp, %rdi
movq %rbx, %rsi
callq 0x7f73
movq (%rsp), %rdi
callq 0x15bba
leaq 0x158(%rsp), %rdi
movl %eax, %esi
callq 0x5420
movq %rax, %rdi
callq 0x5160
leaq 0x8(%rsp), %rdi
callq 0x8466
addq $0x10, %rbx
pushq $0x1
popq %r15
jmp 0x6259
leaq 0xc0(%rsp), %rdi
callq 0x801e
leaq 0x158(%rsp), %rdi
callq 0x5360
movq %rsp, %rdi
pushq $0x2
popq %rdx
movq 0x48(%rsp), %r14
movq %r14, %rsi
callq 0x7cce
movq %rsp, %rdi
callq 0x5470
movl %eax, %ebx
movq %rsp, %rdi
callq 0x7d36
testb %bl, %bl
je 0x6775
movq %rsp, %rdi
pushq $0x2
popq %rdx
movq %r14, %rsi
callq 0x7cce
movq %rsp, %rdi
callq 0x5220
movq %rsp, %rdi
callq 0x7d36
jmp 0x6790
movq 0x1f84c(%rip), %rdi     # 0x25fc8
leaq 0x1096f(%rip), %rsi     # 0x170f2
callq 0x5270
movq %rax, %rdi
callq 0x5160
leaq 0xf8(%rsp), %rdi
callq 0x54c8
leaq 0x118(%rsp), %rdi
callq 0x54c8
leaq 0x158(%rsp), %rdi
callq 0x5390
addq $0x358, %rsp            # imm = 0x358
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x8
popq %rdi
callq 0x5170
leaq 0x108e6(%rip), %rcx     # 0x170be
movq %rcx, (%rax)
movq 0x1f7ce(%rip), %rsi     # 0x25fb0
movq %rax, %rdi
xorl %edx, %edx
callq 0x5410
jmp 0x67f0
jmp 0x680c
movq %rax, %rbx
movq %rsp, %rdi
callq 0x7d36
jmp 0x6930
jmp 0x680c
jmp 0x680c
movq %rax, %rbx
jmp 0x694a
movq %rax, %rbx
jmp 0x6930
movq %rax, %rbx
jmp 0x685c
movq %rax, %rbx
jmp 0x682e
movq %rax, %rbx
jmp 0x6847
movq %rax, %rbx
movq %rsp, %rdi
callq 0x54c8
leaq 0x30(%rsp), %rdi
jmp 0x68a8
movq %rax, %rbx
jmp 0x6854
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x54c8
leaq 0x88(%rsp), %rdi
callq 0x8466
movq %rsp, %rdi
callq 0x54c8
leaq 0xa8(%rsp), %rdi
jmp 0x68a8
jmp 0x687d
jmp 0x687d
jmp 0x687d
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x8466
jmp 0x6880
jmp 0x687d
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
jmp 0x68a8
jmp 0x68bf
movq %rax, %rbx
jmp 0x68de
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
jmp 0x68a8
jmp 0x68c4
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0x8466
jmp 0x6923
jmp 0x6920
jmp 0x68ba
movq %rax, %rbx
jmp 0x68f5
jmp 0x68c9
movq %rax, %rbx
jmp 0x68ff
movq %rax, %rbx
jmp 0x68e8
movq %rax, %rbx
jmp 0x690c
movq %rax, %rbx
jmp 0x6916
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
callq 0x54c8
leaq 0x68(%rsp), %rdi
callq 0x8466
leaq 0x80(%rsp), %rdi
callq 0x54c8
leaq 0x78(%rsp), %rdi
callq 0x8466
leaq 0xa0(%rsp), %rdi
callq 0x54c8
leaq 0x28(%rsp), %rdi
callq 0x54c8
movq %rsp, %rdi
callq 0x54c8
jmp 0x6923
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x801e
leaq 0xf8(%rsp), %rdi
callq 0x54c8
leaq 0x118(%rsp), %rdi
callq 0x54c8
leaq 0x158(%rsp), %rdi
callq 0x5390
movq %rbx, %rdi
callq 0x5430
nop