// File: /workspace/github_cpp_makefile_star2_O2/kobanium[P]Ray/src/mcts/Rating.cpp
// Function: UpdateAroundPreviousMove(game_info_t*, int, long long*, long long*, long long*, int*, bool*, int)
static void
UpdateAroundPreviousMove( game_info_t *game, int color, long long *sum_rate, long long *sum_rate_row, long long *rate, int *update, bool *flag, int index )
{
  double bias[4] = {1.0, 1.0, 1.0, 1.0};

  // 盤端での特殊処理
  if (index == 1) {
    const int pos = game->record[game->moves - 1].pos;
    if ((border_dis_x[pos] == 1 && border_dis_y[pos] == 2) ||
        (border_dis_x[pos] == 2 && border_dis_y[pos] == 1)) {
      for (int i = 0; i < 4; i++) {
        if ((border_dis_x[update[i]] == 1 && border_dis_y[update[i]] == 2) ||
            (border_dis_x[update[i]] == 2 && border_dis_y[update[i]] == 1)) {
          bias[i] = 1000.0;
          break;
        }
      }
    }
  }

  for (int i = 0; i < 4; i++) {
    const int pos = update[i];
    if (game->candidates[pos]){
      if (flag[pos] && bias[i] == 1.0) continue;
      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)]
          * po_previous_distance[index]
          * CalculateTacticalFeatures(&game->tactical_features[pos * ALL_MAX])
          * bias[i];
        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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, 0x18(%rsp)
movl 0xa8(%rsp), %eax
movaps 0x1691a(%rip), %xmm0    # 0x46fb0
movaps %xmm0, 0x50(%rsp)
movapd 0x168fd(%rip), %xmm0    # 0x46fa0
movapd %xmm0, 0x40(%rsp)
cmpl $0x1, %eax
jne 0x3073e
movslq 0x43b0(%rdi), %rdx
shlq $0x4, %rdx
movslq -0xc(%rdx,%rdi), %rdx
leaq 0x1ab1a017(%rip), %r10  # 0x1ab4a6e0
movl (%r10,%rdx,4), %r11d
cmpl $0x2, %r11d
je 0x306e9
cmpl $0x1, %r11d
jne 0x3073e
leaq 0x1ab1ad30(%rip), %r11  # 0x1ab4b410
cmpl $0x2, (%r11,%rdx,4)
je 0x306f7
jmp 0x3073e
leaq 0x1ab1ad20(%rip), %r11  # 0x1ab4b410
cmpl $0x1, (%r11,%rdx,4)
jne 0x3073e
xorl %edx, %edx
leaq 0x1ab1ad10(%rip), %rbx  # 0x1ab4b410
cmpq $0x4, %rdx
je 0x3073e
movslq (%r9,%rdx,4), %r14
movl (%r10,%r14,4), %r11d
cmpl $0x2, %r11d
je 0x30723
cmpl $0x1, %r11d
jne 0x3072a
cmpl $0x2, (%rbx,%r14,4)
jne 0x3072a
jmp 0x3072f
cmpl $0x1, (%rbx,%r14,4)
je 0x3072f
incq %rdx
jmp 0x30700
movabsq $0x408f400000000000, %r10 # imm = 0x408F400000000000
movq %r10, 0x40(%rsp,%rdx,8)
movq 0xa0(%rsp), %rdx
leaq 0x4748(%rdi), %r10
movq %r10, 0x30(%rsp)
movl %eax, %eax
movq %rax, 0x28(%rsp)
leaq 0x97372(%rdi), %rbp
xorl %r12d, %r12d
leaq 0x1aac9246(%rip), %r10  # 0x1aaf99b0
movq %r9, (%rsp)
movq %rcx, 0x10(%rsp)
movq %r8, 0x8(%rsp)
movq %rdi, 0x20(%rsp)
cmpq $0x4, %r12
je 0x308c3
movslq (%r9,%r12,4), %r15
cmpb $0x1, 0x96ce0(%rdi,%r15)
jne 0x308a7
cmpb $0x1, (%rdx,%r15)
jne 0x307b8
movsd 0x40(%rsp,%r12,8), %xmm0
ucomisd 0x13858(%rip), %xmm0    # 0x44008
jne 0x307b8
jnp 0x308bb
movl %r15d, %edx
movl %esi, %r14d
movq %rdi, %rbx
movq %r10, %r13
callq 0x3ec62
movq 0x8(%rsp), %r8
movq 0x10(%rsp), %rcx
movq (%r8,%r15,8), %rdx
movq 0x18(%rsp), %rdi
subq %rdx, (%rdi)
movq (%r8,%r15,8), %rsi
movslq (%r13,%r15,4), %rdx
subq %rsi, (%rcx,%rdx,8)
testb %al, %al
je 0x3088d
movq %rbx, %rdi
movl %r14d, %esi
movl %r15d, %edx
callq 0x3f18e
movq 0x30(%rsp), %rdi
movl %r15d, %esi
callq 0x37bd2
movl %eax, %eax
leaq 0x35508(%rip), %rcx     # 0x65d20
movss (%rcx,%rax,4), %xmm0
movq 0x28(%rsp), %rax
leaq 0x40354f7(%rip), %rcx   # 0x4065d20
mulss (%rcx,%rax,4), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
imulq $0x6, %r15, %rdi
addq %rbp, %rdi
callq 0x310ce
movq %r13, %r10
movq 0x8(%rsp), %r8
movq 0x10(%rsp), %rcx
mulsd 0x38(%rsp), %xmm0
mulsd 0x40(%rsp,%r12,8), %xmm0
cvttsd2si %xmm0, %rax
incq %rax
movq %rax, (%r8,%r15,8)
movq 0x18(%rsp), %rdx
addq %rax, (%rdx)
movq (%r8,%r15,8), %rax
movslq (%r13,%r15,4), %rdx
addq %rax, (%rcx,%rdx,8)
movq (%rsp), %r9
movl %r14d, %esi
movq 0x20(%rsp), %rdi
jmp 0x3089f
movq %r13, %r10
andq $0x0, (%r8,%r15,8)
movq (%rsp), %r9
movl %r14d, %esi
movq %rbx, %rdi
movq 0xa0(%rsp), %rdx
imulq $0x6, %r15, %rax
andw $0x0, 0x4(%rbp,%rax)
andl $0x0, (%rbp,%rax)
movb $0x1, (%rdx,%r15)
incq %r12
jmp 0x3077d
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq