// File: /workspace/github_cpp_makefile_star2_O3/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 0xeaac
movq %rbx, 0x8(%rsp)
movq %rbx, %rdi
callq 0xeaac
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
leaq 0x398cd(%rip), %rax     # 0x428d0
cmpl $0x0, (%rax)
je 0x912e
xorl %r12d, %r12d
leaq 0x30(%rsp), %r15
leaq 0x68(%rsp), %rbp
leaq 0x80(%rsp), %rbx
movq 0x10(%rsp), %rdi
callq 0xeabc
leaq (%r12,%r12,2), %rsi
shlq $0x3, %rsi
addq (%rax), %rsi
movq %r15, %rdi
callq 0xb296
leaq 0x3988b(%rip), %rax     # 0x428d0
movl (%rax), %eax
testl %eax, %eax
je 0x9104
xorl %r14d, %r14d
xorl %r13d, %r13d
cmpq %r13, %r12
je 0x90f2
movq 0x10(%rsp), %rdi
callq 0xeabc
movq (%rax), %rsi
addq %r14, %rsi
leaq 0x50(%rsp), %rdi
callq 0xb078
movq %rbp, %rdi
movq %r15, %rsi
callq 0xb078
movq %rbx, %rdi
leaq 0x50(%rsp), %rsi
movq %rbp, %rdx
callq 0x26bf4
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x90aa
movq 0x78(%rsp), %rsi
subq %rdi, %rsi
callq 0x53b0
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x90c1
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x53b0
movq %r15, %rdi
movq %rbx, %rsi
callq 0xb296
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x90e9
movq 0x90(%rsp), %rsi
subq %rdi, %rsi
callq 0x53b0
leaq 0x397e0(%rip), %rax     # 0x428d0
movl (%rax), %eax
incq %r13
movl %eax, %ecx
addq $0x18, %r14
cmpq %rcx, %r13
jb 0x9055
leaq 0x18(%rsp), %rdi
callq 0xeabc
movq %rax, %rdi
movq %r15, %rsi
callq 0xb26a
incq %r12
leaq 0x397ad(%rip), %rax     # 0x428d0
movl (%rax), %eax
cmpq %rax, %r12
jb 0x9021
leaq 0x18(%rsp), %rdi
callq 0xeabc
movq (%rax), %r15
leaq 0x18(%rsp), %rdi
callq 0xeabc
movq 0x8(%rax), %rbx
cmpq %rbx, %r15
je 0x91ba
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 0xa2e6
cmpq $0x181, %r14            # imm = 0x181
jl 0x91af
leaq 0x180(%r15), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0xa85f
cmpq %rbx, %r12
je 0x91ba
movq %r12, %rdi
callq 0xa960
addq $0x18, %r12
jmp 0x919c
movq %r15, %rdi
movq %rbx, %rsi
callq 0xa85f
movq 0x8(%rsp), %rdi
callq 0xeabc
movq %rax, %rbx
movq 0x8(%rsp), %rdi
callq 0xeabc
movq 0x8(%rax), %r15
leaq 0x18(%rsp), %rdi
callq 0xeabc
movq (%rax), %r12
leaq 0x18(%rsp), %rdi
callq 0xeabc
leaq 0x395bd(%rip), %rcx     # 0x427b0
movl (%rcx), %ecx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq (%rax), %rcx
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0xbb22
leaq 0x396bb(%rip), %rax     # 0x428d0
movl (%rax), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
leaq 0x3959a(%rip), %rax     # 0x427c0
mulsd (%rax), %xmm0
cvttsd2si %xmm0, %rsi
movq 0x8(%rsp), %rdi
callq 0x858c
leaq 0x39690(%rip), %rax     # 0x428d0
movl (%rax), %ebx
movq 0x8(%rsp), %rdi
callq 0xeabc
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 0x8b45
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x9287
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x53b0
leaq 0x18(%rsp), %rdi
callq 0x8122
movq 0x8(%rsp), %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x9330
jmp 0x930c
jmp 0x930c
jmp 0x930c
jmp 0x930c
jmp 0x930c
movq %rax, %rbx
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x92d9
movq 0x78(%rsp), %rsi
subq %rdi, %rsi
callq 0x53b0
jmp 0x92d9
movq %rax, %rbx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x930f
movq 0x60(%rsp), %rsi
jmp 0x9302
movq %rax, %rbx
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x930f
movq 0x90(%rsp), %rsi
subq %rdi, %rsi
callq 0x53b0
jmp 0x930f
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x9326
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x53b0
movq 0x8(%rsp), %rdi
callq 0x8122
leaq 0x18(%rsp), %rdi
callq 0x8122
movq %rbx, %rdi
callq 0x5660