// File: kobanium[P]Ray/src/mcts/Rating.cpp
// Function: UpdateCriticalPoint(game_info_t*, int, long long*, long long*, long long*, int*, int, bool*, int)
static void
UpdateCriticalPoint( game_info_t *game, int color, long long *sum_rate, long long sum_rate_row[], long long rate[], int update_pos[], int update_num, bool *flag, int pm1 )
{
  double gamma;

  for (int i = 0; i < update_num; i++) {
    const int pos = update_pos[i];
    if (pos != NOT_NAKADE && game->candidates[pos]){
      const bool self_atari_flag = CheckSelfAtariForSimulation(game, color, pos);

      // 元あったレートを消去
      *sum_rate -= rate[pos];
      sum_rate_row[board_y[pos]] -= rate[pos];

      if (!self_atari_flag) {
        rate[pos] = 0;
      } else {
        CheckCaptureAndAtariForSimulation(game, color, pos);
        const int dis = DIS(pm1, pos);
        if (dis < 5) {
          gamma = 10000.0 * po_previous_distance[dis - 2];
        } else {
          gamma = 10000.0;
        }
        gamma *= po_pattern[MD2(game->pat, pos)];
        gamma *= CalculateTacticalFeatures(&game->tactical_features[pos * ALL_MAX]);
        rate[pos] = static_cast<long long>(gamma) + 1;

        // 新たに計算したレートを代入      
        *sum_rate += rate[pos];
        sum_rate_row[board_y[pos]] += rate[pos];     
      }
      ClearTacticalFeatures(&game->tactical_features[pos * ALL_MAX]);
      flag[pos] = true;
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movl 0x20(%rbp), %eax
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl 0x10(%rbp), %eax
jge 0x83d76
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x40(%rbp)
cmpl $-0x1, -0x40(%rbp)
je 0x83d66
movq -0x8(%rbp), %rax
movslq -0x40(%rbp), %rcx
testb $0x1, 0x96ce0(%rax,%rcx)
je 0x83d66
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x40(%rbp), %edx
callq 0xa2830
andb $0x1, %al
movb %al, -0x41(%rbp)
movq -0x28(%rbp), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x18(%rbp), %rax
movq (%rax), %rcx
subq %rdx, %rcx
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x20(%rbp), %rax
movslq -0x40(%rbp), %rdx
leaq 0x1aafbf6e(%rip), %rcx  # 0x1ab7fb30
movslq (%rcx,%rdx,4), %rcx
movq (%rax,%rcx,8), %rdx
subq %rsi, %rdx
movq %rdx, (%rax,%rcx,8)
testb $0x1, -0x41(%rbp)
jne 0x83bec
movq -0x28(%rbp), %rax
movslq -0x40(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
jmp 0x83d41
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x40(%rbp), %edx
callq 0xa3180
movslq 0x20(%rbp), %rcx
leaq 0x1aafb1fa(%rip), %rax  # 0x1ab7ee00
movl (%rax,%rcx,4), %eax
movslq -0x40(%rbp), %rdx
leaq 0x1aafb1ec(%rip), %rcx  # 0x1ab7ee00
subl (%rcx,%rdx,4), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movslq %eax, %rcx
leaq 0x1ab4e698(%rip), %rax  # 0x1abd22c0
imulq $0x4c, %rcx, %rcx
addq %rcx, %rax
movslq 0x20(%rbp), %rdx
leaq 0x1aafbef6(%rip), %rcx  # 0x1ab7fb30
movl (%rcx,%rdx,4), %ecx
movslq -0x40(%rbp), %rsi
leaq 0x1aafbee8(%rip), %rdx  # 0x1ab7fb30
subl (%rdx,%rsi,4), %ecx
movl %ecx, %edx
negl %edx
cmovnsl %edx, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x48(%rbp)
cmpl $0x5, -0x48(%rbp)
jge 0x83c8d
movl -0x48(%rbp), %eax
subl $0x2, %eax
movslq %eax, %rcx
leaq 0x406822f(%rip), %rax   # 0x40ebea0
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x2839e(%rip), %xmm0    # 0xac020
mulsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0x83c9a
movsd 0x2838b(%rip), %xmm0    # 0xac020
movsd %xmm0, -0x38(%rbp)
movq -0x8(%rbp), %rdi
addq $0x4748, %rdi           # imm = 0x4748
movl -0x40(%rbp), %esi
callq 0x93d60
movl %eax, %eax
movl %eax, %ecx
leaq 0x681e8(%rip), %rax     # 0xebea0
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
mulsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
imull $0x6, -0x40(%rbp), %eax
cltq
addq %rax, %rdi
callq 0x85150
mulsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
cvttsd2si -0x38(%rbp), %rdx
addq $0x1, %rdx
movq -0x28(%rbp), %rax
movslq -0x40(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x28(%rbp), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x18(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x20(%rbp), %rax
movslq -0x40(%rbp), %rsi
leaq 0x1aafbdfb(%rip), %rcx  # 0x1ab7fb30
movslq (%rcx,%rsi,4), %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
imull $0x6, -0x40(%rbp), %eax
cltq
addq %rax, %rdi
callq 0x79350
movq 0x18(%rbp), %rax
movslq -0x40(%rbp), %rcx
movb $0x1, (%rax,%rcx)
jmp 0x83d68
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x83b40
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)