// File: /workspace/github_c_makefile_star2_O1/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 $0x5d8, %rsp            # imm = 0x5D8
movl %esi, -0x38(%rbp)
movss %xmm0, -0x30(%rbp)
movq %rdi, %rbx
leaq -0x600(%rbp), %rdi
xorl %r14d, %r14d
movl $0x5a8, %edx            # imm = 0x5A8
xorl %esi, %esi
callq 0x31d0
cvtss2sd -0x30(%rbp), %xmm0
movsd 0x49a4b(%rip), %xmm1    # 0x53128
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 0x3120
movsd -0x30(%rbp), %xmm2
addsd %xmm0, %xmm2
incq %r14
cmpq $0x16a, %r14            # imm = 0x16A
jne 0x96ea
xorl %r14d, %r14d
movsd %xmm2, -0x30(%rbp)
movq 0x18(%rbx), %rax
cvtsi2sdl (%rax,%r14,4), %xmm0
movsd -0x50(%rbp), %xmm1
callq 0x3120
movsd -0x30(%rbp), %xmm2
divsd %xmm2, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x600(%rbp,%r14,4)
incq %r14
cmpq $0x16a, %r14            # imm = 0x16A
jne 0x971b
leaq -0x600(%rbp), %r13
movq %r13, %rdi
movl $0x16a, %esi            # imm = 0x16A
callq 0xf171
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
movss %xmm0, -0x50(%rbp)
movss 0x3c(%rbx), %xmm0
movss %xmm0, -0x3c(%rbp)
leaq -0x30(%rsp), %r12
movq %r12, %rsp
pushq $0xa
popq %rdx
movq %r13, %rdi
movl $0x16a, %esi            # imm = 0x16A
movq %r12, %rcx
callq 0xe8e2
movq 0x6083d(%rip), %r13     # 0x69ff8
movq (%r13), %rdi
movq (%rbx), %rsi
movl -0x38(%rbp), %edx
movq %r12, %rcx
callq 0x43a5d
movq %r13, %r12
movq (%r13), %rdi
cvtss2sd 0x3c(%rbx), %xmm0
movq 0x10(%rbx), %rax
cvtss2sd (%rax,%r15,4), %xmm1
cvtss2sd -0x600(%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 0x980c
cvtss2sd 0x3c(%rax), %xmm4
movq 0x18(%rbx), %rax
movl (%rax,%r15,4), %r8d
leaq 0x4ebd3(%rip), %rsi     # 0x583ee
movl -0x34(%rbp), %r15d
movl %r15d, %edx
movl %r14d, %ecx
movb $0x5, %al
callq 0x3280
leaq -0x600(%rbp), %rdi
movl $0x16a, %esi            # imm = 0x16A
callq 0xf278
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 -0x600(%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 0x988a
cvtss2sd 0x3c(%rsi), %xmm4
movq 0x18(%rbx), %rsi
movl (%rsi,%rdx,4), %r8d
leaq 0x4eb55(%rip), %rsi     # 0x583ee
movl %eax, %edx
movb $0x5, %al
callq 0x3280
movq 0x10(%rbx), %rdi
movl $0x16a, %esi            # imm = 0x16A
callq 0xf278
movq (%r13), %rdi
movss 0x3c(%rbx), %xmm0
movq 0x8(%rbx), %rcx
movq 0x10(%rbx), %rdx
movslq %eax, %rsi
movss (%rdx,%rsi,4), %xmm1
movss -0x600(%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 0x98ec
cvtss2sd 0x3c(%rax), %xmm4
movl %esi, %eax
cltd
idivl %r12d
movl %edx, %ecx
cvtss2sd %xmm3, %xmm3
cvtss2sd %xmm2, %xmm2
cvtss2sd %xmm1, %xmm1
cvtss2sd %xmm0, %xmm0
cvtss2sd -0x3c(%rbp), %xmm5
movsd 0x49817(%rip), %xmm7    # 0x53128
addsd %xmm7, %xmm5
movsd 0x49803(%rip), %xmm6    # 0x53120
mulsd %xmm6, %xmm5
cvtsd2ss %xmm5, %xmm8
cvtss2sd -0x50(%rbp), %xmm5
addsd %xmm7, %xmm5
mulsd %xmm6, %xmm5
cvtsd2ss %xmm5, %xmm5
unpcklps %xmm5, %xmm8            # xmm8 = xmm8[0],xmm5[0],xmm8[1],xmm5[1]
movaps %xmm8, -0x50(%rbp)
movl %r15d, %edx
shlq $0x20, %r14
orq %rdx, %r14
movq 0x18(%rbx), %rdx
movl (%rdx,%rsi,4), %r8d
leaq 0x4ea95(%rip), %rsi     # 0x583ee
movl %eax, %edx
movb $0x5, %al
callq 0x3280
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