// File: kobanium[P]Ray/src/mcts/UctSearch.cpp
// Function: CalculateOwnerIndex(uct_node_t*, statistic_t*, int, int*)
static void
CalculateOwnerIndex( uct_node_t *node, statistic_t *node_statistic, int color, int *index )
{
  const double inv_count = (statistic_count.load() > 0) ? 1.0 / statistic_count.load() : 1.0;
  const int child_num = node->child_num;

  index[0] = 0;

  for (int i = 1; i < child_num; i++){
    const int pos = node->child[i].pos;
    index[i] = static_cast<int>(static_cast<double>(node_statistic[pos].colors[color]) * 10.0 * inv_count + 0.5);
    if (index[i] > OWNER_MAX - 1) index[i] = OWNER_MAX - 1;
    if (index[i] < 0)             index[i] = 0;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x38(%rbp)
movq %rsi, -0x40(%rbp)
movl %edx, -0x44(%rbp)
movq %rcx, -0x50(%rbp)
leaq 0x1aaed78f(%rip), %rax  # 0x1ab7a3e0
movq %rax, -0x8(%rbp)
movl $0x5, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x70(%rbp)
movl -0xc(%rbp), %edi
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x25b00
movl %eax, -0x10(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x68(%rbp)
decl %eax
subl $0x2, %eax
jb 0x8cc98
jmp 0x8cc83
movl -0x68(%rbp), %eax
subl $0x5, %eax
je 0x8cca3
jmp 0x8cc8d
movq -0x70(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
jmp 0x8ccac
movq -0x70(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
jmp 0x8ccac
movq -0x70(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jle 0x8cd2f
leaq 0x1aaed727(%rip), %rax  # 0x1ab7a3e0
movq %rax, -0x20(%rbp)
movl $0x5, -0x24(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x80(%rbp)
movl -0x24(%rbp), %edi
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x25b00
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x74(%rbp)
decl %eax
subl $0x2, %eax
jb 0x8cd00
jmp 0x8cceb
movl -0x74(%rbp), %eax
subl $0x5, %eax
je 0x8cd0b
jmp 0x8ccf5
movq -0x80(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
jmp 0x8cd14
movq -0x80(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
jmp 0x8cd14
movq -0x80(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
cvtsi2sdl -0x2c(%rbp), %xmm1
movsd 0x1f2e7(%rip), %xmm0    # 0xac008
divsd %xmm1, %xmm0
movsd %xmm0, -0x88(%rbp)
jmp 0x8cd41
movsd 0x1f2d1(%rip), %xmm0    # 0xac008
movsd %xmm0, -0x88(%rbp)
jmp 0x8cd41
movsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movq -0x38(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x5c(%rbp)
movq -0x50(%rbp), %rax
movl $0x0, (%rax)
movl $0x1, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x5c(%rbp), %eax
jge 0x8ce2b
movq -0x38(%rbp), %rax
addq $0x1c, %rax
movslq -0x60(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movswl (%rax), %eax
movl %eax, -0x64(%rbp)
movq -0x40(%rbp), %rdi
movslq -0x64(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rdi
movslq -0x44(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rdi
callq 0x25780
cvtsi2sd %eax, %xmm0
movsd 0x22307(%rip), %xmm1    # 0xaf0c0
mulsd %xmm1, %xmm0
movsd -0x58(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x1f242(%rip), %xmm1    # 0xac010
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
movq -0x50(%rbp), %rax
movslq -0x60(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x50(%rbp), %rax
movslq -0x60(%rbp), %rcx
cmpl $0xa, (%rax,%rcx,4)
jle 0x8cdfe
movq -0x50(%rbp), %rax
movslq -0x60(%rbp), %rcx
movl $0xa, (%rax,%rcx,4)
movq -0x50(%rbp), %rax
movslq -0x60(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jge 0x8ce1b
movq -0x50(%rbp), %rax
movslq -0x60(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
jmp 0x8ce1d
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x8cd69
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)