// File: /workspace/github_c_makefile_star2_O1/desion[P]terminal/src/hdict.c
// Function: hdict_seek_v2
int hdict_seek_v2(hdict_t *hdict, const char* str_key, off_t *off, uint32_t *length){
    uint32_t low = -1;
    uint32_t high = hdict->idx_num;
    uint32_t mid;
    int hit = 0;
    int count = 0;
    char buf[DATA_BUFFER_SIZE];
    uint64_t key = bkdr_hash(str_key);
    while (low + 1 != high) {
        ++count;
        mid = (low + high) / 2;
        if (key > hdict->idx[mid].key) {
            low = mid;
        } else {
            high = mid;
        } 
    }
     
    if(high >= hdict->idx_num || hdict->idx[high].key != key){
        return hit;
    }
    size_t len = strlen(str_key);
    while(high < hdict->idx_num){
        *off = (hdict->idx[high].pos & 0xFFFFFFFFFF);
        *length = (hdict->idx[high].pos >> 40);
        //compare the string key
        int res = hdict_read(hdict, buf, *length, *off);
        if (res != *length){
            return hit;
        }
        if (res > len && strncmp(buf, str_key, len) == 0 && buf[len] == ':'){
            *off = *off + len + 1;
            *length = *length - len - 1;
            hit = 1;
            return hit;
        }
        high++;
        if(hdict->idx[high].key != key){
            return hit;
        }
    }
    return hit;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2038, %rsp           # imm = 0x2038
movq %rcx, 0x18(%rsp)
movq %rdx, 0x20(%rsp)
movq %rdi, %r12
movl 0x28(%rdi), %r14d
movq %rsi, 0x10(%rsp)
movq %rsi, %rdi
callq 0x42a0
movq %rax, %r13
testl %r14d, %r14d
je 0x2c31
movq 0x30(%r12), %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
leal (%rcx,%r14), %edx
shrl %edx
movq %rdx, %rsi
shlq $0x4, %rsi
cmpq (%rax,%rsi), %r13
ja 0x2c27
movl %edx, %r14d
jmp 0x2c29
movl %edx, %ecx
leal 0x1(%rcx), %edx
cmpl %r14d, %edx
jne 0x2c0f
xorl %r15d, %r15d
cmpl 0x28(%r12), %r14d
jae 0x2d60
movq 0x30(%r12), %rax
movl %r14d, %ecx
shlq $0x4, %rcx
cmpq %r13, (%rax,%rcx)
jne 0x2d60
movq 0x10(%rsp), %rdi
callq 0x2130
movq %rax, %rdx
incq %rax
movq %rax, 0x28(%rsp)
movl %edx, %eax
notl %eax
movl %eax, 0xc(%rsp)
movl $0x0, 0x8(%rsp)
cmpl 0x28(%r12), %r14d
jae 0x2d5b
movq %rdx, %rbx
movq 0x30(%r12), %rax
movl %r14d, %edx
shlq $0x4, %rdx
movq 0x8(%rax,%rdx), %rcx
movabsq $0xffffffffff, %rsi     # imm = 0xFFFFFFFFFF
andq %rsi, %rcx
movq 0x20(%rsp), %rsi
movq %rcx, (%rsi)
movq 0x8(%rax,%rdx), %rdx
shrq $0x28, %rdx
movq 0x18(%rsp), %rbp
movl %edx, (%rbp)
movl 0x38(%r12), %edi
leaq 0x30(%rsp), %rsi
callq 0x23e0
movl (%rbp), %ebp
cmpl %eax, %ebp
jne 0x2d29
cltq
movq %rbx, %rdx
cmpq %rax, %rbx
jae 0x2d35
leaq 0x30(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq %rbx, %rdx
callq 0x2070
movq %rbx, %rdx
testl %eax, %eax
jne 0x2d35
cmpb $0x3a, 0x30(%rsp,%rdx)
jne 0x2d35
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
addq %rcx, (%rax)
addl 0xc(%rsp), %ebp
movq 0x18(%rsp), %rax
movl %ebp, (%rax)
movl $0x1, 0x8(%rsp)
xorl %eax, %eax
movl $0x1, %r15d
jmp 0x2d51
xorl %eax, %eax
movl 0x8(%rsp), %r15d
movq %rbx, %rdx
jmp 0x2d51
incl %r14d
movq 0x30(%r12), %rax
movq %r14, %rcx
shlq $0x4, %rcx
cmpq %r13, (%rax,%rcx)
sete %al
cmovnel 0x8(%rsp), %r15d
testb %al, %al
jne 0x2c7a
jmp 0x2d60
movl 0x8(%rsp), %r15d
movl %r15d, %eax
addq $0x2038, %rsp           # imm = 0x2038
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq