// File: /workspace/github_cpp_makefile_star2_O2/jswaff[P]prophet3/src/pos.cpp
// Function: remove_piece(position*, square_t)
piece_t remove_piece(position* p,square_t sq) {
    assert(p != 0);
    assert(sq >= A8 && sq <= H1);
    assert(p->piece[sq] != NO_PIECE);

    int piece = p->piece[sq];
    uint64 bb_sq = bb_squares[sq];
    if (piece > NO_PIECE) {
        p->white_pieces ^= bb_sq;
        if (piece==PAWN) {
            p->white_pawns ^= bb_sq;
            p->pawn_key ^= zkeys.pieces[PAWN][WHITE][sq];
        } else if (piece==KNIGHT) {
            p->white_knights ^= bb_sq;
        } else if (piece==BISHOP) {
            p->white_bishops ^= bb_sq;
        } else if (piece==ROOK) {
            p->white_rooks ^= bb_sq;
        } else if (piece==QUEEN) {
            p->white_queens ^= bb_sq;
        }
        p->piece_counts[WHITE][piece]--;
        assert(p->piece_counts[WHITE][piece] >= 0);
        p->hash_key ^= zkeys.pieces[piece][WHITE][sq];
    } else {
        p->black_pieces ^= bb_sq;
        if (piece==-PAWN) {
            p->black_pawns ^= bb_sq;
            p->pawn_key ^= zkeys.pieces[PAWN][BLACK][sq];
        } else if (piece==-KNIGHT) {
            p->black_knights ^= bb_sq;
        } else if (piece==-BISHOP) {
            p->black_bishops ^= bb_sq;
        } else if (piece==-ROOK) {
            p->black_rooks ^= bb_sq;
        } else if (piece==-QUEEN) {
            p->black_queens ^= bb_sq;
        }
        p->piece_counts[BLACK][-piece]--;
        assert(p->piece_counts[BLACK][-piece] >= 0);
        p->hash_key ^= zkeys.pieces[-piece][BLACK][sq];
    }

    p->piece[sq] = NO_PIECE;
    return (piece_t)piece;
}

// Assembly:
pushq %rax
testq %rdi, %rdi
je 0xa06b
cmpl $0x40, %esi
jae 0xa084
movl %esi, %ecx
movl (%rdi,%rcx,4), %eax
testq %rax, %rax
je 0xa09d
leaq 0xf3551(%rip), %rdx     # 0xfd4b0
movq (%rdx,%rcx,8), %rdx
testl %eax, %eax
jle 0x9fa3
xorq %rdx, 0x1a8(%rdi)
leal -0x1(%rax), %esi
cmpl $0x4, %esi
ja 0x9feb
leaq 0x1f72f(%rip), %r8      # 0x296ac
movslq (%r8,%rsi,4), %rsi
addq %r8, %rsi
jmpq *%rsi
xorq %rdx, 0x158(%rdi)
leaq 0xf1604(%rip), %rdx     # 0xfb598
movq 0x600(%rdx,%rcx,8), %rdx
movl $0x1c0, %esi            # imm = 0x1C0
jmp 0x9fe7
xorq %rdx, 0x1b0(%rdi)
leal 0x5(%rax), %esi
cmpl $0x4, %esi
ja 0xa041
leaq 0x1f6db(%rip), %r8      # 0x29698
movslq (%r8,%rsi,4), %rsi
addq %r8, %rsi
jmpq *%rsi
movl $0x1a0, %esi            # imm = 0x1A0
jmp 0xa03d
movl $0x198, %esi            # imm = 0x198
jmp 0x9fe7
movl $0x178, %esi            # imm = 0x178
jmp 0x9fe7
movl $0x188, %esi            # imm = 0x188
jmp 0x9fe7
movl $0x168, %esi            # imm = 0x168
xorq %rdx, (%rdi,%rsi)
decl 0x11c(%rdi,%rax,4)
movq %rax, %rdx
shlq $0xa, %rdx
addq 0x3af98(%rip), %rdx     # 0x44f98
leaq (%rdx,%rcx,8), %rdx
addq $0x200, %rdx            # imm = 0x200
jmp 0xa05b
xorq %rdx, 0x160(%rdi)
leaq 0xf157d(%rip), %rdx     # 0xfb598
movq 0x400(%rdx,%rcx,8), %rdx
movl $0x1c0, %esi            # imm = 0x1C0
jmp 0xa03d
movl $0x180, %esi            # imm = 0x180
jmp 0xa03d
movl $0x170, %esi            # imm = 0x170
jmp 0xa03d
movl $0x190, %esi            # imm = 0x190
xorq %rdx, (%rdi,%rsi)
movl %eax, %edx
negl %edx
decl 0x100(%rdi,%rdx,4)
shlq $0xa, %rdx
addq 0x3af41(%rip), %rdx     # 0x44f98
leaq (%rdx,%rcx,8), %rdx
movq (%rdx), %rdx
xorq %rdx, 0x1b8(%rdi)
andl $0x0, (%rdi,%rcx,4)
popq %rcx
retq
leaq 0x1fc8d(%rip), %rdi     # 0x29cff
leaq 0x1f7c8(%rip), %rsi     # 0x29841
leaq 0x1fc86(%rip), %rcx     # 0x29d06
pushq $0x7b
jmp 0xa0b4
leaq 0x1d183(%rip), %rdi     # 0x2720e
leaq 0x1f7af(%rip), %rsi     # 0x29841
leaq 0x1fc6d(%rip), %rcx     # 0x29d06
pushq $0x7c
jmp 0xa0b4
leaq 0x1fc8d(%rip), %rdi     # 0x29d31
leaq 0x1f796(%rip), %rsi     # 0x29841
leaq 0x1fc54(%rip), %rcx     # 0x29d06
pushq $0x7d
popq %rdx
callq 0x20c0