// File: /workspace/github_cpp_makefile_star2_O1/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 $0x88, %rsp
movq %rdi, %rbx
movq 0x18(%rdi), %rax
subq 0x10(%rdi), %rax
movq %rax, 0x70(%rsp)
xorl %eax, %eax
movq %rax, 0x50(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x40(%rsp)
movq %rax, 0x10(%rsp)
movapd %xmm0, (%rsp)
movq 0x10(%rdi), %r12
cmpq %r12, 0x18(%rdi)
je 0x1f75
xorl %ebp, %ebp
movq %rsp, %r14
leaq 0x58(%rsp), %r15
xorl %r13d, %r13d
movq %rbx, %rdi
movl %r13d, %esi
callq 0x1e80
movq %rax, 0x58(%rsp)
addq %rbp, %r12
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2b42
incq %r13
movq 0x10(%rbx), %r12
movq 0x18(%rbx), %rax
subq %r12, %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
addq $0x18, %rbp
cmpq %r13, %rax
ja 0x1f2b
movq (%rsp), %r14
movq 0x8(%rsp), %r15
cmpq %r15, %r14
je 0x1fbe
movq %r15, %rax
subq %r14, %rax
sarq $0x5, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq -0xd3(%rip), %rcx       # 0x1ece
movq %r14, %rdi
movq %r15, %rsi
callq 0x3581
leaq -0xe5(%rip), %rdx       # 0x1ece
movq %r14, %rdi
movq %r15, %rsi
callq 0x364f
movq 0x70(%rsp), %rcx
sarq $0x3, %rcx
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rcx
movq %rcx, %xmm0
punpckldq 0x30ce(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x30d6(%rip), %xmm0     # 0x50c0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x30d2(%rip), %xmm1     # 0x50d0
cvttsd2si %xmm1, %r13d
movq (%rsp), %rax
movq (%rax), %rax
movq 0x8(%rbx), %rcx
cmpq %rcx, %rax
cmovlq %rax, %rcx
movq %rcx, 0x8(%rbx)
testl %r13d, %r13d
jle 0x204a
movl %r13d, %r15d
shlq $0x5, %r15
xorl %r12d, %r12d
leaq 0x40(%rsp), %r14
movq (%rsp), %rax
leaq (%rax,%r12), %rsi
addq $0x8, %rsi
movq %r14, %rdi
callq 0x2b84
addq $0x20, %r12
cmpq %r12, %r15
jne 0x202d
movq 0x18(%rbx), %rax
subq 0x10(%rbx), %rax
shrq $0x3, %rax
imull $0xaaaaaaab, %eax, %eax # imm = 0xAAAAAAAB
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
movq 0x48(%rsp), %rax
subq 0x40(%rsp), %rax
shrq $0x3, %rax
imull $0x55555555, %eax, %r12d # imm = 0x55555555
addl %ecx, %r12d
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movq 0x18(%rbx), %rax
subq 0x10(%rbx), %rax
movslq %r13d, %r15
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
cmpq %r15, %rax
jbe 0x21be
testl %r12d, %r12d
je 0x21be
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movsd %xmm0, 0x80(%rsp)
movq %r15, %r13
shlq $0x5, %r13
orq $0x8, %r13
movq %r15, %r14
negq %r14
incq %r15
leaq 0x20(%rsp), %rbp
leaq (%rax,%r14), %rcx
movq %rcx, %xmm0
movq 0x2fb6(%rip), %xmm1     # 0x50b0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x2fba(%rip), %xmm2     # 0x50c0
subpd %xmm2, %xmm0
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
addsd 0x80(%rsp), %xmm3
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
divsd %xmm0, %xmm3
movapd %xmm3, 0x70(%rsp)
callq 0x1040
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd 0x2f76(%rip), %xmm0     # 0x50d8
movq (%rsp), %rsi
addq %r13, %rsi
movapd 0x70(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jae 0x217f
movq %rbp, %rdi
callq 0x2b84
jmp 0x218c
leaq 0x40(%rsp), %rdi
callq 0x2b84
decl %r12d
movq 0x18(%rbx), %rax
subq 0x10(%rbx), %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
cmpq %r15, %rax
jbe 0x21be
addq $0x20, %r13
decq %r14
incq %r15
testl %r12d, %r12d
jne 0x20e9
movq 0x20(%rsp), %r13
movq 0x28(%rsp), %r14
cmpq %r14, %r13
je 0x228f
leaq 0x18(%r13), %rax
cmpq %r14, %rax
je 0x228f
movl $0x18, %ebp
callq 0x1040
cltq
movq %rbp, %rcx
sarq $0x3, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
incq %rcx
cqto
idivq %rcx
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %r15
cmpq %r15, %rbp
je 0x2277
movq %r13, %rdi
addq %rbp, %rdi
addq %r13, %r15
movq (%r13,%rbp), %rax
movq %rax, 0x58(%rsp)
movq 0x8(%r13,%rbp), %rax
movq %rax, 0x60(%rsp)
movq 0x10(%r13,%rbp), %rax
movq %rax, 0x68(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq %r15, %rsi
callq 0x3b66
movq %r15, %rdi
leaq 0x58(%rsp), %rsi
callq 0x3b66
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x2277
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x1130
leaq 0x18(,%rbp), %rax
addq %r13, %rax
addq $0x18, %rbp
cmpq %r14, %rax
jne 0x21e3
addq $0x10, %rbx
movl %r12d, %eax
sarl $0x1f, %eax
notl %eax
andl %r12d, %eax
leaq (%rax,%rax,2), %rax
leaq 0x18(,%rax,8), %r15
xorl %esi, %esi
leaq 0x40(%rsp), %r14
leaq 0x18(%rsi), %r12
cmpq %r12, %r15
je 0x22cc
addq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x2b84
movq %r12, %rsi
jmp 0x22b1
movq 0x20(%rsp), %r14
movq 0x28(%rsp), %r15
cmpq %r14, %r15
je 0x2302
movq %r14, %r12
movq (%r12), %rdi
testq %rdi, %rdi
je 0x22f4
movq 0x10(%r12), %rsi
subq %rdi, %rsi
callq 0x1130
addq $0x18, %r12
cmpq %r15, %r12
jne 0x22de
movq %r14, 0x28(%rsp)
movq (%rsp), %r14
movq 0x8(%rsp), %r15
cmpq %r14, %r15
je 0x2338
movq %r14, %r12
movq 0x8(%r12), %rdi
testq %rdi, %rdi
je 0x232a
movq 0x18(%r12), %rsi
subq %rdi, %rsi
callq 0x1130
addq $0x20, %r12
cmpq %r15, %r12
jne 0x2313
movq %r14, 0x8(%rsp)
movq (%rbx), %rsi
movq %rbx, %rdi
callq 0x2e32
leaq 0x40(%rsp), %rsi
movq %rbx, %rdi
callq 0x2bba
leaq 0x20(%rsp), %rdi
callq 0x16c0
movq %rsp, %rdi
callq 0x2d32
leaq 0x40(%rsp), %rdi
callq 0x16c0
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x238b
jmp 0x2386
jmp 0x238b
jmp 0x2386
movq %rax, %rbx
jmp 0x2398
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x16c0
movq %rsp, %rdi
callq 0x2d32
leaq 0x40(%rsp), %rdi
callq 0x16c0
movq %rbx, %rdi
callq 0x11c0