// File: 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:
subq $0x128, %rsp            # imm = 0x128
movq %rdi, 0x40(%rsp)
movq %rdi, %rax
movq %rax, 0x48(%rsp)
movq %rdi, 0x120(%rsp)
movq %rsi, 0x118(%rsp)
movb $0x0, 0x117(%rsp)
callq 0x19220
movq 0x118(%rsp), %rdi
callq 0x19230
movq %rax, 0x50(%rsp)
jmp 0xc7b5
movq 0x50(%rsp), %rdi
callq 0xfc20
movq %rax, 0x108(%rsp)
movq 0x118(%rsp), %rdi
callq 0x19230
movq %rax, 0x38(%rsp)
jmp 0xc7db
movq 0x38(%rsp), %rdi
callq 0xfc50
movq %rax, 0xf0(%rsp)
movq 0x108(%rsp), %rdi
movq 0xf0(%rsp), %rsi
callq 0xcb50
jmp 0xc804
movl $0x0, 0xe8(%rsp)
movl 0xe8(%rsp), %eax
leaq 0x900c3(%rip), %rcx     # 0x9c8e0
cmpl (%rcx), %eax
jae 0xca90
movq 0x118(%rsp), %rdi
callq 0x19230
movq %rax, 0x30(%rsp)
jmp 0xc839
movq 0x30(%rsp), %rdi
movl 0xe8(%rsp), %eax
movl %eax, %esi
callq 0x10230
movq %rax, %rsi
leaq 0xd0(%rsp), %rdi
callq 0xfcd0
jmp 0xc85e
movq 0x118(%rsp), %rdi
callq 0x19230
movq %rax, 0x28(%rsp)
jmp 0xc872
movq 0x28(%rsp), %rax
movq %rax, 0xc8(%rsp)
movq 0xc8(%rsp), %rdi
callq 0xfc20
movq %rax, 0xc0(%rsp)
movq 0xc8(%rsp), %rdi
callq 0xfc50
movq %rax, 0xb8(%rsp)
leaq 0xc0(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0xfc80
testb $0x1, %al
jne 0xc8c7
jmp 0xca36
leaq 0xc0(%rsp), %rdi
callq 0xfcc0
movq %rax, %rsi
leaq 0xa0(%rsp), %rdi
callq 0xfcd0
jmp 0xc8e6
leaq 0x70(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0xfcd0
jmp 0xc8fa
leaq 0x58(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0xfcd0
jmp 0xc90e
leaq 0x88(%rsp), %rdi
leaq 0x70(%rsp), %rsi
leaq 0x58(%rsp), %rdx
callq 0x5dd80
jmp 0xc927
leaq 0x58(%rsp), %rdi
callq 0x9af0
leaq 0x70(%rsp), %rdi
callq 0x9af0
leaq 0xd0(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x10250
jmp 0xc952
leaq 0x88(%rsp), %rdi
callq 0x9af0
leaq 0xa0(%rsp), %rdi
callq 0x9af0
leaq 0xc0(%rsp), %rdi
callq 0xfdd0
jmp 0xc8a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0xcb39
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0xca7e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0xca27
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0xc9fa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
leaq 0x58(%rsp), %rdi
callq 0x9af0
leaq 0x70(%rsp), %rdi
callq 0x9af0
jmp 0xca27
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x9af0
leaq 0xa0(%rsp), %rdi
callq 0x9af0
jmp 0xca7e
movq 0x40(%rsp), %rdi
callq 0x19230
movq %rax, 0x20(%rsp)
jmp 0xca47
movq 0x20(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x10190
jmp 0xca5b
leaq 0xd0(%rsp), %rdi
callq 0x9af0
movl 0xe8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe8(%rsp)
jmp 0xc80f
leaq 0xd0(%rsp), %rdi
callq 0x9af0
jmp 0xcb39
movq 0x40(%rsp), %rdi
leaq 0x8ff64(%rip), %rax     # 0x9ca00
movl (%rax), %eax
cvtsi2sd %rax, %xmm0
leaq 0x8fe46(%rip), %rax     # 0x9c8f0
movsd (%rax), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, %esi
callq 0xaaf0
jmp 0xcac0
movq 0x40(%rsp), %rdi
movq 0x118(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x8ff27(%rip), %rax     # 0x9ca00
movl (%rax), %eax
movq %rax, 0x10(%rsp)
callq 0x19230
movq %rax, 0x18(%rsp)
jmp 0xcaec
movq 0x18(%rsp), %rdi
callq 0x10510
movq 0x10(%rsp), %rcx
movq 0x8(%rsp), %rdi
movq 0x40(%rsp), %rsi
movl %ecx, %edx
subl %eax, %edx
callq 0xb340
jmp 0xcb10
movb $0x1, 0x117(%rsp)
testb $0x1, 0x117(%rsp)
jne 0xcb2c
movq 0x40(%rsp), %rdi
callq 0x9440
movq 0x48(%rsp), %rax
addq $0x128, %rsp            # imm = 0x128
retq
movq 0x40(%rsp), %rdi
callq 0x9440
movq 0x100(%rsp), %rdi
callq 0x6850