// File: /workspace/github_cpp_makefile_star2_O2/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 $0x5e8, %rsp            # imm = 0x5E8
movq %r8, 0x38(%rsp)
movq %rcx, 0x30(%rsp)
movq %rdx, 0x28(%rsp)
movl %esi, %r14d
movq %rdi, %r12
movslq 0x43b0(%rdi), %rax
shlq $0x4, %rax
movslq -0xc(%rax,%rdi), %rdx
andl $0x0, 0xc(%rsp)
leaq 0x97372(%rdi), %r15
xorl %eax, %eax
leaq 0x30cbb(%rip), %rbx     # 0x618b0
leaq 0x1ab1baf4(%rip), %rsi  # 0x1ab4c6f0
movslq (%rbx), %rcx
cmpq %rcx, %rax
jge 0x30c1d
movslq (%rsi,%rax,4), %rcx
imulq $0x6, %rcx, %rcx
andw $0x0, 0x4(%r15,%rcx)
andl $0x0, (%r15,%rcx)
incq %rax
jmp 0x30bfc
movq %rdx, 0x18(%rsp)
leaq 0x40(%rsp), %rdx
leaq 0xc(%rsp), %rcx
movq %r12, %rdi
movl %r14d, %esi
callq 0x3d72a
movl 0x43b0(%r12), %eax
addl $-0x2, %eax
cmpl %eax, 0x43c8(%r12)
jne 0x30c61
leaq 0x40(%rsp), %rdx
leaq 0xc(%rsp), %rcx
movq %r12, %rdi
movl %r14d, %esi
callq 0x3ea88
leaq 0x4748(%r12), %rax
movq %rax, 0x10(%rsp)
xorl %ebp, %ebp
leaq 0x1ab1ba79(%rip), %rsi  # 0x1ab4c6f0
movslq (%rbx), %rax
cmpq %rax, %rbp
jge 0x30deb
movslq (%rsi,%rbp,4), %r13
cmpb $0x1, 0x96ce0(%r12,%r13)
jne 0x30dd3
movq %r12, %rdi
movl %r13d, %esi
movl %r14d, %edx
callq 0x3beae
leaq 0x1ab1ba45(%rip), %rsi  # 0x1ab4c6f0
testb %al, %al
je 0x30dd3
movq %r12, %rdi
movl %r14d, %esi
movl %r13d, %edx
callq 0x3ec62
movl %r14d, %esi
movl %eax, %r14d
movq %r12, %rdi
movl %esi, %ebx
movl %r13d, %edx
callq 0x3f18e
testb %r14b, %r14b
je 0x30d7c
movq 0x10(%rsp), %rdi
movl %r13d, %esi
callq 0x37bd2
movl %eax, %eax
leaq 0x3502d(%rip), %rcx     # 0x65d20
cvtss2sd (%rcx,%rax,4), %xmm0
movsd %xmm0, 0x20(%rsp)
imulq $0x6, %r13, %rdi
addq %r15, %rdi
callq 0x310ce
mulsd 0x20(%rsp), %xmm0
movq 0x18(%rsp), %rdx
testl %edx, %edx
je 0x30d91
leaq 0x1aac7f60(%rip), %rcx  # 0x1aaf8c80
movl (%rcx,%r13,4), %eax
subl (%rcx,%rdx,4), %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
leaq 0x1aac8c7b(%rip), %rsi  # 0x1aaf99b0
movl (%rsi,%r13,4), %eax
subl (%rsi,%rdx,4), %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
imulq $0x4c, %rcx, %rax
addq 0x3023a(%rip), %rax     # 0x60f88
movslq (%rax,%rdx,4), %rax
cmpq $0x4, %rax
movl %ebx, %r14d
leaq 0x1ab1b990(%rip), %rsi  # 0x1ab4c6f0
jg 0x30d73
leaq 0x4034fb7(%rip), %rcx   # 0x4065d20
cvtss2sd -0x8(%rcx,%rax,4), %xmm1
mulsd %xmm1, %xmm0
leaq 0x30b36(%rip), %rbx     # 0x618b0
jmp 0x30da2
xorl %eax, %eax
movl %ebx, %r14d
leaq 0x30b28(%rip), %rbx     # 0x618b0
leaq 0x1ab1b961(%rip), %rsi  # 0x1ab4c6f0
jmp 0x30daa
movl %ebx, %r14d
leaq 0x30b15(%rip), %rbx     # 0x618b0
leaq 0x1ab1b94e(%rip), %rsi  # 0x1ab4c6f0
cvttsd2si %xmm0, %rax
incq %rax
movq 0x38(%rsp), %rcx
movq %rax, (%rcx,%r13,8)
movq 0x28(%rsp), %rdx
addq %rax, (%rdx)
movq (%rcx,%r13,8), %rax
leaq 0x1aac8bea(%rip), %rcx  # 0x1aaf99b0
movslq (%rcx,%r13,4), %rcx
movq 0x30(%rsp), %rdx
addq %rax, (%rdx,%rcx,8)
imulq $0x6, %r13, %rax
andw $0x0, 0x4(%r15,%rax)
andl $0x0, (%r15,%rax)
incq %rbp
jmp 0x30c77
addq $0x5e8, %rsp            # imm = 0x5E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq