// File: 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:
subq $0x168, %rsp            # imm = 0x168
movq %rdi, 0x70(%rsp)
movq %rdi, %rax
movq %rax, 0x68(%rsp)
movq %rdi, 0x160(%rsp)
movq %rsi, 0x158(%rsp)
leaq 0x140(%rsp), %rdi
callq 0x19220
movq 0x70(%rsp), %rdi
movb $0x0, 0x13f(%rsp)
callq 0x19220
jmp 0xb9e5
leaq 0x110(%rsp), %rdi
callq 0xfdf0
movl $0x0, 0x10c(%rsp)
movl 0x10c(%rsp), %eax
leaq 0x90ff5(%rip), %rcx     # 0x9ca00
cmpl (%rcx), %eax
jae 0xbc2c
movq 0x158(%rsp), %rdi
callq 0x19230
movq %rax, 0x60(%rsp)
jmp 0xba27
movq 0x60(%rsp), %rdi
movl 0x10c(%rsp), %eax
movl %eax, %esi
callq 0x10230
movq %rax, %rsi
leaq 0x110(%rsp), %rdi
callq 0x10250
jmp 0xba4c
movl $0x0, 0x108(%rsp)
movl 0x108(%rsp), %eax
leaq 0x90f9b(%rip), %rcx     # 0x9ca00
cmpl (%rcx), %eax
jae 0xbbec
movl 0x10c(%rsp), %eax
cmpl 0x108(%rsp), %eax
je 0xbbd4
movq 0x158(%rsp), %rdi
callq 0x19230
movq %rax, 0x58(%rsp)
jmp 0xba95
movq 0x58(%rsp), %rdi
movl 0x108(%rsp), %eax
movl %eax, %esi
callq 0x10230
movq %rax, %rsi
leaq 0xd8(%rsp), %rdi
callq 0xfcd0
jmp 0xbaba
leaq 0xc0(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0xfcd0
jmp 0xbad1
leaq 0xf0(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
leaq 0xc0(%rsp), %rdx
callq 0x5dd80
jmp 0xbaf0
leaq 0xc0(%rsp), %rdi
callq 0x9af0
leaq 0xd8(%rsp), %rdi
callq 0x9af0
leaq 0x110(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x10250
jmp 0xbb21
leaq 0xf0(%rsp), %rdi
callq 0x9af0
jmp 0xbbd4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x130(%rsp)
movl %eax, 0x12c(%rsp)
jmp 0xbe53
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x130(%rsp)
movl %eax, 0x12c(%rsp)
jmp 0xbe16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x130(%rsp)
movl %eax, 0x12c(%rsp)
jmp 0xbb9c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x130(%rsp)
movl %eax, 0x12c(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x9af0
leaq 0xd8(%rsp), %rdi
callq 0x9af0
jmp 0xbe16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x130(%rsp)
movl %eax, 0x12c(%rsp)
leaq 0xf0(%rsp), %rdi
callq 0x9af0
jmp 0xbe16
jmp 0xbbd6
movl 0x108(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x108(%rsp)
jmp 0xba57
leaq 0x140(%rsp), %rdi
callq 0x19230
movq %rax, 0x50(%rsp)
jmp 0xbc00
movq 0x50(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0x10190
jmp 0xbc14
jmp 0xbc16
movl 0x10c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10c(%rsp)
jmp 0xb9fd
leaq 0x140(%rsp), %rdi
callq 0x19230
movq %rax, 0x48(%rsp)
jmp 0xbc40
movq 0x48(%rsp), %rdi
callq 0xfc20
movq %rax, 0xb8(%rsp)
leaq 0x140(%rsp), %rdi
callq 0x19230
movq %rax, 0x40(%rsp)
jmp 0xbc66
movq 0x40(%rsp), %rdi
callq 0xfc50
movq %rax, 0xb0(%rsp)
movq 0xb8(%rsp), %rdi
movq 0xb0(%rsp), %rsi
callq 0xcb50
jmp 0xbc8f
movq 0x70(%rsp), %rdi
callq 0x19230
movq %rax, 0x38(%rsp)
jmp 0xbca0
movq 0x70(%rsp), %rdi
callq 0x19230
movq %rax, 0x30(%rsp)
jmp 0xbcb1
movq 0x30(%rsp), %rdi
callq 0xfc50
movq %rax, 0x98(%rsp)
leaq 0xa0(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x105f0
leaq 0x140(%rsp), %rdi
callq 0x19230
movq %rax, 0x28(%rsp)
jmp 0xbcec
movq 0x28(%rsp), %rdi
callq 0xfc20
movq %rax, 0x90(%rsp)
leaq 0x140(%rsp), %rdi
callq 0x19230
movq %rax, 0x20(%rsp)
jmp 0xbd12
movq 0x20(%rsp), %rdi
callq 0xfc20
movq %rax, 0x80(%rsp)
leaq 0x90bb5(%rip), %rax     # 0x9c8e0
movl (%rax), %eax
movl %eax, %esi
leaq 0x80(%rsp), %rdi
callq 0x10630
movq 0x38(%rsp), %rdi
movq %rax, 0x88(%rsp)
movq 0xa0(%rsp), %rsi
movq 0x90(%rsp), %rdx
movq 0x88(%rsp), %rcx
callq 0x10530
movq %rax, 0x18(%rsp)
jmp 0xbd6d
movq 0x70(%rsp), %rdi
movq 0x18(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0x90c7d(%rip), %rax     # 0x9ca00
movl (%rax), %eax
cvtsi2sd %rax, %xmm0
leaq 0x90b5f(%rip), %rax     # 0x9c8f0
movsd (%rax), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, %esi
callq 0xaaf0
jmp 0xbda7
movq 0x70(%rsp), %rdi
movq 0x158(%rsp), %rax
movq %rax, (%rsp)
leaq 0x90c41(%rip), %rax     # 0x9ca00
movl (%rax), %eax
movq %rax, 0x8(%rsp)
callq 0x19230
movq %rax, 0x10(%rsp)
jmp 0xbdd2
movq 0x10(%rsp), %rdi
callq 0x10510
movq 0x8(%rsp), %rcx
movq (%rsp), %rdi
movq 0x70(%rsp), %rsi
movl %ecx, %edx
subl %eax, %edx
callq 0xb340
jmp 0xbdf5
movb $0x1, 0x13f(%rsp)
leaq 0x110(%rsp), %rdi
callq 0x9af0
testb $0x1, 0x13f(%rsp)
jne 0xbe39
jmp 0xbe2f
leaq 0x110(%rsp), %rdi
callq 0x9af0
movq 0x70(%rsp), %rdi
callq 0x9440
jmp 0xbe53
movq 0x70(%rsp), %rdi
callq 0x9440
leaq 0x140(%rsp), %rdi
callq 0x9440
movq 0x68(%rsp), %rax
addq $0x168, %rsp            # imm = 0x168
retq
leaq 0x140(%rsp), %rdi
callq 0x9440
movq 0x130(%rsp), %rdi
callq 0x6850
nopl (%rax)