// File: /workspace/github_c_makefile_star2_O2/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 0x1105d(%rip), %xmm1    # 0x4c128
divsd %xmm0, %xmm1
movsd %xmm1, -0x50(%rbp)
xorpd %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
cmpq $0x16a, %r14            # imm = 0x16A
je 0x3b10d
movq 0x18(%rbx), %rax
cvtsi2sdl (%rax,%r14,4), %xmm0
movsd -0x50(%rbp), %xmm1
callq 0x3110
movsd -0x30(%rbp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
incq %r14
jmp 0x3b0dd
xorl %r14d, %r14d
cmpq $0x16a, %r14            # imm = 0x16A
je 0x3b145
movq 0x18(%rbx), %rax
cvtsi2sdl (%rax,%r14,4), %xmm0
movsd -0x50(%rbp), %xmm1
callq 0x3110
divsd -0x30(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x610(%rbp,%r14,4)
incq %r14
jmp 0x3b110
leaq -0x610(%rbp), %r13
movq %r13, %rdi
movl $0x16a, %esi            # imm = 0x16A
callq 0x4b9e
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 0x438a
movq 0x28e51(%rip), %r13     # 0x63ff8
movq (%r13), %rdi
movq (%rbx), %rsi
movl -0x38(%rbp), %edx
movq %r12, %rcx
callq 0x3a0b6
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 0x3b1f8
cvtss2sd 0x3c(%rax), %xmm4
movq 0x18(%rbx), %rax
movl (%rax,%r15,4), %r8d
leaq 0x161f7(%rip), %rsi     # 0x513fe
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 0x4c73
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 0x3b276
cvtss2sd 0x3c(%rsi), %xmm4
movq 0x18(%rbx), %rsi
movl (%rsi,%rdx,4), %r8d
leaq 0x16179(%rip), %rsi     # 0x513fe
movl %eax, %edx
movb $0x5, %al
callq 0x3270
movq 0x10(%rbx), %rdi
movl $0x16a, %esi            # imm = 0x16A
callq 0x4c73
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 0x3b2d8
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 0x16041(%rip), %xmm5    # 0x51340
mulpd 0x10f99(%rip), %xmm5    # 0x4c2a0
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 0x160d1(%rip), %rsi     # 0x513fe
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