// File: kobanium[P]Ray/src/mcts/Rating.cpp
// Function: AnalyzePoRating(game_info_t*, int, double*)
void
AnalyzePoRating( game_info_t *game, int color, double rate[] )
{
  const int moves = game->moves;
  const int pm1 = game->record[moves - 1].pos;
  double gamma;
  int update_pos[BOARD_MAX], update_num = 0;  
  
  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);
  CheckRemove2StonesForSimulation(game, color, update_pos, update_num);
  if (game->ko_move == 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 (!IsLegal(game, pos, color)) {
      rate[i] = 0.0;
      continue;
    }
    
    CheckSelfAtariForSimulation(game, color, pos);
    CheckCaptureAndAtariForSimulation(game, color, pos);
    
    gamma = 1.0;
    
    if (pm1 != PASS) {
      const int distance = DIS(pos, pm1);
      if (distance == 2) {
        gamma *= po_neighbor_orig[0];
      } else if (distance == 3) {
        gamma *= po_neighbor_orig[1];
      } else if (distance == 4) {
        gamma *= po_neighbor_orig[2];
      }
    }
    
    gamma *= CalculateTacticalFeatures(&game->tactical_features[pos * ALL_MAX]);
    gamma *= po_pattern[MD2(game->pat, pos)];
    rate[i] = gamma;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd70, %rsp            # imm = 0xD70
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movl 0x43b0(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x20(%rbp)
movl $0x0, -0xd54(%rbp)
movl $0x0, -0xd58(%rbp)
movl -0xd58(%rbp), %eax
leaq 0x62db2(%rip), %rcx     # 0xe7a40
cmpl (%rcx), %eax
jge 0x84cd6
movslq -0xd58(%rbp), %rcx
leaq 0x1ab4dbd0(%rip), %rax  # 0x1abd2870
movl (%rax,%rcx,4), %eax
movl %eax, -0xd5c(%rbp)
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
imull $0x6, -0xd5c(%rbp), %eax
cltq
addq %rax, %rdi
callq 0x79350
movl -0xd58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd58(%rbp)
jmp 0x84c81
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
leaq -0xd50(%rbp), %rdx
leaq -0xd54(%rbp), %rcx
callq 0xa0820
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
leaq -0xd50(%rbp), %rdx
leaq -0xd54(%rbp), %rcx
callq 0xa3400
movq -0x8(%rbp), %rax
movl 0x43c8(%rax), %eax
movl -0x1c(%rbp), %ecx
subl $0x2, %ecx
cmpl %ecx, %eax
jne 0x84d38
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
leaq -0xd50(%rbp), %rdx
leaq -0xd54(%rbp), %rcx
callq 0xa24d0
movl $0x0, -0xd60(%rbp)
movl -0xd60(%rbp), %eax
leaq 0x62cf1(%rip), %rcx     # 0xe7a40
cmpl (%rcx), %eax
jge 0x84f2a
movslq -0xd60(%rbp), %rcx
leaq 0x1ab4db0b(%rip), %rax  # 0x1abd2870
movl (%rax,%rcx,4), %eax
movl %eax, -0xd64(%rbp)
movq -0x8(%rbp), %rdi
movl -0xd64(%rbp), %esi
movl -0xc(%rbp), %edx
callq 0x9d0b0
testb $0x1, %al
jne 0x84d9c
movq -0x18(%rbp), %rax
movslq -0xd60(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
jmp 0x84f16
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0xd64(%rbp), %edx
callq 0xa2830
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0xd64(%rbp), %edx
callq 0xa3180
movsd 0x27240(%rip), %xmm0    # 0xac008
movsd %xmm0, -0x28(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0x84ea7
movslq -0xd64(%rbp), %rcx
leaq 0x1aafa01b(%rip), %rax  # 0x1ab7ee00
movl (%rax,%rcx,4), %eax
movslq -0x20(%rbp), %rdx
leaq 0x1aafa00d(%rip), %rcx  # 0x1ab7ee00
subl (%rcx,%rdx,4), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movslq %eax, %rcx
leaq 0x1ab4d4b9(%rip), %rax  # 0x1abd22c0
imulq $0x4c, %rcx, %rcx
addq %rcx, %rax
movslq -0xd64(%rbp), %rdx
leaq 0x1aafad14(%rip), %rcx  # 0x1ab7fb30
movl (%rcx,%rdx,4), %ecx
movslq -0x20(%rbp), %rsi
leaq 0x1aafad06(%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, -0xd68(%rbp)
cmpl $0x2, -0xd68(%rbp)
jne 0x84e61
movss 0x406705b(%rip), %xmm0  # 0x40ebeac
cvtss2sd %xmm0, %xmm0
mulsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
jmp 0x84ea5
cmpl $0x3, -0xd68(%rbp)
jne 0x84e82
movss 0x406703e(%rip), %xmm0  # 0x40ebeb0
cvtss2sd %xmm0, %xmm0
mulsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
jmp 0x84ea3
cmpl $0x4, -0xd68(%rbp)
jne 0x84ea1
movss 0x4067021(%rip), %xmm0  # 0x40ebeb4
cvtss2sd %xmm0, %xmm0
mulsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
jmp 0x84ea3
jmp 0x84ea5
jmp 0x84ea7
movq -0x8(%rbp), %rdi
addq $0x97372, %rdi          # imm = 0x97372
imull $0x6, -0xd64(%rbp), %eax
cltq
addq %rax, %rdi
callq 0x85150
mulsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movq -0x8(%rbp), %rdi
addq $0x4748, %rdi           # imm = 0x4748
movl -0xd64(%rbp), %esi
callq 0x93d60
movl %eax, %eax
movl %eax, %ecx
leaq 0x66fb2(%rip), %rax     # 0xebea0
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
mulsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x28(%rbp), %xmm0
movq -0x18(%rbp), %rax
movslq -0xd60(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0xd60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd60(%rbp)
jmp 0x84d42
addq $0xd70, %rsp            # imm = 0xD70
popq %rbp
retq
nopw %cs:(%rax,%rax)