// File: /workspace/github_cpp_makefile_star2_O1/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 0x18a07(%rip), %xmm0    # 0x5ff30
movaps %xmm0, 0x50(%rsp)
movapd 0x189ea(%rip), %xmm0    # 0x5ff20
movapd %xmm0, 0x40(%rsp)
cmpl $0x1, %eax
jne 0x475d7
movslq 0x43b0(%r13), %rcx
shlq $0x4, %rcx
movslq -0xc(%rcx,%r13), %rdx
leaq 0x1ab17184(%rip), %rcx  # 0x1ab5e6e0
movl (%rcx,%rdx,4), %r8d
cmpl $0x2, %r8d
je 0x4757f
cmpl $0x1, %r8d
jne 0x475d7
leaq 0x1ab17e9d(%rip), %rdi  # 0x1ab5f410
cmpl $0x2, (%rdi,%rdx,4)
je 0x4758c
cmpl $0x2, %r8d
jne 0x475d7
leaq 0x1ab17e8a(%rip), %rdi  # 0x1ab5f410
cmpl $0x1, (%rdi,%rdx,4)
jne 0x475d7
xorl %edx, %edx
leaq 0x1ab17e7b(%rip), %r10  # 0x1ab5f410
movslq (%r9,%rdx,4), %rdi
movl (%rcx,%rdi,4), %r8d
cmpl $0x2, %r8d
je 0x475b6
cmpl $0x1, %r8d
jne 0x475bd
cmpl $0x2, (%r10,%rdi,4)
je 0x475c8
cmpl $0x2, %r8d
jne 0x475bd
cmpl $0x1, (%r10,%rdi,4)
je 0x475c8
incq %rdx
cmpq $0x4, %rdx
jne 0x47595
jmp 0x475d7
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 0x1aac63ad(%rip), %r8   # 0x1ab0d9b0
movq %r9, 0x10(%rsp)
movq %rdx, 0x8(%rsp)
movq 0x38(%rsp), %r14
movslq (%r9,%r12,4), %r15
cmpb $0x1, 0x96ce0(%r13,%r15)
jne 0x4778d
cmpb $0x1, (%rcx,%r15)
jne 0x47643
movsd 0x40(%rsp,%r12,8), %xmm0
ucomisd 0x159cd(%rip), %xmm0    # 0x5d008
jne 0x47643
jnp 0x477a4
movq %r13, %rdi
movl %ebp, %esi
movl %r15d, %edx
movq %r8, %rbx
callq 0x57e1b
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 0x47770
movq %r13, %rdi
movl %ebp, %esi
movl %r15d, %edx
callq 0x58300
movq 0x30(%rsp), %rdi
movl %r15d, %esi
callq 0x4f857
movq %rbx, %r8
movl %eax, %eax
leaq 0x32682(%rip), %rcx     # 0x79d20
movss (%rcx,%rax,4), %xmm0
movq 0x28(%rsp), %rax
leaq 0x4032671(%rip), %rcx   # 0x4079d20
mulss (%rcx,%rax,4), %xmm0
leaq (%r15,%r15,2), %rax
movzbl 0x97372(%r13,%rax,2), %ecx
leaq 0x4032678(%rip), %rdx   # 0x4079d40
movss (%rdx,%rcx,4), %xmm1
movzbl 0x97373(%r13,%rax,2), %ecx
leaq 0x40326b3(%rip), %rdx   # 0x4079d90
mulss (%rdx,%rcx,4), %xmm1
movzbl 0x97374(%r13,%rax,2), %ecx
leaq 0x40326be(%rip), %rdx   # 0x4079db0
mulss (%rdx,%rcx,4), %xmm1
movzbl 0x97375(%r13,%rax,2), %ecx
leaq 0x40326d9(%rip), %rdx   # 0x4079de0
mulss (%rdx,%rcx,4), %xmm1
movzbl 0x97376(%r13,%rax,2), %ecx
leaq 0x40326d8(%rip), %rdx   # 0x4079df4
mulss (%rdx,%rcx,4), %xmm1
cvtss2sd %xmm0, %xmm0
movzbl 0x97377(%r13,%rax,2), %eax
leaq 0x40326cb(%rip), %rcx   # 0x4079e00
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 0x4777b
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 0x47612
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq