// File: /workspace/github_cpp_makefile_star2_O3/kobanium[P]Ray/src/learn/FactorizationMachines.cpp
// Function: CalculateMoveScore(game_info_t*, int, unsigned int const*, int)
static double
CalculateMoveScore( game_info_t *game, const int pos, const unsigned int tactical_features[], const int distance_index )
{
  const int moves = game->moves;
  const int pm1 = (moves > 1) ? game->record[moves - 1].pos : PASS;
  const int pm2 = (moves > 2) ? game->record[moves - 2].pos : PASS;
  const int pm3 = (moves > 3) ? game->record[moves - 3].pos : PASS;
  const int pm4 = (moves > 4) ? game->record[moves - 4].pos : PASS;
  int dis = 0;
  std::vector<btfm_t*> active_features;
  pattern_hash_t hash_pat;

  if (pos == PASS) {
    if (moves > 1 && pm1 == PASS) {
      active_features.push_back(&pass[UCT_PASS_AFTER_PASS]);
    } else {
      active_features.push_back(&pass[UCT_PASS_AFTER_MOVE]);
    }
  } else {
    if (pm1 != PASS) {
      dis = DIS(pos, pm1);
      if (dis >= MOVE_DISTANCE_MAX - 1) {
        dis = MOVE_DISTANCE_MAX - 1;
      }
      active_features.push_back(&move_distance_1[dis + distance_index]);
    }
    if (pm2 != PASS) {
      dis = DIS(pos, pm2);
      if (dis >= MOVE_DISTANCE_MAX - 1) {
        dis = MOVE_DISTANCE_MAX - 1;
      }
      active_features.push_back(&move_distance_2[dis + distance_index]);
    }
    if (pm3 != PASS) {
      dis = DIS(pos, pm3);
      if (dis >= MOVE_DISTANCE_MAX - 1) {
        dis = MOVE_DISTANCE_MAX - 1;
      }
      active_features.push_back(&move_distance_3[dis + distance_index]);
    }
    if (pm4 != PASS) {
      dis = DIS(pos, pm4);
      if (dis >= MOVE_DISTANCE_MAX - 1) {
        dis = MOVE_DISTANCE_MAX - 1;
      }
      active_features.push_back(&move_distance_4[dis + distance_index]);
    }

    const unsigned int *features = &tactical_features[pos * UCT_INDEX_MAX];

    if (features[UCT_CAPTURE_INDEX]        > 0) active_features.push_back(&capture[features[UCT_CAPTURE_INDEX]]);
    if (features[UCT_SAVE_EXTENSION_INDEX] > 0) active_features.push_back(&save_extension[features[UCT_SAVE_EXTENSION_INDEX]]);
    if (features[UCT_ATARI_INDEX]          > 0) active_features.push_back(&atari[features[UCT_ATARI_INDEX]]);
    if (features[UCT_EXTENSION_INDEX]      > 0) active_features.push_back(&extension[features[UCT_EXTENSION_INDEX]]);
    if (features[UCT_DAME_INDEX]           > 0) active_features.push_back(&dame[features[UCT_DAME_INDEX]]);
    if (features[UCT_CONNECT_INDEX]        > 0) active_features.push_back(&connect[features[UCT_CONNECT_INDEX]]);
    if (features[UCT_THROW_IN_INDEX]       > 0) active_features.push_back(&throw_in[features[UCT_THROW_IN_INDEX]]);

    active_features.push_back(&pos_id[board_pos_id[pos]]);

    PatternHash(&game->pat[pos], &hash_pat);
    const int pat_3x3 = pat3_index[Pat3(game->pat, pos)];
    const int pat_md2 = md2_index[MD2(game->pat, pos)];
    const int md3_idx = SearchIndex(md3_index.data(), hash_pat.list[MD_3]);
    const int md4_idx = SearchIndex(md4_index.data(), hash_pat.list[MD_4]);
    const int md5_idx = SearchIndex(md5_index.data(), hash_pat.list[MD_5 + MD_MAX]);

    if (md5_idx != -1 && md5_target[md5_idx]) {
      active_features.push_back(&md5[md5_idx]);
    } else if (md4_idx != -1 && md4_target[md4_idx]) {
      active_features.push_back(&md4[md4_idx]);
    } else if (md3_idx != -1 && md3_target[md3_idx]) {
      active_features.push_back(&md3[md3_idx]);
    } else if (pat_md2 != 0 && md2_target[pat_md2]) {
      active_features.push_back(&md2[pat_md2]);
    } else {
      active_features.push_back(&pat3[pat_3x3]);
    }
  }

  if (moves > 1 && game->ko_move == game->moves - 1) {
    active_features.push_back(&ko_exist[0]);
  }

  const int feature_num = active_features.size();
  const double gamma = CalculateFirstTerm(active_features, feature_num);
  double theta = feature_num > 1 ? 1.0 : 0.0;

  for (int i = 0; i < feature_num - 1; i++) {
    for (int j = i + 1; j < feature_num; j++) {
      theta *= CalculateSecondTerm(active_features, i, j);
    }
  }

  return gamma + theta;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %r15
movl %esi, %r14d
movq %rdi, %rbx
movl 0x43b0(%rdi), %r12d
cmpl $0x2, %r12d
jl 0x39033
movl %ecx, %ebp
leal -0x1(%r12), %eax
shlq $0x4, %rax
movl $0x0, 0x30(%rsp)
cmpl $0x2, %r12d
jne 0x39054
xorl %esi, %esi
xorl %r13d, %r13d
jmp 0x39090
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
testl %r14d, %r14d
jne 0x39281
jmp 0x395ad
leal -0x2(%r12), %ecx
shlq $0x4, %rcx
movl 0x4(%rbx,%rcx), %r13d
cmpl $0x4, %r12d
jb 0x3908e
leal -0x3(%r12), %ecx
shlq $0x4, %rcx
movl 0x4(%rbx,%rcx), %esi
cmpl $0x4, %r12d
je 0x39090
leal -0x4(%r12), %ecx
shlq $0x4, %rcx
movl 0x4(%rbx,%rcx), %ecx
movl %ecx, 0x30(%rsp)
jmp 0x39090
xorl %esi, %esi
movslq 0x4(%rbx,%rax), %rax
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
testl %r14d, %r14d
je 0x395a5
testl %eax, %eax
movl %esi, 0x28(%rsp)
je 0x39126
movslq %r14d, %rcx
leaq 0x1aad4bbd(%rip), %rdx  # 0x1ab0dc80
movl (%rdx,%rcx,4), %esi
subl (%rdx,%rax,4), %esi
movl %esi, %edx
negl %edx
cmovsl %esi, %edx
leaq 0x1aad58d9(%rip), %rsi  # 0x1ab0e9b0
movl (%rsi,%rcx,4), %ecx
subl (%rsi,%rax,4), %ecx
movl %ecx, %eax
negl %eax
cmovsl %ecx, %eax
imulq $0x4c, %rdx, %rcx
addq 0x3ce81(%rip), %rcx     # 0x75f70
movl (%rcx,%rax,4), %eax
cmpl $0xf, %eax
movl $0xf, %ecx
cmovll %eax, %ecx
addl %ebp, %ecx
movslq %ecx, %rax
imulq $0x218, %rax, %rax      # imm = 0x218
addq 0x3f0e0(%rip), %rax     # 0x781f0
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x3a83c
movl 0x28(%rsp), %esi
testl %r13d, %r13d
je 0x3919b
movslq %r14d, %rax
leaq 0x1aad4b4b(%rip), %rcx  # 0x1ab0dc80
movl (%rcx,%rax,4), %edx
movslq %r13d, %rsi
subl (%rcx,%rsi,4), %edx
movl %edx, %ecx
negl %ecx
cmovsl %edx, %ecx
leaq 0x1aad5864(%rip), %rdx  # 0x1ab0e9b0
movl (%rdx,%rax,4), %eax
subl (%rdx,%rsi,4), %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
imulq $0x4c, %rcx, %rax
addq 0x3ce0c(%rip), %rax     # 0x75f70
movl (%rax,%rdx,4), %eax
cmpl $0xf, %eax
movl $0xf, %ecx
cmovll %eax, %ecx
addl %ebp, %ecx
movslq %ecx, %rax
imulq $0x218, %rax, %rax      # imm = 0x218
addq 0x3f083(%rip), %rax     # 0x78208
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x3a83c
movl 0x28(%rsp), %esi
testl %esi, %esi
movl 0x30(%rsp), %r13d
je 0x39210
movslq %r14d, %rax
leaq 0x1aad4ad2(%rip), %rcx  # 0x1ab0dc80
movl (%rcx,%rax,4), %edx
movslq %esi, %rsi
subl (%rcx,%rsi,4), %edx
movl %edx, %ecx
negl %ecx
cmovsl %edx, %ecx
leaq 0x1aad57eb(%rip), %rdx  # 0x1ab0e9b0
movl (%rdx,%rax,4), %eax
subl (%rdx,%rsi,4), %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
imulq $0x4c, %rcx, %rax
addq 0x3cd93(%rip), %rax     # 0x75f70
movl (%rax,%rdx,4), %eax
cmpl $0xf, %eax
movl $0xf, %ecx
cmovll %eax, %ecx
addl %ebp, %ecx
movslq %ecx, %rax
imulq $0x218, %rax, %rax      # imm = 0x218
addq 0x3f022(%rip), %rax     # 0x78220
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x3a83c
testl %r13d, %r13d
je 0x39281
movslq %r14d, %rax
leaq 0x1aad4a61(%rip), %rcx  # 0x1ab0dc80
movl (%rcx,%rax,4), %edx
movslq %r13d, %rsi
subl (%rcx,%rsi,4), %edx
movl %edx, %ecx
negl %ecx
cmovsl %edx, %ecx
leaq 0x1aad577a(%rip), %rdx  # 0x1ab0e9b0
movl (%rdx,%rax,4), %eax
subl (%rdx,%rsi,4), %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
imulq $0x4c, %rcx, %rax
addq 0x3cd22(%rip), %rax     # 0x75f70
movl (%rax,%rdx,4), %eax
cmpl $0xf, %eax
movl $0xf, %ecx
cmovll %eax, %ecx
addl %ebp, %ecx
movslq %ecx, %rax
imulq $0x218, %rax, %rax      # imm = 0x218
addq 0x3efc9(%rip), %rax     # 0x78238
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x3a83c
leal (,%r14,8), %eax
subl %r14d, %eax
movslq %eax, %r13
movl (%r15,%r13,4), %eax
testq %rax, %rax
je 0x392b8
imulq $0x218, %rax, %rax      # imm = 0x218
addq 0x3eea2(%rip), %rax     # 0x78148
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x3a83c
movl 0x4(%r15,%r13,4), %eax
testq %rax, %rax
je 0x392e2
imulq $0x218, %rax, %rax      # imm = 0x218
addq 0x3ee90(%rip), %rax     # 0x78160
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x3a83c
movl 0x8(%r15,%r13,4), %eax
testq %rax, %rax
je 0x3930c
imulq $0x218, %rax, %rax      # imm = 0x218
addq 0x3ee7e(%rip), %rax     # 0x78178
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x3a83c
movl 0xc(%r15,%r13,4), %eax
testq %rax, %rax
je 0x39336
imulq $0x218, %rax, %rax      # imm = 0x218
addq 0x3ee6c(%rip), %rax     # 0x78190
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x3a83c
movl 0x10(%r15,%r13,4), %eax
testq %rax, %rax
je 0x39360
imulq $0x218, %rax, %rax      # imm = 0x218
addq 0x3ee5a(%rip), %rax     # 0x781a8
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x3a83c
movl 0x14(%r15,%r13,4), %eax
testq %rax, %rax
je 0x3938a
imulq $0x218, %rax, %rax      # imm = 0x218
addq 0x3ee48(%rip), %rax     # 0x781c0
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x3a83c
movl 0x18(%r15,%r13,4), %eax
testq %rax, %rax
je 0x393b4
imulq $0x218, %rax, %rax      # imm = 0x218
addq 0x3ee36(%rip), %rax     # 0x781d8
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x3a83c
movslq %r14d, %r15
leaq 0x1aad3b92(%rip), %rax  # 0x1ab0cf50
movslq (%rax,%r15,4), %rax
imulq $0x218, %rax, %rax      # imm = 0x218
addq 0x3ed60(%rip), %rax     # 0x78130
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x3a83c
leaq (%r15,%r15,2), %rax
leaq (%rbx,%rax,8), %rdi
addq $0x4748, %rdi           # imm = 0x4748
leaq 0x38(%rsp), %rsi
callq 0x51a30
leaq 0x4748(%rbx), %r15
movq %r15, %rdi
movl %r14d, %esi
callq 0x4fc2a
movl %eax, %eax
movq 0x3ec2a(%rip), %rcx     # 0x78040
movslq (%rcx,%rax,4), %r13
movq %r15, %rdi
movl %r14d, %esi
callq 0x4fc36
movl %eax, %eax
movq 0x3ec2a(%rip), %rcx     # 0x78058
movslq (%rcx,%rax,4), %rbp
movq 0x3ec37(%rip), %rdi     # 0x78070
movq 0x40(%rsp), %rsi
callq 0x51d0d
movl %eax, %r14d
movq 0x3ec3b(%rip), %rdi     # 0x78088
movq 0x48(%rsp), %rsi
callq 0x51d0d
movl %eax, %r15d
movq 0x3ec3f(%rip), %rdi     # 0x780a0
movq 0x50(%rsp), %rsi
callq 0x51d0d
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
cmpl $-0x1, %eax
je 0x394d7
movslq %eax, %rdx
leal 0x3f(%rax), %esi
testl %eax, %eax
cmovnsl %eax, %esi
sarl $0x6, %esi
movslq %esi, %rsi
shlq $0x3, %rsi
addq 0x3eec2(%rip), %rsi     # 0x78358
leaq 0x3f(%rcx), %rdi
andq %rdx, %rdi
xorl %r8d, %r8d
cmpq %rcx, %rdi
setbe %r8b
movq -0x8(%rsi,%r8,8), %rsi
btq %rax, %rsi
jae 0x394d7
imulq $0x218, %rdx, %rax      # imm = 0x218
addq 0x3ec58(%rip), %rax     # 0x78118
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x3a83c
jmp 0x39641
cmpl $-0x1, %r15d
je 0x3953c
movslq %r15d, %rax
leal 0x3f(%r15), %edx
testl %r15d, %r15d
cmovnsl %r15d, %edx
sarl $0x6, %edx
movslq %edx, %rdx
shlq $0x3, %rdx
addq 0x3ee34(%rip), %rdx     # 0x78330
leaq 0x3f(%rcx), %rsi
andq %rax, %rsi
xorl %edi, %edi
cmpq %rcx, %rsi
setbe %dil
movq -0x8(%rdx,%rdi,8), %rdx
btq %r15, %rdx
jae 0x3953c
imulq $0x218, %rax, %rax      # imm = 0x218
addq 0x3ebdb(%rip), %rax     # 0x78100
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x3a83c
jmp 0x39641
cmpl $-0x1, %r14d
je 0x395c8
movslq %r14d, %rax
leal 0x3f(%r14), %edx
testl %r14d, %r14d
cmovnsl %r14d, %edx
sarl $0x6, %edx
movslq %edx, %rdx
shlq $0x3, %rdx
addq 0x3eda3(%rip), %rdx     # 0x78308
leaq 0x3f(%rcx), %rsi
andq %rax, %rsi
xorl %edi, %edi
cmpq %rcx, %rsi
setbe %dil
movq -0x8(%rdx,%rdi,8), %rdx
btq %r14, %rdx
jae 0x395c8
imulq $0x218, %rax, %rax      # imm = 0x218
addq 0x3eb5a(%rip), %rax     # 0x780e8
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x3a83c
jmp 0x39641
testl %eax, %eax
je 0x39765
movq 0x3ec9c(%rip), %rax     # 0x78250
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x3a83c
jmp 0x39641
testl %ebp, %ebp
je 0x39621
leal 0x3f(%rbp), %eax
testl %ebp, %ebp
cmovnsl %ebp, %eax
sarl $0x6, %eax
cltq
shlq $0x3, %rax
addq 0x3ecfc(%rip), %rax     # 0x782e0
leaq 0x3f(%rcx), %rdx
andq %rbp, %rdx
xorl %esi, %esi
cmpq %rcx, %rdx
setbe %sil
movq -0x8(%rax,%rsi,8), %rax
btq %rbp, %rax
jae 0x39621
imulq $0x218, %rbp, %rax      # imm = 0x218
addq 0x3eac3(%rip), %rax     # 0x780d0
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x3a83c
jmp 0x39641
imulq $0x218, %r13, %rax      # imm = 0x218
addq 0x3ea89(%rip), %rax     # 0x780b8
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x3a83c
cmpl $0x2, %r12d
jl 0x39670
movl 0x43b0(%rbx), %eax
decl %eax
cmpl %eax, 0x43c8(%rbx)
jne 0x39670
movq 0x3ec0a(%rip), %rax     # 0x78268
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x3a83c
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rax
subq %rdi, %rax
shrq $0x3, %rax
testl %eax, %eax
jle 0x396b2
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movsd 0x23973(%rip), %xmm3    # 0x5d008
xorl %edx, %edx
movq (%rdi,%rdx,8), %rsi
mulsd (%rsi), %xmm3
incq %rdx
cmpq %rdx, %rcx
jne 0x39697
cmpl $0x1, %eax
jne 0x396c0
xorpd %xmm0, %xmm0
jmp 0x3972d
xorpd %xmm0, %xmm0
movsd 0x2394a(%rip), %xmm3    # 0x5d008
jmp 0x39728
leal -0x1(%rax), %ecx
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movsd 0x23938(%rip), %xmm0    # 0x5d008
movl $0x1, %edx
xorl %esi, %esi
movsd 0x257a9(%rip), %xmm4    # 0x5ee88
movq (%rdi,%rsi,8), %r8
incq %rsi
movq %rdx, %r9
movq (%rdi,%r9,8), %r10
xorpd %xmm1, %xmm1
movl $0x1, %r11d
movsd (%r8,%r11,8), %xmm2
mulsd (%r10,%r11,8), %xmm2
addsd %xmm2, %xmm1
incq %r11
cmpq $0x6, %r11
jne 0x396f7
mulsd %xmm4, %xmm1
mulsd %xmm1, %xmm0
incq %r9
cmpq %rax, %r9
jne 0x396e9
incq %rdx
cmpq %rcx, %rsi
jne 0x396df
testq %rdi, %rdi
je 0x39752
movsd %xmm0, 0x28(%rsp)
movsd %xmm3, 0x30(%rsp)
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x6410
movsd 0x28(%rsp), %xmm0
movsd 0x30(%rsp), %xmm3
addsd %xmm3, %xmm0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x218, %eax            # imm = 0x218
addq 0x3eadf(%rip), %rax     # 0x78250
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x3a83c
jmp 0x39647
jmp 0x397ba
jmp 0x397ba
jmp 0x397ba
jmp 0x397ba
jmp 0x397ba
jmp 0x397ba
jmp 0x397ba
jmp 0x397ba
jmp 0x397ba
jmp 0x397ba
jmp 0x397ba
jmp 0x397ba
jmp 0x397ba
jmp 0x397ba
jmp 0x397ba
jmp 0x397ba
jmp 0x397ba
jmp 0x397ba
jmp 0x397ba
jmp 0x397ba
jmp 0x397ba
jmp 0x397ba
jmp 0x397ba
jmp 0x397ba
jmp 0x397ba
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x397d4
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x6410
movq %rbx, %rdi
callq 0x6760