// File: /workspace/github_cpp_makefile_star2_O1/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 0xa909
cmpl $0x40, %esi
jae 0xa928
movl %esi, %ecx
movl (%rdi,%rcx,4), %eax
testq %rax, %rax
je 0xa947
leaq 0xefcb6(%rip), %rdx     # 0xfa4b0
movq (%rdx,%rcx,8), %rdx
testl %eax, %eax
jle 0xa83e
xorq %rdx, 0x1a8(%rdi)
leal -0x1(%rax), %esi
cmpl $0x4, %esi
ja 0xa886
leaq 0x20e64(%rip), %r8      # 0x2b67c
movslq (%r8,%rsi,4), %rsi
addq %r8, %rsi
jmpq *%rsi
xorq %rdx, 0x158(%rdi)
leaq 0xedd69(%rip), %rdx     # 0xf8598
movq 0x600(%rdx,%rcx,8), %rdx
movl $0x1c0, %esi            # imm = 0x1C0
jmp 0xa882
xorq %rdx, 0x1b0(%rdi)
leal 0x5(%rax), %esi
cmpl $0x4, %esi
ja 0xa8dc
leaq 0x20e10(%rip), %r8      # 0x2b668
movslq (%r8,%rsi,4), %rsi
addq %r8, %rsi
jmpq *%rsi
movl $0x1a0, %esi            # imm = 0x1A0
jmp 0xa8d8
movl $0x198, %esi            # imm = 0x198
jmp 0xa882
movl $0x178, %esi            # imm = 0x178
jmp 0xa882
movl $0x188, %esi            # imm = 0x188
jmp 0xa882
movl $0x168, %esi            # imm = 0x168
xorq %rdx, (%rdi,%rsi)
decl 0x11c(%rdi,%rax,4)
movq %rax, %rdx
shlq $0xa, %rdx
addq 0x376fd(%rip), %rdx     # 0x41f98
leaq (%rdx,%rcx,8), %rdx
addq $0x200, %rdx            # imm = 0x200
jmp 0xa8f6
xorq %rdx, 0x160(%rdi)
leaq 0xedce2(%rip), %rdx     # 0xf8598
movq 0x400(%rdx,%rcx,8), %rdx
movl $0x1c0, %esi            # imm = 0x1C0
jmp 0xa8d8
movl $0x180, %esi            # imm = 0x180
jmp 0xa8d8
movl $0x170, %esi            # imm = 0x170
jmp 0xa8d8
movl $0x190, %esi            # imm = 0x190
xorq %rdx, (%rdi,%rsi)
movl %eax, %edx
negl %edx
decl 0x100(%rdi,%rdx,4)
shlq $0xa, %rdx
addq 0x376a6(%rip), %rdx     # 0x41f98
leaq (%rdx,%rcx,8), %rdx
movq (%rdx), %rdx
xorq %rdx, 0x1b8(%rdi)
movl $0x0, (%rdi,%rcx,4)
popq %rcx
retq
leaq 0x213bf(%rip), %rdi     # 0x2bccf
leaq 0x20efa(%rip), %rsi     # 0x2b811
leaq 0x213b8(%rip), %rcx     # 0x2bcd6
movl $0x7b, %edx
callq 0x20d0
leaq 0x1e8df(%rip), %rdi     # 0x2920e
leaq 0x20edb(%rip), %rsi     # 0x2b811
leaq 0x21399(%rip), %rcx     # 0x2bcd6
movl $0x7c, %edx
callq 0x20d0
leaq 0x213b3(%rip), %rdi     # 0x2bd01
leaq 0x20ebc(%rip), %rsi     # 0x2b811
leaq 0x2137a(%rip), %rcx     # 0x2bcd6
movl $0x7d, %edx
callq 0x20d0