// File: /workspace/github_cpp_makefile_star2_O3/jswaff[P]prophet3/src/apply.cpp
// Function: apply_move(position*, unsigned long long, undo*)
void apply_move(position *p,move m,undo *undo_stack) {
    assert(p);
    assert(clear_score(m));
    assert(test_pos_consistency(p));
    assert(undo_stack);

    // capture information to undo move
    undo *u = undo_stack+p->move_counter;
    u->mv = m;
    u->hash_key = p->hash_key;
    u->ep_sq = p->ep_sq;
    u->fifty_counter = p->fifty_counter;
    u->castling_rights = p->castling_rights;

    // clear current values
    p->hash_key ^= zkeys.ptm[p->player];
    p->hash_key ^= zkeys.ep[p->ep_sq];
    p->hash_key ^= zkeys.casting_rights[p->castling_rights];

    p->player = opposite_player(p->player);
    p->move_counter++;
    p->fifty_counter++;  // may get reset

    if (is_capture(m)) {
        p->fifty_counter=0;
        u->captured = remove_captured_piece(p,m);
    } else {
        u->captured = NO_PIECE;
    }
    assert(abs(u->captured)==get_captured_piece(m));

    // this could get reset
    p->ep_sq=NO_SQUARE;

    add_piece_to_destination(p,m);
    remove_castling_availability(p,m);
    remove_piece(p,get_from_sq(m));

    // add in current values
    p->hash_key ^= zkeys.ptm[p->player];
    p->hash_key ^= zkeys.ep[p->ep_sq];
    p->hash_key ^= zkeys.casting_rights[p->castling_rights];

    assert(test_pos_consistency(p));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
testq %rdi, %rdi
je 0x3291
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x78dd
testq %rax, %rax
je 0x32b0
movq %rbx, %rdi
callq 0x231d4
testb %al, %al
je 0x32cf
testq %r15, %r15
je 0x32ee
movl 0x144(%rbx), %eax
shlq $0x5, %rax
movq %r14, (%r15,%rax)
movq 0x1b8(%rbx), %rcx
movq %rcx, 0x8(%r15,%rax)
movl 0x13c(%rbx), %edx
movl %edx, 0x14(%r15,%rax)
movl 0x148(%rbx), %esi
movl %esi, 0x18(%r15,%rax)
movl 0x140(%rbx), %esi
movl %esi, 0x1c(%r15,%rax)
movl 0x138(%rbx), %edi
leaq 0xf542b(%rip), %r12     # 0xf8598
xorq 0x1c00(%r12,%rdi,8), %rcx
addq %rax, %r15
movq %rcx, 0x1b8(%rbx)
xorq 0x1c90(%r12,%rdx,8), %rcx
movq %rcx, 0x1b8(%rbx)
xorq 0x1c10(%r12,%rsi,8), %rcx
movq %rcx, 0x1b8(%rbx)
callq 0xdf74
movl %eax, 0x138(%rbx)
movq 0x144(%rbx), %xmm0
pcmpeqd %xmm1, %xmm1
psubd %xmm1, %xmm0
movq %xmm0, 0x144(%rbx)
movq %r14, %rdi
callq 0x7883
movl %eax, %ecx
xorl %eax, %eax
testb %cl, %cl
je 0x31e5
movl $0x0, 0x148(%rbx)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2ccc
movl %eax, 0x10(%r15)
movl %eax, %ebp
negl %ebp
cmovsl %eax, %ebp
movq %r14, %rdi
callq 0x7879
cmpl %eax, %ebp
jne 0x330d
movl $0x40, 0x13c(%rbx)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2dd1
movq %rbx, %rdi
movq %r14, %rsi
callq 0xa986
movq %r14, %rdi
callq 0x7854
movq %rbx, %rdi
movl %eax, %esi
callq 0xa78d
movl 0x138(%rbx), %eax
movl 0x13c(%rbx), %ecx
movq 0x1b8(%rbx), %rdx
xorq 0x1c00(%r12,%rax,8), %rdx
movq %rdx, 0x1b8(%rbx)
xorq 0x1c90(%r12,%rcx,8), %rdx
movq %rdx, 0x1b8(%rbx)
movl 0x140(%rbx), %eax
xorq 0x1c10(%r12,%rax,8), %rdx
movq %rdx, 0x1b8(%rbx)
movq %rbx, %rdi
callq 0x231d4
testb %al, %al
je 0x332c
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x32064(%rip), %rdi     # 0x352fc
leaq 0x25d73(%rip), %rsi     # 0x29012
leaq 0x25e39(%rip), %rcx     # 0x290df
movl $0x67, %edx
callq 0x20d0
leaq 0x25e52(%rip), %rdi     # 0x29109
leaq 0x25d54(%rip), %rsi     # 0x29012
leaq 0x25e1a(%rip), %rcx     # 0x290df
movl $0x68, %edx
callq 0x20d0
leaq 0x25e42(%rip), %rdi     # 0x29118
leaq 0x25d35(%rip), %rsi     # 0x29012
leaq 0x25dfb(%rip), %rcx     # 0x290df
movl $0x69, %edx
callq 0x20d0
leaq 0x25e3b(%rip), %rdi     # 0x29130
leaq 0x25d16(%rip), %rsi     # 0x29012
leaq 0x25ddc(%rip), %rcx     # 0x290df
movl $0x6a, %edx
callq 0x20d0
leaq 0x25e27(%rip), %rdi     # 0x2913b
leaq 0x25cf7(%rip), %rsi     # 0x29012
leaq 0x25dbd(%rip), %rcx     # 0x290df
movl $0x83, %edx
callq 0x20d0
leaq 0x25de5(%rip), %rdi     # 0x29118
leaq 0x25cd8(%rip), %rsi     # 0x29012
leaq 0x25d9e(%rip), %rcx     # 0x290df
movl $0x91, %edx
callq 0x20d0