// File: /workspace/github_cpp_makefile_star2_O3/jswaff[P]prophet3/src/perft.cpp
// Function: perft_test_fast()
void perft_test_fast() {
    print("starting perft_test_fast\n");
    int32 start_time = milli_timer();
    uint64 total_nodes = 0;

    position pos;
    total_nodes += test_case(&pos,"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",4,197281);
    total_nodes += test_case(&pos,"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1",3,97862);
    total_nodes += test_case(&pos,"8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 1",6,11030083L);
    total_nodes += test_case(&pos,"r3k2r/Pppp1ppp/1b3nbN/nP6/BBP1P3/q4N2/Pp1P2PP/R2Q1RK1 w kq - 0 1",5,15833292L);
    total_nodes += test_case(&pos,"rnbq1k1r/pp1Pbppp/2p5/8/2B5/8/PPP1NnPP/RNBQK2R w KQ - 1 8",4,2103487);
    total_nodes += test_case(&pos,"r4rk1/1pp1qppp/p1np1n2/2b1p1B1/2B1P1b1/P1NP1N2/1PP1QPPP/R4RK1 w - - 0 10",4,3894594L);

    // illegal EP
    total_nodes += test_case(&pos,"3k4/3p4/8/K1P4r/8/8/8/8 b - - 0 1", 6, 1134888);
    total_nodes += test_case(&pos,"8/8/8/8/k1p4R/8/3P4/3K4 w - - 0 1", 6, 1134888);
    total_nodes += test_case(&pos,"8/8/4k3/8/2p5/8/B2P2K1/8 w - - 0 1", 6, 1015133);
    total_nodes += test_case(&pos,"8/b2p2k1/8/2P5/8/4K3/8/8 b - - 0 1", 6, 1015133);

    // ep capture checks opponent
    total_nodes += test_case(&pos,"8/8/1k6/2b5/2pP4/8/5K2/8 b - d3 0 1", 6, 1440467);
    total_nodes += test_case(&pos,"8/5k2/8/2Pp4/2B5/1K6/8/8 w - d6 0 1", 6, 1440467);

    // short castle gives check
    total_nodes += test_case(&pos,"5k2/8/8/8/8/8/8/4K2R w K - 0 1", 6, 661072);
    total_nodes += test_case(&pos,"4k2r/8/8/8/8/8/8/5K2 b k - 0 1", 6, 661072);

    // long castle gives check
    total_nodes += test_case(&pos,"3k4/8/8/8/8/8/8/R3K3 w Q - 0 1", 6, 803711);
    total_nodes += test_case(&pos,"r3k3/8/8/8/8/8/8/3K4 b q - 0 1", 6, 803711);

    // losing castling rights
    total_nodes += test_case(&pos,"r3k2r/1b4bq/8/8/8/8/7B/R3K2R w KQkq - 0 1", 4, 1274206);
    total_nodes += test_case(&pos,"r3k2r/7b/8/8/8/8/1B4BQ/R3K2R b KQkq - 0 1", 4, 1274206);

    // castling prevented
    total_nodes += test_case(&pos,"r3k2r/8/3Q4/8/8/5q2/8/R3K2R b KQkq - 0 1", 4, 1720476);
    total_nodes += test_case(&pos,"r3k2r/8/5Q2/8/8/3q4/8/R3K2R w KQkq - 0 1", 4, 1720476);

    // promote out of check
    total_nodes += test_case(&pos,"2K2r2/4P3/8/8/8/8/8/3k4 w - - 0 1", 6, 3821001);
    total_nodes += test_case(&pos,"3K4/8/8/8/8/8/4p3/2k2R2 b - - 0 1", 6, 3821001);

    // discovered check
    total_nodes += test_case(&pos,"8/8/1P2K3/8/2n5/1q6/8/5k2 b - - 0 1", 5, 1004658);
    total_nodes += test_case(&pos,"5K2/8/1Q6/2N5/8/1p2k3/8/8 w - - 0 1", 5, 1004658);

    // promote to give check
    total_nodes += test_case(&pos,"4k3/1P6/8/8/8/8/K7/8 w - - 0 1", 6, 217342);
    total_nodes += test_case(&pos,"8/k7/8/8/8/8/1p6/4K3 b - - 0 1", 6, 217342);

    // unpromote to check
    total_nodes += test_case(&pos,"8/P1k5/K7/8/8/8/8/8 w - - 0 1", 6, 92683);
    total_nodes += test_case(&pos,"8/8/8/8/8/k7/p1K5/8 b - - 0 1", 6, 92683);

    // self stalemate
    total_nodes += test_case(&pos,"K1k5/8/P7/8/8/8/8/8 w - - 0 1", 6, 2217);
    total_nodes += test_case(&pos,"8/8/8/8/8/p7/8/k1K5 b - - 0 1", 6, 2217);

    // stalemate checkmate
    total_nodes += test_case(&pos,"8/k1P5/8/1K6/8/8/8/8 w - - 0 1", 7, 567584);
    total_nodes += test_case(&pos,"8/8/8/8/1k6/8/K1p5/8 b - - 0 1", 7, 567584);

    // double check
    total_nodes += test_case(&pos,"8/8/2k5/5q2/5n2/8/5K2/8 b - - 0 1", 4, 23527);
    total_nodes += test_case(&pos,"8/5k2/8/5N2/5Q2/2K5/8/8 w - - 0 1", 4, 23527);

    int32 elapsed = milli_timer() - start_time + 1; // div by 0
    print("\n\naverage nps: %lu\n\n",total_nodes*1000/elapsed);

    print("... perft_test_fast complete!\n");
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
leaq 0x2141c(%rip), %rdi     # 0x2b12a
xorl %eax, %eax
callq 0x64b9
callq 0xdf08
movl %eax, %ebx
leaq 0x21421(%rip), %rsi     # 0x2b144
movq %rsp, %r14
movl $0x302a1, %ecx          # imm = 0x302A1
movq %r14, %rdi
movl $0x4, %edx
callq 0x9c6c
leaq 0x2143e(%rip), %rsi     # 0x2b17d
movl $0x17e46, %ecx          # imm = 0x17E46
movq %r14, %rdi
movl $0x3, %edx
callq 0x9c6c
leaq 0x2146a(%rip), %rsi     # 0x2b1c2
movl $0xa84e43, %ecx         # imm = 0xA84E43
movq %r14, %rdi
movl $0x6, %edx
callq 0x9c6c
leaq 0x2147b(%rip), %rsi     # 0x2b1ec
movl $0xf198cc, %ecx         # imm = 0xF198CC
movq %r14, %rdi
movl $0x5, %edx
callq 0x9c6c
leaq 0x214a3(%rip), %rsi     # 0x2b22d
movl $0x2018bf, %ecx         # imm = 0x2018BF
movq %r14, %rdi
movl $0x4, %edx
callq 0x9c6c
leaq 0x214c4(%rip), %rsi     # 0x2b267
movl $0x3b6d42, %ecx         # imm = 0x3B6D42
movq %r14, %rdi
movl $0x4, %edx
callq 0x9c6c
leaq 0x214f4(%rip), %rsi     # 0x2b2b0
movl $0x115128, %ecx         # imm = 0x115128
movq %r14, %rdi
movl $0x6, %edx
callq 0x9c6c
leaq 0x214fd(%rip), %rsi     # 0x2b2d2
movl $0x115128, %ecx         # imm = 0x115128
movq %r14, %rdi
movl $0x6, %edx
callq 0x9c6c
leaq 0x21506(%rip), %rsi     # 0x2b2f4
movl $0xf7d5d, %ecx          # imm = 0xF7D5D
movq %r14, %rdi
movl $0x6, %edx
callq 0x9c6c
leaq 0x21510(%rip), %rsi     # 0x2b317
movl $0xf7d5d, %ecx          # imm = 0xF7D5D
movq %r14, %rdi
movl $0x6, %edx
callq 0x9c6c
leaq 0x2151a(%rip), %rsi     # 0x2b33a
movl $0x15fad3, %ecx         # imm = 0x15FAD3
movq %r14, %rdi
movl $0x6, %edx
callq 0x9c6c
leaq 0x21525(%rip), %rsi     # 0x2b35e
movl $0x15fad3, %ecx         # imm = 0x15FAD3
movq %r14, %rdi
movl $0x6, %edx
callq 0x9c6c
leaq 0x21530(%rip), %rsi     # 0x2b382
movl $0xa1650, %ecx          # imm = 0xA1650
movq %r14, %rdi
movl $0x6, %edx
callq 0x9c6c
leaq 0x21536(%rip), %rsi     # 0x2b3a1
movl $0xa1650, %ecx          # imm = 0xA1650
movq %r14, %rdi
movl $0x6, %edx
callq 0x9c6c
leaq 0x2153c(%rip), %rsi     # 0x2b3c0
movl $0xc437f, %ecx          # imm = 0xC437F
movq %r14, %rdi
movl $0x6, %edx
callq 0x9c6c
leaq 0x21542(%rip), %rsi     # 0x2b3df
movl $0xc437f, %ecx          # imm = 0xC437F
movq %r14, %rdi
movl $0x6, %edx
callq 0x9c6c
leaq 0x21548(%rip), %rsi     # 0x2b3fe
movl $0x13715e, %ecx         # imm = 0x13715E
movq %r14, %rdi
movl $0x4, %edx
callq 0x9c6c
leaq 0x21559(%rip), %rsi     # 0x2b428
movl $0x13715e, %ecx         # imm = 0x13715E
movq %r14, %rdi
movl $0x4, %edx
callq 0x9c6c
leaq 0x2156a(%rip), %rsi     # 0x2b452
movl $0x1a409c, %ecx         # imm = 0x1A409C
movq %r14, %rdi
movl $0x4, %edx
callq 0x9c6c
leaq 0x2157a(%rip), %rsi     # 0x2b47b
movl $0x1a409c, %ecx         # imm = 0x1A409C
movq %r14, %rdi
movl $0x4, %edx
callq 0x9c6c
leaq 0x2158a(%rip), %rsi     # 0x2b4a4
movl $0x3a4dc9, %ecx         # imm = 0x3A4DC9
movq %r14, %rdi
movl $0x6, %edx
callq 0x9c6c
leaq 0x21593(%rip), %rsi     # 0x2b4c6
movl $0x3a4dc9, %ecx         # imm = 0x3A4DC9
movq %r14, %rdi
movl $0x6, %edx
callq 0x9c6c
leaq 0x2159c(%rip), %rsi     # 0x2b4e8
movl $0xf5472, %ecx          # imm = 0xF5472
movq %r14, %rdi
movl $0x5, %edx
callq 0x9c6c
leaq 0x215a7(%rip), %rsi     # 0x2b50c
movl $0xf5472, %ecx          # imm = 0xF5472
movq %r14, %rdi
movl $0x5, %edx
callq 0x9c6c
leaq 0x215b2(%rip), %rsi     # 0x2b530
movl $0x350fe, %ecx          # imm = 0x350FE
movq %r14, %rdi
movl $0x6, %edx
callq 0x9c6c
leaq 0x215b8(%rip), %rsi     # 0x2b54f
movl $0x350fe, %ecx          # imm = 0x350FE
movq %r14, %rdi
movl $0x6, %edx
callq 0x9c6c
leaq 0x215be(%rip), %rsi     # 0x2b56e
movl $0x16a0b, %ecx          # imm = 0x16A0B
movq %r14, %rdi
movl $0x6, %edx
callq 0x9c6c
leaq 0x215c3(%rip), %rsi     # 0x2b58c
movl $0x16a0b, %ecx          # imm = 0x16A0B
movq %r14, %rdi
movl $0x6, %edx
callq 0x9c6c
leaq 0x215c8(%rip), %rsi     # 0x2b5aa
movl $0x8a9, %ecx            # imm = 0x8A9
movq %r14, %rdi
movl $0x6, %edx
callq 0x9c6c
leaq 0x215cd(%rip), %rsi     # 0x2b5c8
movl $0x8a9, %ecx            # imm = 0x8A9
movq %r14, %rdi
movl $0x6, %edx
callq 0x9c6c
leaq 0x215d2(%rip), %rsi     # 0x2b5e6
movl $0x8a920, %ecx          # imm = 0x8A920
movq %r14, %rdi
movl $0x7, %edx
callq 0x9c6c
leaq 0x215d8(%rip), %rsi     # 0x2b605
movl $0x8a920, %ecx          # imm = 0x8A920
movq %r14, %rdi
movl $0x7, %edx
callq 0x9c6c
leaq 0x215de(%rip), %rsi     # 0x2b624
movl $0x5be7, %ecx           # imm = 0x5BE7
movq %r14, %rdi
movl $0x4, %edx
callq 0x9c6c
leaq 0x215e7(%rip), %rsi     # 0x2b646
movl $0x5be7, %ecx           # imm = 0x5BE7
movq %r14, %rdi
movl $0x4, %edx
callq 0x9c6c
callq 0xdf08
subl %ebx, %eax
incl %eax
movslq %eax, %rcx
movabsq $0xe22de30e8, %rax      # imm = 0xE22DE30E8
xorl %edx, %edx
divq %rcx
leaq 0x215d5(%rip), %rdi     # 0x2b668
movq %rax, %rsi
xorl %eax, %eax
callq 0x64b9
leaq 0x215d9(%rip), %rdi     # 0x2b67d
xorl %eax, %eax
callq 0x64b9
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r14
retq
nop