// File: /workspace/github_cpp_makefile_star2_O3/kobanium[P]Ray/src/mcts/Rating.cpp
// Function: Rating(game_info_t*, int, long long*, long long*, long long*)
void
Rating( game_info_t *game, int color, long long *sum_rate, long long *sum_rate_row, long long *rate )
{
  const int pm1 = game->record[game->moves - 1].pos;
  int update_num = 0;
  int update_pos[PURE_BOARD_MAX];  

  for (int i = 0; i < pure_board_max; i++) {
    const int pos = onboard_pos[i];
    ClearTacticalFeatures(&game->tactical_features[pos * ALL_MAX]);
  }
  
  CheckFeaturesForSimulation(game, color, update_pos, update_num);
  if (game->ko_move == game->moves - 2) {
    CheckCaptureAfterKoForSimulation(game, color, update_pos, update_num);
  }

  for (int i = 0; i < pure_board_max; i++) {
    const int pos = onboard_pos[i];
    if (game->candidates[pos] && IsLegalNotEye(game, pos, color)) {
      const bool self_atari_flag = CheckSelfAtariForSimulation(game, color, pos);
      CheckCaptureAndAtariForSimulation(game, color, pos);

      if (!self_atari_flag) {
        rate[pos] = 0;
      } else {
        double gamma = po_pattern[MD2(game->pat, pos)];
        gamma *= CalculateTacticalFeatures(&game->tactical_features[pos * ALL_MAX]);
        if (pm1 != PASS) {
          const int dis = DIS(pos, pm1);
          if (dis < 5) {
            gamma *= po_previous_distance[dis - 2];
          }
        }
        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]);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x5d8, %rsp            # imm = 0x5D8
movq %r8, 0x28(%rsp)
movq %rcx, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
movl %esi, %ebp
movq %rdi, %r12
movslq 0x43b0(%rdi), %rax
shlq $0x4, %rax
movslq -0xc(%rax,%rdi), %rax
movq %rax, 0x10(%rsp)
movl $0x0, 0x4(%rsp)
leaq 0x2ea10(%rip), %r14     # 0x768b0
cmpl $0x0, (%r14)
jle 0x47ed8
leaq 0x97372(%r12), %rax
xorl %ecx, %ecx
leaq 0x1ab19839(%rip), %rdx  # 0x1ab616f0
movslq (%rdx,%rcx,4), %rsi
leaq (%rsi,%rsi,2), %rsi
movw $0x0, 0x4(%rax,%rsi,2)
movl $0x0, (%rax,%rsi,2)
incq %rcx
movslq (%r14), %rsi
cmpq %rsi, %rcx
jl 0x47eb7
leaq 0x30(%rsp), %rdx
leaq 0x4(%rsp), %rcx
movq %r12, %rdi
movl %ebp, %esi
callq 0x5712c
movl 0x43b0(%r12), %eax
addl $-0x2, %eax
cmpl %eax, 0x43c8(%r12)
jne 0x47f15
leaq 0x30(%rsp), %rdx
leaq 0x4(%rsp), %rcx
movq %r12, %rdi
movl %ebp, %esi
callq 0x58535
cmpl $0x0, (%r14)
jle 0x480ec
leaq 0x4748(%r12), %rax
movq %rax, 0x8(%rsp)
leaq 0x97372(%r12), %rbx
xorl %r15d, %r15d
leaq 0x1ab197b2(%rip), %rax  # 0x1ab616f0
movslq (%rax,%r15,4), %r13
cmpb $0x1, 0x96ce0(%r12,%r13)
jne 0x480c4
movq %r12, %rdi
movl %r13d, %esi
movl %ebp, %edx
callq 0x556c8
testb %al, %al
je 0x480c4
movq %r12, %rdi
movl %ebp, %esi
movl %r13d, %edx
callq 0x5871b
movl %eax, %r14d
movq %r12, %rdi
movl %ebp, %esi
movl %r13d, %edx
callq 0x58c25
testb %r14b, %r14b
je 0x48081
movq 0x8(%rsp), %rdi
movl %r13d, %esi
callq 0x4fc36
movl %eax, %eax
leaq 0x32d7e(%rip), %rcx     # 0x7ad20
xorps %xmm1, %xmm1
cvtss2sd (%rcx,%rax,4), %xmm1
leaq (%r13,%r13,2), %rax
movzbl (%rbx,%rax,2), %ecx
leaq 0x4032d86(%rip), %rdx   # 0x407ad40
movss (%rdx,%rcx,4), %xmm0
movzbl 0x1(%rbx,%rax,2), %ecx
leaq 0x4032dc5(%rip), %rdx   # 0x407ad90
mulss (%rdx,%rcx,4), %xmm0
movzbl 0x2(%rbx,%rax,2), %ecx
leaq 0x4032dd4(%rip), %rdx   # 0x407adb0
mulss (%rdx,%rcx,4), %xmm0
movzbl 0x3(%rbx,%rax,2), %ecx
leaq 0x4032df3(%rip), %rdx   # 0x407ade0
mulss (%rdx,%rcx,4), %xmm0
movzbl 0x4(%rbx,%rax,2), %ecx
leaq 0x4032df6(%rip), %rdx   # 0x407adf4
mulss (%rdx,%rcx,4), %xmm0
movzbl 0x5(%rbx,%rax,2), %eax
leaq 0x4032df1(%rip), %rcx   # 0x407ae00
mulss (%rcx,%rax,4), %xmm0
cvtss2sd %xmm0, %xmm0
mulsd %xmm1, %xmm0
movq 0x10(%rsp), %rdx
testl %edx, %edx
je 0x4808c
leaq 0x1aac5c54(%rip), %rcx  # 0x1ab0dc80
movl (%rcx,%r13,4), %eax
subl (%rcx,%rdx,4), %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
leaq 0x1aac696f(%rip), %rsi  # 0x1ab0e9b0
movl (%rsi,%r13,4), %eax
subl (%rsi,%rdx,4), %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
imulq $0x4c, %rcx, %rax
addq 0x2df16(%rip), %rax     # 0x75f70
movslq (%rax,%rdx,4), %rax
cmpq $0x4, %rax
leaq 0x2e847(%rip), %r14     # 0x768b0
jg 0x48093
leaq 0x4032cae(%rip), %rcx   # 0x407ad20
xorps %xmm1, %xmm1
cvtss2sd -0x8(%rcx,%rax,4), %xmm1
mulsd %xmm1, %xmm0
jmp 0x48093
xorl %eax, %eax
leaq 0x2e826(%rip), %r14     # 0x768b0
jmp 0x4809b
leaq 0x2e81d(%rip), %r14     # 0x768b0
cvttsd2si %xmm0, %rax
incq %rax
movq 0x28(%rsp), %rcx
movq %rax, (%rcx,%r13,8)
movq 0x18(%rsp), %rdx
addq %rax, (%rdx)
movq (%rcx,%r13,8), %rax
leaq 0x1aac68f9(%rip), %rcx  # 0x1ab0e9b0
movslq (%rcx,%r13,4), %rcx
movq 0x20(%rsp), %rdx
addq %rax, (%rdx,%rcx,8)
leaq (,%r13,2), %rax
addq %r13, %rax
movw $0x0, 0x4(%rbx,%rax,2)
movl $0x0, (%rbx,%rax,2)
incq %r15
movslq (%r14), %rax
cmpq %rax, %r15
jl 0x47f37
addq $0x5d8, %rsp            # imm = 0x5D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq