// File: /workspace/github_cpp_makefile_star2_O2/GAStudyGroup[P]GPX2/src/base/sources/GAUtils.cpp
// Function: GAUtils::crossAllxAllwithNBestAndReset(Population&)
Population GAUtils::crossAllxAllwithNBestAndReset(Population &pop){
    Population tmpPop, newPop;
    vector<int> currentTour;

    for (unsigned i = 0; i < Config::POP_SIZE; i++) {
        currentTour = pop.getPopulation()[i];
        for (unsigned j = 0; j < Config::POP_SIZE; j++) {
            if (i != j) {
                vector<int> t = GPX2::crossover(pop.getPopulation()[j], currentTour);
                currentTour = t;
            }
        }

        tmpPop.getPopulation().push_back(currentTour);
    }

    sort(tmpPop.getPopulation().begin(), tmpPop.getPopulation().end(),sortPopulation);

    newPop.getPopulation().insert(newPop.getPopulation().end(),tmpPop.getPopulation().begin(),tmpPop.getPopulation().begin()+Config::N_BEST);

    // for(unsigned i=0;i<Config::N_BEST;i++){
    //     newPop.getPopulation().push_back(tmpPop.getPopulation()[i]);
    // }

    fillPopulationWithReset(newPop, Config::POP_SIZE*Config::RESET_PERCENTAGE);

    fillPopulationWithRoulete(pop,newPop,Config::POP_SIZE-newPop.getPopulation().size());

    return newPop;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rsi, 0x10(%rsp)
movq %rdi, %rbx
leaq 0x18(%rsp), %rdi
callq 0xb97c
movq %rbx, 0x8(%rsp)
movq %rbx, %rdi
callq 0xb97c
xorpd %xmm0, %xmm0
leaq 0x30(%rsp), %rax
andq $0x0, 0x10(%rax)
movapd %xmm0, (%rax)
xorl %ebx, %ebx
leaq 0x68(%rsp), %r12
leaq 0x50(%rsp), %r13
leaq 0x80(%rsp), %rbp
xorl %r14d, %r14d
leaq 0x34d7e(%rip), %rax     # 0x3c8c0
movl (%rax), %eax
cmpq %rax, %r14
jae 0x7c1a
movq 0x10(%rsp), %rdi
callq 0xb988
imulq $0x18, %r14, %rsi
addq (%rax), %rsi
leaq 0x30(%rsp), %rdi
callq 0x93b6
movq %r14, 0x48(%rsp)
leaq 0x34d4c(%rip), %rax     # 0x3c8c0
movl (%rax), %eax
xorl %r14d, %r14d
xorl %r15d, %r15d
movl %eax, %ecx
cmpq %rcx, %r15
jae 0x7bf2
cmpq %r14, %rbx
je 0x7be9
movq 0x10(%rsp), %rdi
callq 0xb988
movq (%rax), %rsi
addq %r14, %rsi
movq %r12, %rdi
callq 0x9210
movq %r13, %rdi
leaq 0x30(%rsp), %rsi
callq 0x9210
movq %rbp, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x1f198
movq %r13, %rdi
callq 0x6e4c
movq %r12, %rdi
callq 0x6e4c
leaq 0x30(%rsp), %rdi
movq %rbp, %rsi
callq 0x93b6
movq %rbp, %rdi
callq 0x6e4c
leaq 0x34cd9(%rip), %rax     # 0x3c8c0
movl (%rax), %eax
incq %r15
addq $0x18, %r14
jmp 0x7b7c
leaq 0x18(%rsp), %rdi
callq 0xb988
movq 0x48(%rsp), %r14
movq %rax, %rdi
leaq 0x30(%rsp), %rsi
callq 0x938a
incq %r14
addq $0x18, %rbx
jmp 0x7b3b
leaq 0x18(%rsp), %rdi
callq 0xb988
movq (%rax), %r15
leaq 0x18(%rsp), %rdi
callq 0xb988
movq 0x8(%rax), %rsi
movq %r15, %rdi
callq 0x8442
movq 0x8(%rsp), %rdi
callq 0xb988
movq %rax, %r13
movq 0x8(%rsp), %rdi
callq 0xb988
movq 0x8(%rax), %r15
leaq 0x18(%rsp), %rdi
callq 0xb988
movq (%rax), %r12
leaq 0x18(%rsp), %rdi
callq 0xb988
leaq 0x34b2a(%rip), %rcx     # 0x3c7a0
movl (%rcx), %ecx
imulq $0x18, %rcx, %rcx
addq (%rax), %rcx
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x9480
leaq 0x34c2c(%rip), %rax     # 0x3c8c0
movl (%rax), %eax
cvtsi2sd %rax, %xmm0
leaq 0x34b0e(%rip), %rax     # 0x3c7b0
mulsd (%rax), %xmm0
cvttsd2si %xmm0, %rsi
movq 0x8(%rsp), %rdi
callq 0x730d
leaq 0x34c04(%rip), %rax     # 0x3c8c0
movl (%rax), %ebx
movq 0x8(%rsp), %rdi
callq 0xb988
movq 0x8(%rax), %rcx
subq (%rax), %rcx
pushq $-0x18
popq %rsi
movq %rcx, %rax
cqto
idivq %rsi
addl %eax, %ebx
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl %ebx, %edx
callq 0x776f
leaq 0x30(%rsp), %rdi
callq 0x6e4c
leaq 0x18(%rsp), %rdi
callq 0x6dde
movq 0x8(%rsp), %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x7d67
jmp 0x7d50
jmp 0x7d50
jmp 0x7d50
jmp 0x7d50
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
jmp 0x7d49
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x6e4c
jmp 0x7d44
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x6e4c
jmp 0x7d53
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x6e4c
movq 0x8(%rsp), %rdi
callq 0x6dde
leaq 0x18(%rsp), %rdi
callq 0x6dde
movq %rbx, %rdi
callq 0x5610