// File: /workspace/github_cpp_makefile_star2_O3/jswaff[P]prophet3/test/movegen__test.cpp
// Function: test_gen_king_moves()
void test_gen_king_moves() {
    position pos;

    set_pos(&pos,"8/8/3k4/2n1P3/8/8/3rP3/R3K2R b KQ - 0 1");
    move moves[20];
    move *mp = gen_king_moves(moves,&pos,true,true);
    assert((mp - moves) == 7);
    assert(is_in_move_list(to_move(KING,D6,D7),moves,mp));
    assert(is_in_move_list(to_move(KING,D6,E7),moves,mp));
    assert(is_in_move_list(to_move(KING,D6,E6),moves,mp));
    assert(is_in_move_list(to_capture(KING,D6,E5,PAWN),moves,mp));
    assert(is_in_move_list(to_move(KING,D6,D5),moves,mp));
    assert(is_in_move_list(to_move(KING,D6,C6),moves,mp));
    assert(is_in_move_list(to_move(KING,D6,C7),moves,mp));

    // flip sides
    set_pos(&pos,"8/8/3k4/2n1P3/8/8/3rP3/RN2K2R w KQ - 0 1");
    mp = gen_king_moves(moves,&pos,true,true);
    assert((mp - moves)==5);
    assert(is_in_move_list(to_move(KING,E1,F2),moves,mp));
    assert(is_in_move_list(to_move(KING,E1,F1),moves,mp));
    assert(is_in_move_list(to_move(KING,E1,D1),moves,mp)); // NOTE: illegal move
    assert(is_in_move_list(to_capture(KING,E1,D2,ROOK),moves,mp));
    move mv = to_move(KING,E1,G1);
    set_castle(&mv);
    assert(is_in_move_list(mv,moves,mp));

    // move to a corner
    set_pos(&pos,"k7/8/8/8/8/8/8/7K w - - 0 1");
    mp = gen_king_moves(moves,&pos,true,true);
    assert((mp - moves)==3);
    assert(is_in_move_list(to_move(KING,H1,G1),moves,mp));
    assert(is_in_move_list(to_move(KING,H1,G2),moves,mp));
    assert(is_in_move_list(to_move(KING,H1,H2),moves,mp));

    set_pos(&pos,"k7/8/8/8/8/8/8/7K b - - 0 1");
    mp = gen_king_moves(moves,&pos,true,true);
    assert((mp - moves)==3);
    assert(is_in_move_list(to_move(KING,A8,A7),moves,mp));
    assert(is_in_move_list(to_move(KING,A8,B7),moves,mp));
    assert(is_in_move_list(to_move(KING,A8,B8),moves,mp));

    // cannot castle while in check
    set_pos(&pos,"3k4/8/8/2N1P3/7q/8/4P3/R3K2R w KQ - 0 1");
    mp = gen_king_moves(moves,&pos,true,true);
    assert((mp - moves)==4);
    assert(is_in_move_list(to_move(KING,E1,F1),moves,mp));
    // e1f2 stays in check, but that's handled separately.
    assert(is_in_move_list(to_move(KING,E1,F2),moves,mp));
    assert(is_in_move_list(to_move(KING,E1,D1),moves,mp));
    assert(is_in_move_list(to_move(KING,E1,D2),moves,mp));


    // cannot castle if king will passed through attacked square
    set_pos(&pos,"r3k2r/8/8/8/8/5Q2/8/4K3 b kq - 0 1");
    mp = gen_king_moves(moves,&pos,true,true);
    assert((mp - moves)==6);
    assert(is_in_move_list(to_move(KING,E8,F8),moves,mp));
    assert(is_in_move_list(to_move(KING,E8,F7),moves,mp));
    assert(is_in_move_list(to_move(KING,E8,E7),moves,mp));
    assert(is_in_move_list(to_move(KING,E8,D7),moves,mp));
    assert(is_in_move_list(to_move(KING,E8,D8),moves,mp));
    mv = to_move(KING,E8,C8);
    set_castle(&mv);
    assert(is_in_move_list(mv,moves,mp)); // queenside ok, not kingside
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x278, %rsp            # imm = 0x278
leaq 0x17a6f(%rip), %rsi     # 0x33ad3
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdi
callq 0xaa82
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x80aa
movq %rax, %rbx
subq %r14, %rax
cmpq $0x38, %rax
jne 0x1c6d5
movl $0x6, %edi
movl $0x13, %esi
movl $0xb, %edx
callq 0x775c
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe682
testb %al, %al
je 0x1c6f4
movl $0x6, %edi
movl $0x13, %esi
movl $0xc, %edx
callq 0x775c
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe682
testb %al, %al
je 0x1c713
movl $0x6, %edi
movl $0x13, %esi
movl $0x14, %edx
callq 0x775c
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe682
testb %al, %al
je 0x1c732
movl $0x6, %edi
movl $0x13, %esi
movl $0x1c, %edx
movl $0x1, %ecx
callq 0x777b
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe682
testb %al, %al
je 0x1c751
movl $0x6, %edi
movl $0x13, %esi
movl $0x1b, %edx
callq 0x775c
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe682
testb %al, %al
je 0x1c770
movl $0x6, %edi
movl $0x13, %esi
movl $0x12, %edx
callq 0x775c
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe682
testb %al, %al
je 0x1c78f
movl $0x6, %edi
movl $0x13, %esi
movl $0xa, %edx
callq 0x775c
leaq 0x10(%rsp), %r14
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0xe682
testb %al, %al
je 0x1c7ae
leaq 0x12c8e(%rip), %rsi     # 0x2ee6f
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdi
callq 0xaa82
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x80aa
movq %rax, %rbx
subq %r14, %rax
cmpq $0x28, %rax
jne 0x1c7cd
movl $0x6, %edi
movl $0x3c, %esi
movl $0x35, %edx
callq 0x775c
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe682
testb %al, %al
je 0x1c7ec
movl $0x6, %edi
movl $0x3c, %esi
movl $0x3d, %edx
callq 0x775c
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe682
testb %al, %al
je 0x1c80b
movl $0x6, %edi
movl $0x3c, %esi
movl $0x3b, %edx
callq 0x775c
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe682
testb %al, %al
je 0x1c82a
movl $0x6, %edi
movl $0x3c, %esi
movl $0x33, %edx
movl $0x4, %ecx
callq 0x777b
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe682
testb %al, %al
je 0x1c849
movl $0x6, %edi
movl $0x3c, %esi
movl $0x3e, %edx
callq 0x775c
leaq 0x8(%rsp), %r14
movq %rax, (%r14)
movq %r14, %rdi
callq 0x784f
movq (%r14), %rdi
leaq 0x10(%rsp), %r14
movq %r14, %rsi
movq %rbx, %rdx
callq 0xe682
testb %al, %al
je 0x1c868
leaq 0x17a4e(%rip), %rsi     # 0x33d5f
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdi
callq 0xaa82
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x80aa
movq %rax, %rbx
subq %r14, %rax
cmpq $0x18, %rax
jne 0x1c887
movl $0x6, %edi
movl $0x3f, %esi
movl $0x3e, %edx
callq 0x775c
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe682
testb %al, %al
je 0x1c8a6
movl $0x6, %edi
movl $0x3f, %esi
movl $0x36, %edx
callq 0x775c
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe682
testb %al, %al
je 0x1c8c5
movl $0x6, %edi
movl $0x3f, %esi
movl $0x37, %edx
callq 0x775c
leaq 0x10(%rsp), %r14
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0xe682
testb %al, %al
je 0x1c8e4
leaq 0x17a41(%rip), %rsi     # 0x33e15
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdi
callq 0xaa82
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x80aa
movq %rax, %rbx
subq %r14, %rax
cmpq $0x18, %rax
jne 0x1c903
movl $0x6, %edi
xorl %esi, %esi
movl $0x8, %edx
callq 0x775c
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe682
testb %al, %al
je 0x1c922
movl $0x6, %edi
xorl %esi, %esi
movl $0x9, %edx
callq 0x775c
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe682
testb %al, %al
je 0x1c941
movl $0x6, %edi
xorl %esi, %esi
movl $0x1, %edx
callq 0x775c
leaq 0x10(%rsp), %r14
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0xe682
testb %al, %al
je 0x1c960
leaq 0x17a2d(%rip), %rsi     # 0x33ebb
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdi
callq 0xaa82
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x80aa
movq %rax, %rbx
subq %r14, %rax
cmpq $0x20, %rax
jne 0x1c97f
movl $0x6, %edi
movl $0x3c, %esi
movl $0x3d, %edx
callq 0x775c
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe682
testb %al, %al
je 0x1c99e
movl $0x6, %edi
movl $0x3c, %esi
movl $0x35, %edx
callq 0x775c
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe682
testb %al, %al
je 0x1c9bd
movl $0x6, %edi
movl $0x3c, %esi
movl $0x3b, %edx
callq 0x775c
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe682
testb %al, %al
je 0x1c9dc
movl $0x6, %edi
movl $0x3c, %esi
movl $0x33, %edx
callq 0x775c
leaq 0x10(%rsp), %r14
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0xe682
testb %al, %al
je 0x1c9fb
leaq 0x12952(%rip), %rsi     # 0x2eecf
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdi
callq 0xaa82
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x80aa
movq %rax, %rbx
subq %r14, %rax
cmpq $0x30, %rax
jne 0x1ca1a
movl $0x6, %edi
movl $0x4, %esi
movl $0x5, %edx
callq 0x775c
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe682
testb %al, %al
je 0x1ca39
movl $0x6, %edi
movl $0x4, %esi
movl $0xd, %edx
callq 0x775c
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe682
testb %al, %al
je 0x1ca58
movl $0x6, %edi
movl $0x4, %esi
movl $0xc, %edx
callq 0x775c
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe682
testb %al, %al
je 0x1ca77
movl $0x6, %edi
movl $0x4, %esi
movl $0xb, %edx
callq 0x775c
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe682
testb %al, %al
je 0x1ca96
movl $0x6, %edi
movl $0x4, %esi
movl $0x3, %edx
callq 0x775c
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe682
testb %al, %al
je 0x1cab5
movl $0x6, %edi
movl $0x4, %esi
movl $0x2, %edx
callq 0x775c
leaq 0x8(%rsp), %r14
movq %rax, (%r14)
movq %r14, %rdi
callq 0x784f
movq (%r14), %rdi
leaq 0x10(%rsp), %rsi
movq %rbx, %rdx
callq 0xe682
testb %al, %al
je 0x1cad4
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r14
retq
leaq 0x1741f(%rip), %rdi     # 0x33afb
leaq 0x1666b(%rip), %rsi     # 0x32d4e
leaq 0x17423(%rip), %rcx     # 0x33b0d
movl $0x105, %edx            # imm = 0x105
callq 0x20d0
leaq 0x1742d(%rip), %rdi     # 0x33b28
leaq 0x1664c(%rip), %rsi     # 0x32d4e
leaq 0x17404(%rip), %rcx     # 0x33b0d
movl $0x106, %edx            # imm = 0x106
callq 0x20d0
leaq 0x1743c(%rip), %rdi     # 0x33b56
leaq 0x1662d(%rip), %rsi     # 0x32d4e
leaq 0x173e5(%rip), %rcx     # 0x33b0d
movl $0x107, %edx            # imm = 0x107
callq 0x20d0
leaq 0x1744b(%rip), %rdi     # 0x33b84
leaq 0x1660e(%rip), %rsi     # 0x32d4e
leaq 0x173c6(%rip), %rcx     # 0x33b0d
movl $0x108, %edx            # imm = 0x108
callq 0x20d0
leaq 0x1745a(%rip), %rdi     # 0x33bb2
leaq 0x165ef(%rip), %rsi     # 0x32d4e
leaq 0x173a7(%rip), %rcx     # 0x33b0d
movl $0x109, %edx            # imm = 0x109
callq 0x20d0
leaq 0x17471(%rip), %rdi     # 0x33be8
leaq 0x165d0(%rip), %rsi     # 0x32d4e
leaq 0x17388(%rip), %rcx     # 0x33b0d
movl $0x10a, %edx            # imm = 0x10A
callq 0x20d0
leaq 0x17480(%rip), %rdi     # 0x33c16
leaq 0x165b1(%rip), %rsi     # 0x32d4e
leaq 0x17369(%rip), %rcx     # 0x33b0d
movl $0x10b, %edx            # imm = 0x10B
callq 0x20d0
leaq 0x1748f(%rip), %rdi     # 0x33c44
leaq 0x16592(%rip), %rsi     # 0x32d4e
leaq 0x1734a(%rip), %rcx     # 0x33b0d
movl $0x10c, %edx            # imm = 0x10C
callq 0x20d0
leaq 0x1749e(%rip), %rdi     # 0x33c72
leaq 0x16573(%rip), %rsi     # 0x32d4e
leaq 0x1732b(%rip), %rcx     # 0x33b0d
movl $0x111, %edx            # imm = 0x111
callq 0x20d0
leaq 0x1748f(%rip), %rdi     # 0x33c82
leaq 0x16554(%rip), %rsi     # 0x32d4e
leaq 0x1730c(%rip), %rcx     # 0x33b0d
movl $0x112, %edx            # imm = 0x112
callq 0x20d0
leaq 0x1749e(%rip), %rdi     # 0x33cb0
leaq 0x16535(%rip), %rsi     # 0x32d4e
leaq 0x172ed(%rip), %rcx     # 0x33b0d
movl $0x113, %edx            # imm = 0x113
callq 0x20d0
leaq 0x174ad(%rip), %rdi     # 0x33cde
leaq 0x16516(%rip), %rsi     # 0x32d4e
leaq 0x172ce(%rip), %rcx     # 0x33b0d
movl $0x114, %edx            # imm = 0x114
callq 0x20d0
leaq 0x174bc(%rip), %rdi     # 0x33d0c
leaq 0x164f7(%rip), %rsi     # 0x32d4e
leaq 0x172af(%rip), %rcx     # 0x33b0d
movl $0x115, %edx            # imm = 0x115
callq 0x20d0
leaq 0x174d3(%rip), %rdi     # 0x33d42
leaq 0x164d8(%rip), %rsi     # 0x32d4e
leaq 0x17290(%rip), %rcx     # 0x33b0d
movl $0x118, %edx            # imm = 0x118
callq 0x20d0
leaq 0x174ed(%rip), %rdi     # 0x33d7b
leaq 0x164b9(%rip), %rsi     # 0x32d4e
leaq 0x17271(%rip), %rcx     # 0x33b0d
movl $0x11d, %edx            # imm = 0x11D
callq 0x20d0
leaq 0x174de(%rip), %rdi     # 0x33d8b
leaq 0x1649a(%rip), %rsi     # 0x32d4e
leaq 0x17252(%rip), %rcx     # 0x33b0d
movl $0x11e, %edx            # imm = 0x11E
callq 0x20d0
leaq 0x174ed(%rip), %rdi     # 0x33db9
leaq 0x1647b(%rip), %rsi     # 0x32d4e
leaq 0x17233(%rip), %rcx     # 0x33b0d
movl $0x11f, %edx            # imm = 0x11F
callq 0x20d0
leaq 0x174fc(%rip), %rdi     # 0x33de7
leaq 0x1645c(%rip), %rsi     # 0x32d4e
leaq 0x17214(%rip), %rcx     # 0x33b0d
movl $0x120, %edx            # imm = 0x120
callq 0x20d0
leaq 0x17471(%rip), %rdi     # 0x33d7b
leaq 0x1643d(%rip), %rsi     # 0x32d4e
leaq 0x171f5(%rip), %rcx     # 0x33b0d
movl $0x124, %edx            # imm = 0x124
callq 0x20d0
leaq 0x17508(%rip), %rdi     # 0x33e31
leaq 0x1641e(%rip), %rsi     # 0x32d4e
leaq 0x171d6(%rip), %rcx     # 0x33b0d
movl $0x125, %edx            # imm = 0x125
callq 0x20d0
leaq 0x17517(%rip), %rdi     # 0x33e5f
leaq 0x163ff(%rip), %rsi     # 0x32d4e
leaq 0x171b7(%rip), %rcx     # 0x33b0d
movl $0x126, %edx            # imm = 0x126
callq 0x20d0
leaq 0x17526(%rip), %rdi     # 0x33e8d
leaq 0x163e0(%rip), %rsi     # 0x32d4e
leaq 0x17198(%rip), %rcx     # 0x33b0d
movl $0x127, %edx            # imm = 0x127
callq 0x20d0
leaq 0x1755d(%rip), %rdi     # 0x33ee3
leaq 0x163c1(%rip), %rsi     # 0x32d4e
leaq 0x17179(%rip), %rcx     # 0x33b0d
movl $0x12c, %edx            # imm = 0x12C
callq 0x20d0
leaq 0x1730b(%rip), %rdi     # 0x33cb0
leaq 0x163a2(%rip), %rsi     # 0x32d4e
leaq 0x1715a(%rip), %rcx     # 0x33b0d
movl $0x12d, %edx            # imm = 0x12D
callq 0x20d0
leaq 0x172be(%rip), %rdi     # 0x33c82
leaq 0x16383(%rip), %rsi     # 0x32d4e
leaq 0x1713b(%rip), %rcx     # 0x33b0d
movl $0x12f, %edx            # imm = 0x12F
callq 0x20d0
leaq 0x172fb(%rip), %rdi     # 0x33cde
leaq 0x16364(%rip), %rsi     # 0x32d4e
leaq 0x1711c(%rip), %rcx     # 0x33b0d
movl $0x130, %edx            # imm = 0x130
callq 0x20d0
leaq 0x174f1(%rip), %rdi     # 0x33ef3
leaq 0x16345(%rip), %rsi     # 0x32d4e
leaq 0x170fd(%rip), %rcx     # 0x33b0d
movl $0x131, %edx            # imm = 0x131
callq 0x20d0
leaq 0x17500(%rip), %rdi     # 0x33f21
leaq 0x16326(%rip), %rsi     # 0x32d4e
leaq 0x170de(%rip), %rcx     # 0x33b0d
movl $0x137, %edx            # imm = 0x137
callq 0x20d0
leaq 0x174f1(%rip), %rdi     # 0x33f31
leaq 0x16307(%rip), %rsi     # 0x32d4e
leaq 0x170bf(%rip), %rcx     # 0x33b0d
movl $0x138, %edx            # imm = 0x138
callq 0x20d0
leaq 0x17500(%rip), %rdi     # 0x33f5f
leaq 0x162e8(%rip), %rsi     # 0x32d4e
leaq 0x170a0(%rip), %rcx     # 0x33b0d
movl $0x139, %edx            # imm = 0x139
callq 0x20d0
leaq 0x1750f(%rip), %rdi     # 0x33f8d
leaq 0x162c9(%rip), %rsi     # 0x32d4e
leaq 0x17081(%rip), %rcx     # 0x33b0d
movl $0x13a, %edx            # imm = 0x13A
callq 0x20d0
leaq 0x1751e(%rip), %rdi     # 0x33fbb
leaq 0x162aa(%rip), %rsi     # 0x32d4e
leaq 0x17062(%rip), %rcx     # 0x33b0d
movl $0x13b, %edx            # imm = 0x13B
callq 0x20d0
leaq 0x1752d(%rip), %rdi     # 0x33fe9
leaq 0x1628b(%rip), %rsi     # 0x32d4e
leaq 0x17043(%rip), %rcx     # 0x33b0d
movl $0x13c, %edx            # imm = 0x13C
callq 0x20d0
leaq 0x17267(%rip), %rdi     # 0x33d42
leaq 0x1626c(%rip), %rsi     # 0x32d4e
leaq 0x17024(%rip), %rcx     # 0x33b0d
movl $0x13f, %edx            # imm = 0x13F
callq 0x20d0