// File: /workspace/github_cpp_makefile_star2_O3/grmauri[P]pmm/pmm.cpp
// Function: busca_tabu(int, double, tSolucao&, double&, double&)
void busca_tabu(const int tam_lista, const double tempo_max, Solucao &s, double &tempo_melhor, double &tempo_total)
{
    clock_t hI, hF;
    Solucao s_vizinha;
    int flag, pos, mocOri, foOri, melViz, melObj, melMoc, melPos, qtd_lista, **lista_tabu;
    printf("\n\n>>> EXECUTANDO A BT...\n\n");
    hI = clock();
    heuConAle(s);
    calcFO(s);
    hF = clock();
    tempo_melhor = ((double)(hF - hI))/CLOCKS_PER_SEC;
    #ifdef DBG
        printf("FO: %d\tTempo: %.2f\n", s.funObj, tempo_melhor);
    #endif
    tempo_total = tempo_melhor;
    memcpy(&s_vizinha, &s, sizeof(s));
    //---------------------------
    // Criar a lista tabu - linha 1 guarda o objeto, e linha 2 guarda a mochila
    lista_tabu = new int*[2];
    lista_tabu[0] = new int[tam_lista];
    lista_tabu[1] = new int[tam_lista];
    qtd_lista = 0;
    //---------------------------
    while(tempo_total < tempo_max)
    {
        //---------------------------
        // Verificar a melhor vizinha
        melViz = -INT_MAX;
        flag = -1; // todos os vizinhos na lista e nao ha melhora
        for(int j = 0; j < numObj; j++)
        {
            mocOri = s_vizinha.vetIdMocObj[j];
            foOri = s_vizinha.funObj;
            for(int i = -1; i < numMoc; i++)
            {
                if(i != s_vizinha.vetIdMocObj[j])
                {
                    s_vizinha.vetIdMocObj[j] = i;
                    calcFO(s_vizinha);
                    pos = procurar_lista(lista_tabu, qtd_lista, j, i);
                    if(pos != -1) // esta na lista tabu
                    {
                        if(s_vizinha.funObj > s.funObj) // vizinha melhor que a melhor
                        {
                            flag = 0; // esta na lista tabu, mas e melhor do que a melhor
                            melViz = s_vizinha.funObj;
                            melMoc = i;
                            melObj = j;
                            melPos = pos; // posicao na lista tabu
                        }
                    }
                    else // nao esta na lista
                    {
                        if(s_vizinha.funObj > melViz)
                        {
                            flag = 1; // melhor vizinha que nao esta na lista tabu
                            melViz = s_vizinha.funObj;
                            melMoc = i;
                            melObj = j;
                            melPos = -1; // nao esta na lista tabu
                        }
                    }
                }
            }
            s_vizinha.vetIdMocObj[j] = mocOri;
            s_vizinha.funObj = foOri;
        }
        //---------------------------
        // Atualizar a lista e gerar a melhor vizinha
        if(flag == -1) // todos os vizinhos na lista e nenhuma melhora encontrada, entao aplica-se o primeiro movimento da lista (FIFO)
        {
            melObj = lista_tabu[0][0];
            melMoc = lista_tabu[1][0];
            s_vizinha.vetIdMocObj[melObj] = melMoc;
            calcFO(s_vizinha);
            remover_lista(lista_tabu, qtd_lista, 0);
        }
        else
        {
            if(flag == 0) // vizinha melhor que a melhor solucao, entao remove-se o movimento que gerou a vizinha
                remover_lista(lista_tabu, qtd_lista, melPos);
            else // movimento que gerou a vizinha nao esta na lista, entao deve-se inserir
                inserir_lista(lista_tabu, qtd_lista, tam_lista, melObj, melMoc);
            s_vizinha.vetIdMocObj[melObj] = melMoc;
            s_vizinha.funObj = melViz;
        }
        //--------------------------------------
        // Atualizar a melhor solucao
        if(s_vizinha.funObj > s.funObj)
        {
            memcpy(&s, &s_vizinha, sizeof(s_vizinha));
            hF = clock();
            tempo_melhor = ((double)(hF - hI))/CLOCKS_PER_SEC;
            #ifdef DBG
                printf("FO: %d\tTempo: %.2f\n", s.funObj, tempo_melhor);
            #endif
        }
        //--------------------------------------
        hF = clock();
        tempo_total = ((double)hF - hI)/CLOCKS_PER_SEC;
    }
    delete[] lista_tabu[0];
    delete[] lista_tabu[1];
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x938, %rsp            # imm = 0x938
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r12
movsd %xmm0, 0x50(%rsp)
movl %edi, %ebp
leaq 0x2e6e(%rip), %rdi      # 0x6588
callq 0x21c0
callq 0x20a0
movq %rax, %r15
movq %r12, %rdi
callq 0x42bb
movq %r12, %rdi
callq 0x42ff
callq 0x20a0
movq %r15, 0x40(%rsp)
subq %r15, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x28e4(%rip), %xmm0     # 0x6038
movsd %xmm0, (%r14)
movl 0x898(%r12), %esi
leaq 0x299b(%rip), %rdi      # 0x6103
movb $0x1, %al
callq 0x2050
movq %r14, 0x70(%rsp)
movsd (%r14), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %rbx, 0x80(%rsp)
movsd %xmm0, (%rbx)
leaq 0x9c(%rsp), %rdi
movl $0x89c, %edx            # imm = 0x89C
movq %r12, %rsi
callq 0x20c0
movl $0x10, %edi
callq 0x2030
movq %rax, %r14
movl %ebp, %eax
shlq $0x2, %rax
movl %ebp, 0x30(%rsp)
testl %ebp, %ebp
movq $-0x1, %rbx
cmovnsq %rax, %rbx
movq %rbx, %rdi
callq 0x2030
movq %rax, %rbp
movq %rax, (%r14)
movq %rbx, %rdi
callq 0x2030
movq %rax, %r13
movq %r14, 0x58(%rsp)
movq %rax, 0x8(%r14)
movl $0x0, 0xc(%rsp)
movsd 0x50(%rsp), %xmm0
ucomisd 0x10(%rsp), %xmm0
jbe 0x3b2a
xorps %xmm0, %xmm0
cvtsi2sdq 0x40(%rsp), %xmm0
movsd %xmm0, 0x78(%rsp)
movq %rbp, %rax
addq $0x4, %rax
movq %rax, 0x68(%rsp)
movq %r13, %rax
addq $0x4, %rax
movq %rax, 0x60(%rsp)
movq %rax, 0x20(%rsp)
movq %r12, 0x48(%rsp)
movq %rbp, 0x90(%rsp)
movslq 0x5903(%rip), %rax      # 0x9144
movq %rax, 0x88(%rsp)
testq %rax, %rax
jle 0x39ed
movl %r15d, 0x10(%rsp)
movq %r14, 0x28(%rsp)
movl 0x58e6(%rip), %edx      # 0x9148
movl 0xc(%rsp), %r14d
movl 0x898(%r12), %eax
movl %eax, 0x3c(%rsp)
movl $0xffffffff, 0x1c(%rsp) # imm = 0xFFFFFFFF
movl $0x80000001, %esi       # imm = 0x80000001
movl 0x934(%rsp), %eax
movl %eax, 0x34(%rsp)
xorl %ebx, %ebx
movl 0x164(%rsp,%rbx,4), %eax
movl %eax, 0x38(%rsp)
testl %edx, %edx
js 0x3963
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpl 0x164(%rsp,%rbx,4), %r12d
je 0x3957
movl %r12d, 0x164(%rsp,%rbx,4)
leaq 0x9c(%rsp), %rdi
movl %esi, %r15d
movq %r13, %rbp
movl %edx, %r13d
callq 0x42ff
movl %r13d, %edx
movq %rbp, %r13
movq 0x90(%rsp), %rbp
movl %r15d, %esi
testl %r14d, %r14d
jle 0x3902
xorl %eax, %eax
movl (%rbp,%rax,4), %ecx
cmpq %rcx, %rbx
jne 0x38fa
cmpl %r12d, (%r13,%rax,4)
je 0x392f
incq %rax
cmpq %rax, %r14
jne 0x38ea
movl 0x934(%rsp), %eax
cmpl %esi, %eax
jle 0x3957
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rcx, 0x20(%rsp)
movl $0x1, 0x1c(%rsp)
movl %eax, %esi
movl %ebx, %eax
movq %rax, 0x28(%rsp)
movl %r12d, 0x10(%rsp)
jmp 0x3957
movl 0x934(%rsp), %ecx
cmpl 0x3c(%rsp), %ecx
jle 0x3957
movl $0x0, 0x1c(%rsp)
movl %ecx, %esi
movl %ebx, %ecx
movq %rcx, 0x28(%rsp)
movl %r12d, 0x10(%rsp)
movq %rax, 0x20(%rsp)
incl %r12d
cmpl %edx, %r12d
jne 0x38a6
movl 0x38(%rsp), %eax
movl %eax, 0x164(%rsp,%rbx,4)
movl 0x34(%rsp), %eax
movl %eax, 0x934(%rsp)
incq %rbx
cmpq 0x88(%rsp), %rbx
jne 0x388d
movl 0x1c(%rsp), %eax
cmpl $-0x1, %eax
je 0x39e8
testl %eax, %eax
movq 0x48(%rsp), %r12
jne 0x3a62
movq 0x20(%rsp), %rax
leal 0x1(%rax), %ecx
movslq 0xc(%rsp), %rax
cmpl %eax, %ecx
movq 0x28(%rsp), %r14
movl 0x10(%rsp), %r15d
jge 0x39dd
movslq 0x20(%rsp), %rcx
incq %rcx
movl (%rbp,%rcx,4), %edx
movl %edx, -0x4(%rbp,%rcx,4)
movl (%r13,%rcx,4), %edx
movl %edx, -0x4(%r13,%rcx,4)
incq %rcx
cmpq %rax, %rcx
jl 0x39c3
decl %eax
movl %eax, 0xc(%rsp)
jmp 0x3a89
movq 0x48(%rsp), %r12
movslq (%rbp), %r14
movl (%r13), %r15d
movl %r15d, 0x164(%rsp,%r14,4)
leaq 0x9c(%rsp), %rdi
callq 0x42ff
movslq 0xc(%rsp), %rbx
cmpq $0x2, %rbx
jl 0x3a53
leaq -0x4(,%rbx,4), %rdx
movq %rbp, %rdi
movq 0x68(%rsp), %rsi
movl %r15d, 0x10(%rsp)
movq %r14, %r15
movq %r12, %r14
movq %rdx, %r12
callq 0x21e0
movq %r13, %rdi
movq 0x60(%rsp), %rsi
movq %r12, %rdx
movq %r14, %r12
movq %r15, %r14
movl 0x10(%rsp), %r15d
callq 0x21e0
decl %ebx
movl %ebx, 0xc(%rsp)
movl 0x934(%rsp), %esi
jmp 0x3a9b
movq 0x58(%rsp), %rdi
movl %esi, %ebx
leaq 0xc(%rsp), %rsi
movl 0x30(%rsp), %edx
movq 0x28(%rsp), %r14
movl %r14d, %ecx
movl 0x10(%rsp), %r15d
movl %r15d, %r8d
callq 0x4460
movl %ebx, %esi
movslq %r14d, %rax
movl %r15d, 0x164(%rsp,%rax,4)
movl %esi, 0x934(%rsp)
cmpl 0x898(%r12), %esi
jle 0x3af3
movl $0x89c, %edx            # imm = 0x89C
movq %r12, %rdi
leaq 0x9c(%rsp), %rsi
callq 0x20c0
callq 0x20a0
subq 0x40(%rsp), %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x2564(%rip), %xmm0     # 0x6038
movq 0x70(%rsp), %rax
movsd %xmm0, (%rax)
movl 0x898(%r12), %esi
leaq 0x2617(%rip), %rdi      # 0x6103
movb $0x1, %al
callq 0x2050
callq 0x20a0
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
subsd 0x78(%rsp), %xmm0
divsd 0x252a(%rip), %xmm0     # 0x6038
movq 0x80(%rsp), %rax
movsd %xmm0, (%rax)
movsd 0x50(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x383a
movq %rbp, %rdi
callq 0x2140
movq %r13, %rdi
addq $0x938, %rsp            # imm = 0x938
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2140