// File: /workspace/github_cpp_makefile_star2_O1/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 0xeac4
movq %rbx, 0x8(%rsp)
movq %rbx, %rdi
callq 0xeac4
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
leaq 0x398c6(%rip), %rax     # 0x428e0
cmpl $0x0, (%rax)
je 0x9142
xorl %r12d, %r12d
leaq 0x30(%rsp), %r15
leaq 0x68(%rsp), %rbp
leaq 0x80(%rsp), %rbx
movq 0x10(%rsp), %rdi
callq 0xead4
leaq (%r12,%r12,2), %rsi
shlq $0x3, %rsi
addq (%rax), %rsi
movq %r15, %rdi
callq 0xb27a
leaq 0x39884(%rip), %rax     # 0x428e0
cmpl $0x0, (%rax)
je 0x9118
xorl %r14d, %r14d
xorl %r13d, %r13d
cmpq %r13, %r12
je 0x90ff
movq 0x10(%rsp), %rdi
callq 0xead4
movq (%rax), %rsi
addq %r14, %rsi
leaq 0x50(%rsp), %rdi
callq 0xb05c
movq %rbp, %rdi
movq %r15, %rsi
callq 0xb05c
movq %rbx, %rdi
leaq 0x50(%rsp), %rsi
movq %rbp, %rdx
callq 0x26a04
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x90c0
movq 0x78(%rsp), %rsi
subq %rdi, %rsi
callq 0x53c0
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x90d7
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x53c0
movq %r15, %rdi
movq %rbx, %rsi
callq 0xb27a
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x90ff
movq 0x90(%rsp), %rsi
subq %rdi, %rsi
callq 0x53c0
incq %r13
leaq 0x397d7(%rip), %rax     # 0x428e0
movl (%rax), %eax
addq $0x18, %r14
cmpq %rax, %r13
jb 0x906b
leaq 0x18(%rsp), %rdi
callq 0xead4
movq %rax, %rdi
movq %r15, %rsi
callq 0xb24e
incq %r12
leaq 0x397a9(%rip), %rax     # 0x428e0
movl (%rax), %eax
cmpq %rax, %r12
jb 0x9038
leaq 0x18(%rsp), %rdi
callq 0xead4
movq (%rax), %r15
leaq 0x18(%rsp), %rdi
callq 0xead4
movq 0x8(%rax), %rbx
cmpq %rbx, %r15
je 0x91ce
movq %rbx, %r14
subq %r15, %r14
movq %r14, %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rcx
bsrq %rcx, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r15, %rdi
movq %rbx, %rsi
callq 0xa304
cmpq $0x181, %r14            # imm = 0x181
jl 0x91c3
leaq 0x180(%r15), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0xa850
cmpq %rbx, %r12
je 0x91ce
movq %r12, %rdi
callq 0xa955
addq $0x18, %r12
jmp 0x91b0
movq %r15, %rdi
movq %rbx, %rsi
callq 0xa850
movq 0x8(%rsp), %rdi
callq 0xead4
movq %rax, %rbx
movq 0x8(%rsp), %rdi
callq 0xead4
movq 0x8(%rax), %r15
leaq 0x18(%rsp), %rdi
callq 0xead4
movq (%rax), %r12
leaq 0x18(%rsp), %rdi
callq 0xead4
leaq 0x395b9(%rip), %rcx     # 0x427c0
movl (%rcx), %ecx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq (%rax), %rcx
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0xbafc
leaq 0x396b7(%rip), %rax     # 0x428e0
movl (%rax), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
leaq 0x39596(%rip), %rax     # 0x427d0
mulsd (%rax), %xmm0
cvttsd2si %xmm0, %rsi
movq 0x8(%rsp), %rdi
callq 0x8566
leaq 0x3968c(%rip), %rax     # 0x428e0
movl (%rax), %ebx
movq 0x8(%rsp), %rdi
callq 0xead4
movq 0x8(%rax), %rcx
subq (%rax), %rcx
shrq $0x3, %rcx
imull $0x55555555, %ecx, %eax # imm = 0x55555555
addl %eax, %ebx
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl %ebx, %edx
callq 0x8b5b
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x929b
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x53c0
leaq 0x18(%rsp), %rdi
callq 0x8102
movq 0x8(%rsp), %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x9344
jmp 0x9320
jmp 0x9320
jmp 0x9320
jmp 0x9320
jmp 0x9320
movq %rax, %rbx
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x92ed
movq 0x78(%rsp), %rsi
subq %rdi, %rsi
callq 0x53c0
jmp 0x92ed
movq %rax, %rbx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x9323
movq 0x60(%rsp), %rsi
jmp 0x9316
movq %rax, %rbx
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x9323
movq 0x90(%rsp), %rsi
subq %rdi, %rsi
callq 0x53c0
jmp 0x9323
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x933a
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x53c0
movq 0x8(%rsp), %rdi
callq 0x8102
leaq 0x18(%rsp), %rdi
callq 0x8102
movq %rbx, %rdi
callq 0x5670