// File: jswaff[P]prophet3/src/pos.cpp
// Function: equal_pos(position*, position*, bool)
bool equal_pos(position* p1,position* p2,bool strict) {
    for (int32 sq=0;sq<64;sq++) {
        if (p1->piece[sq] != p2->piece[sq]) {
            return false;
        }
    }
    assert(p1->white_pawns==p2->white_pawns);
    assert(p1->black_pawns==p2->black_pawns);

    assert(p1->white_knights==p2->white_knights);
    assert(p1->black_knights==p2->black_knights);

    assert(p1->white_bishops==p2->white_bishops);
    assert(p1->black_bishops==p2->black_bishops);

    assert(p1->white_rooks==p2->white_rooks);
    assert(p1->black_rooks==p2->black_rooks);

    assert(p1->white_queens==p2->white_queens);
    assert(p1->black_queens==p2->black_queens);

    assert(p1->white_pieces==p2->white_pieces);
    assert(p1->black_pieces==p2->black_pieces);

    // if that's true then piece counts should be equal
    assert(p1->piece_counts[WHITE][PAWN]==p2->piece_counts[WHITE][PAWN]);
    assert(p1->piece_counts[WHITE][ROOK]==p2->piece_counts[WHITE][ROOK]);
    assert(p1->piece_counts[WHITE][KNIGHT]==p2->piece_counts[WHITE][KNIGHT]);
    assert(p1->piece_counts[WHITE][BISHOP]==p2->piece_counts[WHITE][BISHOP]);
    assert(p1->piece_counts[WHITE][QUEEN]==p2->piece_counts[WHITE][QUEEN]);

    assert(p1->piece_counts[BLACK][PAWN]==p2->piece_counts[BLACK][PAWN]);
    assert(p1->piece_counts[BLACK][ROOK]==p2->piece_counts[BLACK][ROOK]);
    assert(p1->piece_counts[BLACK][KNIGHT]==p2->piece_counts[BLACK][KNIGHT]);
    assert(p1->piece_counts[BLACK][BISHOP]==p2->piece_counts[BLACK][BISHOP]);
    assert(p1->piece_counts[BLACK][QUEEN]==p2->piece_counts[BLACK][QUEEN]);

    if (p1->player != p2->player) return false;
    if (p1->ep_sq != p2->ep_sq) return false;
    if (p1->castling_rights != p2->castling_rights) return false;
    if (p1->white_king != p2->white_king) return false;
    if (p1->black_king != p2->black_king) return false;
    if (strict) {
        if (p1->move_counter != p2->move_counter) return false;
        if (p1->fifty_counter != p2->fifty_counter) return false;
    }

    // if all that is equal the hash keys should be too
    assert(p1->hash_key==p2->hash_key);
    assert(p1->pawn_key==p2->pawn_key);

    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movb %dl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movl $0x0, -0x20(%rbp)
cmpl $0x40, -0x20(%rbp)
jge 0xe4e2
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x18(%rbp), %rcx
movslq -0x20(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
je 0xe4d5
movb $0x0, -0x1(%rbp)
jmp 0xeb08
jmp 0xe4d7
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xe4ae
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x158(%rcx), %rax
jne 0xe4fc
jmp 0xe51b
leaq 0x29156(%rip), %rdi     # 0x37659
leaq 0x29170(%rip), %rsi     # 0x3767a
movl $0x20, %edx
leaq 0x29170(%rip), %rcx     # 0x37686
callq 0x20c0
movq -0x10(%rbp), %rax
movq 0x160(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x160(%rcx), %rax
jne 0xe535
jmp 0xe554
leaq 0x29177(%rip), %rdi     # 0x376b3
leaq 0x29137(%rip), %rsi     # 0x3767a
movl $0x21, %edx
leaq 0x29137(%rip), %rcx     # 0x37686
callq 0x20c0
movq -0x10(%rbp), %rax
movq 0x168(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x168(%rcx), %rax
jne 0xe56e
jmp 0xe58d
leaq 0x2915f(%rip), %rdi     # 0x376d4
leaq 0x290fe(%rip), %rsi     # 0x3767a
movl $0x23, %edx
leaq 0x290fe(%rip), %rcx     # 0x37686
callq 0x20c0
movq -0x10(%rbp), %rax
movq 0x170(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x170(%rcx), %rax
jne 0xe5a7
jmp 0xe5c6
leaq 0x2914b(%rip), %rdi     # 0x376f9
leaq 0x290c5(%rip), %rsi     # 0x3767a
movl $0x24, %edx
leaq 0x290c5(%rip), %rcx     # 0x37686
callq 0x20c0
movq -0x10(%rbp), %rax
movq 0x178(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x178(%rcx), %rax
jne 0xe5e0
jmp 0xe5ff
leaq 0x29137(%rip), %rdi     # 0x3771e
leaq 0x2908c(%rip), %rsi     # 0x3767a
movl $0x26, %edx
leaq 0x2908c(%rip), %rcx     # 0x37686
callq 0x20c0
movq -0x10(%rbp), %rax
movq 0x180(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x180(%rcx), %rax
jne 0xe619
jmp 0xe638
leaq 0x29123(%rip), %rdi     # 0x37743
leaq 0x29053(%rip), %rsi     # 0x3767a
movl $0x27, %edx
leaq 0x29053(%rip), %rcx     # 0x37686
callq 0x20c0
movq -0x10(%rbp), %rax
movq 0x188(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x188(%rcx), %rax
jne 0xe652
jmp 0xe671
leaq 0x2910f(%rip), %rdi     # 0x37768
leaq 0x2901a(%rip), %rsi     # 0x3767a
movl $0x29, %edx
leaq 0x2901a(%rip), %rcx     # 0x37686
callq 0x20c0
movq -0x10(%rbp), %rax
movq 0x190(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x190(%rcx), %rax
jne 0xe68b
jmp 0xe6aa
leaq 0x290f7(%rip), %rdi     # 0x37789
leaq 0x28fe1(%rip), %rsi     # 0x3767a
movl $0x2a, %edx
leaq 0x28fe1(%rip), %rcx     # 0x37686
callq 0x20c0
movq -0x10(%rbp), %rax
movq 0x198(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x198(%rcx), %rax
jne 0xe6c4
jmp 0xe6e3
leaq 0x290df(%rip), %rdi     # 0x377aa
leaq 0x28fa8(%rip), %rsi     # 0x3767a
movl $0x2c, %edx
leaq 0x28fa8(%rip), %rcx     # 0x37686
callq 0x20c0
movq -0x10(%rbp), %rax
movq 0x1a0(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x1a0(%rcx), %rax
jne 0xe6fd
jmp 0xe71c
leaq 0x290c9(%rip), %rdi     # 0x377cd
leaq 0x28f6f(%rip), %rsi     # 0x3767a
movl $0x2d, %edx
leaq 0x28f6f(%rip), %rcx     # 0x37686
callq 0x20c0
movq -0x10(%rbp), %rax
movq 0x1a8(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x1a8(%rcx), %rax
jne 0xe736
jmp 0xe755
leaq 0x290b3(%rip), %rdi     # 0x377f0
leaq 0x28f36(%rip), %rsi     # 0x3767a
movl $0x2f, %edx
leaq 0x28f36(%rip), %rcx     # 0x37686
callq 0x20c0
movq -0x10(%rbp), %rax
movq 0x1b0(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x1b0(%rcx), %rax
jne 0xe76f
jmp 0xe78e
leaq 0x2909d(%rip), %rdi     # 0x37813
leaq 0x28efd(%rip), %rsi     # 0x3767a
movl $0x30, %edx
leaq 0x28efd(%rip), %rcx     # 0x37686
callq 0x20c0
movq -0x10(%rbp), %rax
movl 0x120(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x120(%rcx), %eax
jne 0xe7a6
jmp 0xe7c5
leaq 0x29089(%rip), %rdi     # 0x37836
leaq 0x28ec6(%rip), %rsi     # 0x3767a
movl $0x33, %edx
leaq 0x28ec6(%rip), %rcx     # 0x37686
callq 0x20c0
movq -0x10(%rbp), %rax
movl 0x12c(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x12c(%rcx), %eax
jne 0xe7dd
jmp 0xe7fc
leaq 0x2908f(%rip), %rdi     # 0x37873
leaq 0x28e8f(%rip), %rsi     # 0x3767a
movl $0x34, %edx
leaq 0x28e8f(%rip), %rcx     # 0x37686
callq 0x20c0
movq -0x10(%rbp), %rax
movl 0x124(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x124(%rcx), %eax
jne 0xe814
jmp 0xe833
leaq 0x29095(%rip), %rdi     # 0x378b0
leaq 0x28e58(%rip), %rsi     # 0x3767a
movl $0x35, %edx
leaq 0x28e58(%rip), %rcx     # 0x37686
callq 0x20c0
movq -0x10(%rbp), %rax
movl 0x128(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x128(%rcx), %eax
jne 0xe84b
jmp 0xe86a
leaq 0x2909f(%rip), %rdi     # 0x378f1
leaq 0x28e21(%rip), %rsi     # 0x3767a
movl $0x36, %edx
leaq 0x28e21(%rip), %rcx     # 0x37686
callq 0x20c0
movq -0x10(%rbp), %rax
movl 0x130(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x130(%rcx), %eax
jne 0xe882
jmp 0xe8a1
leaq 0x290a9(%rip), %rdi     # 0x37932
leaq 0x28dea(%rip), %rsi     # 0x3767a
movl $0x37, %edx
leaq 0x28dea(%rip), %rcx     # 0x37686
callq 0x20c0
movq -0x10(%rbp), %rax
movl 0x104(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x104(%rcx), %eax
jne 0xe8b9
jmp 0xe8d8
leaq 0x290b1(%rip), %rdi     # 0x37971
leaq 0x28db3(%rip), %rsi     # 0x3767a
movl $0x39, %edx
leaq 0x28db3(%rip), %rcx     # 0x37686
callq 0x20c0
movq -0x10(%rbp), %rax
movl 0x110(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x110(%rcx), %eax
jne 0xe8f0
jmp 0xe90f
leaq 0x290b7(%rip), %rdi     # 0x379ae
leaq 0x28d7c(%rip), %rsi     # 0x3767a
movl $0x3a, %edx
leaq 0x28d7c(%rip), %rcx     # 0x37686
callq 0x20c0
movq -0x10(%rbp), %rax
movl 0x108(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x108(%rcx), %eax
jne 0xe927
jmp 0xe946
leaq 0x290bd(%rip), %rdi     # 0x379eb
leaq 0x28d45(%rip), %rsi     # 0x3767a
movl $0x3b, %edx
leaq 0x28d45(%rip), %rcx     # 0x37686
callq 0x20c0
movq -0x10(%rbp), %rax
movl 0x10c(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x10c(%rcx), %eax
jne 0xe95e
jmp 0xe97d
leaq 0x290c7(%rip), %rdi     # 0x37a2c
leaq 0x28d0e(%rip), %rsi     # 0x3767a
movl $0x3c, %edx
leaq 0x28d0e(%rip), %rcx     # 0x37686
callq 0x20c0
movq -0x10(%rbp), %rax
movl 0x114(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x114(%rcx), %eax
jne 0xe995
jmp 0xe9b4
leaq 0x290d1(%rip), %rdi     # 0x37a6d
leaq 0x28cd7(%rip), %rsi     # 0x3767a
movl $0x3d, %edx
leaq 0x28cd7(%rip), %rcx     # 0x37686
callq 0x20c0
movq -0x10(%rbp), %rax
movl 0x138(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x138(%rcx), %eax
je 0xe9d3
movb $0x0, -0x1(%rbp)
jmp 0xeb08
movq -0x10(%rbp), %rax
movl 0x13c(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x13c(%rcx), %eax
je 0xe9f2
movb $0x0, -0x1(%rbp)
jmp 0xeb08
movq -0x10(%rbp), %rax
movl 0x140(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x140(%rcx), %eax
je 0xea11
movb $0x0, -0x1(%rbp)
jmp 0xeb08
movq -0x10(%rbp), %rax
movl 0x14c(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x14c(%rcx), %eax
je 0xea30
movb $0x0, -0x1(%rbp)
jmp 0xeb08
movq -0x10(%rbp), %rax
movl 0x150(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x150(%rcx), %eax
je 0xea4f
movb $0x0, -0x1(%rbp)
jmp 0xeb08
testb $0x1, -0x19(%rbp)
je 0xea92
movq -0x10(%rbp), %rax
movl 0x144(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x144(%rcx), %eax
je 0xea74
movb $0x0, -0x1(%rbp)
jmp 0xeb08
movq -0x10(%rbp), %rax
movl 0x148(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x148(%rcx), %eax
je 0xea90
movb $0x0, -0x1(%rbp)
jmp 0xeb08
jmp 0xea92
movq -0x10(%rbp), %rax
movq 0x1b8(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x1b8(%rcx), %rax
jne 0xeaac
jmp 0xeacb
leaq 0x28ff9(%rip), %rdi     # 0x37aac
leaq 0x28bc0(%rip), %rsi     # 0x3767a
movl $0x4a, %edx
leaq 0x28bc0(%rip), %rcx     # 0x37686
callq 0x20c0
movq -0x10(%rbp), %rax
movq 0x1c0(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x1c0(%rcx), %rax
jne 0xeae5
jmp 0xeb04
leaq 0x28fdb(%rip), %rdi     # 0x37ac7
leaq 0x28b87(%rip), %rsi     # 0x3767a
movl $0x4b, %edx
leaq 0x28b87(%rip), %rcx     # 0x37686
callq 0x20c0
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)