// File: kobanium[P]Ray/./include/mcts/AnalysisData.hpp
// Function: PrincipalVariationData::PrincipalVariationData(uct_node_t const&, int, int)
PrincipalVariationData( const uct_node_t &root, const int child_index, const int depth_limit = 100 )
    : move(root.child[child_index].pos), playout_win_rate(CalculateWinningRate(root.child[child_index])),
      prior(root.child[child_index].rate), visits(root.child[child_index].move_count.load()), pv_depth_limit(depth_limit)
  {
    const child_node_t &child = root.child[child_index];

    pv.push_back(ParsePoint(child.pos));

    int index = child.index;

    while (pv.size() < pv_depth_limit && index != NOT_EXPANDED) {
      const uct_node_t &node = GetNode(index);
      const child_node_t *children = node.child;
      const int num_children = node.child_num;

      if (node.move_count == 0) {
        break;
      }

      int max_count = children[PASS_INDEX].move_count;
      int max_index = PASS_INDEX;

      for (int i = 1; i < num_children; i++) {
        if (children[i].move_count > max_count) {
          max_count = children[i].move_count;
          max_index = i;
        }
      }

      pv.push_back(ParsePoint(children[max_index].pos));
      index= children[max_index].index;
    }
  }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
movl %edx, -0x2c(%rbp)
movl %ecx, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x28(%rbp), %rcx
movslq -0x2c(%rbp), %rsi
leaq (%rsi,%rsi,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rsi, %rdx
movswl 0x1c(%rcx,%rdx), %ecx
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rdx
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdx, %rcx
leaq 0x1c(%rax,%rcx), %rdi
callq 0x882e0
movq -0xc8(%rbp), %rax
movsd %xmm0, 0x8(%rax)
movq -0x28(%rbp), %rcx
movslq -0x2c(%rbp), %rsi
leaq (%rsi,%rsi,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rsi, %rdx
movss 0x30(%rcx,%rdx), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x10(%rax)
addq $0x18, %rax
movq %rax, -0xc0(%rbp)
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rdx
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdx, %rcx
leaq 0x20(%rax,%rcx), %rax
movq %rax, -0x8(%rbp)
movl $0x5, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movl -0xc(%rbp), %edi
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x25b00
movl %eax, -0xac(%rbp)
jmp 0x28c67
movl -0xac(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0xcc(%rbp)
decl %eax
subl $0x2, %eax
jb 0x28c9d
jmp 0x28c82
movl -0xcc(%rbp), %eax
subl $0x5, %eax
je 0x28cab
jmp 0x28c8f
movq -0xb8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
jmp 0x28cc1
movq -0xb8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
jmp 0x28cc1
movq -0xb8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
jmp 0x28cc1
movq %rax, %rdi
callq 0x25ac0
movq -0xc8(%rbp), %rdi
movq -0xc0(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, (%rax)
movl -0x30(%rbp), %eax
movl %eax, 0x1c(%rdi)
addq $0x20, %rdi
movq %rdi, -0xe0(%rbp)
movq %rdi, %rax
movq %rax, -0xd8(%rbp)
callq 0x29b60
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rdx
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdx, %rcx
leaq 0x1c(%rax,%rcx), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movswl (%rax), %esi
leaq -0x58(%rbp), %rdi
callq 0x9f090
jmp 0x28d22
movq -0xe0(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x29b80
jmp 0x28d34
leaq -0x58(%rbp), %rdi
callq 0x7ae8
movq -0x38(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x68(%rbp)
movq -0xc8(%rbp), %rdi
addq $0x20, %rdi
callq 0x29bb0
movq %rax, %rcx
movq -0xc8(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, %edx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, -0xe1(%rbp)
jae 0x28d80
cmpl $-0x1, -0x68(%rbp)
setne %al
movb %al, -0xe1(%rbp)
movb -0xe1(%rbp), %al
testb $0x1, %al
jne 0x28d8f
jmp 0x28f21
movl -0x68(%rbp), %edi
callq 0x88e10
movq %rax, -0xf0(%rbp)
jmp 0x28da0
movq -0xf0(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
addq $0x1c, %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x7c(%rbp)
movq -0x70(%rbp), %rdi
addq $0x8, %rdi
callq 0x25780
cmpl $0x0, %eax
jne 0x28e03
jmp 0x28f21
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x28f2a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x7ae8
jmp 0x28f2a
movq -0x78(%rbp), %rdi
addq $0x4, %rdi
callq 0x25780
movl %eax, -0x80(%rbp)
movl $0x0, -0x84(%rbp)
movl $0x1, -0x88(%rbp)
movl -0x88(%rbp), %eax
cmpl -0x7c(%rbp), %eax
jge 0x28e8f
movq -0x78(%rbp), %rdi
movslq -0x88(%rbp), %rax
imulq $0x1c, %rax, %rax
addq %rax, %rdi
addq $0x4, %rdi
callq 0x25780
cmpl -0x80(%rbp), %eax
jle 0x28e7c
movq -0x78(%rbp), %rdi
movslq -0x88(%rbp), %rax
imulq $0x1c, %rax, %rax
addq %rax, %rdi
addq $0x4, %rdi
callq 0x25780
movl %eax, -0x80(%rbp)
movl -0x88(%rbp), %eax
movl %eax, -0x84(%rbp)
jmp 0x28e7e
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x28e27
movq -0xc8(%rbp), %rax
addq $0x20, %rax
movq %rax, -0xf8(%rbp)
movq -0x78(%rbp), %rax
movslq -0x84(%rbp), %rdx
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdx, %rcx
movswl (%rax,%rcx), %esi
leaq -0xa8(%rbp), %rdi
callq 0x9f090
jmp 0x28ec9
movq -0xf8(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x29b80
jmp 0x28ede
leaq -0xa8(%rbp), %rdi
callq 0x7ae8
movq -0x78(%rbp), %rax
movslq -0x84(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movl %eax, -0x68(%rbp)
jmp 0x28d47
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x7ae8
jmp 0x28f2a
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0xd8(%rbp), %rdi
callq 0x29bd0
movq -0x60(%rbp), %rdi
callq 0x79b0
nop