// File: /workspace/github_cpp_makefile_star2_O1/yangwanyuan[P]HLKVDS/src/IndexManager.cc
// Function: hlkvds::IndexManager::Set(char*, unsigned long)
bool IndexManager::Set(char* buff, uint64_t length) {
    if (length != sizeOndisk_) {
        return false;
    }
    char* buf_ptr = buff;

    //Set TS
    int64_t time_len = KVTime::SizeOf();
    time_t t;
    memcpy((void *)&t, (const void*)buf_ptr, time_len);
    lastTime_->SetTime(t);
    buf_ptr += time_len;

    __DEBUG("memcpy timestamp: %s at %p, at %ld", KVTime::ToChar(*lastTime_), (void *)buf_ptr, (int64_t)(buf_ptr-buff));

    //Set Index
    uint64_t counter_table_len = sizeof(int) * htSize_;
    char * counter_table_ptr = buf_ptr;
    char * ht_ptr = buf_ptr + counter_table_len;

    uint32_t total_entry = 0;
    uint64_t counter_size = sizeof(int);
    uint64_t entry_ondisk_size = IndexManager::SizeOfHashEntryOnDisk();

    for (uint32_t i = 0; i < htSize_; i++) {

        int slot_num = 0;
        memcpy((void*)&slot_num, (const void *)counter_table_ptr, sizeof(int));

        if (slot_num > 0) {
            for (int j = 0; j < slot_num; j++) {
                HashEntryOnDisk entry_ondisk;
                memcpy((void*)&entry_ondisk, (const void *)ht_ptr, entry_ondisk_size);
                HashEntry entry(entry_ondisk, *lastTime_, 0);
                hashtable_[i].entryList_->put(entry);
                total_entry++;
                ht_ptr += entry_ondisk_size;
            }
        }

        counter_table_ptr += counter_size;
    }

    if (total_entry != keyCounter_) {
        __ERROR("The Key Number is conflit between superblock and index!!!!!");
        return false;
    }

    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
xorl %r15d, %r15d
cmpq %rdx, 0x10(%rdi)
jne 0x1157d
movq %rsi, %r14
movq (%rsi), %rsi
movq %rdi, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq 0x40(%rax), %rdi
callq 0x209d4
movq 0x8(%rsp), %rsi
movl 0x8(%rsi), %eax
testq %rax, %rax
je 0x11573
movq %r14, %rcx
leaq (%r14,%rax,4), %rbp
addq $0x8, %rbp
addq $0x8, %rcx
xorl %edx, %edx
leaq 0x40(%rsp), %r12
xorl %r15d, %r15d
movl (%rcx), %r14d
testl %r14d, %r14d
jle 0x11560
movq %rcx, 0x20(%rsp)
addl %r14d, %r15d
movl %r15d, 0x14(%rsp)
movq %rdx, 0x18(%rsp)
leaq (%rdx,%rdx,2), %rax
shlq $0x4, %rax
movq %rax, 0x28(%rsp)
movq %r12, %rdi
callq 0x10d70
movups (%rbp), %xmm0
movups 0x10(%rbp), %xmm1
movups 0x1a(%rbp), %xmm2
movups %xmm2, 0x5a(%rsp)
movaps %xmm1, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movq 0x8(%rsp), %rax
movq 0x40(%rax), %rsi
leaq 0x30(%rsp), %r15
movq %r15, %rdi
callq 0x209fc
leaq 0x70(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %r13
movq %r12, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x10eec
movq %r15, %rdi
callq 0x20a7a
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x28(%rsp), %rcx
movq (%rax,%rcx), %rdi
movq %rbx, %rsi
callq 0x1223c
addq $0x2a, %rbp
movq %rbx, %rdi
callq 0x11066
movq %r13, %rdi
callq 0x10e32
movq %r13, %r12
decl %r14d
jne 0x114ba
movl 0x14(%rsp), %r15d
movq 0x20(%rsp), %rcx
movq 0x18(%rsp), %rdx
movq 0x8(%rsp), %rsi
addq $0x4, %rcx
incq %rdx
movl 0x8(%rsi), %eax
cmpq %rax, %rdx
jb 0x1148f
cmpl 0x18(%rsi), %r15d
sete %r15b
jne 0x11592
movl %r15d, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x736f
jmp 0x1157d
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x20a7a
jmp 0x115ba
movq %rax, %rbx
jmp 0x115ba
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x11066
leaq 0x40(%rsp), %rdi
callq 0x10e32
movq %rbx, %rdi
callq 0x6680