// File: /workspace/github_cpp_makefile_star2_O1/jswaff[P]prophet3/src/pos.cpp
// Function: add_piece(position*, int, square_t)
void add_piece(position* p,int32 piece,square_t sq) {
    assert(piece != NO_PIECE);
    assert(sq >= 0 && sq < 64);
    assert(p->piece[sq]==NO_PIECE);

    p->piece[sq] = piece;
    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]++;
        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]++;
        p->hash_key ^= zkeys.pieces[-piece][BLACK][sq];
    }
}

// Assembly:
pushq %rax
testl %esi, %esi
je 0xa775
cmpl $0x40, %edx
jae 0xa794
movl %edx, %eax
cmpl $0x0, (%rdi,%rax,4)
jne 0xa7b3
movl %esi, (%rdi,%rax,4)
leaq 0xefe4b(%rip), %rcx     # 0xfa4b0
movq (%rcx,%rax,8), %rcx
testl %esi, %esi
jle 0xa6ab
orq %rcx, 0x1a8(%rdi)
leal -0x1(%rsi), %edx
cmpl $0x4, %edx
ja 0xa6f9
leaq 0x20fd1(%rip), %r8      # 0x2b654
movslq (%r8,%rdx,4), %rdx
addq %r8, %rdx
jmpq *%rdx
orq %rcx, 0x158(%rdi)
leaq 0xedefe(%rip), %rcx     # 0xf8598
movq 0x600(%rcx,%rax,8), %rcx
xorq %rcx, 0x1c0(%rdi)
jmp 0xa6f9
orq %rcx, 0x1b0(%rdi)
leal 0x5(%rsi), %edx
cmpl $0x4, %edx
ja 0xa751
leaq 0x20f7b(%rip), %r8      # 0x2b640
movslq (%r8,%rdx,4), %rdx
addq %r8, %rdx
jmpq *%rdx
orq %rcx, 0x1a0(%rdi)
jmp 0xa751
orq %rcx, 0x198(%rdi)
jmp 0xa6f9
orq %rcx, 0x178(%rdi)
jmp 0xa6f9
orq %rcx, 0x188(%rdi)
jmp 0xa6f9
orq %rcx, 0x168(%rdi)
movl %esi, %ecx
incl 0x11c(%rdi,%rcx,4)
shlq $0xa, %rcx
addq 0x3788b(%rip), %rcx     # 0x41f98
leaq (%rcx,%rax,8), %rax
addq $0x200, %rax            # imm = 0x200
jmp 0xa769
orq %rcx, 0x160(%rdi)
leaq 0xede71(%rip), %rcx     # 0xf8598
movq 0x400(%rcx,%rax,8), %rcx
xorq %rcx, 0x1c0(%rdi)
jmp 0xa751
orq %rcx, 0x180(%rdi)
jmp 0xa751
orq %rcx, 0x170(%rdi)
jmp 0xa751
orq %rcx, 0x190(%rdi)
negl %esi
incl 0x100(%rdi,%rsi,4)
shlq $0xa, %rsi
addq 0x37833(%rip), %rsi     # 0x41f98
leaq (%rsi,%rax,8), %rax
movq (%rax), %rax
xorq %rax, 0x1b8(%rdi)
popq %rax
retq
leaq 0x201f5(%rip), %rdi     # 0x2a971
leaq 0x2108e(%rip), %rsi     # 0x2b811
leaq 0x214ef(%rip), %rcx     # 0x2bc79
movl $0x51, %edx
callq 0x20d0
leaq 0x2150a(%rip), %rdi     # 0x2bca5
leaq 0x2106f(%rip), %rsi     # 0x2b811
leaq 0x214d0(%rip), %rcx     # 0x2bc79
movl $0x52, %edx
callq 0x20d0
leaq 0x214fe(%rip), %rdi     # 0x2bcb8
leaq 0x21050(%rip), %rsi     # 0x2b811
leaq 0x214b1(%rip), %rcx     # 0x2bc79
movl $0x53, %edx
callq 0x20d0