// File: /workspace/github_cpp_makefile_star2_O1/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 0x21ba3(%rip), %rsi     # 0x43c70
leaq 0x28(%rsp), %rdi
callq 0xecfe
movq 0x28(%rsp), %r13
movq 0x30(%rsp), %rbp
cmpq %rbp, %r13
je 0x2215e
leaq 0xc(%rsp), %r14
leaq 0x10(%rsp), %r15
leaq 0x48(%rsp), %r12
movl (%r13), %eax
movl %eax, 0xc(%rsp)
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
movq %r14, %rdx
callq 0x226f5
cmpq 0x8(%rbx), %rax
jne 0x22155
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0x21e68
movl 0xc(%rsp), %eax
movl %eax, 0x48(%rsp)
movsd %xmm0, 0x50(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x2214a
movupd 0x48(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x10, 0x18(%rsp)
jmp 0x22155
movq %r15, %rdi
movq %r12, %rdx
callq 0x2278e
addq $0x4, %r13
cmpq %rbp, %r13
jne 0x220f5
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x22175
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x53c0
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rbx
cmpq %rbx, %r14
je 0x2222d
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 0x22323
cmpq $0x101, %r15            # imm = 0x101
jl 0x22222
leaq 0x100(%r14), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x2262c
cmpq %rbx, %r15
je 0x2222d
addq $0x108, %r14            # imm = 0x108
movl (%r15), %eax
movsd 0x8(%r15), %xmm0
movsd -0x8(%r15), %xmm1
ucomisd %xmm0, %xmm1
movq %r15, %rcx
jbe 0x2220c
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 0x221ef
addq $-0x8, %rcx
movl %eax, (%rcx)
movsd %xmm0, 0x8(%rcx)
addq $0x10, %r15
addq $0x10, %r14
cmpq %rbx, %r15
jne 0x221d4
jmp 0x2222d
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2262c
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
xorpd %xmm0, %xmm0
cmpq %rcx, %rax
je 0x2224b
addsd 0x8(%rax), %xmm0
addq $0x10, %rax
jmp 0x2223b
movsd %xmm0, 0x40(%rsp)
leaq 0x20690(%rip), %rdi     # 0x428e8
callq 0xbf67
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rax
cmpq %rax, %rdi
sete %cl
je 0x222ae
mulsd 0x40(%rsp), %xmm0
xorpd %xmm1, %xmm1
addsd %xmm1, %xmm0
subsd 0x8(%rdi), %xmm0
ucomisd %xmm0, %xmm1
movl (%rdi), %ebx
jae 0x222ae
leaq 0x10(%rdi), %rdx
cmpq %rax, %rdx
sete %cl
je 0x222ae
subsd 0x8(%rdx), %xmm0
leaq 0x10(%rdx), %rsi
ucomisd %xmm0, %xmm1
jb 0x222a7
movl (%rdx), %ebx
movq %rsi, %rdx
jb 0x2228e
jmp 0x222ae
testb %cl, %cl
je 0x222b5
movl -0x10(%rax), %ebx
testq %rdi, %rdi
je 0x222c7
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x53c0
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x222da
movq %rax, %rbx
jmp 0x222fb
jmp 0x222e1
movq %rax, %rbx
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x222fb
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x53c0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x22312
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x53c0
movq %rbx, %rdi
callq 0x5670