// File: /workspace/github_cpp_makefile_star2_O1/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 0x2dc84(%rip), %r14     # 0x758b0
cmpl $0x0, (%r14)
jle 0x47c64
leaq 0x97372(%r12), %rax
xorl %ecx, %ecx
leaq 0x1ab18aad(%rip), %rdx  # 0x1ab606f0
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 0x47c43
leaq 0x30(%rsp), %rdx
leaq 0x4(%rsp), %rcx
movq %r12, %rdi
movl %ebp, %esi
callq 0x56786
movl 0x43b0(%r12), %eax
addl $-0x2, %eax
cmpl %eax, 0x43c8(%r12)
jne 0x47ca1
leaq 0x30(%rsp), %rdx
leaq 0x4(%rsp), %rcx
movq %r12, %rdi
movl %ebp, %esi
callq 0x57c3b
cmpl $0x0, (%r14)
jle 0x47e91
leaq 0x4748(%r12), %rax
movq %rax, 0x8(%rsp)
leaq 0x97372(%r12), %rbx
xorl %r15d, %r15d
leaq 0x1ab18a26(%rip), %rax  # 0x1ab606f0
movslq (%rax,%r15,4), %r13
cmpb $0x1, 0x96ce0(%r12,%r13)
jne 0x47e69
movq %r12, %rdi
movl %r13d, %esi
movl %ebp, %edx
callq 0x54d03
testb %al, %al
je 0x47e69
movq %r12, %rdi
movl %ebp, %esi
movl %r13d, %edx
callq 0x57e1b
movl %eax, %r14d
movq %r12, %rdi
movl %ebp, %esi
movl %r13d, %edx
callq 0x58300
testb %r14b, %r14b
je 0x47e26
movq 0x8(%rsp), %rdi
movl %r13d, %esi
callq 0x4f857
movl %eax, %eax
leaq 0x31ff2(%rip), %rcx     # 0x79d20
xorps %xmm1, %xmm1
cvtss2sd (%rcx,%rax,4), %xmm1
leaq (%r13,%r13,2), %rax
movzbl 0x97372(%r12,%rax,2), %ecx
leaq 0x4031ff5(%rip), %rdx   # 0x4079d40
movss (%rdx,%rcx,4), %xmm0
movzbl 0x97373(%r12,%rax,2), %ecx
leaq 0x4032030(%rip), %rdx   # 0x4079d90
mulss (%rdx,%rcx,4), %xmm0
movzbl 0x97374(%r12,%rax,2), %ecx
leaq 0x403203b(%rip), %rdx   # 0x4079db0
mulss (%rdx,%rcx,4), %xmm0
movzbl 0x97375(%r12,%rax,2), %ecx
leaq 0x4032056(%rip), %rdx   # 0x4079de0
mulss (%rdx,%rcx,4), %xmm0
movzbl 0x97376(%r12,%rax,2), %ecx
leaq 0x4032055(%rip), %rdx   # 0x4079df4
mulss (%rdx,%rcx,4), %xmm0
movzbl 0x97377(%r12,%rax,2), %eax
leaq 0x403204c(%rip), %rcx   # 0x4079e00
mulss (%rcx,%rax,4), %xmm0
cvtss2sd %xmm0, %xmm0
mulsd %xmm1, %xmm0
movq 0x10(%rsp), %rdx
testl %edx, %edx
je 0x47e31
leaq 0x1aac4eaf(%rip), %rcx  # 0x1ab0cc80
movl (%rcx,%r13,4), %eax
subl (%rcx,%rdx,4), %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
leaq 0x1aac5bca(%rip), %rsi  # 0x1ab0d9b0
movl (%rsi,%r13,4), %eax
subl (%rsi,%rdx,4), %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
imulq $0x4c, %rcx, %rax
addq 0x2d171(%rip), %rax     # 0x74f70
movslq (%rax,%rdx,4), %rax
cmpq $0x4, %rax
leaq 0x2daa2(%rip), %r14     # 0x758b0
jg 0x47e38
leaq 0x4031f09(%rip), %rcx   # 0x4079d20
xorps %xmm1, %xmm1
cvtss2sd -0x8(%rcx,%rax,4), %xmm1
mulsd %xmm1, %xmm0
jmp 0x47e38
xorl %eax, %eax
leaq 0x2da81(%rip), %r14     # 0x758b0
jmp 0x47e40
leaq 0x2da78(%rip), %r14     # 0x758b0
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 0x1aac5b54(%rip), %rcx  # 0x1ab0d9b0
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 0x47cc3
addq $0x5d8, %rsp            # imm = 0x5D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq