// File: /workspace/github_c_makefile_star2_O0/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
subq $0x6a0, %rsp            # imm = 0x6A0
movq %rdi, -0x18(%rbp)
movss %xmm0, -0x1c(%rbp)
movl %esi, -0x20(%rbp)
leaq -0x5d0(%rbp), %rdi
xorl %esi, %esi
movl $0x5a8, %edx            # imm = 0x5A8
callq 0x3190
leaq -0x10(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x3190
xorps %xmm0, %xmm0
movsd %xmm0, -0x5d8(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x16a, -0x24(%rbp)     # imm = 0x16A
jge 0x5aacb
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x24(%rbp), %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm0
movss -0x1c(%rbp), %xmm1
cvtss2sd %xmm1, %xmm2
movsd 0x165b9(%rip), %xmm1    # 0x71060
divsd %xmm2, %xmm1
callq 0x30e0
addsd -0x5d8(%rbp), %xmm0
movsd %xmm0, -0x5d8(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x5aa7c
movl $0x0, -0x24(%rbp)
cmpl $0x16a, -0x24(%rbp)     # imm = 0x16A
jge 0x5ab2a
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x24(%rbp), %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm0
movss -0x1c(%rbp), %xmm1
cvtss2sd %xmm1, %xmm2
movsd 0x16563(%rip), %xmm1    # 0x71060
divsd %xmm2, %xmm1
callq 0x30e0
divsd -0x5d8(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movslq -0x24(%rbp), %rax
movss %xmm0, -0x5d0(%rbp,%rax,4)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x5aad2
leaq -0x5d0(%rbp), %rdi
movl $0x16a, %esi            # imm = 0x16A
callq 0x5a80
movl %eax, -0x5dc(%rbp)
movslq -0x5dc(%rbp), %rax
imulq $0x6bca1af3, %rax, %rax # imm = 0x6BCA1AF3
movq %rax, %rcx
shrq $0x3f, %rcx
sarq $0x23, %rax
addl %ecx, %eax
movl %eax, -0x8(%rbp)
movslq -0x5dc(%rbp), %rcx
movl %ecx, %eax
imulq $0x6bca1af3, %rcx, %rdx # imm = 0x6BCA1AF3
movq %rdx, %rcx
shrq $0x3f, %rcx
sarq $0x23, %rdx
addl %ecx, %edx
movl %edx, %ecx
leal (%rcx,%rcx,8), %esi
movl %esi, %edx
leal (%rcx,%rdx,2), %ecx
subl %ecx, %eax
movl %eax, -0x4(%rbp)
movq -0x18(%rbp), %rax
movss 0x3c(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x164c0(%rip), %xmm2    # 0x71060
addsd %xmm2, %xmm0
movsd 0x1829c(%rip), %xmm1    # 0x72e48
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x10(%rbp)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x5dc(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm2, %xmm0
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0xc(%rbp)
movq %rsp, %rax
movq %rax, -0x5e8(%rbp)
movq %rsp, %rcx
addq $-0x30, %rcx
movq %rcx, -0x628(%rbp)
movq %rcx, %rsp
leaq -0x5d0(%rbp), %rdi
movl $0x16a, %esi            # imm = 0x16A
movl $0xa, %edx
callq 0x4b70
movq -0x628(%rbp), %rcx
movq 0x283d7(%rip), %rax     # 0x82ff8
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
movl -0x20(%rbp), %edx
callq 0x59360
movq 0x283be(%rip), %rax     # 0x82ff8
movq (%rax), %rax
movq %rax, -0x620(%rbp)
movl -0x5dc(%rbp), %eax
movl $0x13, %ecx
cltd
idivl %ecx
movl %eax, -0x618(%rbp)
movl -0x5dc(%rbp), %eax
movl $0x13, %ecx
cltd
idivl %ecx
movl %edx, -0x614(%rbp)
movq -0x18(%rbp), %rax
movss 0x3c(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x610(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x5dc(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x608(%rbp)
movslq -0x5dc(%rbp), %rax
movss -0x5d0(%rbp,%rax,4), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x600(%rbp)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x5dc(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x5f8(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x5dc(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x5ad15
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x5dc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movss 0x3c(%rax), %xmm0
movss %xmm0, -0x62c(%rbp)
jmp 0x5ad22
xorps %xmm0, %xmm0
movss %xmm0, -0x62c(%rbp)
jmp 0x5ad22
movsd -0x5f8(%rbp), %xmm3
movsd -0x600(%rbp), %xmm2
movsd -0x608(%rbp), %xmm1
movsd -0x610(%rbp), %xmm0
movl -0x614(%rbp), %ecx
movl -0x618(%rbp), %edx
movq -0x620(%rbp), %rdi
movss -0x62c(%rbp), %xmm4
cvtss2sd %xmm4, %xmm4
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x5dc(%rbp), %rsi
movl (%rax,%rsi,4), %r8d
leaq 0x1af18(%rip), %rsi     # 0x75c93
movb $0x5, %al
callq 0x3240
leaq -0x5d0(%rbp), %rdi
movl $0x16a, %esi            # imm = 0x16A
callq 0x5c30
movl %eax, -0x5ec(%rbp)
movq 0x28258(%rip), %rax     # 0x82ff8
movq (%rax), %rax
movq %rax, -0x660(%rbp)
movl -0x5ec(%rbp), %eax
movl $0x13, %ecx
cltd
idivl %ecx
movl %eax, -0x658(%rbp)
movl -0x5ec(%rbp), %eax
movl $0x13, %ecx
cltd
idivl %ecx
movl %edx, -0x654(%rbp)
movq -0x18(%rbp), %rax
movss 0x3c(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x650(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x5ec(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x648(%rbp)
movslq -0x5ec(%rbp), %rax
movss -0x5d0(%rbp,%rax,4), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x640(%rbp)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x5ec(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x638(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x5ec(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x5ae7b
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x5ec(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movss 0x3c(%rax), %xmm0
movss %xmm0, -0x664(%rbp)
jmp 0x5ae88
xorps %xmm0, %xmm0
movss %xmm0, -0x664(%rbp)
jmp 0x5ae88
movsd -0x638(%rbp), %xmm3
movsd -0x640(%rbp), %xmm2
movsd -0x648(%rbp), %xmm1
movsd -0x650(%rbp), %xmm0
movl -0x654(%rbp), %ecx
movl -0x658(%rbp), %edx
movq -0x660(%rbp), %rdi
movss -0x664(%rbp), %xmm4
cvtss2sd %xmm4, %xmm4
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x5ec(%rbp), %rsi
movl (%rax,%rsi,4), %r8d
leaq 0x1adb2(%rip), %rsi     # 0x75c93
movb $0x5, %al
callq 0x3240
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movl $0x16a, %esi            # imm = 0x16A
callq 0x5c30
movl %eax, -0x5ec(%rbp)
movq 0x280f1(%rip), %rax     # 0x82ff8
movq (%rax), %rax
movq %rax, -0x698(%rbp)
movl -0x5ec(%rbp), %eax
movl $0x13, %ecx
cltd
idivl %ecx
movl %eax, -0x690(%rbp)
movl -0x5ec(%rbp), %eax
movl $0x13, %ecx
cltd
idivl %ecx
movl %edx, -0x68c(%rbp)
movq -0x18(%rbp), %rax
movss 0x3c(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x688(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x5ec(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x680(%rbp)
movslq -0x5ec(%rbp), %rax
movss -0x5d0(%rbp,%rax,4), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x678(%rbp)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x5ec(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x670(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x5ec(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x5afe2
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x5ec(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movss 0x3c(%rax), %xmm0
movss %xmm0, -0x69c(%rbp)
jmp 0x5afef
xorps %xmm0, %xmm0
movss %xmm0, -0x69c(%rbp)
jmp 0x5afef
movsd -0x670(%rbp), %xmm3
movsd -0x678(%rbp), %xmm2
movsd -0x680(%rbp), %xmm1
movsd -0x688(%rbp), %xmm0
movl -0x68c(%rbp), %ecx
movl -0x690(%rbp), %edx
movq -0x698(%rbp), %rdi
movss -0x69c(%rbp), %xmm4
cvtss2sd %xmm4, %xmm4
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x5ec(%rbp), %rsi
movl (%rax,%rsi,4), %r8d
leaq 0x1ac4b(%rip), %rsi     # 0x75c93
movb $0x5, %al
callq 0x3240
movq -0x5e8(%rbp), %rax
movq %rax, %rsp
movsd -0x10(%rbp), %xmm0
movq -0x8(%rbp), %rax
movq %rbp, %rsp
popq %rbp
retq
nopw (%rax,%rax)