// File: /workspace/github_cpp_makefile_star2_O1/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 $0xd48, %rsp            # imm = 0xD48
movq %rdx, 0x18(%rsp)
movl %esi, %ebp
movq %rdi, %r14
movslq 0x43b0(%rdi), %rbx
movq %rbx, %rax
shlq $0x4, %rax
movslq -0xc(%rax,%rdi), %r15
movl $0x0, 0x4(%rsp)
leaq 0x2d9d0(%rip), %rdi     # 0x758b0
cmpl $0x0, (%rdi)
jle 0x47f16
leaq 0x97372(%r14), %rax
xorl %ecx, %ecx
leaq 0x1ab187fb(%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 (%rdi), %rsi
cmpq %rsi, %rcx
jl 0x47ef5
leaq 0x20(%rsp), %r13
leaq 0x4(%rsp), %r12
movq %r14, %rdi
movl %ebp, %esi
movq %r13, %rdx
movq %r12, %rcx
callq 0x56786
movq %r14, %rdi
movl %ebp, %esi
movq %r13, %rdx
movq %r12, %rcx
callq 0x584a2
leal -0x2(%rbx), %eax
cmpl %eax, 0x43c8(%r14)
jne 0x47f60
leaq 0x20(%rsp), %rdx
leaq 0x4(%rsp), %rcx
movq %r14, %rdi
movl %ebp, %esi
callq 0x57c3b
leaq 0x2d949(%rip), %r12     # 0x758b0
cmpl $0x0, (%r12)
jle 0x48119
leaq 0x4748(%r14), %rax
movq %rax, 0x8(%rsp)
xorl %ebx, %ebx
leaq 0x1ab18769(%rip), %rax  # 0x1ab606f0
movl (%rax,%rbx,4), %r13d
movq %r14, %rdi
movl %r13d, %esi
movl %ebp, %edx
callq 0x54a9c
xorpd %xmm0, %xmm0
testb %al, %al
je 0x480ff
movslq %r13d, %r12
movq %r14, %rdi
movl %ebp, %esi
movl %r13d, %edx
callq 0x57e1b
movq %r14, %rdi
movl %ebp, %esi
movl %r12d, %edx
callq 0x58300
movsd 0x1503f(%rip), %xmm0    # 0x5d008
testl %r15d, %r15d
je 0x48044
leaq 0x1aac4cab(%rip), %rcx  # 0x1ab0cc80
movl (%rcx,%r12,4), %eax
subl (%rcx,%r15,4), %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
leaq 0x1aac59c5(%rip), %rdx  # 0x1ab0d9b0
movl (%rdx,%r12,4), %eax
subl (%rdx,%r15,4), %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
imulq $0x4c, %rcx, %rax
addq 0x2cf6b(%rip), %rax     # 0x74f70
movl (%rax,%rdx,4), %eax
cmpl $0x4, %eax
je 0x48039
cmpl $0x3, %eax
je 0x4802c
movsd 0x14fee(%rip), %xmm0    # 0x5d008
cmpl $0x2, %eax
jne 0x48044
xorps %xmm0, %xmm0
cvtss2sd 0x4031d02(%rip), %xmm0  # 0x4079d2c
jmp 0x48044
xorps %xmm0, %xmm0
cvtss2sd 0x4031cf9(%rip), %xmm0  # 0x4079d30
jmp 0x48044
xorps %xmm0, %xmm0
cvtss2sd 0x4031cf0(%rip), %xmm0  # 0x4079d34
leaq (%r12,%r12,2), %rax
movzbl 0x97372(%r14,%rax,2), %ecx
leaq 0x4031ce8(%rip), %rdx   # 0x4079d40
movss (%rdx,%rcx,4), %xmm1
movzbl 0x97373(%r14,%rax,2), %ecx
leaq 0x4031d23(%rip), %rdx   # 0x4079d90
mulss (%rdx,%rcx,4), %xmm1
movzbl 0x97374(%r14,%rax,2), %ecx
leaq 0x4031d2e(%rip), %rdx   # 0x4079db0
mulss (%rdx,%rcx,4), %xmm1
movzbl 0x97375(%r14,%rax,2), %ecx
leaq 0x4031d49(%rip), %rdx   # 0x4079de0
mulss (%rdx,%rcx,4), %xmm1
movzbl 0x97376(%r14,%rax,2), %ecx
leaq 0x4031d48(%rip), %rdx   # 0x4079df4
mulss (%rdx,%rcx,4), %xmm1
movzbl 0x97377(%r14,%rax,2), %eax
leaq 0x4031d3f(%rip), %rcx   # 0x4079e00
mulss (%rcx,%rax,4), %xmm1
cvtss2sd %xmm1, %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movq 0x8(%rsp), %rdi
movl %r12d, %esi
callq 0x4f857
movl %eax, %eax
leaq 0x31c36(%rip), %rcx     # 0x79d20
xorps %xmm0, %xmm0
cvtss2sd (%rcx,%rax,4), %xmm0
mulsd 0x10(%rsp), %xmm0
leaq 0x2d7b1(%rip), %r12     # 0x758b0
movq 0x18(%rsp), %rax
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
movslq (%r12), %rax
cmpq %rax, %rbx
jl 0x47f80
addq $0xd48, %rsp            # imm = 0xD48
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq