// File: /workspace/github_cpp_makefile_star2_O2/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 0x17584(%rip), %rsi     # 0x31b96
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdi
callq 0xa1b8
leaq 0x10(%rsp), %r14
pushq $0x1
popq %rcx
movq %r14, %rdi
movq %rbx, %rsi
movl %ecx, %edx
callq 0x7b3b
movq %rax, %rbx
subq %r14, %rax
cmpq $0x38, %rax
jne 0x1abbf
pushq $0x6
popq %rdi
pushq $0x13
popq %rsi
pushq $0xb
popq %rdx
callq 0x7284
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xdacb
testb %al, %al
je 0x1abde
pushq $0x6
popq %rdi
pushq $0x13
popq %rsi
pushq $0xc
popq %rdx
callq 0x7284
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xdacb
testb %al, %al
je 0x1abfd
pushq $0x6
popq %rdi
pushq $0x13
popq %rsi
pushq $0x14
popq %rdx
callq 0x7284
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xdacb
testb %al, %al
je 0x1ac1c
pushq $0x6
popq %rdi
pushq $0x13
popq %rsi
pushq $0x1c
popq %rdx
pushq $0x1
popq %rcx
callq 0x72a3
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xdacb
testb %al, %al
je 0x1ac3b
pushq $0x6
popq %rdi
pushq $0x13
popq %rsi
pushq $0x1b
popq %rdx
callq 0x7284
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xdacb
testb %al, %al
je 0x1ac5a
pushq $0x6
popq %rdi
pushq $0x13
popq %rsi
pushq $0x12
popq %rdx
callq 0x7284
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xdacb
testb %al, %al
je 0x1ac79
pushq $0x6
popq %rdi
pushq $0x13
popq %rsi
pushq $0xa
popq %rdx
callq 0x7284
leaq 0x10(%rsp), %r14
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0xdacb
testb %al, %al
je 0x1ac98
leaq 0x126c1(%rip), %rsi     # 0x2ce1f
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdi
callq 0xa1b8
pushq $0x1
popq %rcx
movq %r14, %rdi
movq %rbx, %rsi
movl %ecx, %edx
callq 0x7b3b
movq %rax, %rbx
subq %r14, %rax
cmpq $0x28, %rax
jne 0x1acb7
pushq $0x6
popq %rdi
pushq $0x3c
popq %rsi
pushq $0x35
popq %rdx
callq 0x7284
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xdacb
testb %al, %al
je 0x1acd6
pushq $0x6
popq %rdi
pushq $0x3c
popq %rsi
pushq $0x3d
popq %rdx
callq 0x7284
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xdacb
testb %al, %al
je 0x1acf5
pushq $0x6
popq %rdi
pushq $0x3c
popq %rsi
pushq $0x3b
popq %rdx
callq 0x7284
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xdacb
testb %al, %al
je 0x1ad14
pushq $0x6
popq %rdi
pushq $0x3c
popq %rsi
pushq $0x33
popq %rdx
pushq $0x4
popq %rcx
callq 0x72a3
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xdacb
testb %al, %al
je 0x1ad33
pushq $0x6
popq %rdi
pushq $0x3c
popq %rsi
pushq $0x3e
popq %rdx
callq 0x7284
leaq 0x8(%rsp), %r14
movq %rax, (%r14)
movq %r14, %rdi
callq 0x7366
movq (%r14), %rdi
leaq 0x10(%rsp), %r14
movq %r14, %rsi
movq %rbx, %rdx
callq 0xdacb
testb %al, %al
je 0x1ad52
leaq 0x175b9(%rip), %rsi     # 0x31e22
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdi
callq 0xa1b8
pushq $0x1
popq %rcx
movq %r14, %rdi
movq %rbx, %rsi
movl %ecx, %edx
callq 0x7b3b
movq %rax, %rbx
subq %r14, %rax
cmpq $0x18, %rax
jne 0x1ad71
pushq $0x6
popq %rdi
pushq $0x3f
popq %rsi
pushq $0x3e
popq %rdx
callq 0x7284
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xdacb
testb %al, %al
je 0x1ad90
pushq $0x6
popq %rdi
pushq $0x3f
popq %rsi
pushq $0x36
popq %rdx
callq 0x7284
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xdacb
testb %al, %al
je 0x1adaf
pushq $0x6
popq %rdi
pushq $0x3f
popq %rsi
pushq $0x37
popq %rdx
callq 0x7284
leaq 0x10(%rsp), %r14
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0xdacb
testb %al, %al
je 0x1adce
leaq 0x175c3(%rip), %rsi     # 0x31ed8
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdi
callq 0xa1b8
pushq $0x1
popq %rcx
movq %r14, %rdi
movq %rbx, %rsi
movl %ecx, %edx
callq 0x7b3b
movq %rax, %rbx
subq %r14, %rax
cmpq $0x18, %rax
jne 0x1aded
pushq $0x6
popq %rdi
pushq $0x8
popq %rdx
xorl %esi, %esi
callq 0x7284
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xdacb
testb %al, %al
je 0x1ae0c
pushq $0x6
popq %rdi
pushq $0x9
popq %rdx
xorl %esi, %esi
callq 0x7284
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xdacb
testb %al, %al
je 0x1ae2b
pushq $0x6
popq %rdi
pushq $0x1
popq %rdx
xorl %esi, %esi
callq 0x7284
leaq 0x10(%rsp), %r14
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0xdacb
testb %al, %al
je 0x1ae4a
leaq 0x175c0(%rip), %rsi     # 0x31f7e
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdi
callq 0xa1b8
pushq $0x1
popq %rcx
movq %r14, %rdi
movq %rbx, %rsi
movl %ecx, %edx
callq 0x7b3b
movq %rax, %rbx
subq %r14, %rax
cmpq $0x20, %rax
jne 0x1ae69
pushq $0x6
popq %rdi
pushq $0x3c
popq %rsi
pushq $0x3d
popq %rdx
callq 0x7284
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xdacb
testb %al, %al
je 0x1ae88
pushq $0x6
popq %rdi
pushq $0x3c
popq %rsi
pushq $0x35
popq %rdx
callq 0x7284
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xdacb
testb %al, %al
je 0x1aea7
pushq $0x6
popq %rdi
pushq $0x3c
popq %rsi
pushq $0x3b
popq %rdx
callq 0x7284
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xdacb
testb %al, %al
je 0x1aec6
pushq $0x6
popq %rdi
pushq $0x3c
popq %rsi
pushq $0x33
popq %rdx
callq 0x7284
leaq 0x10(%rsp), %r14
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0xdacb
testb %al, %al
je 0x1aee5
leaq 0x123ef(%rip), %rsi     # 0x2ce7f
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdi
callq 0xa1b8
pushq $0x1
popq %rcx
movq %r14, %rdi
movq %rbx, %rsi
movl %ecx, %edx
callq 0x7b3b
movq %rax, %rbx
subq %r14, %rax
cmpq $0x30, %rax
jne 0x1af04
pushq $0x6
popq %rdi
pushq $0x4
popq %rsi
pushq $0x5
popq %rdx
callq 0x7284
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xdacb
testb %al, %al
je 0x1af23
pushq $0x6
popq %rdi
pushq $0x4
popq %rsi
pushq $0xd
popq %rdx
callq 0x7284
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xdacb
testb %al, %al
je 0x1af42
pushq $0x6
popq %rdi
pushq $0x4
popq %rsi
pushq $0xc
popq %rdx
callq 0x7284
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xdacb
testb %al, %al
je 0x1af61
pushq $0x6
popq %rdi
pushq $0x4
popq %rsi
pushq $0xb
popq %rdx
callq 0x7284
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xdacb
testb %al, %al
je 0x1af80
pushq $0x6
popq %rdi
pushq $0x4
popq %rsi
pushq $0x3
popq %rdx
callq 0x7284
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xdacb
testb %al, %al
je 0x1af9f
pushq $0x6
popq %rdi
pushq $0x4
popq %rsi
pushq $0x2
popq %rdx
callq 0x7284
leaq 0x8(%rsp), %r14
movq %rax, (%r14)
movq %r14, %rdi
callq 0x7366
movq (%r14), %rdi
leaq 0x10(%rsp), %rsi
movq %rbx, %rdx
callq 0xdacb
testb %al, %al
je 0x1afbe
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r14
retq
leaq 0x16ff8(%rip), %rdi     # 0x31bbe
leaq 0x16244(%rip), %rsi     # 0x30e11
leaq 0x16ffc(%rip), %rcx     # 0x31bd0
movl $0x105, %edx            # imm = 0x105
callq 0x20c0
leaq 0x17006(%rip), %rdi     # 0x31beb
leaq 0x16225(%rip), %rsi     # 0x30e11
leaq 0x16fdd(%rip), %rcx     # 0x31bd0
movl $0x106, %edx            # imm = 0x106
callq 0x20c0
leaq 0x17015(%rip), %rdi     # 0x31c19
leaq 0x16206(%rip), %rsi     # 0x30e11
leaq 0x16fbe(%rip), %rcx     # 0x31bd0
movl $0x107, %edx            # imm = 0x107
callq 0x20c0
leaq 0x17024(%rip), %rdi     # 0x31c47
leaq 0x161e7(%rip), %rsi     # 0x30e11
leaq 0x16f9f(%rip), %rcx     # 0x31bd0
movl $0x108, %edx            # imm = 0x108
callq 0x20c0
leaq 0x17033(%rip), %rdi     # 0x31c75
leaq 0x161c8(%rip), %rsi     # 0x30e11
leaq 0x16f80(%rip), %rcx     # 0x31bd0
movl $0x109, %edx            # imm = 0x109
callq 0x20c0
leaq 0x1704a(%rip), %rdi     # 0x31cab
leaq 0x161a9(%rip), %rsi     # 0x30e11
leaq 0x16f61(%rip), %rcx     # 0x31bd0
movl $0x10a, %edx            # imm = 0x10A
callq 0x20c0
leaq 0x17059(%rip), %rdi     # 0x31cd9
leaq 0x1618a(%rip), %rsi     # 0x30e11
leaq 0x16f42(%rip), %rcx     # 0x31bd0
movl $0x10b, %edx            # imm = 0x10B
callq 0x20c0
leaq 0x17068(%rip), %rdi     # 0x31d07
leaq 0x1616b(%rip), %rsi     # 0x30e11
leaq 0x16f23(%rip), %rcx     # 0x31bd0
movl $0x10c, %edx            # imm = 0x10C
callq 0x20c0
leaq 0x17077(%rip), %rdi     # 0x31d35
leaq 0x1614c(%rip), %rsi     # 0x30e11
leaq 0x16f04(%rip), %rcx     # 0x31bd0
movl $0x111, %edx            # imm = 0x111
callq 0x20c0
leaq 0x17068(%rip), %rdi     # 0x31d45
leaq 0x1612d(%rip), %rsi     # 0x30e11
leaq 0x16ee5(%rip), %rcx     # 0x31bd0
movl $0x112, %edx            # imm = 0x112
callq 0x20c0
leaq 0x17077(%rip), %rdi     # 0x31d73
leaq 0x1610e(%rip), %rsi     # 0x30e11
leaq 0x16ec6(%rip), %rcx     # 0x31bd0
movl $0x113, %edx            # imm = 0x113
callq 0x20c0
leaq 0x17086(%rip), %rdi     # 0x31da1
leaq 0x160ef(%rip), %rsi     # 0x30e11
leaq 0x16ea7(%rip), %rcx     # 0x31bd0
movl $0x114, %edx            # imm = 0x114
callq 0x20c0
leaq 0x17095(%rip), %rdi     # 0x31dcf
leaq 0x160d0(%rip), %rsi     # 0x30e11
leaq 0x16e88(%rip), %rcx     # 0x31bd0
movl $0x115, %edx            # imm = 0x115
callq 0x20c0
leaq 0x170ac(%rip), %rdi     # 0x31e05
leaq 0x160b1(%rip), %rsi     # 0x30e11
leaq 0x16e69(%rip), %rcx     # 0x31bd0
movl $0x118, %edx            # imm = 0x118
callq 0x20c0
leaq 0x170c6(%rip), %rdi     # 0x31e3e
leaq 0x16092(%rip), %rsi     # 0x30e11
leaq 0x16e4a(%rip), %rcx     # 0x31bd0
movl $0x11d, %edx            # imm = 0x11D
callq 0x20c0
leaq 0x170b7(%rip), %rdi     # 0x31e4e
leaq 0x16073(%rip), %rsi     # 0x30e11
leaq 0x16e2b(%rip), %rcx     # 0x31bd0
movl $0x11e, %edx            # imm = 0x11E
callq 0x20c0
leaq 0x170c6(%rip), %rdi     # 0x31e7c
leaq 0x16054(%rip), %rsi     # 0x30e11
leaq 0x16e0c(%rip), %rcx     # 0x31bd0
movl $0x11f, %edx            # imm = 0x11F
callq 0x20c0
leaq 0x170d5(%rip), %rdi     # 0x31eaa
leaq 0x16035(%rip), %rsi     # 0x30e11
leaq 0x16ded(%rip), %rcx     # 0x31bd0
movl $0x120, %edx            # imm = 0x120
callq 0x20c0
leaq 0x1704a(%rip), %rdi     # 0x31e3e
leaq 0x16016(%rip), %rsi     # 0x30e11
leaq 0x16dce(%rip), %rcx     # 0x31bd0
movl $0x124, %edx            # imm = 0x124
callq 0x20c0
leaq 0x170e1(%rip), %rdi     # 0x31ef4
leaq 0x15ff7(%rip), %rsi     # 0x30e11
leaq 0x16daf(%rip), %rcx     # 0x31bd0
movl $0x125, %edx            # imm = 0x125
callq 0x20c0
leaq 0x170f0(%rip), %rdi     # 0x31f22
leaq 0x15fd8(%rip), %rsi     # 0x30e11
leaq 0x16d90(%rip), %rcx     # 0x31bd0
movl $0x126, %edx            # imm = 0x126
callq 0x20c0
leaq 0x170ff(%rip), %rdi     # 0x31f50
leaq 0x15fb9(%rip), %rsi     # 0x30e11
leaq 0x16d71(%rip), %rcx     # 0x31bd0
movl $0x127, %edx            # imm = 0x127
callq 0x20c0
leaq 0x17136(%rip), %rdi     # 0x31fa6
leaq 0x15f9a(%rip), %rsi     # 0x30e11
leaq 0x16d52(%rip), %rcx     # 0x31bd0
movl $0x12c, %edx            # imm = 0x12C
callq 0x20c0
leaq 0x16ee4(%rip), %rdi     # 0x31d73
leaq 0x15f7b(%rip), %rsi     # 0x30e11
leaq 0x16d33(%rip), %rcx     # 0x31bd0
movl $0x12d, %edx            # imm = 0x12D
callq 0x20c0
leaq 0x16e97(%rip), %rdi     # 0x31d45
leaq 0x15f5c(%rip), %rsi     # 0x30e11
leaq 0x16d14(%rip), %rcx     # 0x31bd0
movl $0x12f, %edx            # imm = 0x12F
callq 0x20c0
leaq 0x16ed4(%rip), %rdi     # 0x31da1
leaq 0x15f3d(%rip), %rsi     # 0x30e11
leaq 0x16cf5(%rip), %rcx     # 0x31bd0
movl $0x130, %edx            # imm = 0x130
callq 0x20c0
leaq 0x170ca(%rip), %rdi     # 0x31fb6
leaq 0x15f1e(%rip), %rsi     # 0x30e11
leaq 0x16cd6(%rip), %rcx     # 0x31bd0
movl $0x131, %edx            # imm = 0x131
callq 0x20c0
leaq 0x170d9(%rip), %rdi     # 0x31fe4
leaq 0x15eff(%rip), %rsi     # 0x30e11
leaq 0x16cb7(%rip), %rcx     # 0x31bd0
movl $0x137, %edx            # imm = 0x137
callq 0x20c0
leaq 0x170ca(%rip), %rdi     # 0x31ff4
leaq 0x15ee0(%rip), %rsi     # 0x30e11
leaq 0x16c98(%rip), %rcx     # 0x31bd0
movl $0x138, %edx            # imm = 0x138
callq 0x20c0
leaq 0x170d9(%rip), %rdi     # 0x32022
leaq 0x15ec1(%rip), %rsi     # 0x30e11
leaq 0x16c79(%rip), %rcx     # 0x31bd0
movl $0x139, %edx            # imm = 0x139
callq 0x20c0
leaq 0x170e8(%rip), %rdi     # 0x32050
leaq 0x15ea2(%rip), %rsi     # 0x30e11
leaq 0x16c5a(%rip), %rcx     # 0x31bd0
movl $0x13a, %edx            # imm = 0x13A
callq 0x20c0
leaq 0x170f7(%rip), %rdi     # 0x3207e
leaq 0x15e83(%rip), %rsi     # 0x30e11
leaq 0x16c3b(%rip), %rcx     # 0x31bd0
movl $0x13b, %edx            # imm = 0x13B
callq 0x20c0
leaq 0x17106(%rip), %rdi     # 0x320ac
leaq 0x15e64(%rip), %rsi     # 0x30e11
leaq 0x16c1c(%rip), %rcx     # 0x31bd0
movl $0x13c, %edx            # imm = 0x13C
callq 0x20c0
leaq 0x16e40(%rip), %rdi     # 0x31e05
leaq 0x15e45(%rip), %rsi     # 0x30e11
leaq 0x16bfd(%rip), %rcx     # 0x31bd0
movl $0x13f, %edx            # imm = 0x13F
callq 0x20c0