// File: ATOMIC-LICHESS[P]ATOMKRAFT/search.cpp
// Function: (anonymous namespace)::RootMove::extract_pv_from_tt(Position&)
void RootMove::extract_pv_from_tt(Position& pos) {

    StateInfo state[PLY_MAX_PLUS_2], *st = state;
    TTEntry* tte;
    int ply = 1;
    Key SAVE[PLY_MAX_PLUS_2]; int H=0;

    assert(pv[0] != MOVE_NONE && pos.move_is_legal(pv[0]));

    pos.do_move(pv[0], *st++);

    while (   (tte = TT.probe(pos.get_key())) != NULL
           && tte->move() != MOVE_NONE
           && pos.move_is_legal(tte->move())
           && ply < PLY_MAX
           && (!pos.is_draw<false>() || ply < 2))
    {
      for (int h=0;h<H;h++) if (pos.get_key()==SAVE[h]) goto EXIT;
      SAVE[H++]=pos.get_key();    // modification so that reps are not repeated
        pv[ply] = tte->move();
        pos.do_move(pv[ply++], *st++);
    }
  EXIT:
    pv[ply] = MOVE_NONE;

    do pos.undo_move(pv[--ply]); while (ply);
  }

// Assembly:
subq $0x4358, %rsp           # imm = 0x4358
movq %rdi, 0x4350(%rsp)
movq %rsi, 0x4348(%rsp)
movq 0x4350(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x380(%rsp), %rcx
movq %rcx, 0x378(%rsp)
movl $0x1, 0x36c(%rsp)
movl $0x0, 0x2c(%rsp)
movq 0x4348(%rsp), %rdi
movl 0x10(%rax), %esi
movq 0x378(%rsp), %rdx
movq %rdx, %rax
addq $0xa0, %rax
movq %rax, 0x378(%rsp)
callq 0x3a390
movq 0x4348(%rsp), %rdi
callq 0x4ea00
movq %rax, %rsi
leaq 0x3b2719(%rip), %rdi    # 0x3fb890
callq 0x516c0
movq %rax, %rcx
movq %rcx, 0x370(%rsp)
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, 0x1f(%rsp)
je 0x49229
movq 0x370(%rsp), %rdi
callq 0x4ea20
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, 0x1f(%rsp)
je 0x49229
movq 0x4348(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x370(%rsp), %rdi
callq 0x4ea20
movq 0x10(%rsp), %rdi
movl %eax, %esi
callq 0x39680
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, 0x1f(%rsp)
jne 0x491e6
jmp 0x49229
xorl %eax, %eax
cmpl $0x64, 0x36c(%rsp)
movb %al, 0x1f(%rsp)
jge 0x49229
movq 0x4348(%rsp), %rdi
callq 0x3e8a0
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, 0xf(%rsp)
jne 0x49212
jmp 0x49221
cmpl $0x2, 0x36c(%rsp)
setl %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
movb %al, 0x1f(%rsp)
movb 0x1f(%rsp), %al
testb $0x1, %al
jne 0x49236
jmp 0x492fe
movl $0x0, 0x28(%rsp)
movl 0x28(%rsp), %eax
cmpl 0x2c(%rsp), %eax
jge 0x49275
movq 0x4348(%rsp), %rdi
callq 0x4ea00
movslq 0x28(%rsp), %rcx
cmpq 0x30(%rsp,%rcx,8), %rax
jne 0x49266
jmp 0x49300
jmp 0x49268
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0x4923e
movq 0x4348(%rsp), %rdi
callq 0x4ea00
movq %rax, %rcx
movl 0x2c(%rsp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x2c(%rsp)
cltq
movq %rcx, 0x30(%rsp,%rax,8)
movq 0x370(%rsp), %rdi
callq 0x4ea20
movl %eax, %edx
movq 0x20(%rsp), %rax
movslq 0x36c(%rsp), %rcx
movl %edx, 0x10(%rax,%rcx,4)
movq 0x4348(%rsp), %rdi
movl 0x36c(%rsp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, 0x36c(%rsp)
movslq %ecx, %rcx
movl 0x10(%rax,%rcx,4), %esi
movq 0x378(%rsp), %rdx
movq %rdx, %rax
addq $0xa0, %rax
movq %rax, 0x378(%rsp)
callq 0x3a390
jmp 0x49160
jmp 0x49300
movq 0x20(%rsp), %rax
movslq 0x36c(%rsp), %rcx
movl $0x0, 0x10(%rax,%rcx,4)
movq 0x20(%rsp), %rax
movq 0x4348(%rsp), %rdi
movl 0x36c(%rsp), %ecx
addl $-0x1, %ecx
movl %ecx, 0x36c(%rsp)
movslq %ecx, %rcx
movl 0x10(%rax,%rcx,4), %esi
callq 0x3c620
cmpl $0x0, 0x36c(%rsp)
jne 0x49315
addq $0x4358, %rsp           # imm = 0x4358
retq
nopw %cs:(%rax,%rax)