// File: /workspace/github_c_makefile_star2_O3/SimpleDoger[P]Darknet_CPU_Only/go.c
// Function: pick_move
move pick_move(mcts_tree *tree, float temp, int player)
{
    int i;
    float probs[19*19+1] = {0};
    move m = {0};
    double sum = 0;
    /*
    for(i = 0; i < 19*19+1; ++i){
        probs[i] = tree->visit_count[i];
    }
    */
    //softmax(probs, 19*19+1, temp, 1, probs);
    for(i = 0; i < 19*19+1; ++i){
        sum += pow(tree->visit_count[i], 1./temp);
    }
    for(i = 0; i < 19*19+1; ++i){
        probs[i] = pow(tree->visit_count[i], 1./temp) / sum;
    }

    int index = sample_array(probs, 19*19+1);
    m.row = index / 19;
    m.col = index % 19;
    m.value = (tree->result+1.)/2.;
    m.mcts  = (tree->mean[index]+1.)/2.;

    int indexes[nind];
    top_k(probs, 19*19+1, nind, indexes);
    print_board(stderr, tree->board, player, indexes);

    fprintf(stderr, "%d %d, Result: %f, Prior: %f, Prob: %f, Mean Value: %f, Child Result: %f, Visited: %d\n", index/19, index%19, tree->result, tree->prior[index], probs[index], tree->mean[index], (tree->children[index])?tree->children[index]->result:0, tree->visit_count[index]);
    int ind = max_index(probs, 19*19+1);
    fprintf(stderr, "%d %d, Result: %f, Prior: %f, Prob: %f, Mean Value: %f, Child Result: %f, Visited: %d\n", ind/19, ind%19, tree->result, tree->prior[ind], probs[ind], tree->mean[ind], (tree->children[ind])?tree->children[ind]->result:0, tree->visit_count[ind]);
    ind = max_index(tree->prior, 19*19+1);
    fprintf(stderr, "%d %d, Result: %f, Prior: %f, Prob: %f, Mean Value: %f, Child Result: %f, Visited: %d\n", ind/19, ind%19, tree->result, tree->prior[ind], probs[ind], tree->mean[ind], (tree->children[ind])?tree->children[ind]->result:0, tree->visit_count[ind]);
    return m;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x5e8, %rsp            # imm = 0x5E8
movl %esi, -0x38(%rbp)
movss %xmm0, -0x30(%rbp)
movq %rdi, %rbx
leaq -0x610(%rbp), %rdi
xorl %r14d, %r14d
movl $0x5a8, %edx            # imm = 0x5A8
xorl %esi, %esi
callq 0x31c0
cvtss2sd -0x30(%rbp), %xmm0
movsd 0x4b49c(%rip), %xmm1    # 0x55150
divsd %xmm0, %xmm1
xorpd %xmm2, %xmm2
movsd %xmm1, -0x50(%rbp)
movsd %xmm2, -0x30(%rbp)
movq 0x18(%rbx), %rax
cvtsi2sdl (%rax,%r14,4), %xmm0
movsd -0x50(%rbp), %xmm1
callq 0x3110
movsd -0x30(%rbp), %xmm2
addsd %xmm0, %xmm2
incq %r14
cmpq $0x16a, %r14            # imm = 0x16A
jne 0x9cc1
xorl %r14d, %r14d
movsd %xmm2, -0x30(%rbp)
movq 0x18(%rbx), %rax
cvtsi2sdl (%rax,%r14,4), %xmm0
movsd -0x50(%rbp), %xmm1
callq 0x3110
movsd -0x30(%rbp), %xmm2
divsd %xmm2, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x610(%rbp,%r14,4)
incq %r14
cmpq $0x16a, %r14            # imm = 0x16A
jne 0x9cf7
leaq -0x610(%rbp), %r13
movq %r13, %rdi
movl $0x16a, %esi            # imm = 0x16A
callq 0xf97d
movl %eax, %ecx
movq %rsp, -0x30(%rbp)
pushq $0x13
popq %rsi
cltd
idivl %esi
movl %eax, -0x34(%rbp)
movl %edx, %r14d
movq 0x28(%rbx), %rax
movslq %ecx, %r15
movss (%rax,%r15,4), %xmm0
movaps %xmm0, -0x50(%rbp)
movss 0x3c(%rbx), %xmm0
movaps %xmm0, -0x60(%rbp)
leaq -0x30(%rsp), %r12
movq %r12, %rsp
pushq $0xa
popq %rdx
movq %r13, %rdi
movl $0x16a, %esi            # imm = 0x16A
movq %r12, %rcx
callq 0xf0cd
movq 0x62268(%rip), %r13     # 0x6bff8
movq (%r13), %rdi
movq (%rbx), %rsi
movl -0x38(%rbp), %edx
movq %r12, %rcx
callq 0x45d3f
movq %r13, %r12
movq (%r13), %rdi
cvtss2sd 0x3c(%rbx), %xmm0
movq 0x10(%rbx), %rax
cvtss2sd (%rax,%r15,4), %xmm1
cvtss2sd -0x610(%rbp,%r15,4), %xmm2
movq 0x8(%rbx), %rax
movq 0x28(%rbx), %rcx
cvtss2sd (%rcx,%r15,4), %xmm3
movq (%rax,%r15,8), %rax
xorps %xmm4, %xmm4
testq %rax, %rax
je 0x9de1
cvtss2sd 0x3c(%rax), %xmm4
movq 0x18(%rbx), %rax
movl (%rax,%r15,4), %r8d
leaq 0x50756(%rip), %rsi     # 0x5a546
movl -0x34(%rbp), %r15d
movl %r15d, %edx
movl %r14d, %ecx
movb $0x5, %al
callq 0x3270
leaq -0x610(%rbp), %rdi
movl $0x16a, %esi            # imm = 0x16A
callq 0xfa87
movl %eax, %esi
movq %r12, %r13
movq (%r12), %rdi
cltd
pushq $0x13
popq %r12
idivl %r12d
movl %edx, %ecx
cvtss2sd 0x3c(%rbx), %xmm0
movq 0x10(%rbx), %r8
movslq %esi, %rdx
cvtss2sd (%r8,%rdx,4), %xmm1
cvtss2sd -0x610(%rbp,%rdx,4), %xmm2
movq 0x8(%rbx), %rsi
movq 0x28(%rbx), %r8
cvtss2sd (%r8,%rdx,4), %xmm3
movq (%rsi,%rdx,8), %rsi
testq %rsi, %rsi
xorps %xmm4, %xmm4
je 0x9e5f
cvtss2sd 0x3c(%rsi), %xmm4
movq 0x18(%rbx), %rsi
movl (%rsi,%rdx,4), %r8d
leaq 0x506d8(%rip), %rsi     # 0x5a546
movl %eax, %edx
movb $0x5, %al
callq 0x3270
movq 0x10(%rbx), %rdi
movl $0x16a, %esi            # imm = 0x16A
callq 0xfa87
movq (%r13), %rdi
movss 0x3c(%rbx), %xmm0
movq 0x8(%rbx), %rcx
movq 0x10(%rbx), %rdx
movslq %eax, %rsi
movss (%rdx,%rsi,4), %xmm1
movss -0x610(%rbp,%rsi,4), %xmm2
movq 0x28(%rbx), %rax
movss (%rax,%rsi,4), %xmm3
movq (%rcx,%rsi,8), %rax
xorps %xmm4, %xmm4
testq %rax, %rax
je 0x9ec1
cvtss2sd 0x3c(%rax), %xmm4
movl %esi, %eax
cltd
idivl %r12d
movl %edx, %ecx
cvtss2sd %xmm3, %xmm3
cvtss2sd %xmm2, %xmm2
cvtss2sd %xmm1, %xmm1
movaps -0x60(%rbp), %xmm5
unpcklps -0x50(%rbp), %xmm5      # xmm5 = xmm5[0],mem[0],xmm5[1],mem[1]
cvtps2pd %xmm5, %xmm5
addpd 0x50558(%rip), %xmm5    # 0x5a440
mulpd 0x4b3f0(%rip), %xmm5    # 0x552e0
cvtpd2ps %xmm5, %xmm5
movapd %xmm5, -0x50(%rbp)
cvtss2sd %xmm0, %xmm0
movl %r15d, %edx
shlq $0x20, %r14
orq %rdx, %r14
movq 0x18(%rbx), %rdx
movl (%rdx,%rsi,4), %r8d
leaq 0x50630(%rip), %rsi     # 0x5a546
movl %eax, %edx
movb $0x5, %al
callq 0x3270
movq -0x30(%rbp), %rsp
movaps -0x50(%rbp), %xmm0
movq %r14, %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq