// File: /workspace/github_cpp_makefile_star2_O3/cpirc[P]Monochrome/src/perft.cpp
// Function: perft_tt(TT*, Position const&, int)
std::uint64_t perft_tt(TT* tt, const Position& pos, const int depth) {
    assert(tt);

    if (depth == 0) {
        return 1;
    }

    TTEntry entry = tt_poll(tt, pos.hash_key);
    if (entry.hash_key == pos.hash_key && tt_depth(entry.data) == depth) {
        return tt_nodes(entry.data);
    }

    uint64_t nodes = 0;
    Move moves[256];
    int movecount = generate(pos, moves);
    for (int i = 0; i < movecount; i++) {
        Position npos = pos;

        make_move(npos, moves[i]);
        if (is_checked(npos, THEM)) continue;

        nodes += perft_tt(tt, npos, depth - 1);
    }

    tt_add_perft(tt, pos.hash_key, depth, nodes);

    return nodes;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x488, %rsp            # imm = 0x488
movq %rdi, -0x38(%rbp)
testq %rdi, %rdi
je 0x671b
movl %edx, %r14d
testl %edx, %edx
je 0x66c0
movq %rsi, %r15
movq 0x48(%rsi), %rsi
movq -0x38(%rbp), %rdi
callq 0x94d9
cmpq 0x48(%r15), %rdx
jne 0x6545
movl %eax, %ecx
andl $0x7f, %ecx
cmpl $0x40, %ecx
jae 0x673a
cmpl %r14d, %ecx
jne 0x6545
shrq $0x7, %rax
movslq %eax, %rbx
jmp 0x66e7
leaq -0x4b0(%rbp), %rsi
movq %r15, %rdi
callq 0x5d4e
testl %eax, %eax
movq %r14, -0x48(%rbp)
jle 0x66c7
leaq 0x50(%r15), %rbx
leal -0x1(%r14), %ecx
movl %ecx, -0x3c(%rbp)
movl %eax, %r14d
xorl %r12d, %r12d
leaq -0xb0(%rbp), %r13
movq $0x0, -0x30(%rbp)
movl $0xa, %ecx
movq %r13, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq -0x60(%rbp), %rdi
movq %rbx, %rsi
callq 0x5300
movl -0x4b0(%rbp,%r12,4), %esi
movq %r13, %rdi
callq 0x47a0
movq -0x88(%rbp), %rax
movq -0x78(%rbp), %rdx
movq %rdx, %rcx
andq %rax, %rcx
je 0x66fc
bsfq %rcx, %rdi
movq -0x80(%rbp), %rcx
orq %rcx, %rdx
leal (,%rdi,8), %esi
movq -0xb0(%rbp), %r9
movq -0xa8(%rbp), %r8
leaq 0xabd8(%rip), %r10      # 0x111c0
andq 0x200(%r10,%rsi), %r9
leaq 0xafc9(%rip), %r10      # 0x115c0
andq (%r10,%rsi), %r8
leaq 0x5e9e(%rip), %r10      # 0xc4a0
movq (%r10,%rsi), %r10
andq %rdx, %r10
leaq 0x5c90(%rip), %r11      # 0xc2a0
imulq (%r11,%rsi), %r10
orq %r9, %r8
shrq $0x37, %r10
movl %edi, %r9d
shll $0xc, %r9d
addq 0xa986(%rip), %r9       # 0x10fb0
movq (%r9,%r10,8), %r9
movq -0xa0(%rbp), %r10
andq %r9, %r10
leaq 0x5961(%rip), %r11      # 0xbfa0
andq (%r11,%rsi), %rdx
leaq 0x5756(%rip), %r11      # 0xbda0
imulq (%r11,%rsi), %rdx
orq %r8, %r10
shrq $0x34, %rdx
shll $0xf, %edi
addq 0xa938(%rip), %rdi      # 0x10f98
movq (%rdi,%rdx,8), %rdx
movq -0x98(%rbp), %rdi
andq %rdx, %rdi
orq %r10, %rdi
orq %r9, %rdx
leaq 0xb145(%rip), %r8       # 0x117c0
andq (%r8,%rsi), %rax
orq %rdi, %rax
andq -0x90(%rbp), %rdx
orq %rdx, %rax
testq %rcx, %rax
jne 0x66a4
movq -0x38(%rbp), %rdi
movq %r13, %rsi
movl -0x3c(%rbp), %edx
callq 0x64e4
addq %rax, -0x30(%rbp)
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x66b2
callq 0x31a0
incq %r12
cmpq %r12, %r14
jne 0x6580
jmp 0x66cf
movl $0x1, %ebx
jmp 0x66e7
movq $0x0, -0x30(%rbp)
movq 0x48(%r15), %rsi
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rdx
movq -0x30(%rbp), %rbx
movq %rbx, %rcx
callq 0x9719
movq %rbx, %rax
addq $0x488, %rsp            # imm = 0x488
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x554d(%rip), %rdi      # 0xbc50
leaq 0x5549(%rip), %rsi      # 0xbc53
leaq 0x5551(%rip), %rcx      # 0xbc62
movl $0x3e, %edx
callq 0x3100
leaq 0x6322(%rip), %rdi      # 0xca44
leaq 0x631e(%rip), %rsi      # 0xca47
leaq 0x6325(%rip), %rcx      # 0xca55
movl $0x38, %edx
callq 0x3100
leaq 0x63cb(%rip), %rdi      # 0xcb0c
leaq 0x6399(%rip), %rsi      # 0xcae1
leaq 0x639b(%rip), %rcx      # 0xcaea
movl $0x64, %edx
callq 0x3100
movq %rax, %rbx
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x676a
callq 0x31a0
movq %rbx, %rdi
callq 0x32d0