// File: /workspace/github_cpp_makefile_star2_O2/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, %r12
movsd %xmm0, 0x78(%rsp)
movl %edi, %ebp
leaq 0x26df(%rip), %rdi      # 0x5558
callq 0x21b0
callq 0x20b0
movq %rax, %r15
movq %r12, %rdi
callq 0x38af
movq %r12, %rdi
callq 0x38ec
callq 0x20b0
subq %r15, %rax
cvtsi2sd %rax, %xmm0
divsd 0x218d(%rip), %xmm0     # 0x5038
movsd %xmm0, (%r14)
movl 0x898(%r12), %esi
leaq 0x2214(%rip), %rdi      # 0x50d3
movb $0x1, %al
callq 0x2050
movq %r14, 0x60(%rsp)
movsd (%r14), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %rbx, 0x70(%rsp)
movsd %xmm0, (%rbx)
leaq 0x8c(%rsp), %rdi
movl $0x89c, %edx            # imm = 0x89C
movq %r12, %rsi
callq 0x20d0
pushq $0x10
popq %rdi
callq 0x2030
movq %rax, %r14
movl %ebp, %eax
shlq $0x2, %rax
movl %ebp, 0x34(%rsp)
testl %ebp, %ebp
pushq $-0x1
popq %rbx
cmovnsq %rax, %rbx
movq %rbx, %rdi
callq 0x2030
movq %rax, 0x48(%rsp)
movq %rax, (%r14)
movq %rbx, %rdi
callq 0x2030
movsd 0x10(%rsp), %xmm1
leaq 0xc(%rsp), %rcx
andl $0x0, (%rcx)
movq %r14, 0x28(%rsp)
movq %rax, 0x40(%rsp)
movq %rax, 0x8(%r14)
movq %r15, 0x58(%rsp)
cvtsi2sd %r15, %xmm0
movsd %xmm0, 0x68(%rsp)
movq %r12, 0x50(%rsp)
movsd 0x78(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x31a4
movl %ebp, 0x8(%rsp)
movq %rbx, 0x20(%rsp)
movl 0x51ba(%rip), %ecx      # 0x8134
movl 0x51b7(%rip), %r13d     # 0x8138
movl 0xc(%rsp), %r15d
testl %ecx, %ecx
movl $0x0, %eax
cmovlel %eax, %ecx
movq %rcx, 0x80(%rsp)
movl 0x898(%r12), %ebp
movl $0x80000001, %r14d      # imm = 0x80000001
xorl %r12d, %r12d
pushq $-0x1
popq %rax
movl %eax, 0x10(%rsp)
cmpq 0x80(%rsp), %r12
je 0x3083
movl 0x154(%rsp,%r12,4), %eax
movl %eax, 0x3c(%rsp)
movl 0x924(%rsp), %eax
movl %eax, 0x38(%rsp)
pushq $-0x1
popq %rbx
cmpl %r13d, %ebx
jge 0x3064
cmpl 0x154(%rsp,%r12,4), %ebx
je 0x305d
movl %ebx, 0x154(%rsp,%r12,4)
leaq 0x8c(%rsp), %rdi
callq 0x38ec
movq 0x28(%rsp), %rdi
movl %r15d, %esi
movl %r12d, %edx
movl %ebx, %ecx
callq 0x39eb
movl 0x924(%rsp), %ecx
cmpl $-0x1, %eax
je 0x303b
cmpl %ebp, %ecx
jle 0x305d
movl $0x0, 0x10(%rsp)
movl %ecx, %r14d
movl %r12d, %ecx
movq %rcx, 0x20(%rsp)
movl %ebx, 0x8(%rsp)
jmp 0x3059
cmpl %r14d, %ecx
jle 0x305d
pushq $0x1
popq %rax
movl %eax, 0x10(%rsp)
movl %ecx, %r14d
movl %r12d, %eax
movq %rax, 0x20(%rsp)
movl %ebx, 0x8(%rsp)
pushq $-0x1
popq %rax
movl %eax, 0x1c(%rsp)
incl %ebx
jmp 0x2fd8
movl 0x3c(%rsp), %eax
movl %eax, 0x154(%rsp,%r12,4)
movl 0x38(%rsp), %eax
movl %eax, 0x924(%rsp)
incq %r12
jmp 0x2fb0
movl 0x10(%rsp), %eax
cmpl $-0x1, %eax
je 0x30b3
testl %eax, %eax
movq 0x50(%rsp), %r12
jne 0x30f6
movq 0x28(%rsp), %rdi
leaq 0xc(%rsp), %rsi
movl 0x1c(%rsp), %edx
callq 0x3a18
movq 0x20(%rsp), %rbx
movl 0x8(%rsp), %ebp
jmp 0x3117
movq 0x48(%rsp), %rax
movslq (%rax), %rbx
movq 0x40(%rsp), %rax
movl (%rax), %ebp
movl %ebp, 0x154(%rsp,%rbx,4)
leaq 0x8c(%rsp), %rdi
callq 0x38ec
movq 0x28(%rsp), %rdi
leaq 0xc(%rsp), %rsi
xorl %edx, %edx
callq 0x3a18
movl 0x924(%rsp), %r14d
movq 0x50(%rsp), %r12
jmp 0x3129
movq 0x28(%rsp), %rdi
leaq 0xc(%rsp), %rsi
movl 0x34(%rsp), %edx
movq 0x20(%rsp), %rbx
movl %ebx, %ecx
movl 0x8(%rsp), %ebp
movl %ebp, %r8d
callq 0x3a42
movslq %ebx, %rax
movl %ebp, 0x154(%rsp,%rax,4)
movl %r14d, 0x924(%rsp)
cmpl 0x898(%r12), %r14d
jle 0x317e
movl $0x89c, %edx            # imm = 0x89C
movq %r12, %rdi
leaq 0x8c(%rsp), %rsi
callq 0x20d0
callq 0x20b0
subq 0x58(%rsp), %rax
cvtsi2sd %rax, %xmm0
divsd 0x1ed9(%rip), %xmm0     # 0x5038
movq 0x60(%rsp), %rax
movsd %xmm0, (%rax)
movl 0x898(%r12), %esi
leaq 0x1f5c(%rip), %rdi      # 0x50d3
movb $0x1, %al
callq 0x2050
callq 0x20b0
cvtsi2sd %rax, %xmm1
subsd 0x68(%rsp), %xmm1
divsd 0x1ea2(%rip), %xmm1     # 0x5038
movq 0x70(%rsp), %rax
movsd %xmm1, (%rax)
jmp 0x2f5b
movq 0x48(%rsp), %rdi
callq 0x2140
movq 0x40(%rsp), %rdi
addq $0x928, %rsp            # imm = 0x928
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2140