// File: jswaff[P]prophet3/test/hash__test.cpp
// Function: test_overwrite()
void test_overwrite() {
    clear_hash_table(&htbl);
    position pos;
    set_pos(&pos,"8/k7/p7/3Qp2P/n1P5/3KP3/1q6/8 b - - ");

    uint64 key = build_hash_key(&pos);
    move mv = to_move(PAWN,E5,E4);
    store_hash_entry(&htbl,key,build_hash_val(LOWER_BOUND,5,1001,mv));

    uint64 val = get_hash_entry(&htbl,key);
    assert(val!=0);
    assert(get_hash_entry_type(val)==LOWER_BOUND);
    assert(get_hash_entry_move(val)==mv);
    assert(get_hash_entry_score(val)==1001);
    assert(get_hash_entry_depth(val)==5);

    // overwrite with different score/depth
    store_hash_entry(&htbl,key,build_hash_val(LOWER_BOUND,6,900,mv));
    val = get_hash_entry(&htbl,key);
    assert(val!=0);
    assert(get_hash_entry_type(val)==LOWER_BOUND);
    assert(get_hash_entry_move(val)==mv);
    assert(get_hash_entry_score(val)==900);
    assert(get_hash_entry_depth(val)==6);

    // use different key to store new entry
    uint64 key2 = ~key;

    uint64 val2 = get_hash_entry(&htbl,key2);
    assert(val2==0);
    store_hash_entry(&htbl,key2,build_hash_val(LOWER_BOUND,7,800,mv));
    val2 = get_hash_entry(&htbl,key2);
    assert(val2 != 0);

    // make sure we didn't overwrite earlier entry
    assert(val==get_hash_entry(&htbl,key));
    assert(val2==get_hash_entry(&htbl,key2));
    assert(val != val2);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x220, %rsp            # imm = 0x220
leaq 0xe211e(%rip), %rdi     # 0x1030b0
callq 0x88c0
leaq -0x1c8(%rbp), %rdi
leaq 0x1dac7(%rip), %rsi     # 0x3ea6c
callq 0xf3e0
leaq -0x1c8(%rbp), %rdi
callq 0x81f0
movq %rax, -0x1d0(%rbp)
movl $0x1, %edi
movl $0x1c, %esi
movl $0x24, %edx
callq 0xa830
movq %rax, -0x1d8(%rbp)
movq -0x1d0(%rbp), %rax
movq %rax, -0x1f8(%rbp)
movq -0x1d8(%rbp), %rcx
movl $0x1, %edi
movl $0x5, %esi
movl $0x3e9, %edx            # imm = 0x3E9
callq 0x8470
movq -0x1f8(%rbp), %rsi
movq %rax, %rdx
leaq 0xe209e(%rip), %rdi     # 0x1030b0
callq 0x8a50
movq -0x1d0(%rbp), %rsi
leaq 0xe208b(%rip), %rdi     # 0x1030b0
callq 0x8980
movq %rax, -0x1e0(%rbp)
cmpq $0x0, -0x1e0(%rbp)
je 0x2103d
jmp 0x2105c
leaq 0x1d6e8(%rip), %rdi     # 0x3e72c
leaq 0x1d2b0(%rip), %rsi     # 0x3e2fb
movl $0x216, %edx            # imm = 0x216
leaq 0x1da3a(%rip), %rcx     # 0x3ea91
callq 0x20c0
movq -0x1e0(%rbp), %rdi
callq 0x8710
cmpl $0x1, %eax
jne 0x2106f
jmp 0x2108e
leaq 0x1d407(%rip), %rdi     # 0x3e47d
leaq 0x1d27e(%rip), %rsi     # 0x3e2fb
movl $0x217, %edx            # imm = 0x217
leaq 0x1da08(%rip), %rcx     # 0x3ea91
callq 0x20c0
movq -0x1e0(%rbp), %rdi
callq 0x87d0
cmpq -0x1d8(%rbp), %rax
jne 0x210a5
jmp 0x210c4
leaq 0x1d45a(%rip), %rdi     # 0x3e506
leaq 0x1d248(%rip), %rsi     # 0x3e2fb
movl $0x218, %edx            # imm = 0x218
leaq 0x1d9d2(%rip), %rcx     # 0x3ea91
callq 0x20c0
movq -0x1e0(%rbp), %rdi
callq 0x8750
cmpl $0x3e9, %eax            # imm = 0x3E9
jne 0x210d9
jmp 0x210f8
leaq 0x1d9c7(%rip), %rdi     # 0x3eaa7
leaq 0x1d214(%rip), %rsi     # 0x3e2fb
movl $0x219, %edx            # imm = 0x219
leaq 0x1d99e(%rip), %rcx     # 0x3ea91
callq 0x20c0
movq -0x1e0(%rbp), %rdi
callq 0x8730
cmpl $0x5, %eax
jne 0x2110b
jmp 0x2112a
leaq 0x1d6e8(%rip), %rdi     # 0x3e7fa
leaq 0x1d1e2(%rip), %rsi     # 0x3e2fb
movl $0x21a, %edx            # imm = 0x21A
leaq 0x1d96c(%rip), %rcx     # 0x3ea91
callq 0x20c0
movq -0x1d0(%rbp), %rax
movq %rax, -0x200(%rbp)
movq -0x1d8(%rbp), %rcx
movl $0x1, %edi
movl $0x6, %esi
movl $0x384, %edx            # imm = 0x384
callq 0x8470
movq -0x200(%rbp), %rsi
movq %rax, %rdx
leaq 0xe1f4c(%rip), %rdi     # 0x1030b0
callq 0x8a50
movq -0x1d0(%rbp), %rsi
leaq 0xe1f39(%rip), %rdi     # 0x1030b0
callq 0x8980
movq %rax, -0x1e0(%rbp)
cmpq $0x0, -0x1e0(%rbp)
je 0x2118f
jmp 0x211ae
leaq 0x1d596(%rip), %rdi     # 0x3e72c
leaq 0x1d15e(%rip), %rsi     # 0x3e2fb
movl $0x21f, %edx            # imm = 0x21F
leaq 0x1d8e8(%rip), %rcx     # 0x3ea91
callq 0x20c0
movq -0x1e0(%rbp), %rdi
callq 0x8710
cmpl $0x1, %eax
jne 0x211c1
jmp 0x211e0
leaq 0x1d2b5(%rip), %rdi     # 0x3e47d
leaq 0x1d12c(%rip), %rsi     # 0x3e2fb
movl $0x220, %edx            # imm = 0x220
leaq 0x1d8b6(%rip), %rcx     # 0x3ea91
callq 0x20c0
movq -0x1e0(%rbp), %rdi
callq 0x87d0
cmpq -0x1d8(%rbp), %rax
jne 0x211f7
jmp 0x21216
leaq 0x1d308(%rip), %rdi     # 0x3e506
leaq 0x1d0f6(%rip), %rsi     # 0x3e2fb
movl $0x221, %edx            # imm = 0x221
leaq 0x1d880(%rip), %rcx     # 0x3ea91
callq 0x20c0
movq -0x1e0(%rbp), %rdi
callq 0x8750
cmpl $0x384, %eax            # imm = 0x384
jne 0x2122b
jmp 0x2124a
leaq 0x1d895(%rip), %rdi     # 0x3eac7
leaq 0x1d0c2(%rip), %rsi     # 0x3e2fb
movl $0x222, %edx            # imm = 0x222
leaq 0x1d84c(%rip), %rcx     # 0x3ea91
callq 0x20c0
movq -0x1e0(%rbp), %rdi
callq 0x8730
cmpl $0x6, %eax
jne 0x2125d
jmp 0x2127c
leaq 0x1d882(%rip), %rdi     # 0x3eae6
leaq 0x1d090(%rip), %rsi     # 0x3e2fb
movl $0x223, %edx            # imm = 0x223
leaq 0x1d81a(%rip), %rcx     # 0x3ea91
callq 0x20c0
movq -0x1d0(%rbp), %rax
xorq $-0x1, %rax
movq %rax, -0x1e8(%rbp)
movq -0x1e8(%rbp), %rsi
leaq 0xe1e14(%rip), %rdi     # 0x1030b0
callq 0x8980
movq %rax, -0x1f0(%rbp)
cmpq $0x0, -0x1f0(%rbp)
jne 0x212b4
jmp 0x212d3
leaq 0x1d3e0(%rip), %rdi     # 0x3e69b
leaq 0x1d039(%rip), %rsi     # 0x3e2fb
movl $0x229, %edx            # imm = 0x229
leaq 0x1d7c3(%rip), %rcx     # 0x3ea91
callq 0x20c0
movq -0x1e8(%rbp), %rax
movq %rax, -0x208(%rbp)
movq -0x1d8(%rbp), %rcx
movl $0x1, %edi
movl $0x7, %esi
movl $0x320, %edx            # imm = 0x320
callq 0x8470
movq -0x208(%rbp), %rsi
movq %rax, %rdx
leaq 0xe1da3(%rip), %rdi     # 0x1030b0
callq 0x8a50
movq -0x1e8(%rbp), %rsi
leaq 0xe1d90(%rip), %rdi     # 0x1030b0
callq 0x8980
movq %rax, -0x1f0(%rbp)
cmpq $0x0, -0x1f0(%rbp)
je 0x21338
jmp 0x21357
leaq 0x1d7c4(%rip), %rdi     # 0x3eb03
leaq 0x1cfb5(%rip), %rsi     # 0x3e2fb
movl $0x22c, %edx            # imm = 0x22C
leaq 0x1d73f(%rip), %rcx     # 0x3ea91
callq 0x20c0
movq -0x1e0(%rbp), %rax
movq %rax, -0x210(%rbp)
movq -0x1d0(%rbp), %rsi
leaq 0xe1d3d(%rip), %rdi     # 0x1030b0
callq 0x8980
movq %rax, %rcx
movq -0x210(%rbp), %rax
cmpq %rcx, %rax
jne 0x21389
jmp 0x213a8
leaq 0x1d77d(%rip), %rdi     # 0x3eb0d
leaq 0x1cf64(%rip), %rsi     # 0x3e2fb
movl $0x22f, %edx            # imm = 0x22F
leaq 0x1d6ee(%rip), %rcx     # 0x3ea91
callq 0x20c0
movq -0x1f0(%rbp), %rax
movq %rax, -0x218(%rbp)
movq -0x1e8(%rbp), %rsi
leaq 0xe1cec(%rip), %rdi     # 0x1030b0
callq 0x8980
movq %rax, %rcx
movq -0x218(%rbp), %rax
cmpq %rcx, %rax
jne 0x213da
jmp 0x213f9
leaq 0x1d74b(%rip), %rdi     # 0x3eb2c
leaq 0x1cf13(%rip), %rsi     # 0x3e2fb
movl $0x230, %edx            # imm = 0x230
leaq 0x1d69d(%rip), %rcx     # 0x3ea91
callq 0x20c0
movq -0x1e0(%rbp), %rax
cmpq -0x1f0(%rbp), %rax
je 0x2140b
jmp 0x2142a
leaq 0x1d73b(%rip), %rdi     # 0x3eb4d
leaq 0x1cee2(%rip), %rsi     # 0x3e2fb
movl $0x231, %edx            # imm = 0x231
leaq 0x1d66c(%rip), %rcx     # 0x3ea91
callq 0x20c0
addq $0x220, %rsp            # imm = 0x220
popq %rbp
retq
nopw %cs:(%rax,%rax)