// File: /workspace/github_cpp_makefile_star2_O1/GAStudyGroup[P]GPX2/src/base/sources/GAUtils.cpp
// Function: GAUtils::crossNBestxAllwithReset(Population&)
Population GAUtils::crossNBestxAllwithReset(Population &pop) {
    Population newPop;

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

    for (unsigned i = 0; i < Config::N_BEST; i++) {
        vector<int> savedTour = pop.getPopulation()[i];
        for (vector<int> t : pop.getPopulation()) {
            vector<int> tmp = GPX2::crossover(savedTour, t);
            savedTour = tmp;
        }
        newPop.getPopulation().push_back(savedTour);
    }

    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, %r12
movq %rdi, 0x8(%rsp)
callq 0xeac4
movq %r12, %rdi
callq 0xead4
movq (%rax), %r14
movq %r12, %rdi
callq 0xead4
movq 0x8(%rax), %rbx
cmpq %rbx, %r14
je 0x9a8d
movq %rbx, %r15
subq %r14, %r15
movq %r15, %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 %r14, %rdi
movq %rbx, %rsi
callq 0xa304
cmpq $0x181, %r15            # imm = 0x181
jl 0x9a82
leaq 0x180(%r14), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0xa850
cmpq %rbx, %r15
je 0x9a8d
movq %r15, %rdi
callq 0xa955
addq $0x18, %r15
jmp 0x9a6f
movq %r14, %rdi
movq %rbx, %rsi
callq 0xa850
leaq 0x38d2c(%rip), %rax     # 0x427c0
cmpl $0x0, (%rax)
je 0x9be8
xorl %r14d, %r14d
leaq 0x80(%rsp), %r15
leaq 0x50(%rsp), %r13
leaq 0x38(%rsp), %rbp
leaq 0x68(%rsp), %rbx
movq %r12, 0x10(%rsp)
movq %r12, %rdi
callq 0xead4
leaq (%r14,%r14,2), %rsi
shlq $0x3, %rsi
addq (%rax), %rsi
movq %r15, %rdi
callq 0xb05c
movq %r14, 0x18(%rsp)
movq %r12, %rdi
callq 0xead4
movq (%rax), %r14
movq 0x8(%rax), %r12
cmpq %r12, %r14
je 0x9b97
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0xb05c
movq %r13, %rdi
movq %r15, %rsi
callq 0xb05c
movq %rbp, %rdi
leaq 0x20(%rsp), %rsi
callq 0xb05c
movq %rbx, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x26a04
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x9b3e
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x53c0
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x9b55
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x53c0
movq %r15, %rdi
movq %rbx, %rsi
callq 0xb27a
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x9b77
movq 0x78(%rsp), %rsi
subq %rdi, %rsi
callq 0x53c0
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x9b8e
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x53c0
addq $0x18, %r14
jmp 0x9aeb
movq 0x8(%rsp), %rdi
callq 0xead4
movq 0x18(%rsp), %r14
movq %rax, %rdi
movq %r15, %rsi
callq 0xb24e
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
movq 0x10(%rsp), %r12
je 0x9bd3
movq 0x90(%rsp), %rsi
subq %rdi, %rsi
callq 0x53c0
incq %r14
leaq 0x38be3(%rip), %rax     # 0x427c0
movl (%rax), %eax
cmpq %rax, %r14
jb 0x9abc
leaq 0x38cf1(%rip), %rbx     # 0x428e0
movl (%rbx), %eax
cvtsi2sd %rax, %xmm0
leaq 0x38bd3(%rip), %rax     # 0x427d0
mulsd (%rax), %xmm0
cvttsd2si %xmm0, %rsi
movq 0x8(%rsp), %rdi
callq 0x8566
movl (%rbx), %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 %r12, %rdi
movq 0x8(%rsp), %rsi
movl %ebx, %edx
callq 0x8b5b
movq 0x8(%rsp), %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9c5d
jmp 0x9c5d
jmp 0x9ccd
jmp 0x9ccd
movq %rax, %rbx
jmp 0x9ced
movq %rax, %rbx
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x9cb4
movq 0x78(%rsp), %rsi
jmp 0x9ca7
movq %rax, %rbx
jmp 0x9c98
movq %rax, %rbx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x9c98
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x53c0
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x9cb4
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x53c0
jmp 0x9cb4
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x9cd0
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x53c0
jmp 0x9cd0
movq %rax, %rbx
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x9ced
movq 0x90(%rsp), %rsi
subq %rdi, %rsi
callq 0x53c0
movq 0x8(%rsp), %rdi
callq 0x8102
movq %rbx, %rdi
callq 0x5670