// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x2060, %rsp           # imm = 0x2060
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, -0x30(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x18(%rbp), %rdi
callq 0x5170
movq %rax, -0x2048(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
cmpl -0x30(%rbp), %eax
je 0x2c77
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x2c(%rbp), %eax
addl -0x30(%rbp), %eax
shrl %eax
movl %eax, -0x34(%rbp)
movq -0x2048(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x30(%rcx), %rcx
movl -0x34(%rbp), %edx
shlq $0x4, %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jbe 0x2c6f
movl -0x34(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x2c75
movl -0x34(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0x2c2a
movl -0x30(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jae 0x2ca1
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x30(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
cmpq -0x2048(%rbp), %rax
je 0x2cac
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x2e0c
movq -0x18(%rbp), %rdi
callq 0x2120
movq %rax, -0x2050(%rbp)
movl -0x30(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jae 0x2e06
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x30(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movabsq $0xffffffffff, %rcx     # imm = 0xFFFFFFFFFF
andq 0x8(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x30(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shrq $0x28, %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rdi
leaq -0x2040(%rbp), %rsi
movq -0x28(%rbp), %rax
movl (%rax), %edx
movq -0x20(%rbp), %rax
movq (%rax), %rcx
callq 0x2e20
movl %eax, -0x2054(%rbp)
movl -0x2054(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl (%rcx), %eax
je 0x2d51
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x2e0c
movslq -0x2054(%rbp), %rax
cmpq -0x2050(%rbp), %rax
jbe 0x2dd2
leaq -0x2040(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x2050(%rbp), %rdx
callq 0x2070
cmpl $0x0, %eax
jne 0x2dd2
movq -0x2050(%rbp), %rax
movsbl -0x2040(%rbp,%rax), %eax
cmpl $0x3a, %eax
jne 0x2dd2
movq -0x20(%rbp), %rax
movq (%rax), %rcx
addq -0x2050(%rbp), %rcx
addq $0x1, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movl (%rax), %eax
subq -0x2050(%rbp), %rax
subq $0x1, %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movl $0x1, -0x38(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x2e0c
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x30(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
cmpq -0x2048(%rbp), %rax
je 0x2e01
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x2e0c
jmp 0x2cbc
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x2060, %rsp           # imm = 0x2060
popq %rbp
retq
nopl (%rax,%rax)