// File: kobanium[P]Ray/src/mcts/UctSearch.cpp
// Function: CalculateCriticality(int)
static void
CalculateCriticality( int color )
{
  const int other = GetOppositeColor(color);
  const double inv_count = (statistic_count.load() > 0) ? 1.0 / statistic_count.load() : 1.0;
  const double win = static_cast<double>(uct_node[current_root].win) / uct_node[current_root].move_count;
  const double lose = 1.0 - win;
  double tmp;

  for (int i = 0; i < pure_board_max; i++) {
    const int pos = onboard_pos[i];

    tmp = statistic[pos].colors[static_cast<int>(StatisticInformation::Win)] * inv_count
      - ((statistic[pos].colors[color] * inv_count) * win
         + (statistic[pos].colors[other] * inv_count) * lose);

    criticality[pos] = tmp;
    if (tmp < 0) tmp = 0;
    criticality_index[pos] = static_cast<int>(tmp * CRITICALITY_TERM);
    if (criticality_index[pos] > criticality_max - 1) criticality_index[pos] = criticality_max - 1;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movl %edi, -0x30(%rbp)
movl -0x30(%rbp), %edi
callq 0x25810
movl %eax, -0x34(%rbp)
leaq 0x1aaee800(%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, -0x64(%rbp)
decl %eax
subl $0x2, %eax
jb 0x8bc27
jmp 0x8bc12
movl -0x64(%rbp), %eax
subl $0x5, %eax
je 0x8bc32
jmp 0x8bc1c
movq -0x70(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
jmp 0x8bc3b
movq -0x70(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
jmp 0x8bc3b
movq -0x70(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jle 0x8bcbe
leaq 0x1aaee798(%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 0x8bc8f
jmp 0x8bc7a
movl -0x74(%rbp), %eax
subl $0x5, %eax
je 0x8bc9a
jmp 0x8bc84
movq -0x80(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
jmp 0x8bca3
movq -0x80(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
jmp 0x8bca3
movq -0x80(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
cvtsi2sdl -0x2c(%rbp), %xmm1
movsd 0x20358(%rip), %xmm0    # 0xac008
divsd %xmm1, %xmm0
movsd %xmm0, -0x88(%rbp)
jmp 0x8bcd0
movsd 0x20342(%rip), %xmm0    # 0xac008
movsd %xmm0, -0x88(%rbp)
jmp 0x8bcd0
movsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movq 0x1aac0dcc(%rip), %rdi  # 0x1ab4cab0
movslq 0x1aac0dcd(%rip), %rax  # 0x1ab4cab8
imulq $0x4548, %rax, %rax     # imm = 0x4548
addq %rax, %rdi
addq $0xc, %rdi
callq 0x25780
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x90(%rbp)
movq 0x1aac0d9f(%rip), %rdi  # 0x1ab4cab0
movslq 0x1aac0da0(%rip), %rax  # 0x1ab4cab8
imulq $0x4548, %rax, %rax     # imm = 0x4548
addq %rax, %rdi
addq $0x8, %rdi
callq 0x25780
movsd -0x90(%rbp), %xmm0
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd 0x202c0(%rip), %xmm0    # 0xac008
subsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
leaq 0x5bcdd(%rip), %rcx     # 0xe7a40
cmpl (%rcx), %eax
jge 0x8bef4
movslq -0x5c(%rbp), %rcx
leaq 0x1ab46afa(%rip), %rax  # 0x1abd2870
movl (%rax,%rcx,4), %eax
movl %eax, -0x60(%rbp)
movslq -0x60(%rbp), %rax
leaq 0x1aaeb1c9(%rip), %rdi  # 0x1ab76f50
shlq $0x4, %rax
addq %rax, %rdi
addq $0xc, %rdi
callq 0x25780
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x98(%rbp)
movslq -0x60(%rbp), %rax
leaq 0x1aaeb195(%rip), %rdi  # 0x1ab76f50
shlq $0x4, %rax
addq %rax, %rdi
movslq -0x30(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rdi
callq 0x25780
cvtsi2sd %eax, %xmm0
mulsd -0x40(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movslq -0x60(%rbp), %rax
leaq 0x1aaeb155(%rip), %rdi  # 0x1ab76f50
shlq $0x4, %rax
addq %rax, %rdi
movslq -0x34(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rdi
callq 0x25780
movsd -0xb0(%rbp), %xmm1
movsd -0xa8(%rbp), %xmm4
movsd -0xa0(%rbp), %xmm0
movsd -0x98(%rbp), %xmm2
cvtsi2sd %eax, %xmm3
mulsd -0x40(%rbp), %xmm3
mulsd -0x50(%rbp), %xmm3
mulsd %xmm4, %xmm1
addsd %xmm3, %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
movslq -0x60(%rbp), %rcx
leaq 0x1aaef2a4(%rip), %rax  # 0x1ab7b120
movsd %xmm0, (%rax,%rcx,8)
xorps %xmm0, %xmm0
ucomisd -0x58(%rbp), %xmm0
jbe 0x8be93
xorps %xmm0, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd 0x2017d(%rip), %xmm0    # 0xac018
mulsd -0x58(%rbp), %xmm0
cvttsd2si %xmm0, %edx
movslq -0x60(%rbp), %rcx
leaq 0x1aaee541(%rip), %rax  # 0x1ab7a3f0
movl %edx, (%rax,%rcx,4)
movslq -0x60(%rbp), %rcx
leaq 0x1aaee533(%rip), %rax  # 0x1ab7a3f0
movl (%rax,%rcx,4), %eax
movl 0x5bb42(%rip), %ecx     # 0xe7a08
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x8bee4
movl 0x5bb35(%rip), %edx     # 0xe7a08
subl $0x1, %edx
movslq -0x60(%rbp), %rcx
leaq 0x1aaee50f(%rip), %rax  # 0x1ab7a3f0
movl %edx, (%rax,%rcx,4)
jmp 0x8bee6
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x8bd59
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax)