// File: jswaff[P]prophet3/test/search__test.cpp
// Function: test_hash_table()
void test_hash_table() {
    position pos;
    reset_pos(&pos);
    clear_hash_table(&htbl);

    position save_pos;
    memcpy(&save_pos,&pos,sizeof(position));

    search_stats stats; stats.nodes=0; stats.last_pv.n=0;
    start_timer(10000);
    stats.first_line_searched.n=0;
    set_abort_search(false);

    // make a (ridiculous) entry up.  the program would never play 1. a4, UNLESS of course it would be a piece up!
    // make 1. ... a5 a rook up for white, everything else a queen up, and verify PV is 1. a4 a5
    move a2a4 = to_move(PAWN,A2,A4);
    apply_move(&pos,a2a4,gundos);
    position save_pos2;
    memcpy(&save_pos2,&pos,sizeof(position));

    move a7a5 = to_move(PAWN,A7,A5);

    move moves[50];
    move *endp = gen_legal_moves(moves,&pos,true,true);
    assert(is_in_move_list(a7a5,moves,endp));

    for (move *mp=moves;mp<endp;mp++) {
        apply_move(&pos,*mp,gundos);

        int32 score = 900;
        if (*mp == a7a5) {
            score = 500;
        }
        store_hash_entry(&htbl,pos.hash_key,build_hash_val(EXACT_SCORE,1,score,*mp));

        memcpy(&pos,&save_pos2,sizeof(position));
    }
    memcpy(&pos,&save_pos,sizeof(position));

    move_line pv; pv.n=0;
    search(&pos,&pv,-INF,INF,3,&stats,move_stack,gundos,false);
    assert(pv.n==2);
    assert(a2a4==pv.mv[0]);
    assert(a7a5==pv.mv[1]);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10e0, %rsp           # imm = 0x10E0
leaq -0x1c8(%rbp), %rdi
callq 0xf390
leaq 0xd2f62(%rip), %rdi     # 0x1030b0
callq 0x88c0
leaq -0x390(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
movl $0x1c8, %edx            # imm = 0x1C8
callq 0x20f0
movq $0x0, -0x9f8(%rbp)
movl $0x0, -0x9e8(%rbp)
movl $0x2710, %edi           # imm = 0x2710
callq 0x2f8b0
movl $0x0, -0x6c0(%rbp)
xorl %edi, %edi
callq 0x10200
movl $0x1, %edi
movl $0x30, %esi
movl $0x20, %edx
callq 0xa830
movq %rax, -0xa18(%rbp)
movq -0xa18(%rbp), %rsi
leaq -0x1c8(%rbp), %rdi
leaq 0xa3ae5(%rip), %rdx     # 0xd3cb0
callq 0x3620
leaq -0xbe0(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
movl $0x1c8, %edx            # imm = 0x1C8
callq 0x20f0
movl $0x1, %edi
movl $0x8, %esi
movl $0x18, %edx
callq 0xa830
movq %rax, -0xbe8(%rbp)
leaq -0xd80(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
movl $0x1, %ecx
movl %ecx, %edx
callq 0xac70
movq %rax, -0xd88(%rbp)
movq -0xbe8(%rbp), %rdi
leaq -0xd80(%rbp), %rsi
movq -0xd88(%rbp), %rdx
callq 0x14c10
testb $0x1, %al
jne 0x30244
jmp 0x30246
jmp 0x30265
leaq 0x13191(%rip), %rdi     # 0x433de
leaq 0x12f52(%rip), %rsi     # 0x431a6
movl $0xb0, %edx
leaq 0x1319f(%rip), %rcx     # 0x433ff
callq 0x20c0
leaq -0xd80(%rbp), %rax
movq %rax, -0xd90(%rbp)
movq -0xd90(%rbp), %rax
cmpq -0xd88(%rbp), %rax
jae 0x3033a
movq -0xd90(%rbp), %rax
movq (%rax), %rsi
leaq -0x1c8(%rbp), %rdi
leaq 0xa3a11(%rip), %rdx     # 0xd3cb0
callq 0x3620
movl $0x384, -0xd94(%rbp)    # imm = 0x384
movq -0xd90(%rbp), %rax
movq (%rax), %rax
cmpq -0xbe8(%rbp), %rax
jne 0x302cb
movl $0x1f4, -0xd94(%rbp)    # imm = 0x1F4
movq -0x10(%rbp), %rax
movq %rax, -0x10c8(%rbp)
movl -0xd94(%rbp), %edx
movq -0xd90(%rbp), %rax
movq (%rax), %rcx
movl $0x3, %edi
movl $0x1, %esi
callq 0x8470
movq -0x10c8(%rbp), %rsi
movq %rax, %rdx
leaq 0xd2daa(%rip), %rdi     # 0x1030b0
callq 0x8a50
leaq -0x1c8(%rbp), %rdi
leaq -0xbe0(%rbp), %rsi
movl $0x1c8, %edx            # imm = 0x1C8
callq 0x20f0
movq -0xd90(%rbp), %rax
addq $0x8, %rax
movq %rax, -0xd90(%rbp)
jmp 0x30273
leaq -0x1c8(%rbp), %rdi
leaq -0x390(%rbp), %rsi
movl $0x1c8, %edx            # imm = 0x1C8
callq 0x20f0
movl $0x0, -0x10c0(%rbp)
leaq -0x1c8(%rbp), %rdi
leaq -0x10c0(%rbp), %rsi
movl $0xfffcf2c0, %edx       # imm = 0xFFFCF2C0
movl $0x30d40, %ecx          # imm = 0x30D40
movl $0x3, %r8d
leaq -0xa10(%rbp), %r9
leaq 0x890bf8(%rip), %r10    # 0x8c0f80
leaq 0xa3921(%rip), %rax     # 0xd3cb0
xorl %r11d, %r11d
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movl $0x0, 0x10(%rsp)
callq 0x10350
cmpl $0x2, -0x10c0(%rbp)
jne 0x303b3
jmp 0x303d2
leaq 0x1305c(%rip), %rdi     # 0x43416
leaq 0x12de5(%rip), %rsi     # 0x431a6
movl $0xc1, %edx
leaq 0x13032(%rip), %rcx     # 0x433ff
callq 0x20c0
movq -0xa18(%rbp), %rax
cmpq -0x10b8(%rbp), %rax
jne 0x303e4
jmp 0x30403
leaq 0x13033(%rip), %rdi     # 0x4341e
leaq 0x12db4(%rip), %rsi     # 0x431a6
movl $0xc2, %edx
leaq 0x13001(%rip), %rcx     # 0x433ff
callq 0x20c0
movq -0xbe8(%rbp), %rax
cmpq -0x10b0(%rbp), %rax
jne 0x30415
jmp 0x30434
leaq 0x13011(%rip), %rdi     # 0x4342d
leaq 0x12d83(%rip), %rsi     # 0x431a6
movl $0xc3, %edx
leaq 0x12fd0(%rip), %rcx     # 0x433ff
callq 0x20c0
addq $0x10e0, %rsp           # imm = 0x10E0
popq %rbp
retq
nopl (%rax)