// File: jswaff[P]prophet3/src/next.cpp
// Function: good_pawn_move(position*, unsigned long long)
bool good_pawn_move(position *p,move m) {

    square_t from_sq = get_from_sq(m);
    square_t to_sq = get_to_sq(m);
    piece_t captured_piece = get_captured_piece(m);

    if (captured_piece==NO_PIECE) {
        if (p->piece[to_sq] != NO_PIECE) return false;
        if (p->player==WHITE) {
            square_t nsq = north(from_sq);
            square_t nnsq = north(nsq);
            if (to_sq==nsq || (to_sq==nnsq && p->piece[nsq]==NO_PIECE)) return true;
        } else {
            square_t ssq = south(from_sq);
            square_t sssq = south(ssq);
            if (to_sq==ssq || (to_sq==sssq && p->piece[ssq]==NO_PIECE)) return true;
        }
    } else {
        if (!(bb_pawn_attacks[from_sq][p->player] & bb_squares[to_sq])) return false;
        if (p->player==WHITE) {
            if (is_epcapture(m)) {
                if (to_sq==p->ep_sq && p->piece[south(to_sq)]==-PAWN) return true;
            } else {
                if (p->piece[to_sq]==-captured_piece) return true;
            }
        } else {
            if (is_epcapture(m)) {
                if (to_sq==p->ep_sq && p->piece[north(to_sq)]==PAWN) return true;
            } else {
                if (p->piece[to_sq]==captured_piece) return true;
            }
        }
    }

    return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0xaa80
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rdi
callq 0xaaa0
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
callq 0xab00
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0xd772
movq -0x10(%rbp), %rax
movl -0x20(%rbp), %ecx
cmpl $0x0, (%rax,%rcx,4)
je 0xd6e4
movb $0x0, -0x1(%rbp)
jmp 0xd886
movq -0x10(%rbp), %rax
cmpl $0x1, 0x138(%rax)
jne 0xd72f
movl -0x1c(%rbp), %edi
callq 0x12410
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %edi
callq 0x12410
movl %eax, -0x2c(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x28(%rbp), %eax
je 0xd724
movl -0x20(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jne 0xd72d
movq -0x10(%rbp), %rax
movl -0x28(%rbp), %ecx
cmpl $0x0, (%rax,%rcx,4)
jne 0xd72d
movb $0x1, -0x1(%rbp)
jmp 0xd886
jmp 0xd76d
movl -0x1c(%rbp), %edi
callq 0x12490
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %edi
callq 0x12490
movl %eax, -0x34(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x30(%rbp), %eax
je 0xd762
movl -0x20(%rbp), %eax
cmpl -0x34(%rbp), %eax
jne 0xd76b
movq -0x10(%rbp), %rax
movl -0x30(%rbp), %ecx
cmpl $0x0, (%rax,%rcx,4)
jne 0xd76b
movb $0x1, -0x1(%rbp)
jmp 0xd886
jmp 0xd76d
jmp 0xd882
movl -0x1c(%rbp), %eax
movl %eax, %ecx
leaq 0xf84f2(%rip), %rax     # 0x105c70
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x10(%rbp), %rcx
movl 0x138(%rcx), %ecx
movq (%rax,%rcx,8), %rax
movl -0x20(%rbp), %ecx
movl %ecx, %edx
leaq 0xf7ed1(%rip), %rcx     # 0x105670
andq (%rcx,%rdx,8), %rax
cmpq $0x0, %rax
jne 0xd7b2
movb $0x0, -0x1(%rbp)
jmp 0xd886
movq -0x10(%rbp), %rax
cmpl $0x1, 0x138(%rax)
jne 0xd823
movq -0x18(%rbp), %rdi
callq 0xab50
testb $0x1, %al
jne 0xd7ce
jmp 0xd806
movl -0x20(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x13c(%rcx), %eax
jne 0xd804
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movl -0x20(%rbp), %edi
callq 0x12490
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, %ecx
cmpl $-0x1, (%rax,%rcx,4)
jne 0xd804
movb $0x1, -0x1(%rbp)
jmp 0xd886
jmp 0xd821
movq -0x10(%rbp), %rax
movl -0x20(%rbp), %ecx
movl (%rax,%rcx,4), %eax
xorl %ecx, %ecx
subl -0x24(%rbp), %ecx
cmpl %ecx, %eax
jne 0xd81f
movb $0x1, -0x1(%rbp)
jmp 0xd886
jmp 0xd821
jmp 0xd880
movq -0x18(%rbp), %rdi
callq 0xab50
testb $0x1, %al
jne 0xd832
jmp 0xd867
movl -0x20(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x13c(%rcx), %eax
jne 0xd865
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x20(%rbp), %edi
callq 0x12410
movl %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, %ecx
cmpl $0x1, (%rax,%rcx,4)
jne 0xd865
movb $0x1, -0x1(%rbp)
jmp 0xd886
jmp 0xd87e
movq -0x10(%rbp), %rax
movl -0x20(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x24(%rbp), %eax
jne 0xd87c
movb $0x1, -0x1(%rbp)
jmp 0xd886
jmp 0xd87e
jmp 0xd880
jmp 0xd882
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)