// File: /workspace/github_cpp_makefile_star2_O1/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 0x1787b(%rip), %rsi     # 0x33a53
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdi
callq 0xaa74
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x8018
movq %rax, %rbx
subq %r14, %rax
cmpq $0x38, %rax
jne 0x1c849
movl $0x6, %edi
movl $0x13, %esi
movl $0xb, %edx
callq 0x76b8
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe727
testb %al, %al
je 0x1c868
movl $0x6, %edi
movl $0x13, %esi
movl $0xc, %edx
callq 0x76b8
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe727
testb %al, %al
je 0x1c887
movl $0x6, %edi
movl $0x13, %esi
movl $0x14, %edx
callq 0x76b8
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe727
testb %al, %al
je 0x1c8a6
movl $0x6, %edi
movl $0x13, %esi
movl $0x1c, %edx
movl $0x1, %ecx
callq 0x76d7
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe727
testb %al, %al
je 0x1c8c5
movl $0x6, %edi
movl $0x13, %esi
movl $0x1b, %edx
callq 0x76b8
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe727
testb %al, %al
je 0x1c8e4
movl $0x6, %edi
movl $0x13, %esi
movl $0x12, %edx
callq 0x76b8
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe727
testb %al, %al
je 0x1c903
movl $0x6, %edi
movl $0x13, %esi
movl $0xa, %edx
callq 0x76b8
leaq 0x10(%rsp), %r14
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0xe727
testb %al, %al
je 0x1c922
leaq 0x12a9a(%rip), %rsi     # 0x2edef
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdi
callq 0xaa74
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x8018
movq %rax, %rbx
subq %r14, %rax
cmpq $0x28, %rax
jne 0x1c941
movl $0x6, %edi
movl $0x3c, %esi
movl $0x35, %edx
callq 0x76b8
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe727
testb %al, %al
je 0x1c960
movl $0x6, %edi
movl $0x3c, %esi
movl $0x3d, %edx
callq 0x76b8
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe727
testb %al, %al
je 0x1c97f
movl $0x6, %edi
movl $0x3c, %esi
movl $0x3b, %edx
callq 0x76b8
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe727
testb %al, %al
je 0x1c99e
movl $0x6, %edi
movl $0x3c, %esi
movl $0x33, %edx
movl $0x4, %ecx
callq 0x76d7
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe727
testb %al, %al
je 0x1c9bd
movl $0x6, %edi
movl $0x3c, %esi
movl $0x3e, %edx
callq 0x76b8
leaq 0x8(%rsp), %r14
movq %rax, (%r14)
movq %r14, %rdi
callq 0x77ab
movq (%r14), %rdi
leaq 0x10(%rsp), %r14
movq %r14, %rsi
movq %rbx, %rdx
callq 0xe727
testb %al, %al
je 0x1c9dc
leaq 0x1785a(%rip), %rsi     # 0x33cdf
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdi
callq 0xaa74
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x8018
movq %rax, %rbx
subq %r14, %rax
cmpq $0x18, %rax
jne 0x1c9fb
movl $0x6, %edi
movl $0x3f, %esi
movl $0x3e, %edx
callq 0x76b8
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe727
testb %al, %al
je 0x1ca1a
movl $0x6, %edi
movl $0x3f, %esi
movl $0x36, %edx
callq 0x76b8
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe727
testb %al, %al
je 0x1ca39
movl $0x6, %edi
movl $0x3f, %esi
movl $0x37, %edx
callq 0x76b8
leaq 0x10(%rsp), %r14
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0xe727
testb %al, %al
je 0x1ca58
leaq 0x1784d(%rip), %rsi     # 0x33d95
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdi
callq 0xaa74
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x8018
movq %rax, %rbx
subq %r14, %rax
cmpq $0x18, %rax
jne 0x1ca77
movl $0x6, %edi
xorl %esi, %esi
movl $0x8, %edx
callq 0x76b8
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe727
testb %al, %al
je 0x1ca96
movl $0x6, %edi
xorl %esi, %esi
movl $0x9, %edx
callq 0x76b8
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe727
testb %al, %al
je 0x1cab5
movl $0x6, %edi
xorl %esi, %esi
movl $0x1, %edx
callq 0x76b8
leaq 0x10(%rsp), %r14
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0xe727
testb %al, %al
je 0x1cad4
leaq 0x17839(%rip), %rsi     # 0x33e3b
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdi
callq 0xaa74
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x8018
movq %rax, %rbx
subq %r14, %rax
cmpq $0x20, %rax
jne 0x1caf3
movl $0x6, %edi
movl $0x3c, %esi
movl $0x3d, %edx
callq 0x76b8
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe727
testb %al, %al
je 0x1cb12
movl $0x6, %edi
movl $0x3c, %esi
movl $0x35, %edx
callq 0x76b8
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe727
testb %al, %al
je 0x1cb31
movl $0x6, %edi
movl $0x3c, %esi
movl $0x3b, %edx
callq 0x76b8
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe727
testb %al, %al
je 0x1cb50
movl $0x6, %edi
movl $0x3c, %esi
movl $0x33, %edx
callq 0x76b8
leaq 0x10(%rsp), %r14
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0xe727
testb %al, %al
je 0x1cb6f
leaq 0x1275e(%rip), %rsi     # 0x2ee4f
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdi
callq 0xaa74
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x8018
movq %rax, %rbx
subq %r14, %rax
cmpq $0x30, %rax
jne 0x1cb8e
movl $0x6, %edi
movl $0x4, %esi
movl $0x5, %edx
callq 0x76b8
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe727
testb %al, %al
je 0x1cbad
movl $0x6, %edi
movl $0x4, %esi
movl $0xd, %edx
callq 0x76b8
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe727
testb %al, %al
je 0x1cbcc
movl $0x6, %edi
movl $0x4, %esi
movl $0xc, %edx
callq 0x76b8
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe727
testb %al, %al
je 0x1cbeb
movl $0x6, %edi
movl $0x4, %esi
movl $0xb, %edx
callq 0x76b8
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe727
testb %al, %al
je 0x1cc0a
movl $0x6, %edi
movl $0x4, %esi
movl $0x3, %edx
callq 0x76b8
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xe727
testb %al, %al
je 0x1cc29
movl $0x6, %edi
movl $0x4, %esi
movl $0x2, %edx
callq 0x76b8
leaq 0x8(%rsp), %r14
movq %rax, (%r14)
movq %r14, %rdi
callq 0x77ab
movq (%r14), %rdi
leaq 0x10(%rsp), %rsi
movq %rbx, %rdx
callq 0xe727
testb %al, %al
je 0x1cc48
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r14
retq
leaq 0x1722b(%rip), %rdi     # 0x33a7b
leaq 0x16477(%rip), %rsi     # 0x32cce
leaq 0x1722f(%rip), %rcx     # 0x33a8d
movl $0x105, %edx            # imm = 0x105
callq 0x20d0
leaq 0x17239(%rip), %rdi     # 0x33aa8
leaq 0x16458(%rip), %rsi     # 0x32cce
leaq 0x17210(%rip), %rcx     # 0x33a8d
movl $0x106, %edx            # imm = 0x106
callq 0x20d0
leaq 0x17248(%rip), %rdi     # 0x33ad6
leaq 0x16439(%rip), %rsi     # 0x32cce
leaq 0x171f1(%rip), %rcx     # 0x33a8d
movl $0x107, %edx            # imm = 0x107
callq 0x20d0
leaq 0x17257(%rip), %rdi     # 0x33b04
leaq 0x1641a(%rip), %rsi     # 0x32cce
leaq 0x171d2(%rip), %rcx     # 0x33a8d
movl $0x108, %edx            # imm = 0x108
callq 0x20d0
leaq 0x17266(%rip), %rdi     # 0x33b32
leaq 0x163fb(%rip), %rsi     # 0x32cce
leaq 0x171b3(%rip), %rcx     # 0x33a8d
movl $0x109, %edx            # imm = 0x109
callq 0x20d0
leaq 0x1727d(%rip), %rdi     # 0x33b68
leaq 0x163dc(%rip), %rsi     # 0x32cce
leaq 0x17194(%rip), %rcx     # 0x33a8d
movl $0x10a, %edx            # imm = 0x10A
callq 0x20d0
leaq 0x1728c(%rip), %rdi     # 0x33b96
leaq 0x163bd(%rip), %rsi     # 0x32cce
leaq 0x17175(%rip), %rcx     # 0x33a8d
movl $0x10b, %edx            # imm = 0x10B
callq 0x20d0
leaq 0x1729b(%rip), %rdi     # 0x33bc4
leaq 0x1639e(%rip), %rsi     # 0x32cce
leaq 0x17156(%rip), %rcx     # 0x33a8d
movl $0x10c, %edx            # imm = 0x10C
callq 0x20d0
leaq 0x172aa(%rip), %rdi     # 0x33bf2
leaq 0x1637f(%rip), %rsi     # 0x32cce
leaq 0x17137(%rip), %rcx     # 0x33a8d
movl $0x111, %edx            # imm = 0x111
callq 0x20d0
leaq 0x1729b(%rip), %rdi     # 0x33c02
leaq 0x16360(%rip), %rsi     # 0x32cce
leaq 0x17118(%rip), %rcx     # 0x33a8d
movl $0x112, %edx            # imm = 0x112
callq 0x20d0
leaq 0x172aa(%rip), %rdi     # 0x33c30
leaq 0x16341(%rip), %rsi     # 0x32cce
leaq 0x170f9(%rip), %rcx     # 0x33a8d
movl $0x113, %edx            # imm = 0x113
callq 0x20d0
leaq 0x172b9(%rip), %rdi     # 0x33c5e
leaq 0x16322(%rip), %rsi     # 0x32cce
leaq 0x170da(%rip), %rcx     # 0x33a8d
movl $0x114, %edx            # imm = 0x114
callq 0x20d0
leaq 0x172c8(%rip), %rdi     # 0x33c8c
leaq 0x16303(%rip), %rsi     # 0x32cce
leaq 0x170bb(%rip), %rcx     # 0x33a8d
movl $0x115, %edx            # imm = 0x115
callq 0x20d0
leaq 0x172df(%rip), %rdi     # 0x33cc2
leaq 0x162e4(%rip), %rsi     # 0x32cce
leaq 0x1709c(%rip), %rcx     # 0x33a8d
movl $0x118, %edx            # imm = 0x118
callq 0x20d0
leaq 0x172f9(%rip), %rdi     # 0x33cfb
leaq 0x162c5(%rip), %rsi     # 0x32cce
leaq 0x1707d(%rip), %rcx     # 0x33a8d
movl $0x11d, %edx            # imm = 0x11D
callq 0x20d0
leaq 0x172ea(%rip), %rdi     # 0x33d0b
leaq 0x162a6(%rip), %rsi     # 0x32cce
leaq 0x1705e(%rip), %rcx     # 0x33a8d
movl $0x11e, %edx            # imm = 0x11E
callq 0x20d0
leaq 0x172f9(%rip), %rdi     # 0x33d39
leaq 0x16287(%rip), %rsi     # 0x32cce
leaq 0x1703f(%rip), %rcx     # 0x33a8d
movl $0x11f, %edx            # imm = 0x11F
callq 0x20d0
leaq 0x17308(%rip), %rdi     # 0x33d67
leaq 0x16268(%rip), %rsi     # 0x32cce
leaq 0x17020(%rip), %rcx     # 0x33a8d
movl $0x120, %edx            # imm = 0x120
callq 0x20d0
leaq 0x1727d(%rip), %rdi     # 0x33cfb
leaq 0x16249(%rip), %rsi     # 0x32cce
leaq 0x17001(%rip), %rcx     # 0x33a8d
movl $0x124, %edx            # imm = 0x124
callq 0x20d0
leaq 0x17314(%rip), %rdi     # 0x33db1
leaq 0x1622a(%rip), %rsi     # 0x32cce
leaq 0x16fe2(%rip), %rcx     # 0x33a8d
movl $0x125, %edx            # imm = 0x125
callq 0x20d0
leaq 0x17323(%rip), %rdi     # 0x33ddf
leaq 0x1620b(%rip), %rsi     # 0x32cce
leaq 0x16fc3(%rip), %rcx     # 0x33a8d
movl $0x126, %edx            # imm = 0x126
callq 0x20d0
leaq 0x17332(%rip), %rdi     # 0x33e0d
leaq 0x161ec(%rip), %rsi     # 0x32cce
leaq 0x16fa4(%rip), %rcx     # 0x33a8d
movl $0x127, %edx            # imm = 0x127
callq 0x20d0
leaq 0x17369(%rip), %rdi     # 0x33e63
leaq 0x161cd(%rip), %rsi     # 0x32cce
leaq 0x16f85(%rip), %rcx     # 0x33a8d
movl $0x12c, %edx            # imm = 0x12C
callq 0x20d0
leaq 0x17117(%rip), %rdi     # 0x33c30
leaq 0x161ae(%rip), %rsi     # 0x32cce
leaq 0x16f66(%rip), %rcx     # 0x33a8d
movl $0x12d, %edx            # imm = 0x12D
callq 0x20d0
leaq 0x170ca(%rip), %rdi     # 0x33c02
leaq 0x1618f(%rip), %rsi     # 0x32cce
leaq 0x16f47(%rip), %rcx     # 0x33a8d
movl $0x12f, %edx            # imm = 0x12F
callq 0x20d0
leaq 0x17107(%rip), %rdi     # 0x33c5e
leaq 0x16170(%rip), %rsi     # 0x32cce
leaq 0x16f28(%rip), %rcx     # 0x33a8d
movl $0x130, %edx            # imm = 0x130
callq 0x20d0
leaq 0x172fd(%rip), %rdi     # 0x33e73
leaq 0x16151(%rip), %rsi     # 0x32cce
leaq 0x16f09(%rip), %rcx     # 0x33a8d
movl $0x131, %edx            # imm = 0x131
callq 0x20d0
leaq 0x1730c(%rip), %rdi     # 0x33ea1
leaq 0x16132(%rip), %rsi     # 0x32cce
leaq 0x16eea(%rip), %rcx     # 0x33a8d
movl $0x137, %edx            # imm = 0x137
callq 0x20d0
leaq 0x172fd(%rip), %rdi     # 0x33eb1
leaq 0x16113(%rip), %rsi     # 0x32cce
leaq 0x16ecb(%rip), %rcx     # 0x33a8d
movl $0x138, %edx            # imm = 0x138
callq 0x20d0
leaq 0x1730c(%rip), %rdi     # 0x33edf
leaq 0x160f4(%rip), %rsi     # 0x32cce
leaq 0x16eac(%rip), %rcx     # 0x33a8d
movl $0x139, %edx            # imm = 0x139
callq 0x20d0
leaq 0x1731b(%rip), %rdi     # 0x33f0d
leaq 0x160d5(%rip), %rsi     # 0x32cce
leaq 0x16e8d(%rip), %rcx     # 0x33a8d
movl $0x13a, %edx            # imm = 0x13A
callq 0x20d0
leaq 0x1732a(%rip), %rdi     # 0x33f3b
leaq 0x160b6(%rip), %rsi     # 0x32cce
leaq 0x16e6e(%rip), %rcx     # 0x33a8d
movl $0x13b, %edx            # imm = 0x13B
callq 0x20d0
leaq 0x17339(%rip), %rdi     # 0x33f69
leaq 0x16097(%rip), %rsi     # 0x32cce
leaq 0x16e4f(%rip), %rcx     # 0x33a8d
movl $0x13c, %edx            # imm = 0x13C
callq 0x20d0
leaq 0x17073(%rip), %rdi     # 0x33cc2
leaq 0x16078(%rip), %rsi     # 0x32cce
leaq 0x16e30(%rip), %rcx     # 0x33a8d
movl $0x13f, %edx            # imm = 0x13F
callq 0x20d0