// File: 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
movq %rsp, %rbp
subq $0x610, %rsp            # imm = 0x610
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x43b0(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x5e4(%rbp)
movl -0x5e4(%rbp), %eax
leaq 0x63103(%rip), %rcx     # 0xe7a40
cmpl (%rcx), %eax
jge 0x84985
movslq -0x5e4(%rbp), %rcx
leaq 0x1ab4df21(%rip), %rax  # 0x1abd2870
movl (%rax,%rcx,4), %eax
movl %eax, -0x5e8(%rbp)
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
imull $0x6, -0x5e8(%rbp), %eax
cltq
addq %rax, %rdi
callq 0x79350
movl -0x5e4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5e4(%rbp)
jmp 0x84930
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
leaq -0x5e0(%rbp), %rdx
leaq -0x30(%rbp), %rcx
callq 0xa0820
movq -0x8(%rbp), %rax
movl 0x43c8(%rax), %eax
movq -0x8(%rbp), %rcx
movl 0x43b0(%rcx), %ecx
subl $0x2, %ecx
cmpl %ecx, %eax
jne 0x849ce
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
leaq -0x5e0(%rbp), %rdx
leaq -0x30(%rbp), %rcx
callq 0xa24d0
movl $0x0, -0x5ec(%rbp)
movl -0x5ec(%rbp), %eax
leaq 0x6305b(%rip), %rcx     # 0xe7a40
cmpl (%rcx), %eax
jge 0x84c1f
movslq -0x5ec(%rbp), %rcx
leaq 0x1ab4de75(%rip), %rax  # 0x1abd2870
movl (%rax,%rcx,4), %eax
movl %eax, -0x5f0(%rbp)
movq -0x8(%rbp), %rax
movslq -0x5f0(%rbp), %rcx
testb $0x1, 0x96ce0(%rax,%rcx)
je 0x84bef
movq -0x8(%rbp), %rdi
movl -0x5f0(%rbp), %esi
movl -0xc(%rbp), %edx
callq 0x9d460
testb $0x1, %al
jne 0x84a38
jmp 0x84bef
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x5f0(%rbp), %edx
callq 0xa2830
andb $0x1, %al
movb %al, -0x5f1(%rbp)
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x5f0(%rbp), %edx
callq 0xa3180
testb $0x1, -0x5f1(%rbp)
jne 0x84a85
movq -0x28(%rbp), %rax
movslq -0x5f0(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
jmp 0x84ba9
movq -0x8(%rbp), %rdi
addq $0x4748, %rdi           # imm = 0x4748
movl -0x5f0(%rbp), %esi
callq 0x93d60
movl %eax, %eax
movl %eax, %ecx
leaq 0x673fa(%rip), %rax     # 0xebea0
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x600(%rbp)
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
imull $0x6, -0x5f0(%rbp), %eax
cltq
addq %rax, %rdi
callq 0x85150
mulsd -0x600(%rbp), %xmm0
movsd %xmm0, -0x600(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x84b8d
movslq -0x5f0(%rbp), %rcx
leaq 0x1aafa305(%rip), %rax  # 0x1ab7ee00
movl (%rax,%rcx,4), %eax
movslq -0x2c(%rbp), %rdx
leaq 0x1aafa2f7(%rip), %rcx  # 0x1ab7ee00
subl (%rcx,%rdx,4), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movslq %eax, %rcx
leaq 0x1ab4d7a3(%rip), %rax  # 0x1abd22c0
imulq $0x4c, %rcx, %rcx
addq %rcx, %rax
movslq -0x5f0(%rbp), %rdx
leaq 0x1aafaffe(%rip), %rcx  # 0x1ab7fb30
movl (%rcx,%rdx,4), %ecx
movslq -0x2c(%rbp), %rsi
leaq 0x1aafaff0(%rip), %rdx  # 0x1ab7fb30
subl (%rdx,%rsi,4), %ecx
movl %ecx, %edx
negl %edx
cmovnsl %edx, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x604(%rbp)
cmpl $0x5, -0x604(%rbp)
jge 0x84b8b
movl -0x604(%rbp), %eax
subl $0x2, %eax
movslq %eax, %rcx
leaq 0x406732e(%rip), %rax   # 0x40ebea0
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
mulsd -0x600(%rbp), %xmm0
movsd %xmm0, -0x600(%rbp)
jmp 0x84b8d
cvttsd2si -0x600(%rbp), %rdx
addq $0x1, %rdx
movq -0x28(%rbp), %rax
movslq -0x5f0(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x28(%rbp), %rax
movslq -0x5f0(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x18(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movslq -0x5f0(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x20(%rbp), %rax
movslq -0x5f0(%rbp), %rsi
leaq 0x1aafaf4d(%rip), %rcx  # 0x1ab7fb30
movslq (%rcx,%rsi,4), %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
imull $0x6, -0x5f0(%rbp), %eax
cltq
addq %rax, %rdi
callq 0x79350
movl -0x5ec(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5ec(%rbp)
jmp 0x849d8
addq $0x610, %rsp            # imm = 0x610
popq %rbp
retq
nopl (%rax,%rax)