// File: /workspace/github_cpp_makefile_star2_O3/gabrielfelipeg[P]TravellingSalesman-GeneticAlgo/src/population.cpp
// Function: Population::select()
void Population::select(){
    int elitism = population.size() * 0.1;
    std::vector <Individual> newPop;
    std::vector < std::pair<long long, Individual> > aux;
    for(int i = 0; i < population.size(); i++){
        aux.emplace_back(F(i), population[i]);
    }
    sort(aux.begin(), aux.end(), comparator);
    currentBest = std::min(currentBest, aux[0].first);
    for(int i = 0; i < elitism; i++){
        newPop.emplace_back(aux[i].second);    
    }
    int needed = ((int)population.size() / 2) - (int)newPop.size();
    std::vector <Individual> secondChance;
    for(int i = elitism; i < population.size() && needed; i++){
        double chance = (population.size() - i + elitism * 1.0) / ((double)population.size() * population.size() * 1.0 - population.size());
        double random = ((double)rand()) / RAND_MAX;
        if(chance >= random){
            newPop.emplace_back(aux[i].second);
            needed--;
        }else{
            secondChance.emplace_back(aux[i].second);
        }
    }
    int ind = 0;
    std::random_shuffle(secondChance.begin(), secondChance.end());
    while(needed > 0){
        needed--;
        newPop.emplace_back(secondChance[ind++]);
    }
    secondChance.clear();
    aux.clear();
    population.clear();
    population = newPop;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdi, %r14
movq 0x10(%rdi), %r15
movq 0x18(%rdi), %rax
subq %r15, %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
movq %rax, %xmm0
punpckldq 0x3088(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x3090(%rip), %xmm0     # 0x50f0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x309c(%rip), %xmm1     # 0x5110
leaq 0x10(%rdi), %rax
movq %rax, 0x70(%rsp)
cvttsd2si %xmm1, %eax
movl %eax, 0x40(%rsp)
xorl %ebx, %ebx
movq %rbx, 0x60(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x50(%rsp)
leaq 0x20(%rsp), %r12
movq %rbx, 0x10(%r12)
movapd %xmm0, (%r12)
movq %rsp, %r13
xorl %ebp, %ebp
movq %r14, %rdi
movl %ebp, %esi
callq 0x1fbe
movq %rax, (%rsp)
addq %rbx, %r15
movq %r12, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x2cde
incq %rbp
movq 0x10(%r14), %r15
movq 0x18(%r14), %rax
subq %r15, %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
addq $0x18, %rbx
cmpq %rbp, %rax
ja 0x20ab
movq 0x20(%rsp), %r15
movq 0x28(%rsp), %r12
cmpq %r12, %r15
je 0x2149
movq %r12, %rax
subq %r15, %rax
sarq $0x5, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq -0x110(%rip), %rcx      # 0x2010
movq %r15, %rdi
movq %r12, %rsi
callq 0x36ed
movl 0x40(%rsp), %r13d
leaq -0x127(%rip), %rdx      # 0x2010
movq %r15, %rdi
movq %r12, %rsi
callq 0x37bb
movq 0x20(%rsp), %r15
jmp 0x214e
movl 0x40(%rsp), %r13d
movq (%r15), %rax
movq 0x8(%r14), %rcx
cmpq %rcx, %rax
cmovlq %rax, %rcx
movq %rcx, 0x8(%r14)
testl %r13d, %r13d
jle 0x2192
movl %r13d, %ebx
shlq $0x5, %rbx
xorl %r12d, %r12d
leaq 0x50(%rsp), %r15
movq 0x20(%rsp), %rax
leaq (%rax,%r12), %rsi
addq $0x8, %rsi
movq %r15, %rdi
callq 0x2d28
addq $0x20, %r12
cmpq %r12, %rbx
jne 0x2174
movq 0x18(%r14), %rax
subq 0x10(%r14), %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
movq 0x58(%rsp), %rdx
subq 0x50(%rsp), %rdx
shrq $0x3, %rdx
imull $0x55555555, %edx, %ebp # imm = 0x55555555
addl %ecx, %ebp
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movslq %r13d, %r12
cmpq %r12, %rax
jbe 0x23bc
testl %ebp, %ebp
je 0x23bc
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movsd %xmm0, 0x78(%rsp)
movq %r12, %r13
shlq $0x5, %r13
orq $0x8, %r13
movq %r12, %r15
negq %r15
incq %r12
movq %rsp, %rbx
leaq (%rax,%r15), %rcx
movq %rcx, %xmm0
movq 0x2eb9(%rip), %xmm1     # 0x50e0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x2ebd(%rip), %xmm2     # 0x50f0
subpd %xmm2, %xmm0
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
addsd 0x78(%rsp), %xmm3
movapd %xmm3, 0x40(%rsp)
movq %rax, %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
subpd %xmm2, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
mulsd %xmm1, %xmm0
subsd %xmm1, %xmm0
shufpd $0x2, 0x2e83(%rip), %xmm0 # xmm0 = xmm0[0],mem[1]
movapd %xmm0, 0x80(%rsp)
callq 0x1040
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movapd 0x40(%rsp), %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
divpd 0x80(%rsp), %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
movq 0x20(%rsp), %rsi
addq %r13, %rsi
ucomisd %xmm0, %xmm1
jae 0x22c5
movq %rbx, %rdi
callq 0x2d28
jmp 0x22d1
leaq 0x50(%rsp), %rdi
callq 0x2d28
decl %ebp
movq 0x18(%r14), %rax
subq 0x10(%r14), %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
cmpq %r12, %rax
jbe 0x2302
addq $0x20, %r13
decq %r15
incq %r12
testl %ebp, %ebp
jne 0x2216
movq (%rsp), %r15
movq 0x8(%rsp), %r12
cmpq %r12, %r15
je 0x23bc
leaq 0x18(%r15), %rax
cmpq %r12, %rax
je 0x23bc
movl $0x18, %r13d
callq 0x1040
cltq
movq %r13, %rcx
sarq $0x3, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
incq %rcx
cqto
idivq %rcx
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %r14
cmpq %r14, %r13
je 0x23a7
leaq (%r15,%r13), %rdi
addq %r15, %r14
movq 0x10(%r15,%r13), %rbx
movups (%r15,%r13), %xmm0
movaps %xmm0, 0x40(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq %r14, %rsi
callq 0x3cc2
movq (%r14), %rdi
movq 0x10(%r14), %rsi
movapd 0x40(%rsp), %xmm0
movupd %xmm0, (%r14)
movq %rbx, 0x10(%r14)
testq %rdi, %rdi
je 0x23a7
subq %rdi, %rsi
callq 0x1130
leaq (%r15,%r13), %rax
addq $0x18, %rax
addq $0x18, %r13
cmpq %r12, %rax
jne 0x2327
movl %ebp, %eax
sarl $0x1f, %eax
notl %eax
andl %ebp, %eax
leaq (%rax,%rax,2), %rax
leaq 0x18(,%rax,8), %rbx
xorl %esi, %esi
leaq 0x50(%rsp), %r14
leaq 0x18(%rsi), %r15
cmpq %r15, %rbx
je 0x23f2
addq (%rsp), %rsi
movq %r14, %rdi
callq 0x2d28
movq %r15, %rsi
jmp 0x23d8
movq (%rsp), %rbx
movq 0x8(%rsp), %r14
cmpq %rbx, %r14
je 0x2425
movq %rbx, %r15
movq (%r15), %rdi
testq %rdi, %rdi
je 0x2417
movq 0x10(%r15), %rsi
subq %rdi, %rsi
callq 0x1130
addq $0x18, %r15
cmpq %r14, %r15
jne 0x2403
movq %rbx, 0x8(%rsp)
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %r14
cmpq %rbx, %r14
je 0x245a
movq %rbx, %r15
movq 0x8(%r15), %rdi
testq %rdi, %rdi
je 0x244c
movq 0x18(%r15), %rsi
subq %rdi, %rsi
callq 0x1130
addq $0x20, %r15
cmpq %r14, %r15
jne 0x2437
movq %rbx, 0x28(%rsp)
movq 0x70(%rsp), %rbx
movq (%rbx), %rsi
movq %rbx, %rdi
callq 0x3008
leaq 0x50(%rsp), %rsi
movq %rbx, %rdi
callq 0x2d64
movq %rsp, %rdi
callq 0x16e6
leaq 0x20(%rsp), %rdi
callq 0x2f02
leaq 0x50(%rsp), %rdi
callq 0x16e6
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x24ad
jmp 0x24ba
jmp 0x24ad
jmp 0x24ba
movq %rax, %rbx
movq %rsp, %rdi
callq 0x16e6
jmp 0x24bd
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x2f02
leaq 0x50(%rsp), %rdi
callq 0x16e6
movq %rbx, %rdi
callq 0x11c0
nop