// File: /workspace/github_cpp_makefile_star2_O3/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 %r8, 0x38(%rsp)
movq %rcx, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
movl %esi, %ebp
movq %rdi, %r13
movl 0xa8(%rsp), %eax
movaps 0x18858(%rip), %xmm0    # 0x60000
movaps %xmm0, 0x50(%rsp)
movapd 0x1883b(%rip), %xmm0    # 0x5fff0
movapd %xmm0, 0x40(%rsp)
cmpl $0x1, %eax
jne 0x4784b
movslq 0x43b0(%r13), %rcx
shlq $0x4, %rcx
movslq -0xc(%rcx,%r13), %rdx
leaq 0x1ab17f05(%rip), %rcx  # 0x1ab5f6e0
movl (%rcx,%rdx,4), %edi
cmpl $0x2, %edi
je 0x477f7
cmpl $0x1, %edi
jne 0x4784b
leaq 0x1ab18c21(%rip), %rdi  # 0x1ab60410
cmpl $0x2, (%rdi,%rdx,4)
je 0x47804
jmp 0x4784b
leaq 0x1ab18c12(%rip), %rdi  # 0x1ab60410
cmpl $0x1, (%rdi,%rdx,4)
jne 0x4784b
xorl %edx, %edx
leaq 0x1ab18c03(%rip), %r10  # 0x1ab60410
movslq (%r9,%rdx,4), %rdi
movl (%rcx,%rdi,4), %r8d
cmpl $0x2, %r8d
je 0x4782a
cmpl $0x1, %r8d
jne 0x47831
cmpl $0x2, (%r10,%rdi,4)
jne 0x47831
jmp 0x4783c
cmpl $0x1, (%r10,%rdi,4)
je 0x4783c
incq %rdx
cmpq $0x4, %rdx
jne 0x4780d
jmp 0x4784b
movabsq $0x408f400000000000, %rcx # imm = 0x408F400000000000
movq %rcx, 0x40(%rsp,%rdx,8)
movq 0xa0(%rsp), %rcx
leaq 0x4748(%r13), %rdx
movq %rdx, 0x30(%rsp)
movl %eax, %eax
movq %rax, 0x28(%rsp)
leaq 0x97372(%r13), %rdx
xorl %r12d, %r12d
leaq 0x1aac7139(%rip), %r8   # 0x1ab0e9b0
movq %r9, 0x10(%rsp)
movq %rdx, 0x8(%rsp)
movq 0x38(%rsp), %r14
movslq (%r9,%r12,4), %r15
cmpb $0x1, 0x96ce0(%r13,%r15)
jne 0x47a01
cmpb $0x1, (%rcx,%r15)
jne 0x478b7
movsd 0x40(%rsp,%r12,8), %xmm0
ucomisd 0x15759(%rip), %xmm0    # 0x5d008
jne 0x478b7
jnp 0x47a18
movq %r13, %rdi
movl %ebp, %esi
movl %r15d, %edx
movq %r8, %rbx
callq 0x5871b
movq (%r14,%r15,8), %rcx
movq 0x18(%rsp), %rdi
subq %rcx, (%rdi)
movq (%r14,%r15,8), %rcx
movslq (%rbx,%r15,4), %rdx
movq 0x20(%rsp), %rsi
subq %rcx, (%rsi,%rdx,8)
testb %al, %al
je 0x479e4
movq %r13, %rdi
movl %ebp, %esi
movl %r15d, %edx
callq 0x58c25
movq 0x30(%rsp), %rdi
movl %r15d, %esi
callq 0x4fc36
movq %rbx, %r8
movl %eax, %eax
leaq 0x3340e(%rip), %rcx     # 0x7ad20
movss (%rcx,%rax,4), %xmm0
movq 0x28(%rsp), %rax
leaq 0x40333fd(%rip), %rcx   # 0x407ad20
mulss (%rcx,%rax,4), %xmm0
leaq (%r15,%r15,2), %rax
movzbl 0x97372(%r13,%rax,2), %ecx
leaq 0x4033404(%rip), %rdx   # 0x407ad40
movss (%rdx,%rcx,4), %xmm1
movzbl 0x97373(%r13,%rax,2), %ecx
leaq 0x403343f(%rip), %rdx   # 0x407ad90
mulss (%rdx,%rcx,4), %xmm1
movzbl 0x97374(%r13,%rax,2), %ecx
leaq 0x403344a(%rip), %rdx   # 0x407adb0
mulss (%rdx,%rcx,4), %xmm1
movzbl 0x97375(%r13,%rax,2), %ecx
leaq 0x4033465(%rip), %rdx   # 0x407ade0
mulss (%rdx,%rcx,4), %xmm1
movzbl 0x97376(%r13,%rax,2), %ecx
leaq 0x4033464(%rip), %rdx   # 0x407adf4
mulss (%rdx,%rcx,4), %xmm1
cvtss2sd %xmm0, %xmm0
movzbl 0x97377(%r13,%rax,2), %eax
leaq 0x4033457(%rip), %rcx   # 0x407ae00
mulss (%rcx,%rax,4), %xmm1
cvtss2sd %xmm1, %xmm1
mulsd %xmm0, %xmm1
mulsd 0x40(%rsp,%r12,8), %xmm1
cvttsd2si %xmm1, %rax
incq %rax
movq %rax, (%r14,%r15,8)
movq 0x18(%rsp), %rcx
addq %rax, (%rcx)
movq (%r14,%r15,8), %rax
movslq (%rbx,%r15,4), %rcx
movq 0x20(%rsp), %rdx
addq %rax, (%rdx,%rcx,8)
jmp 0x479ef
movq %rbx, %r8
movq $0x0, (%r14,%r15,8)
movq 0x10(%rsp), %r9
movq 0xa0(%rsp), %rcx
movq 0x8(%rsp), %rdx
leaq (%r15,%r15,2), %rax
movw $0x0, 0x4(%rdx,%rax,2)
movl $0x0, (%rdx,%rax,2)
movb $0x1, (%rcx,%r15)
incq %r12
cmpq $0x4, %r12
jne 0x47886
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq