// File: kobanium[P]Ray/src/mcts/Rating.cpp
// Function: UpdateNeighborCoordinates(game_info_t*, int, long long*, long long*, long long*, int, int*, bool*)
static void
UpdateNeighborCoordinates( game_info_t *game, int color, long long *sum_rate, long long sum_rate_row[], long long rate[], int update_num, int update[], bool flag[] )
{
  for (int i = 0; i < update_num; i++) {
    for (int j = 0; j < UPDATE_NUM; j++) {
      const int pos = update[i] + neighbor[j];
      if (flag[pos]) continue;

      if (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 double gamma = po_pattern[MD2(game->pat, pos)]
            * 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
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x842cf
movl $0x0, -0x34(%rbp)
cmpl $0xd, -0x34(%rbp)
jge 0x842bf
movq 0x10(%rbp), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movslq -0x34(%rbp), %rdx
leaq 0x67d2f(%rip), %rcx     # 0xebe60
addl (%rcx,%rdx,4), %eax
movl %eax, -0x38(%rbp)
movq 0x18(%rbp), %rax
movslq -0x38(%rbp), %rcx
testb $0x1, (%rax,%rcx)
je 0x8414a
jmp 0x842b1
movq -0x8(%rbp), %rax
movslq -0x38(%rbp), %rcx
testb $0x1, 0x96ce0(%rax,%rcx)
je 0x8428c
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x38(%rbp), %edx
callq 0xa2830
andb $0x1, %al
movb %al, -0x39(%rbp)
movq -0x28(%rbp), %rax
movslq -0x38(%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 -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x20(%rbp), %rax
movslq -0x38(%rbp), %rdx
leaq 0x1aafb988(%rip), %rcx  # 0x1ab7fb30
movslq (%rcx,%rdx,4), %rcx
movq (%rax,%rcx,8), %rdx
subq %rsi, %rdx
movq %rdx, (%rax,%rcx,8)
testb $0x1, -0x39(%rbp)
jne 0x841d2
movq -0x28(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
jmp 0x8428a
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x38(%rbp), %edx
callq 0xa3180
movq -0x8(%rbp), %rdi
addq $0x4748, %rdi           # imm = 0x4748
movl -0x38(%rbp), %esi
callq 0x93d60
movl %eax, %eax
movl %eax, %ecx
leaq 0x67ca1(%rip), %rax     # 0xebea0
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x50(%rbp)
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
imull $0x6, -0x38(%rbp), %eax
cltq
addq %rax, %rdi
callq 0x85150
movaps %xmm0, %xmm1
movsd -0x50(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
cvttsd2si -0x48(%rbp), %rdx
addq $0x1, %rdx
movq -0x28(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x28(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x18(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x20(%rbp), %rax
movslq -0x38(%rbp), %rsi
leaq 0x1aafb8b2(%rip), %rcx  # 0x1ab7fb30
movslq (%rcx,%rsi,4), %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
jmp 0x8428c
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
imull $0x6, -0x38(%rbp), %eax
cltq
addq %rax, %rdi
callq 0x79350
movq 0x18(%rbp), %rax
movslq -0x38(%rbp), %rcx
movb $0x1, (%rax,%rcx)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x84111
jmp 0x842c1
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x840fe
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)