// File: jswaff[P]prophet3/src/hash.cpp
// Function: build_hash_val(hash_entry_t, int, int, unsigned long long)
uint64 build_hash_val(hash_entry_t entry_type,int32 depth,int32 score,move mv) {
    assert(entry_type >= LOWER_BOUND && entry_type <= EXACT_SCORE);
    assert(depth >= 0);
    assert(depth <= 0xFFFF);
    assert(abs(score) <= CHECKMATE);
    assert(abs(score) <= 0xFFFF);
    set_move_score(&mv,0);

    // convert mate scores
    if (score > CHECKMATE-500) {
        if (entry_type==UPPER_BOUND) {
            // failing low on mate.  don't allow a cutoff, just store any associated move
            entry_type = MOVE_ONLY;
        } else {
            // convert to fail high
            entry_type = LOWER_BOUND;
            score = CHECKMATE-500;
        }
    } else if (score < -(CHECKMATE-500)) {
        if (entry_type==LOWER_BOUND) {
            // failing high on -mate.
            entry_type = MOVE_ONLY;
        } else {
            // convert to fail low
            entry_type = UPPER_BOUND;
            score = -(CHECKMATE-500);
        }
    }

    uint64 val = entry_type;
    val |= ((uint64)depth) << 2;
    if (score >= 0) {
        val |= ((uint64)score) << 18;
    } else {
        val |= ((uint64)-score) << 18;
        val |= ((uint64)1) << 34;
    }
    val |= ((uint64)mv) << 35;

    return val;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movl %edx, -0xc(%rbp)
movq %rcx, -0x18(%rbp)
xorl %eax, %eax
cmpl $0x1, -0x4(%rbp)
movb %al, -0x21(%rbp)
jl 0x849a
cmpl $0x3, -0x4(%rbp)
setle %al
movb %al, -0x21(%rbp)
movb -0x21(%rbp), %al
testb $0x1, %al
jne 0x84a3
jmp 0x84a5
jmp 0x84c4
leaq 0x2df23(%rip), %rdi     # 0x363cf
leaq 0x2deca(%rip), %rsi     # 0x3637d
movl $0x3d, %edx
leaq 0x2df47(%rip), %rcx     # 0x36406
callq 0x20c0
cmpl $0x0, -0x8(%rbp)
jl 0x84cc
jmp 0x84eb
leaq 0x2df6b(%rip), %rdi     # 0x3643e
leaq 0x2dea3(%rip), %rsi     # 0x3637d
movl $0x3e, %edx
leaq 0x2df20(%rip), %rcx     # 0x36406
callq 0x20c0
cmpl $0xffff, -0x8(%rbp)     # imm = 0xFFFF
jg 0x84f6
jmp 0x8515
leaq 0x2df4c(%rip), %rdi     # 0x36449
leaq 0x2de79(%rip), %rsi     # 0x3637d
movl $0x3f, %edx
leaq 0x2def6(%rip), %rcx     # 0x36406
callq 0x20c0
movl -0xc(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
jg 0x8528
jmp 0x8547
leaq 0x2df2a(%rip), %rdi     # 0x36459
leaq 0x2de47(%rip), %rsi     # 0x3637d
movl $0x40, %edx
leaq 0x2dec4(%rip), %rcx     # 0x36406
callq 0x20c0
movl -0xc(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
jg 0x855a
jmp 0x8579
leaq 0x2df10(%rip), %rdi     # 0x36471
leaq 0x2de15(%rip), %rsi     # 0x3637d
movl $0x41, %edx
leaq 0x2de92(%rip), %rcx     # 0x36406
callq 0x20c0
leaq -0x18(%rbp), %rdi
xorl %esi, %esi
callq 0xabe0
cmpl $0xfe0b, -0xc(%rbp)     # imm = 0xFE0B
jle 0x85ac
cmpl $0x2, -0x4(%rbp)
jne 0x859c
movl $0x0, -0x4(%rbp)
jmp 0x85aa
movl $0x1, -0x4(%rbp)
movl $0xfe0b, -0xc(%rbp)     # imm = 0xFE0B
jmp 0x85d6
cmpl $0xffff01f5, -0xc(%rbp) # imm = 0xFFFF01F5
jge 0x85d4
cmpl $0x1, -0x4(%rbp)
jne 0x85c4
movl $0x0, -0x4(%rbp)
jmp 0x85d2
movl $0x2, -0x4(%rbp)
movl $0xffff01f5, -0xc(%rbp) # imm = 0xFFFF01F5
jmp 0x85d4
jmp 0x85d6
movl -0x4(%rbp), %eax
movq %rax, -0x20(%rbp)
movslq -0x8(%rbp), %rax
shlq $0x2, %rax
orq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpl $0x0, -0xc(%rbp)
jl 0x8605
movslq -0xc(%rbp), %rax
shlq $0x12, %rax
orq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x862a
xorl %eax, %eax
subl -0xc(%rbp), %eax
cltq
shlq $0x12, %rax
orq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movabsq $0x400000000, %rax      # imm = 0x400000000
orq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
shlq $0x23, %rax
orq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)