// File: /workspace/github_cpp_makefile_star2_O3/kobanium[P]Ray/src/mcts/UctSearch.cpp
// Function: InitializeUctSearch()
void
InitializeUctSearch( void )
{
  int i;

  // Progressive Wideningの初期化  
  pw[0] = 0;
  for (i = 1; i <= PURE_BOARD_MAX; i++) {  
    pw[i] = pw[i - 1] + static_cast<int>(40 * pow(PROGRESSIVE_WIDENING, i - 1));
    if (pw[i] > 10000000) break;
  }
  for (i = i + 1; i <= PURE_BOARD_MAX; i++) { 
    pw[i] = INT_MAX;
  }

  mutex_nodes = new std::mutex[uct_hash_size];

  // UCTのノードのメモリを確保
  uct_node = new uct_node_t[uct_hash_size];

  std::cerr << "Require " << uct_hash_size * sizeof(uct_node_t) / 1024 / 1024 << " Mbytes for Uct Node" << std::endl << std::endl;
  std::cerr << sizeof(uct_node_t) << std::endl;
  std::cerr << sizeof(child_node_t) * UCT_CHILD_MAX << std::endl;
  
  if (uct_node == NULL) {
    std::cerr << "Cannot allocate memory !!" << std::endl;
    std::cerr << "You must reduce tree size !!" << std::endl;
    exit(1);
  }

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl $0x0, 0x1aab8634(%rip)  # 0x1ab02b50
xorl %r14d, %r14d
movq $-0x14, %r15
leaq 0x1aab8623(%rip), %rbx  # 0x1ab02b50
xorl %eax, %eax
movl %eax, %ebp
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
movsd 0x15b17(%rip), %xmm0    # 0x60058
callq 0x6740
mulsd 0x15b12(%rip), %xmm0    # 0x60060
cvttsd2si %xmm0, %eax
addl %ebp, %eax
movl %eax, 0x4(%rbx,%r14,4)
cmpl $0x989680, %eax         # imm = 0x989680
jg 0x4a575
incq %r14
addq $-0x4, %r15
cmpq $0x169, %r14            # imm = 0x169
jne 0x4a52f
jmp 0x4a682
leaq 0x1(%r14), %rax
cmpq $0x168, %rax            # imm = 0x168
ja 0x4a682
subq %r15, %rbx
movl $0x16b, %eax            # imm = 0x16B
subq %r14, %rax
movl $0x167, %ecx            # imm = 0x167
subq %r14, %rcx
movq %rcx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
andq $-0x4, %rax
xorl %ecx, %ecx
movdqa 0x15ad0(%rip), %xmm1    # 0x60080
movdqa 0x152d8(%rip), %xmm2    # 0x5f890
movdqa 0x152e0(%rip), %xmm3    # 0x5f8a0
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
movq %rcx, %xmm5
pshufd $0x44, %xmm5, %xmm5     # xmm5 = xmm5[0,1,0,1]
movdqa %xmm5, %xmm6
por %xmm2, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
movd %xmm6, %edx
notl %edx
testb $0x1, %dl
je 0x4a611
movl $0x7fffffff, -0xc(%rbx) # imm = 0x7FFFFFFF
pxor %xmm4, %xmm6
pextrw $0x4, %xmm6, %edx
testb $0x1, %dl
je 0x4a626
movl $0x7fffffff, -0x8(%rbx) # imm = 0x7FFFFFFF
por %xmm1, %xmm5
pxor %xmm3, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
pxor %xmm4, %xmm5
pextrw $0x0, %xmm5, %edx
testb $0x1, %dl
je 0x4a661
movl $0x7fffffff, -0x4(%rbx) # imm = 0x7FFFFFFF
pextrw $0x4, %xmm5, %edx
testb $0x1, %dl
je 0x4a671
movl $0x7fffffff, (%rbx)     # imm = 0x7FFFFFFF
addq $0x4, %rcx
addq $0x10, %rbx
cmpq %rcx, %rax
jne 0x4a5c8
leaq 0x2c247(%rip), %r15     # 0x768d0
movl (%r15), %r12d
leaq (,%r12,8), %rax
leaq (%rax,%rax,4), %r14
movq %r14, %rdi
callq 0x6030
movq %rax, %rbx
testq %r12, %r12
je 0x4a6d6
addq $-0x28, %r14
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
movq %r14, %rax
mulq %rcx
shrq $0x5, %rdx
leaq (%rdx,%rdx,4), %rax
leaq 0x28(,%rax,8), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x6200
movq %rbx, 0x1aab8a1b(%rip)  # 0x1ab030f8
imulq $0x4548, %r12, %rdi     # imm = 0x4548
callq 0x6030
movq %rax, 0x1aa91240(%rip)  # 0x1aadb930
movq 0x2b8f1(%rip), %rbx     # 0x75fe8
leaq 0x15992(%rip), %rsi     # 0x60090
movl $0x8, %edx
movq %rbx, %rdi
callq 0x6490
movl (%r15), %eax
imulq $0x4548, %rax, %rsi     # imm = 0x4548
shrq $0x14, %rsi
movq %rbx, %rdi
callq 0x6280
movq %rax, %r14
leaq 0x1596e(%rip), %rsi     # 0x60099
movl $0x14, %edx
movq %rax, %rdi
callq 0x6490
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x63c0
movsbl %al, %esi
movq %r14, %rdi
callq 0x6040
movq %rax, %rdi
callq 0x6290
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x63c0
movsbl %al, %esi
movq %r14, %rdi
callq 0x6040
movq %rax, %rdi
callq 0x6290
movl $0x4548, %esi           # imm = 0x4548
movq %rbx, %rdi
callq 0x6280
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x63c0
movsbl %al, %esi
movq %r14, %rdi
callq 0x6040
movq %rax, %rdi
callq 0x6290
movl $0x2798, %esi           # imm = 0x2798
movq %rbx, %rdi
callq 0x6280
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x63c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x6040
movq %rax, %rdi
callq 0x6290
cmpq $0x0, 0x1aa91131(%rip)  # 0x1aadb930
je 0x4a80a
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x2b7d7(%rip), %rbx     # 0x75fe8
leaq 0x15896(%rip), %rsi     # 0x600ae
movq %rbx, %rdi
callq 0x63e0
movq %rax, %rdi
callq 0x6190
leaq 0x15899(%rip), %rsi     # 0x600c8
movq %rbx, %rdi
callq 0x63e0
movq %rax, %rdi
callq 0x6190
movl $0x1, %edi
callq 0x64e0