// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd58, %rsp            # imm = 0xD58
movq %rdx, 0x28(%rsp)
movl %esi, %ebp
movq %rdi, %r14
movslq 0x43b0(%rdi), %r15
movq %r15, %rax
shlq $0x4, %rax
movslq -0xc(%rax,%rdi), %rax
movq %rax, 0x18(%rsp)
andl $0x0, 0xc(%rsp)
leaq 0x97372(%rdi), %rbx
xorl %eax, %eax
leaq 0x30a6b(%rip), %rdx     # 0x618b0
movslq (%rdx), %rcx
cmpq %rcx, %rax
jge 0x30e6b
leaq 0x1ab1b89c(%rip), %rcx  # 0x1ab4c6f0
movslq (%rcx,%rax,4), %rcx
imulq $0x6, %rcx, %rcx
andw $0x0, 0x4(%rbx,%rcx)
andl $0x0, (%rbx,%rcx)
incq %rax
jmp 0x30e45
leaq 0x30(%rsp), %r13
leaq 0xc(%rsp), %r12
movq %r14, %rdi
movl %ebp, %esi
movq %r13, %rdx
movq %r12, %rcx
callq 0x3d72a
movq %r14, %rdi
movl %ebp, %esi
movq %r13, %rdx
movq %r12, %rcx
callq 0x3f312
leal -0x2(%r15), %eax
cmpl %eax, 0x43c8(%r14)
jne 0x30eb6
leaq 0x30(%rsp), %rdx
leaq 0xc(%rsp), %rcx
movq %r14, %rdi
movl %ebp, %esi
callq 0x3ea88
leaq 0x4748(%r14), %rax
movq %rax, 0x20(%rsp)
xorl %r15d, %r15d
leaq 0x309e4(%rip), %r12     # 0x618b0
movslq (%r12), %rax
cmpq %rax, %r15
jge 0x30ff2
leaq 0x1ab1b810(%rip), %rax  # 0x1ab4c6f0
movl (%rax,%r15,4), %r13d
movq %r14, %rdi
movl %r13d, %esi
movl %ebp, %edx
callq 0x3bc4c
xorpd %xmm0, %xmm0
testb %al, %al
je 0x30fdf
movslq %r13d, %r12
movq %r14, %rdi
movl %ebp, %esi
movl %r13d, %edx
callq 0x3ec62
movq %r14, %rdi
movl %ebp, %esi
movl %r12d, %edx
callq 0x3f18e
movsd 0x130e6(%rip), %xmm0    # 0x44008
cmpl $0x0, 0x18(%rsp)
je 0x30f99
leaq 0x1aac7d50(%rip), %rcx  # 0x1aaf8c80
movl (%rcx,%r12,4), %eax
movq 0x18(%rsp), %rdx
subl (%rcx,%rdx,4), %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
leaq 0x1aac8a66(%rip), %rsi  # 0x1aaf99b0
movl (%rsi,%r12,4), %eax
subl (%rsi,%rdx,4), %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
imulq $0x4c, %rcx, %rax
addq 0x30025(%rip), %rax     # 0x60f88
movl (%rax,%rdx,4), %eax
cmpl $0x4, %eax
je 0x30f91
cmpl $0x3, %eax
je 0x30f87
movsd 0x13090(%rip), %xmm0    # 0x44008
cmpl $0x2, %eax
jne 0x30f99
cvtss2sd 0x4034da7(%rip), %xmm0  # 0x4065d2c
jmp 0x30f99
cvtss2sd 0x4034da1(%rip), %xmm0  # 0x4065d30
jmp 0x30f99
cvtss2sd 0x4034d9b(%rip), %xmm0  # 0x4065d34
movsd %xmm0, 0x10(%rsp)
imulq $0x6, %r12, %rdi
addq %rbx, %rdi
callq 0x310ce
mulsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x20(%rsp), %rdi
movl %r12d, %esi
callq 0x37bd2
movl %eax, %eax
leaq 0x34d53(%rip), %rcx     # 0x65d20
cvtss2sd (%rcx,%rax,4), %xmm0
mulsd 0x10(%rsp), %xmm0
leaq 0x308d1(%rip), %r12     # 0x618b0
movq 0x28(%rsp), %rax
movsd %xmm0, (%rax,%r15,8)
incq %r15
jmp 0x30ecc
addq $0xd58, %rsp            # imm = 0xD58
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq