// File: SethKasmann[P]clever-girl/src/state.cpp
// Function: State::make_t(unsigned short)
void State::make_t(Move pMove)
{
    assert(pMove != nullMove);
    assert(getSrc(pMove) < no_sq);
    assert(getDst(pMove) < no_sq);
    Square src, dst;
    PieceType moved, captured;
    bool epFlag = false;
    bool gamePhase = false;


    src = getSrc(pMove);
    dst = getDst(pMove);
    moved = onSquare(src);
    assert(moved != none);
    captured = onSquare(dst);
    assert(captured != king);

    // Update the Fifty Move Rule
    mFiftyMoveRule++;

    // Remove the ep file and castle rights from the zobrist key.
    if (mEnPassant)
        mKey ^= Zobrist::key(get_file(mEnPassant));

    mKey ^= Zobrist::key(mCastleRights);

    if (captured != none && !isCastle(pMove))
    {
        mFiftyMoveRule = 0;
        removePiece(mThem, captured, dst);
        if (captured == pawn)
            mPawnKey ^= Zobrist::key(mThem, pawn, dst);
        gamePhase = true;
    }

    if (isCastle(pMove))
    {
        // Kingside Castle
        if (dst < src)
        {
            movePiece(mUs, rook, src-3, dst+1);
            movePiece(mUs, king, src, dst);
        }
        // Queenside Castle
        else
        {
            movePiece(mUs, rook, src+4, dst-1);
            movePiece(mUs, king, src, dst);
        }
    }
    else
        movePiece(mUs, moved, src, dst);

    if (moved == pawn)
    {
        mFiftyMoveRule = 0;
        mPawnKey ^= Zobrist::key(mUs, pawn, src, dst);

        // Check for double pawn push.
        if (int(std::max(src, dst)) - int(std::min(src, dst)) == 16)
        {
            mEnPassant = mUs == white ? square_bb[dst - 8]
                                      : square_bb[dst + 8];

            mKey ^= Zobrist::key(get_file(mEnPassant));
            epFlag = true;
        }
        else if (getPiecePromo(pMove))
        {
            mPawnKey ^= Zobrist::key(mUs, pawn, dst);
            removePiece(mUs, pawn, dst);
            addPiece(mUs, getPiecePromo(pMove), dst);
            gamePhase = true;
        }
        else if (mEnPassant & square_bb[dst])
        {
            Square epCapture = (mUs == white) ? dst - 8 : dst + 8;
            mPawnKey ^= Zobrist::key(mThem, pawn, epCapture);
            removePiece(mThem, pawn, epCapture);
            gamePhase = true;
        }
    }

    if (!epFlag)
        mEnPassant = 0;

    if (gamePhase)
        setGamePhase();

    // Update castle rights.
    mCastleRights &= Castle_rights[src];
    mCastleRights &= Castle_rights[dst];

    mKey ^= Zobrist::key(mCastleRights);

    assert(!check());
    assert((mEnPassant & getOccupancyBB()) == 0);
    swapTurn();

    setPins(white);
    setPins(black);
    setCheckers();
}

// Assembly:
subq $0x58, %rsp
movw %si, %ax
movq %rdi, 0x50(%rsp)
movw %ax, 0x4e(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x28(%rsp)
movb $0x0, 0x3b(%rsp)
movb $0x0, 0x3a(%rsp)
movzwl 0x4e(%rsp), %edi
callq 0x26810
movl %eax, 0x48(%rsp)
movzwl 0x4e(%rsp), %edi
callq 0x26830
movq 0x28(%rsp), %rdi
movl %eax, 0x44(%rsp)
movl 0x48(%rsp), %esi
callq 0x29bd0
movq 0x28(%rsp), %rdi
movl %eax, 0x40(%rsp)
movl 0x44(%rsp), %esi
callq 0x29bd0
movl %eax, %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0x3c(%rsp)
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
cmpq $0x0, 0x30(%rax)
je 0x383e1
movq 0x28(%rsp), %rax
movq 0x30(%rax), %rdi
callq 0x39b20
movl %eax, %edi
callq 0x39b00
movq %rax, %rcx
movq 0x28(%rsp), %rax
xorq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
movq 0x28(%rsp), %rax
movl 0xc(%rax), %edi
callq 0x39ae0
movq %rax, %rcx
movq 0x28(%rsp), %rax
xorq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
cmpl $0x6, 0x3c(%rsp)
je 0x3845e
movzwl 0x4e(%rsp), %edi
callq 0x3a1d0
testb $0x1, %al
jne 0x3845e
movq 0x28(%rsp), %rdi
movl $0x0, 0x8(%rdi)
movl 0x4(%rdi), %esi
movl 0x3c(%rsp), %edx
movl 0x44(%rsp), %ecx
callq 0x3ac00
cmpl $0x0, 0x3c(%rsp)
jne 0x38459
movq 0x28(%rsp), %rax
movl 0x4(%rax), %edi
movl 0x44(%rsp), %edx
xorl %esi, %esi
callq 0x39a70
movq %rax, %rcx
movq 0x28(%rsp), %rax
xorq 0x20(%rax), %rcx
movq %rcx, 0x20(%rax)
movb $0x1, 0x3a(%rsp)
movzwl 0x4e(%rsp), %edi
callq 0x3a1d0
testb $0x1, %al
jne 0x38471
jmp 0x3853d
movl 0x44(%rsp), %eax
cmpl 0x48(%rsp), %eax
jae 0x384dc
movq 0x28(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x20(%rsp)
movl 0x48(%rsp), %edi
movl $0x3, %esi
callq 0x24e80
movl %eax, 0x24(%rsp)
movl 0x44(%rsp), %edi
movl $0x1, %esi
callq 0x24e60
movl 0x20(%rsp), %esi
movl 0x24(%rsp), %ecx
movq 0x28(%rsp), %rdi
movl %eax, %r8d
movl $0x3, %edx
callq 0x3aeb0
movq 0x28(%rsp), %rdi
movl (%rdi), %esi
movl 0x48(%rsp), %ecx
movl 0x44(%rsp), %r8d
movl $0x5, %edx
callq 0x3aeb0
jmp 0x3853b
movq 0x28(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x18(%rsp)
movl 0x48(%rsp), %edi
movl $0x4, %esi
callq 0x24e60
movl %eax, 0x1c(%rsp)
movl 0x44(%rsp), %edi
movl $0x1, %esi
callq 0x24e80
movl 0x18(%rsp), %esi
movl 0x1c(%rsp), %ecx
movq 0x28(%rsp), %rdi
movl %eax, %r8d
movl $0x3, %edx
callq 0x3aeb0
movq 0x28(%rsp), %rdi
movl (%rdi), %esi
movl 0x48(%rsp), %ecx
movl 0x44(%rsp), %r8d
movl $0x5, %edx
callq 0x3aeb0
jmp 0x38556
movq 0x28(%rsp), %rdi
movl (%rdi), %esi
movl 0x40(%rsp), %edx
movl 0x48(%rsp), %ecx
movl 0x44(%rsp), %r8d
callq 0x3aeb0
cmpl $0x0, 0x40(%rsp)
jne 0x38748
movq 0x28(%rsp), %rax
movl $0x0, 0x8(%rax)
movl (%rax), %edi
movl 0x48(%rsp), %edx
movl 0x44(%rsp), %ecx
xorl %esi, %esi
callq 0x3b180
movq %rax, %rcx
movq 0x28(%rsp), %rax
xorq 0x20(%rax), %rcx
movq %rcx, 0x20(%rax)
leaq 0x48(%rsp), %rdi
leaq 0x44(%rsp), %rsi
callq 0x3b1f0
movl (%rax), %eax
movl %eax, 0x14(%rsp)
leaq 0x48(%rsp), %rdi
leaq 0x44(%rsp), %rsi
callq 0x3b230
movq %rax, %rcx
movl 0x14(%rsp), %eax
subl (%rcx), %eax
cmpl $0x10, %eax
jne 0x3864c
movq 0x28(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x385f2
movl 0x44(%rsp), %edi
movl $0x8, %esi
callq 0x24e80
movl %eax, %eax
movl %eax, %ecx
leaq 0x11c529(%rip), %rax    # 0x154b10
movq (%rax,%rcx,8), %rax
movq %rax, 0x8(%rsp)
jmp 0x38614
movl 0x44(%rsp), %edi
movl $0x8, %esi
callq 0x24e60
movl %eax, %eax
movl %eax, %ecx
leaq 0x11c505(%rip), %rax    # 0x154b10
movq (%rax,%rcx,8), %rax
movq %rax, 0x8(%rsp)
movq 0x28(%rsp), %rax
movq 0x8(%rsp), %rcx
movq %rcx, 0x30(%rax)
movq 0x30(%rax), %rdi
callq 0x39b20
movl %eax, %edi
callq 0x39b00
movq %rax, %rcx
movq 0x28(%rsp), %rax
xorq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
movb $0x1, 0x3b(%rsp)
jmp 0x38746
movzwl 0x4e(%rsp), %edi
callq 0x268e0
cmpl $0x0, %eax
je 0x386ba
movq 0x28(%rsp), %rax
movl (%rax), %edi
movl 0x44(%rsp), %edx
xorl %esi, %esi
callq 0x39a70
movq 0x28(%rsp), %rdi
xorq 0x20(%rdi), %rax
movq %rax, 0x20(%rdi)
movl (%rdi), %esi
movl 0x44(%rsp), %ecx
xorl %edx, %edx
callq 0x3ac00
movq 0x28(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x4(%rsp)
movzwl 0x4e(%rsp), %edi
callq 0x268e0
movq 0x28(%rsp), %rdi
movl 0x4(%rsp), %esi
movl %eax, %edx
movl 0x44(%rsp), %ecx
callq 0x39850
movb $0x1, 0x3a(%rsp)
jmp 0x38744
movq 0x28(%rsp), %rax
movq 0x30(%rax), %rax
movl 0x44(%rsp), %ecx
movl %ecx, %edx
leaq 0x11c440(%rip), %rcx    # 0x154b10
andq (%rcx,%rdx,8), %rax
cmpq $0x0, %rax
je 0x38742
movq 0x28(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x386f7
movl 0x44(%rsp), %edi
movl $0x8, %esi
callq 0x24e80
movl %eax, (%rsp)
jmp 0x38708
movl 0x44(%rsp), %edi
movl $0x8, %esi
callq 0x24e60
movl %eax, (%rsp)
movq 0x28(%rsp), %rax
movl (%rsp), %ecx
movl %ecx, 0x34(%rsp)
movl 0x4(%rax), %edi
movl 0x34(%rsp), %edx
xorl %esi, %esi
callq 0x39a70
movq 0x28(%rsp), %rdi
xorq 0x20(%rdi), %rax
movq %rax, 0x20(%rdi)
movl 0x4(%rdi), %esi
movl 0x34(%rsp), %ecx
xorl %edx, %edx
callq 0x3ac00
movb $0x1, 0x3a(%rsp)
jmp 0x38744
jmp 0x38746
jmp 0x38748
testb $0x1, 0x3b(%rsp)
jne 0x3875c
movq 0x28(%rsp), %rax
movq $0x0, 0x30(%rax)
testb $0x1, 0x3a(%rsp)
je 0x3876d
movq 0x28(%rsp), %rdi
callq 0x39cc0
movq 0x28(%rsp), %rax
movl 0x48(%rsp), %ecx
movl %ecx, %edx
leaq 0xad01(%rip), %rcx      # 0x43480
movl (%rcx,%rdx,4), %ecx
andl 0xc(%rax), %ecx
movl %ecx, 0xc(%rax)
movl 0x44(%rsp), %ecx
movl %ecx, %edx
leaq 0xaceb(%rip), %rcx      # 0x43480
movl (%rcx,%rdx,4), %ecx
andl 0xc(%rax), %ecx
movl %ecx, 0xc(%rax)
movl 0xc(%rax), %edi
callq 0x39ae0
movq 0x28(%rsp), %rdi
xorq 0x18(%rdi), %rax
movq %rax, 0x18(%rdi)
callq 0x3b270
movq 0x28(%rsp), %rdi
xorl %esi, %esi
callq 0x36bf0
movq 0x28(%rsp), %rdi
movl $0x1, %esi
callq 0x36bf0
movq 0x28(%rsp), %rdi
callq 0x39b40
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)