// File: /workspace/github_cpp_makefile_star2_O3/GAStudyGroup[P]GPX2/src/cross/AntColony/Ant.cpp
// Function: Ant::nextStep()
int Ant::nextStep(){
    vector<Choice> choices;
    double sum{0.0},rng{0.0};

    for(unsigned city : Globals::map.getCityList()){
        if(find(path.begin(),path.end(),city) == path.end()){
            choices.push_back(make_pair(city,calcChance(city)));   
        }
    }

    sort(choices.begin(),choices.end(),[](Choice& a, Choice& b){return a.second<b.second;});
    
    for(Choice c : choices){
        sum+=c.second;
    }
    
    uniform_real_distribution<double> dist(0.0,sum);
    
    rng = dist(Globals::urng);
    for(Choice c : choices){
        rng-=c.second;
        if(rng<=0){
            return c.first;
        }
    }
    return choices.back().first;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
leaq 0x21b29(%rip), %rsi     # 0x43c60
leaq 0x28(%rsp), %rdi
callq 0xece6
movq 0x28(%rsp), %r14
movq 0x30(%rsp), %rbp
cmpq %rbp, %r14
je 0x221cc
leaq 0xc(%rsp), %r15
leaq 0x10(%rsp), %r12
leaq 0x48(%rsp), %r13
movl (%r14), %eax
movl %eax, 0xc(%rsp)
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
movq %r15, %rdx
callq 0x22744
cmpq 0x8(%rbx), %rax
jne 0x221be
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0x21ece
movl 0xc(%rsp), %eax
movl %eax, 0x48(%rsp)
movsd %xmm0, 0x50(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x221b3
movupd 0x48(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x10, 0x18(%rsp)
jmp 0x221be
movq %r12, %rdi
movq %r13, %rdx
callq 0x227ea
addq $0x4, %r14
cmpq %rbp, %r14
jne 0x2215f
movq 0x28(%rsp), %r14
testq %r14, %r14
je 0x221e1
movq 0x38(%rsp), %rsi
subq %r14, %rsi
movq %r14, %rdi
callq 0x53b0
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rbx
cmpq %rbx, %r14
je 0x22299
movq %rbx, %r15
subq %r14, %r15
movq %r15, %rax
sarq $0x4, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x22375
cmpq $0x101, %r15            # imm = 0x101
jl 0x2228e
leaq 0x100(%r14), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x2267b
cmpq %rbx, %r15
je 0x22299
addq $0x108, %r14            # imm = 0x108
movl (%r15), %eax
movsd 0x8(%r15), %xmm0
movsd -0x8(%r15), %xmm1
ucomisd %xmm0, %xmm1
movq %r15, %rcx
jbe 0x22278
movq %r14, %rcx
movl -0x18(%rcx), %edx
movl %edx, -0x8(%rcx)
movsd %xmm1, (%rcx)
movsd -0x20(%rcx), %xmm1
addq $-0x10, %rcx
ucomisd %xmm0, %xmm1
ja 0x2225b
addq $-0x8, %rcx
movl %eax, (%rcx)
movsd %xmm0, 0x8(%rcx)
addq $0x10, %r15
addq $0x10, %r14
cmpq %rbx, %r15
jne 0x22240
jmp 0x22299
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2267b
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
xorpd %xmm0, %xmm0
cmpq %rcx, %rax
je 0x222b7
addsd 0x8(%rax), %xmm0
addq $0x10, %rax
jmp 0x222a7
movsd %xmm0, 0x40(%rsp)
leaq 0x20614(%rip), %rdi     # 0x428d8
callq 0xbf8f
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x222fd
mulsd 0x40(%rsp), %xmm0
xorpd %xmm1, %xmm1
addsd %xmm1, %xmm0
movq %rdi, %rcx
subsd 0x8(%rcx), %xmm0
ucomisd %xmm0, %xmm1
jae 0x22304
addq $0x10, %rcx
cmpq %rax, %rcx
jne 0x222e9
addq $-0x10, %rax
movq %rax, %rcx
movl (%rcx), %ebx
testq %rdi, %rdi
je 0x22318
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x53b0
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2232b
movq %rax, %rbx
jmp 0x2234c
jmp 0x22332
movq %rax, %rbx
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x2234c
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x53b0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x22363
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x53b0
movq %rbx, %rdi
callq 0x5660
nop