// File: EduBic[P]TSP-MetaheuristicSolvers/./neighborimprovement.h
// Function: BestImprovement::execute(TSP const&, TSPSolution const&, move&)
double execute(const TSP &tsp, const TSPSolution &currSol, TSPMove &move) {
        //cout << endl << endl << "------------- find neighbor --------------";

        // Determine the *move* yielding the best 2-opt neigbor solution
        double bestCostVariation = tsp.infinite;

        // initial and final position are fixed (initial/final node remains 0)
        for ( uint a = 1 ; a < currSol.sequence.size() - 2 ; a++ ) {

            int h = currSol.sequence[a-1];
            int i = currSol.sequence[a];

            for ( uint b = a + 1 ; b < currSol.sequence.size() - 1 ; b++ ) {
                int j = currSol.sequence[b];
                int l = currSol.sequence[b+1];

                // incremental evaluation --> bestCostVariation (instead of best cost)
                double neighCostVariation = - tsp.cost[h][i] - tsp.cost[j][l]
                                            + tsp.cost[h][j] + tsp.cost[i][l];

                //cout << endl << "Move from " << a << " to " << b;
                //cout << "\tNeighbor Variation = " << neighCostVariation << " - BestCostVariation = " << bestCostVariation;

                if ( neighCostVariation < bestCostVariation ) {
                    //cout << "\tSave! Best neighbor found until now";

                    bestCostVariation = neighCostVariation;
                    move.from = a;
                    move.to = b;
                }
            }
        }

        //cout << endl << "-----------------------------" << endl;
        return bestCostVariation;
    }

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movq %rdx, 0x60(%rsp)
movq %rcx, 0x58(%rsp)
movq 0x68(%rsp), %rax
movsd 0x20(%rax), %xmm0
movsd %xmm0, 0x50(%rsp)
movl $0x1, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
movq %rax, 0x28(%rsp)
movq 0x60(%rsp), %rdi
callq 0x7c40
movq %rax, %rcx
movq 0x28(%rsp), %rax
subq $0x2, %rcx
cmpq %rcx, %rax
jae 0xd757
movq 0x60(%rsp), %rdi
movl 0x4c(%rsp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x87d0
movl (%rax), %eax
movl %eax, 0x48(%rsp)
movq 0x60(%rsp), %rdi
movl 0x4c(%rsp), %eax
movl %eax, %esi
callq 0x87d0
movl (%rax), %eax
movl %eax, 0x44(%rsp)
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
movl 0x40(%rsp), %eax
movq %rax, 0x20(%rsp)
movq 0x60(%rsp), %rdi
callq 0x7c40
movq %rax, %rcx
movq 0x20(%rsp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0xd745
movq 0x60(%rsp), %rdi
movl 0x40(%rsp), %eax
movl %eax, %esi
callq 0x87d0
movl (%rax), %eax
movl %eax, 0x3c(%rsp)
movq 0x60(%rsp), %rdi
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x87d0
movl (%rax), %eax
movl %eax, 0x38(%rsp)
movq 0x68(%rsp), %rdi
addq $0x8, %rdi
movslq 0x48(%rsp), %rsi
callq 0x87f0
movq %rax, %rdi
movslq 0x44(%rsp), %rsi
callq 0x8810
movsd (%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x68(%rsp), %rdi
addq $0x8, %rdi
movslq 0x3c(%rsp), %rsi
callq 0x87f0
movq %rax, %rdi
movslq 0x38(%rsp), %rsi
callq 0x8810
movsd 0x8(%rsp), %xmm0
subsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x68(%rsp), %rdi
addq $0x8, %rdi
movslq 0x48(%rsp), %rsi
callq 0x87f0
movq %rax, %rdi
movslq 0x3c(%rsp), %rsi
callq 0x8810
movsd 0x10(%rsp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x68(%rsp), %rdi
addq $0x8, %rdi
movslq 0x44(%rsp), %rsi
callq 0x87f0
movq %rax, %rdi
movslq 0x38(%rsp), %rsi
callq 0x8810
movsd 0x18(%rsp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x30(%rsp), %xmm1
movsd 0x50(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xd733
movsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
movl 0x4c(%rsp), %ecx
movq 0x58(%rsp), %rax
movl %ecx, (%rax)
movl 0x40(%rsp), %ecx
movq 0x58(%rsp), %rax
movl %ecx, 0x4(%rax)
jmp 0xd735
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0xd5d4
jmp 0xd747
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0xd570
movsd 0x50(%rsp), %xmm0
addq $0x78, %rsp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)