// File: /workspace/github_cpp_makefile_star2_O1/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 $0x928, %rsp            # imm = 0x928
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r15
movsd %xmm0, 0x60(%rsp)
movl %edi, %ebp
leaq 0x2ecd(%rip), %rdi      # 0x6558
callq 0x21c0
callq 0x20a0
movq %rax, %r12
movq %r15, %rdi
callq 0x4220
movq %r15, %rdi
callq 0x4264
callq 0x20a0
movq %r12, 0x50(%rsp)
subq %r12, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x2973(%rip), %xmm0     # 0x6038
movsd %xmm0, (%r14)
movl 0x898(%r15), %esi
leaq 0x29fb(%rip), %rdi      # 0x60d3
movb $0x1, %al
callq 0x2050
movq %r14, 0x68(%rsp)
movsd (%r14), %xmm0
movsd %xmm0, (%rbx)
leaq 0x8c(%rsp), %rdi
movl $0x89c, %edx            # imm = 0x89C
movq %r15, %rsi
callq 0x20c0
movl %ebp, 0x30(%rsp)
movslq %ebp, %rax
leaq (,%rax,4), %rcx
testl %eax, %eax
movq $-0x1, %r12
cmovnsq %rcx, %r12
movq %r12, %rdi
callq 0x2030
movq %rax, %r13
movq %r12, %rdi
callq 0x2030
movq %rax, %rbp
movq %rbx, 0x78(%rsp)
movsd 0x60(%rsp), %xmm0
ucomisd (%rbx), %xmm0
jbe 0x3a8f
xorps %xmm0, %xmm0
cvtsi2sdq 0x50(%rsp), %xmm0
movsd %xmm0, 0x70(%rsp)
movq %r13, %rax
addq $0x4, %rax
movq %rax, 0x48(%rsp)
movq %rbp, %rax
addq $0x4, %rax
movq %rax, 0x40(%rsp)
xorl %ebx, %ebx
movq %rax, 0x20(%rsp)
movq %rax, 0x18(%rsp)
movq %r15, 0x58(%rsp)
movslq 0x59bb(%rip), %rax      # 0x9144
movq %rax, 0x80(%rsp)
testq %rax, %rax
movq %rbx, 0x28(%rsp)
jle 0x38c7
movl 0x59a2(%rip), %r12d     # 0x9148
movl %ebx, %r14d
movl 0x898(%r15), %eax
movl %eax, 0x3c(%rsp)
movl $0xffffffff, 0x14(%rsp) # imm = 0xFFFFFFFF
movl $0x80000001, 0x10(%rsp) # imm = 0x80000001
xorl %ebx, %ebx
movl 0x154(%rsp,%rbx,4), %eax
movl %eax, 0x38(%rsp)
movl 0x924(%rsp), %eax
movl %eax, 0x34(%rsp)
testl %r12d, %r12d
js 0x389e
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpl 0x154(%rsp,%rbx,4), %r15d
je 0x3892
movl %r15d, 0x154(%rsp,%rbx,4)
leaq 0x8c(%rsp), %rdi
callq 0x4264
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $0x0, 0x28(%rsp)
jle 0x3839
xorl %ecx, %ecx
movl (%r13,%rcx,4), %edx
cmpq %rdx, %rbx
jne 0x382d
cmpl %r15d, (%rbp,%rcx,4)
je 0x3837
incq %rcx
cmpq %rcx, %r14
jne 0x381c
jmp 0x3839
movl %ecx, %eax
movl 0x924(%rsp), %ecx
cmpl $-0x1, %eax
je 0x386a
cmpl 0x3c(%rsp), %ecx
jle 0x3892
movl $0x0, 0x14(%rsp)
movl %ecx, 0x10(%rsp)
movl %ebx, %ecx
movq %rcx, 0x18(%rsp)
movl %r15d, 0xc(%rsp)
movq %rax, 0x20(%rsp)
jmp 0x3892
cmpl 0x10(%rsp), %ecx
jle 0x3892
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x20(%rsp)
movl $0x1, 0x14(%rsp)
movl %ecx, 0x10(%rsp)
movl %ebx, %eax
movq %rax, 0x18(%rsp)
movl %r15d, 0xc(%rsp)
incl %r15d
cmpl %r12d, %r15d
jne 0x37eb
movl 0x38(%rsp), %eax
movl %eax, 0x154(%rsp,%rbx,4)
movl 0x34(%rsp), %eax
movl %eax, 0x924(%rsp)
incq %rbx
cmpq 0x80(%rsp), %rbx
jne 0x37c6
jmp 0x38d7
movl $0x80000001, 0x10(%rsp) # imm = 0x80000001
movl $0xffffffff, 0x14(%rsp) # imm = 0xFFFFFFFF
movl 0x14(%rsp), %eax
cmpl $-0x1, %eax
je 0x3932
testl %eax, %eax
movq 0x58(%rsp), %r15
movq 0x28(%rsp), %rbx
jne 0x3993
movq 0x20(%rsp), %rax
incl %eax
cmpl %ebx, %eax
jge 0x3922
movslq 0x20(%rsp), %rax
incq %rax
movslq %ebx, %rcx
movl (%r13,%rax,4), %edx
movl %edx, -0x4(%r13,%rax,4)
movl (%rbp,%rax,4), %edx
movl %edx, -0x4(%rbp,%rax,4)
incq %rax
cmpq %rcx, %rax
jl 0x3908
decl %ebx
movq 0x18(%rsp), %rax
movl 0xc(%rsp), %ecx
jmp 0x39ea
movslq (%r13), %rax
movl (%rbp), %ecx
movq %rax, 0x18(%rsp)
movl %ecx, 0xc(%rsp)
movl %ecx, 0x154(%rsp,%rax,4)
leaq 0x8c(%rsp), %rdi
callq 0x4264
movq 0x28(%rsp), %rbx
cmpl $0x2, %ebx
movq 0x58(%rsp), %r15
jl 0x398f
movl %ebx, %eax
leaq -0x4(,%rax,4), %r14
movq %r13, %rdi
movq 0x48(%rsp), %rsi
movq %r14, %rdx
callq 0x21e0
movq %rbp, %rdi
movq 0x40(%rsp), %rsi
movq %r14, %rdx
callq 0x21e0
decl %ebx
jmp 0x39fe
cmpl 0x30(%rsp), %ebx
movq 0x18(%rsp), %rax
movl 0xc(%rsp), %ecx
jne 0x39dc
cmpl $0x2, %ebx
jl 0x39da
movl %ebx, %eax
leaq -0x4(,%rax,4), %r14
movq %r13, %rdi
movq 0x48(%rsp), %rsi
movq %r14, %rdx
callq 0x21e0
movq %rbp, %rdi
movq 0x40(%rsp), %rsi
movq %r14, %rdx
callq 0x21e0
movl 0xc(%rsp), %ecx
movq 0x18(%rsp), %rax
decl %ebx
movslq %ebx, %rbx
movl %eax, (%r13,%rbx,4)
movl %ecx, (%rbp,%rbx,4)
incl %ebx
cltq
movl %ecx, 0x154(%rsp,%rax,4)
movl 0x10(%rsp), %eax
movl %eax, 0x924(%rsp)
movl 0x924(%rsp), %eax
cmpl 0x898(%r15), %eax
jle 0x3a5b
movl $0x89c, %edx            # imm = 0x89C
movq %r15, %rdi
leaq 0x8c(%rsp), %rsi
callq 0x20c0
callq 0x20a0
subq 0x50(%rsp), %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x25fb(%rip), %xmm0     # 0x6038
movq 0x68(%rsp), %rax
movsd %xmm0, (%rax)
movl 0x898(%r15), %esi
leaq 0x267f(%rip), %rdi      # 0x60d3
movb $0x1, %al
callq 0x2050
callq 0x20a0
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
subsd 0x70(%rsp), %xmm0
divsd 0x25c2(%rip), %xmm0     # 0x6038
movq 0x78(%rsp), %rax
movsd %xmm0, (%rax)
movsd 0x60(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x3782
movq %r13, %rdi
callq 0x2140
movq %rbp, %rdi
addq $0x928, %rsp            # imm = 0x928
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2140