// File: SethKasmann[P]clever-girl/src/move_generator.cpp
// Function: void MoveList::pushCastle<(MoveType)4>()
void MoveList::pushCastle()
{
    Square k = mState.getKingSquare(mState.getOurColor());

    if (mState.canCastleKingside() &&
        !(between_hor[k][k-3] & mState.getOccupancyBB()) &&
        !mState.attacked(k-1) && 
        !mState.attacked(k-2)) 
    {
        if (T == MoveType::QuietChecks)
        {
            if (square_bb[k-1] & mState.getCheckSquaresBB(rook))
                push(makeCastle(k, k-2));
        }
        else
            push(makeCastle(k, k-2));
    }

    if (mState.canCastleQueenside() && 
        !(between_hor[k][k+4] & mState.getOccupancyBB()) && 
        !mState.attacked(k+1) && 
        !mState.attacked(k+2))
    {
        if (T == MoveType::QuietChecks)
        {
            if (square_bb[k+1] & mState.getCheckSquaresBB(rook))
                push(makeCastle(k, k+2));
        }
        else
            push(makeCastle(k, k+2));
    }
}

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x70(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x18(%rax), %rcx
movq %rcx, 0x58(%rsp)
movq 0x18(%rax), %rdi
callq 0x24ca0
movq 0x58(%rsp), %rdi
movl %eax, %esi
callq 0x24ea0
movl %eax, %ecx
movq 0x60(%rsp), %rax
movl %ecx, 0x6c(%rsp)
movq 0x18(%rax), %rdi
callq 0x2b1c0
testb $0x1, %al
jne 0x2afde
jmp 0x2b0c0
movl 0x6c(%rsp), %eax
movl %eax, %ecx
leaq 0x132d25(%rip), %rax    # 0x15dd10
shlq $0x9, %rcx
addq %rcx, %rax
movq %rax, 0x48(%rsp)
movl 0x6c(%rsp), %edi
movl $0x3, %esi
callq 0x24e80
movq 0x48(%rsp), %rcx
movl %eax, %edx
movq 0x60(%rsp), %rax
movl %edx, %edx
movq (%rcx,%rdx,8), %rcx
movq %rcx, 0x50(%rsp)
movq 0x18(%rax), %rdi
callq 0x24bc0
movq %rax, %rcx
movq 0x50(%rsp), %rax
andq %rcx, %rax
cmpq $0x0, %rax
jne 0x2b0c0
movq 0x60(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x40(%rsp)
movl 0x6c(%rsp), %edi
movl $0x1, %esi
callq 0x24e80
movq 0x40(%rsp), %rdi
movl %eax, %esi
callq 0x2b210
testb $0x1, %al
jne 0x2b0c0
movq 0x60(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x38(%rsp)
movl 0x6c(%rsp), %edi
movl $0x2, %esi
callq 0x24e80
movq 0x38(%rsp), %rdi
movl %eax, %esi
callq 0x2b210
testb $0x1, %al
jne 0x2b0c0
movl 0x6c(%rsp), %eax
movl %eax, 0x34(%rsp)
movl 0x6c(%rsp), %edi
movl $0x2, %esi
callq 0x24e80
movl 0x34(%rsp), %edi
movl %eax, %esi
callq 0x2b350
movq 0x60(%rsp), %rdi
movzwl %ax, %esi
callq 0x26df0
movq 0x60(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x2b380
testb $0x1, %al
jne 0x2b0d7
jmp 0x2b1b9
movl 0x6c(%rsp), %eax
movl %eax, %ecx
leaq 0x132c2c(%rip), %rax    # 0x15dd10
shlq $0x9, %rcx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movl 0x6c(%rsp), %edi
movl $0x4, %esi
callq 0x24e60
movq 0x20(%rsp), %rcx
movl %eax, %edx
movq 0x60(%rsp), %rax
movl %edx, %edx
movq (%rcx,%rdx,8), %rcx
movq %rcx, 0x28(%rsp)
movq 0x18(%rax), %rdi
callq 0x24bc0
movq %rax, %rcx
movq 0x28(%rsp), %rax
andq %rcx, %rax
cmpq $0x0, %rax
jne 0x2b1b9
movq 0x60(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x18(%rsp)
movl 0x6c(%rsp), %edi
movl $0x1, %esi
callq 0x24e60
movq 0x18(%rsp), %rdi
movl %eax, %esi
callq 0x2b210
testb $0x1, %al
jne 0x2b1b9
movq 0x60(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x10(%rsp)
movl 0x6c(%rsp), %edi
movl $0x2, %esi
callq 0x24e60
movq 0x10(%rsp), %rdi
movl %eax, %esi
callq 0x2b210
testb $0x1, %al
jne 0x2b1b9
movl 0x6c(%rsp), %eax
movl %eax, 0xc(%rsp)
movl 0x6c(%rsp), %edi
movl $0x2, %esi
callq 0x24e60
movl 0xc(%rsp), %edi
movl %eax, %esi
callq 0x2b350
movq 0x60(%rsp), %rdi
movzwl %ax, %esi
callq 0x26df0
addq $0x78, %rsp
retq
nop