// File: /workspace/github_cpp_makefile_star2_O1/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 0x3287
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x783c
testq %rax, %rax
je 0x32a6
movq %rbx, %rdi
callq 0x23354
testb %al, %al
je 0x32c5
testq %r15, %r15
je 0x32e4
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 0xf5429(%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 0xdfc4
movl %eax, 0x138(%rbx)
incl 0x144(%rbx)
incl 0x148(%rbx)
movq %r14, %rdi
callq 0x77df
movl %eax, %ecx
xorl %eax, %eax
testb %cl, %cl
je 0x31db
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 0x77d5
cmpl %eax, %ebp
jne 0x3303
movl $0x40, 0x13c(%rbx)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2dd3
movq %rbx, %rdi
movq %r14, %rsi
callq 0xa9cb
movq %r14, %rdi
callq 0x77b0
movq %rbx, %rdi
movl %eax, %esi
callq 0xa7d2
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 0x23354
testb %al, %al
je 0x3322
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x31fee(%rip), %rdi     # 0x3527c
leaq 0x25d7d(%rip), %rsi     # 0x29012
leaq 0x25e43(%rip), %rcx     # 0x290df
movl $0x67, %edx
callq 0x20d0
leaq 0x25e5c(%rip), %rdi     # 0x29109
leaq 0x25d5e(%rip), %rsi     # 0x29012
leaq 0x25e24(%rip), %rcx     # 0x290df
movl $0x68, %edx
callq 0x20d0
leaq 0x25e4c(%rip), %rdi     # 0x29118
leaq 0x25d3f(%rip), %rsi     # 0x29012
leaq 0x25e05(%rip), %rcx     # 0x290df
movl $0x69, %edx
callq 0x20d0
leaq 0x25e45(%rip), %rdi     # 0x29130
leaq 0x25d20(%rip), %rsi     # 0x29012
leaq 0x25de6(%rip), %rcx     # 0x290df
movl $0x6a, %edx
callq 0x20d0
leaq 0x25e31(%rip), %rdi     # 0x2913b
leaq 0x25d01(%rip), %rsi     # 0x29012
leaq 0x25dc7(%rip), %rcx     # 0x290df
movl $0x83, %edx
callq 0x20d0
leaq 0x25def(%rip), %rdi     # 0x29118
leaq 0x25ce2(%rip), %rsi     # 0x29012
leaq 0x25da8(%rip), %rcx     # 0x290df
movl $0x91, %edx
callq 0x20d0