// File: kobanium[P]Ray/src/mcts/Rating.cpp
// Function: CaptureUpdateColor(game_info_t*, int, long long*, long long*, long long*, int*, bool*)
static void
CaptureUpdateColor( game_info_t *game, const int color, long long *sum_rate, long long sum_rate_row[], long long rate[], int update[], bool flag[] )
{
  int update_pos = update[0];

  while (update_pos < CAPTURE_END) {
    for (int i = 0; i < UPDATE_NUM; i++) {
      const int pos = update_pos + neighbor[i];
      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;
    }
    const int next_pos = update[update_pos];
    update[update_pos] = 0;
    update_pos = next_pos;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x30(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x34(%rbp)
cmpl $0x2b7, -0x34(%rbp)     # imm = 0x2B7
jge 0x846ce
movl $0x0, -0x38(%rbp)
cmpl $0xd, -0x38(%rbp)
jge 0x846a6
movl -0x34(%rbp), %eax
movslq -0x38(%rbp), %rdx
leaq 0x67948(%rip), %rcx     # 0xebe60
addl (%rcx,%rdx,4), %eax
movl %eax, -0x3c(%rbp)
movq 0x10(%rbp), %rax
movslq -0x3c(%rbp), %rcx
testb $0x1, (%rax,%rcx)
je 0x84531
jmp 0x84698
movq -0x8(%rbp), %rax
movslq -0x3c(%rbp), %rcx
testb $0x1, 0x96ce0(%rax,%rcx)
je 0x84673
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x3c(%rbp), %edx
callq 0xa2830
andb $0x1, %al
movb %al, -0x3d(%rbp)
movq -0x28(%rbp), %rax
movslq -0x3c(%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 -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x20(%rbp), %rax
movslq -0x3c(%rbp), %rdx
leaq 0x1aafb5a1(%rip), %rcx  # 0x1ab7fb30
movslq (%rcx,%rdx,4), %rcx
movq (%rax,%rcx,8), %rdx
subq %rsi, %rdx
movq %rdx, (%rax,%rcx,8)
testb $0x1, -0x3d(%rbp)
jne 0x845b9
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
jmp 0x84671
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x3c(%rbp), %edx
callq 0xa3180
movq -0x8(%rbp), %rdi
addq $0x4748, %rdi           # imm = 0x4748
movl -0x3c(%rbp), %esi
callq 0x93d60
movl %eax, %eax
movl %eax, %ecx
leaq 0x678ba(%rip), %rax     # 0xebea0
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x58(%rbp)
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
imull $0x6, -0x3c(%rbp), %eax
cltq
addq %rax, %rdi
callq 0x85150
movaps %xmm0, %xmm1
movsd -0x58(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
cvttsd2si -0x48(%rbp), %rdx
addq $0x1, %rdx
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x18(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x20(%rbp), %rax
movslq -0x3c(%rbp), %rsi
leaq 0x1aafb4cb(%rip), %rcx  # 0x1ab7fb30
movslq (%rcx,%rsi,4), %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
jmp 0x84673
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
imull $0x6, -0x3c(%rbp), %eax
cltq
addq %rax, %rdi
callq 0x79350
movq 0x10(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movb $0x1, (%rax,%rcx)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x84500
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x4c(%rbp)
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x4c(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x844ec
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)