// File: /workspace/github_cpp_makefile_star2_O2/kobanium[P]Ray/src/mcts/UctSearch.cpp
// Function: UctSearch(game_info_t*, int, std::mersenne_twister_engine<unsigned long, 64ul, 312ul, 156ul, 31ul, 13043109905998158313ul, 29ul, 6148914691236517205ul, 17ul, 8202884508482404352ul, 37ul, 18444473444759240704ul, 43ul, 6364136223846793005ul>&, int, int&)
static int 
UctSearch( game_info_t *game, int color, std::mt19937_64 &mt, int current, int &winner )
{
  int result = 0, next_index;
  double score;
  child_node_t *uct_child = uct_node[current].child;  

  // 現在見ているノードをロック
  mutex_nodes[current].lock();
  // UCB値最大の手を求める
  next_index = SelectMaxUcbChild(current, color, mt);
  // 選んだ手を着手
  PutStone(game, uct_child[next_index].pos, color);
  // 色を入れ替える
  color = GetOppositeColor(color);

  if ((uct_child[next_index].move_count + uct_child[next_index].virtual_loss) < GetExpandThreshold(game)) {
    AddVirtualLoss(uct_node[current], uct_child[next_index]);

    memcpy(game->seki, uct_node[current].seki, sizeof(bool) * BOARD_MAX);
    
    // 現在見ているノードのロックを解除
    mutex_nodes[current].unlock();

    // 終局まで対局のシミュレーション
    Simulation(game, color, mt);

    // 隅の曲がり四目の確認
    CheckBentFourInTheCorner(game);
    
    // コミを含めない盤面のスコアを求める
    score = static_cast<double>(CalculateScore(game));
    
    // コミを考慮した勝敗
    if (my_color == S_BLACK) {
      if (score - dynamic_komi[my_color] >= 0) {
        result = (color == S_BLACK ? 0 : 1);
        winner = S_BLACK;
      } else {
        result = (color == S_WHITE ? 0 : 1);
        winner = S_WHITE;
      }
    } else {
      if (score - dynamic_komi[my_color] > 0) {
        result = (color == S_BLACK ? 0 : 1);
        winner = S_BLACK;
      } else {
        result = (color == S_WHITE ? 0 : 1);
        winner = S_WHITE;
      }
    }
    // 統計情報の記録
    Statistic(game, winner);
  } else {
    // Virtual Lossを加算
    AddVirtualLoss(uct_node[current], uct_child[next_index]);
    // ノードの展開の確認
    if (uct_child[next_index].index == -1) {
      // ノードの展開中はロック
      mutex_expand.lock();
      // ノードの展開
      uct_child[next_index].index = ExpandNode(game, color, current);
      // ノード展開のロックの解除
      mutex_expand.unlock();
    }
    // 現在見ているノードのロックを解除
    mutex_nodes[current].unlock();
    // 手番を入れ替えて1手深く読む
    result = UctSearch(game, color, mt, uct_child[next_index].index, winner);
  }

  // 探索結果の反映
  UpdateResult(uct_node[current], uct_child[next_index], result);

  mutex_nodes[current].lock();
  UpdateOwnership(uct_node[current], game, GetOppositeColor(color));
  mutex_nodes[current].unlock();

  return 1 - result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, 0x38(%rsp)
movq %rdx, %rbp
movl %esi, %r12d
movq %rdi, %r15
movslq %ecx, %rbx
imulq $0x4548, %rbx, %rcx     # imm = 0x4548
movq 0x1aa92404(%rip), %r14  # 0x1aac6930
movq %rcx, 0x30(%rsp)
addq %rcx, %r14
imulq $0x28, %rbx, %rax
movq 0x1aab9bb9(%rip), %rdi  # 0x1aaee0f8
movq %rax, 0x28(%rsp)
addq %rax, %rdi
callq 0x26c50
movl %ebx, %edi
movl %r12d, %esi
movq %rbp, 0x18(%rsp)
movq %rbp, %rdx
callq 0x34c38
cltq
imulq $0x1c, %rax, %rax
leaq (%rax,%r14), %rbx
addq $0x1c, %rbx
movswl (%rbx), %esi
movq %r15, %rdi
movl %r12d, %edx
callq 0x3c2f8
movl 0x4(%rbx), %eax
movq %rbx, 0x40(%rsp)
movl 0x8(%rbx), %r13d
addl %eax, %r13d
movl 0x43b0(%r15), %eax
cmpl $0x3, %eax
movq %r15, 0x8(%rsp)
jl 0x345bc
leal -0x1(%rax), %ecx
shlq $0x4, %rcx
cmpl $0x0, 0x4(%r15,%rcx)
jne 0x345bc
addl $-0x2, %eax
shlq $0x4, %rax
cmpl $0x0, 0x4(%r15,%rax)
je 0x34a37
movl 0x2d2b9(%rip), %r14d    # 0x6187c
movl %r12d, %ebx
xorl $0x3, %ebx
movq 0x1aa92360(%rip), %rdi  # 0x1aac6930
movq 0x30(%rsp), %r15
addq %r15, %rdi
movq 0x40(%rsp), %rbp
movq %rbp, %rsi
callq 0x32844
cmpl %r14d, %r13d
jge 0x34688
movl %r12d, 0x14(%rsp)
movq 0x8(%rsp), %r14
leaq 0x97029(%r14), %rdi
movq 0x1aa9232a(%rip), %rax  # 0x1aac6930
leaq (%rax,%r15), %rsi
addq $0x27b4, %rsi           # imm = 0x27B4
movl $0x349, %edx            # imm = 0x349
callq 0x6310
movq 0x1aab9ad6(%rip), %rdi  # 0x1aaee0f8
movq 0x28(%rsp), %rax
addq %rax, %rdi
callq 0x62d0
movq %r14, %rdi
movl %ebx, %esi
movq 0x18(%rsp), %rdx
callq 0x31140
movq %r14, %rdi
callq 0x3c9dd
movq %r14, %rdi
callq 0x3cb19
cvtsi2sd %eax, %xmm0
movslq 0x1aac238f(%rip), %rax  # 0x1aaf69e8
cmpq $0x1, %rax
jne 0x347e9
leaq 0x1aac38c6(%rip), %rax  # 0x1aaf7f30
xorl %r12d, %r12d
ucomisd 0x8(%rax), %xmm0
setb %r12b
pushq $0x2
popq %rax
subl %r12d, %eax
movl %eax, 0x18(%rsp)
incl %r12d
jmp 0x34807
cmpl $-0x1, 0x10(%rbp)
movq 0x28(%rsp), %r13
jne 0x349af
leaq 0x1aac2952(%rip), %rdi  # 0x1aaf6ff0
callq 0x26c50
movq 0x8(%rsp), %rax
movl 0x43b0(%rax), %edx
movq 0x43f0(%rax), %r14
movq %r14, %rdi
movl %ebx, %esi
movq %rdx, %r15
callq 0x3d24a
leaq 0x2d207(%rip), %rcx     # 0x618d0
cmpl (%rcx), %eax
jne 0x3499b
movq %r14, %rdi
movl %ebx, %esi
movq %r15, %r14
movl %r14d, %edx
movq %rcx, %r15
callq 0x3d1d5
cmpl (%r15), %eax
je 0x34a42
movl %r12d, 0x14(%rsp)
movslq %r14d, %rdx
shlq $0x4, %rdx
movq 0x8(%rsp), %rcx
movl -0xc(%rdx,%rcx), %esi
xorl %edx, %edx
cmpl $0x2, %r14d
jl 0x34717
addl $-0x2, %r14d
shlq $0x4, %r14
movl 0x4(%rcx,%r14), %edx
movl %eax, 0x24(%rsp)
movl %eax, %eax
imulq $0x4548, %rax, %r14     # imm = 0x4548
movq 0x1aa92205(%rip), %rdi  # 0x1aac6930
addq %r14, %rdi
movl %esi, 0x4c(%rsp)
callq 0x327d0
movq 0x1aa921f2(%rip), %rax  # 0x1aac6930
movq %r14, 0x50(%rsp)
leaq (%rax,%r14), %rdi
addq $0x1c, %rdi
leaq 0x10(%rsp), %rsi
andl $0x0, (%rsi)
xorl %r12d, %r12d
movq %rdi, %r15
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x3281e
movq 0x8(%rsp), %rdx
leaq 0x2d142(%rip), %r13     # 0x618b0
leaq 0x1aabc10b(%rip), %rbp  # 0x1aaf0880
movslq (%r13), %rax
cmpq %rax, %r12
jge 0x348bb
leaq 0x1ab17f67(%rip), %rax  # 0x1ab4c6f0
movslq (%rax,%r12,4), %r14
cmpb $0x1, (%r14,%rbp)
jne 0x347e4
movq 0x8(%rsp), %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0x3bc4c
movq 0x8(%rsp), %rdx
testb %al, %al
je 0x347e4
movq 0x8(%rsp), %rdi
movl %ebx, %esi
movl %r14d, %edx
callq 0x4273b
movq 0x8(%rsp), %rdx
testb %al, %al
je 0x347e4
movslq 0x10(%rsp), %rax
imulq $0x1c, %rax, %rdi
addq %r15, %rdi
leaq 0x10(%rsp), %rsi
movl %r14d, %edx
xorl %ecx, %ecx
callq 0x3281e
movq 0x8(%rsp), %rdx
incq %r12
jmp 0x34775
leaq 0x1aac3740(%rip), %rcx  # 0x1aaf7f30
xorl %edx, %edx
ucomisd (%rcx,%rax,8), %xmm0
seta %dl
pushq $0x2
popq %r12
subl %edx, %r12d
incl %edx
movl %edx, 0x18(%rsp)
movq 0x38(%rsp), %rax
movl %r12d, (%rax)
movq 0x8(%rsp), %rcx
leaq 0x4748(%rcx), %rax
movq %rax, 0x38(%rsp)
xorl %r13d, %r13d
leaq 0x2d086(%rip), %rbp     # 0x618b0
leaq 0x1ab17ebf(%rip), %r15  # 0x1ab4c6f0
leaq 0x1aabc598(%rip), %rbx  # 0x1aaf0dd0
movslq (%rbp), %rax
cmpq %rax, %r13
jge 0x3488e
movslq (%r15,%r13,4), %r14
movsbl 0x43f8(%rcx,%r14), %eax
testl %eax, %eax
jne 0x34871
movq 0x38(%rsp), %rdi
movl %r14d, %esi
callq 0x37bc6
movq 0x8(%rsp), %rcx
movl %eax, %eax
leaq 0x1aae5e73(%rip), %rdx  # 0x1ab1a6e0
movzbl (%rdx,%rax), %eax
shlq $0x4, %r14
addq %rbx, %r14
cltq
lock
incl (%r14,%rax,4)
cmpl %r12d, %eax
jne 0x34889
lock
incl 0xc(%r14)
incq %r13
jmp 0x34838
xorl %ebx, %ebx
movl 0x14(%rsp), %r12d
cmpl %r12d, 0x18(%rsp)
setne %bl
lock
incl 0x1aabf9bc(%rip)        # 0x1aaf4260
movq 0x28(%rsp), %r13
movq %rcx, %r14
movq 0x30(%rsp), %r15
movq 0x40(%rsp), %rbp
jmp 0x349dc
movl 0x10(%rsp), %eax
movq 0x1aa9206a(%rip), %rcx  # 0x1aac6930
movq 0x50(%rsp), %r12
movl %eax, 0x18(%rcx,%r12)
movq %rdx, %r14
movq %rdx, %rdi
movl %ebx, %esi
movl 0x24(%rsp), %edx
callq 0x3429c
movq 0x1aa92048(%rip), %rax  # 0x1aac6930
leaq (%rax,%r12), %rsi
addq $0x27b4, %rsi           # imm = 0x27B4
movq %r14, %rdi
callq 0x3d368
movq 0x1aa9202e(%rip), %rax  # 0x1aac6930
incl 0x14(%rax,%r12)
movq 0x30(%rsp), %rcx
addq %rax, %rcx
addq $0x30, %rcx
movl -0x18(%rcx), %eax
xorl %edx, %edx
testl %eax, %eax
cmovlel %edx, %eax
imulq $0x1c, %rax, %rsi
xorpd %xmm0, %xmm0
xorl %eax, %eax
movl 0x14(%rsp), %r12d
movq 0x28(%rsp), %r13
movq 0x40(%rsp), %rbp
movl 0x4c(%rsp), %r8d
cmpq %rdx, %rsi
je 0x34961
movswl -0x14(%rcx,%rdx), %edi
cmpl %edi, %r8d
je 0x3495b
cvtss2sd (%rcx,%rdx), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x3495b
movapd %xmm1, %xmm0
movl %edi, %eax
addq $0x1c, %rdx
jmp 0x3493b
movl 0x10(%rsp), %edx
xorl %ecx, %ecx
testl %edx, %edx
cmovlel %ecx, %edx
imulq $0x1c, %rdx, %rdx
addq $0x1c, %rdx
leaq 0x1c(%rcx), %rsi
cmpq %rsi, %rdx
je 0x34997
movswl (%r15,%rcx), %edi
movq %rsi, %rcx
cmpl %edi, %eax
jne 0x34974
cmpb $0x0, -0x4(%r15,%rsi)
jne 0x34997
movb $0x1, -0x3(%r15,%rsi)
movl 0x24(%rsp), %eax
movl %eax, 0x10(%rbp)
leaq 0x1aac264b(%rip), %rdi  # 0x1aaf6ff0
callq 0x62d0
movq 0x30(%rsp), %r15
movq 0x1aab9742(%rip), %rdi  # 0x1aaee0f8
addq %r13, %rdi
callq 0x62d0
movl 0x10(%rbp), %ecx
movq 0x8(%rsp), %r14
movq %r14, %rdi
movl %ebx, %esi
movq 0x18(%rsp), %rdx
movq 0x38(%rsp), %r8
callq 0x344ff
movl %eax, %ebx
movq 0x1aa91f4d(%rip), %rdi  # 0x1aac6930
addq %r15, %rdi
movq %rbp, %rsi
movl %ebx, %edx
callq 0x3284d
movq 0x1aab9701(%rip), %rdi  # 0x1aaee0f8
addq %r13, %rdi
callq 0x26c50
addq 0x1aa91f2a(%rip), %r15  # 0x1aac6930
movq %r15, %rdi
movq %r14, %rsi
movl %r12d, %edx
callq 0x32904
addq 0x1aab96dd(%rip), %r13  # 0x1aaee0f8
movq %r13, %rdi
callq 0x62d0
xorl $0x1, %ebx
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x7ffffffe, %r14d      # imm = 0x7FFFFFFE
jmp 0x345c3
leaq 0x12634(%rip), %rdi     # 0x4707d
leaq 0x12644(%rip), %rsi     # 0x47094
leaq 0x12677(%rip), %rcx     # 0x470ce
movl $0x328, %edx            # imm = 0x328
callq 0x6230