// File: /workspace/github_cpp_makefile_star2_O2/kobanium[P]Ray/src/mcts/UctSearch.cpp
// Function: ParallelUctSearchPondering(thread_arg_t*)
static void
ParallelUctSearchPondering( thread_arg_t *arg )
{
  const thread_arg_t *targ = (thread_arg_t *)arg;
  const int color = targ->color;
  int winner = 0, interval = CRITICALITY_INTERVAL;
  bool enough_size = true;
  bool use_analysis = targ->lz_analysis_cs > 0 ? true : false;
  game_info_t *game = AllocateGame();
  ray_clock::time_point analysis_timer;

  // スレッドIDが0のスレッドだけ別の処理をする
  // 探索回数が閾値を超える, または探索が打ち切られたらループを抜ける
  if (targ->thread_id == 0) {
    analysis_timer = ray_clock::now();
    do {
      // 探索回数を1回増やす
      IncrementPoCount();
      // 盤面のコピー
      CopyGame(game, targ->game);
      // 1回プレイアウトする
      UctSearch(game, color, mt[targ->thread_id], current_root, winner);
      // ハッシュに余裕があるか確認
      enough_size = CheckRemainingHashSize();
      // OwnerとCriticalityを計算する
      if (GetPoCount() > interval) {
        CalculateOwner(color);
        CalculateCriticality(color);
        interval += CRITICALITY_INTERVAL;
      }

      if (use_analysis &&
          static_cast<int>(100 * GetSpendTime(analysis_timer)) > targ->lz_analysis_cs) {
        analysis_timer = ray_clock::now();
        PrintLeelaZeroAnalyze(&uct_node[current_root]);
      }

    } while (!pondering_stop && enough_size);
  } else {
    do {
      // 探索回数を1回増やす
      IncrementPoCount();
      // 盤面のコピー
      CopyGame(game, targ->game);
      // 1回プレイアウトする
      UctSearch(game, color, mt[targ->thread_id], current_root, winner);
      // ハッシュに余裕があるか確認
      enough_size = CheckRemainingHashSize();
    } while (!pondering_stop && enough_size);
  }

  // メモリの解放
  FreeGame(game);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movl 0xc(%rdi), %ebp
movl 0x10(%rdi), %r15d
callq 0x3b148
andq $0x0, 0x8(%rsp)
movq %rax, %r14
cmpl $0x0, 0x8(%rbx)
je 0x33a63
leaq 0x1aa92f2e(%rip), %r12  # 0x1aac6940
leaq 0x14(%rsp), %r15
callq 0x35c74
movq (%rbx), %rsi
movq %r14, %rdi
callq 0x3b5f2
movslq 0x8(%rbx), %rax
imulq $0x9c8, %rax, %rdx      # imm = 0x9C8
addq %r12, %rdx
movl 0x1aa92efd(%rip), %ecx  # 0x1aac6938
movq %r14, %rdi
movl %ebp, %esi
movq %r15, %r8
callq 0x344ff
callq 0x3d2a4
testb %al, %al
je 0x33b27
testb $0x1, 0x1aabd16e(%rip)  # 0x1aaf0bca
je 0x33a17
jmp 0x33b27
callq 0x6060
leaq 0x8(%rsp), %rcx
movq %rax, (%rcx)
pushq $0x64
popq %r12
callq 0x35c74
movq (%rbx), %rsi
movq %r14, %rdi
callq 0x3b5f2
movslq 0x8(%rbx), %rax
imulq $0x9c8, %rax, %rdx      # imm = 0x9C8
leaq 0x1aa92eaa(%rip), %rax  # 0x1aac6940
addq %rax, %rdx
movl 0x1aa92e99(%rip), %ecx  # 0x1aac6938
movq %r14, %rdi
movl %ebp, %esi
leaq 0x14(%rsp), %r8
callq 0x344ff
callq 0x3d2a4
movl %eax, %r13d
callq 0x35c49
cmpl %r12d, %eax
jle 0x33ad2
movl %ebp, %edi
callq 0x34a61
movl %ebp, %edi
callq 0x34b0d
addl $0x64, %r12d
testl %r15d, %r15d
jle 0x33b16
leaq 0x8(%rsp), %rdi
callq 0x355d9
mulsd 0x1052f(%rip), %xmm0    # 0x44018
cvttsd2si %xmm0, %eax
cmpl %eax, 0x10(%rbx)
jge 0x33b16
callq 0x6060
movq %rax, 0x8(%rsp)
movslq 0x1aa92e35(%rip), %rax  # 0x1aac6938
imulq $0x4548, %rax, %rdi     # imm = 0x4548
addq 0x1aa92e1f(%rip), %rdi  # 0x1aac6930
callq 0x108dc
movb 0x1aabd0ae(%rip), %al   # 0x1aaf0bca
xorb $0x1, %al
testb %al, %r13b
jne 0x33a74
movq %r14, %rdi
callq 0x3b163
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq