// File: /workspace/github_cpp_makefile_star2_O1/jswaff[P]prophet3/src/apply.cpp
// Function: add_piece_to_destination(position*, unsigned long long)
void add_piece_to_destination(position* p,move m) {
    square_t from_sq=get_from_sq(m),to_sq=get_to_sq(m);
    int32 piece = p->piece[from_sq];
    add_piece(p,piece,to_sq);
    switch (piece) {
    case PAWN:
        p->fifty_counter=0;
        if (to_sq==north(north(from_sq))) {
            p->ep_sq=north(from_sq);
        } else if (get_rank(to_sq)==RANK_8) {
            assert(get_promopiece(m) != NO_PIECE);
            remove_piece(p,to_sq);
            add_piece(p,get_promopiece(m),to_sq);
        }
        break;
    case -PAWN:
        p->fifty_counter=0;
        if (to_sq==south(south(from_sq))) {
            p->ep_sq=south(from_sq);
        } else if (get_rank(to_sq)==RANK_1) {
            assert(get_promopiece(m) != NO_PIECE);
            remove_piece(p,to_sq);
            add_piece(p,-get_promopiece(m),to_sq);
        }
        break;
    case KING:
        p->white_king=to_sq;
        // move rook if this is a castle
        if (from_sq==E1) {
            if (to_sq==G1) {
                assert(is_castle(m));
                p->fifty_counter=0;
                remove_piece(p,H1);
                add_piece(p,ROOK,F1);
            } else if (to_sq==C1) {
                assert(is_castle(m));
                p->fifty_counter=0;
                remove_piece(p,A1);
                add_piece(p,ROOK,D1);
            }
        }
        break;
    case -KING:
        p->black_king=to_sq;
        if (from_sq==E8) {
            if (to_sq==G8) {
                assert(is_castle(m));
                p->fifty_counter=0;
                remove_piece(p,H8);
                add_piece(p,-ROOK,F8);
            } else if (to_sq==C8) {
                assert(is_castle(m));
                p->fifty_counter=0;
                remove_piece(p,A8);
                add_piece(p,-ROOK,D8);
            }
        }
        break;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x77b0
movl %eax, %r15d
movq %r14, %rdi
callq 0x77b7
movl %eax, %ebp
movl %r15d, %eax
movl (%rbx,%rax,4), %r12d
movq %rbx, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0xa63d
testl %r12d, %r12d
jg 0x2e4a
cmpl $-0x6, %r12d
je 0x2e92
cmpl $-0x1, %r12d
jne 0x2f81
movl $0x0, 0x148(%rbx)
movl %r15d, %edi
callq 0xcc4a
movl %eax, %edi
callq 0xcc4a
cmpl %eax, %ebp
jne 0x2f44
movl %r15d, %edi
callq 0xcc4a
jmp 0x2e87
cmpl $0x6, %r12d
je 0x2eed
cmpl $0x1, %r12d
jne 0x2f81
movl $0x0, 0x148(%rbx)
movl %r15d, %edi
callq 0xcc11
movl %eax, %edi
callq 0xcc11
cmpl %eax, %ebp
jne 0x2f76
movl %r15d, %edi
callq 0xcc11
movl %eax, 0x13c(%rbx)
jmp 0x2f81
movl %ebp, 0x150(%rbx)
cmpl $0x4, %r15d
jne 0x2f81
cmpl $0x2, %ebp
je 0x2fb5
cmpl $0x6, %ebp
jne 0x2f81
movq %r14, %rdi
callq 0x77f3
testb %al, %al
je 0x3067
movl $0x0, 0x148(%rbx)
movq %rbx, %rdi
movl $0x7, %esi
callq 0xa7d2
movq %rbx, %rdi
movl $0xfffffffc, %esi       # imm = 0xFFFFFFFC
movl $0x5, %edx
jmp 0x301c
movl %ebp, 0x14c(%rbx)
cmpl $0x3c, %r15d
jne 0x2f81
cmpl $0x3a, %ebp
je 0x2fe8
cmpl $0x3e, %ebp
jne 0x2f81
movq %r14, %rdi
callq 0x77f3
testb %al, %al
je 0x3086
movl $0x0, 0x148(%rbx)
movq %rbx, %rdi
movl $0x3f, %esi
callq 0xa7d2
movq %rbx, %rdi
movl $0x4, %esi
movl $0x3d, %edx
jmp 0x301c
movl %ebp, %edi
callq 0xca75
cmpl $0x7, %eax
jne 0x2f81
movq %r14, %rdi
callq 0x77cb
testl %eax, %eax
je 0x3029
movq %rbx, %rdi
movl %ebp, %esi
callq 0xa7d2
movq %r14, %rdi
callq 0x77cb
negl %eax
jmp 0x2fac
movl %ebp, %edi
callq 0xca75
testl %eax, %eax
je 0x2f8a
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0x77cb
testl %eax, %eax
je 0x3048
movq %rbx, %rdi
movl %ebp, %esi
callq 0xa7d2
movq %r14, %rdi
callq 0x77cb
movq %rbx, %rdi
movl %eax, %esi
movl %ebp, %edx
jmp 0x301c
movq %r14, %rdi
callq 0x77f3
testb %al, %al
je 0x30a5
movl $0x0, 0x148(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0xa7d2
movq %rbx, %rdi
movl $0xfffffffc, %esi       # imm = 0xFFFFFFFC
movl $0x3, %edx
jmp 0x301c
movq %r14, %rdi
callq 0x77f3
testb %al, %al
je 0x30c4
movl $0x0, 0x148(%rbx)
movq %rbx, %rdi
movl $0x38, %esi
callq 0xa7d2
movq %rbx, %rdi
movl $0x4, %esi
movl $0x3b, %edx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xa63d
leaq 0x26054(%rip), %rdi     # 0x29084
leaq 0x25fdb(%rip), %rsi     # 0x29012
leaq 0x26064(%rip), %rcx     # 0x290a2
movl $0x3d, %edx
callq 0x20d0
leaq 0x26035(%rip), %rdi     # 0x29084
leaq 0x25fbc(%rip), %rsi     # 0x29012
leaq 0x26045(%rip), %rcx     # 0x290a2
movl $0x33, %edx
callq 0x20d0
leaq 0x26064(%rip), %rdi     # 0x290d2
leaq 0x25f9d(%rip), %rsi     # 0x29012
leaq 0x26026(%rip), %rcx     # 0x290a2
movl $0x57, %edx
callq 0x20d0
leaq 0x26045(%rip), %rdi     # 0x290d2
leaq 0x25f7e(%rip), %rsi     # 0x29012
leaq 0x26007(%rip), %rcx     # 0x290a2
movl $0x47, %edx
callq 0x20d0
leaq 0x26026(%rip), %rdi     # 0x290d2
leaq 0x25f5f(%rip), %rsi     # 0x29012
leaq 0x25fe8(%rip), %rcx     # 0x290a2
movl $0x5c, %edx
callq 0x20d0
leaq 0x26007(%rip), %rdi     # 0x290d2
leaq 0x25f40(%rip), %rsi     # 0x29012
leaq 0x25fc9(%rip), %rcx     # 0x290a2
movl $0x4c, %edx
callq 0x20d0