// File: /workspace/github_cpp_makefile_star2_O3/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
movl $0x0, %eax
cmpq %rdx, 0x10(%rdi)
jne 0x116b0
movq %rsi, %r15
movq %rdi, %rbx
movq (%rsi), %rsi
movq 0x40(%rdi), %rdi
callq 0x2098c
xorl %edx, %edx
movq %rbx, 0x8(%rsp)
movl 0x8(%rbx), %eax
testq %rax, %rax
je 0x116a4
leaq (%r15,%rax,4), %rbp
addq $0x8, %rbp
addq $0x8, %r15
xorl %esi, %esi
leaq 0x40(%rsp), %r12
xorl %edx, %edx
movl (%r15), %r14d
testl %r14d, %r14d
jle 0x11692
movq %r15, 0x20(%rsp)
addl %r14d, %edx
movl %edx, 0x14(%rsp)
movq %rsi, 0x18(%rsp)
leaq (%rsi,%rsi,2), %rax
shlq $0x4, %rax
movq %rax, 0x28(%rsp)
movq %r12, %rdi
callq 0x10ea4
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 0x209b4
leaq 0x70(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %r13
movq %r12, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x11020
movq %r15, %rdi
callq 0x20a32
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x28(%rsp), %rcx
movq (%rax,%rcx), %rdi
movq %rbx, %rsi
callq 0x12376
addq $0x2a, %rbp
movq %rbx, %rdi
callq 0x1119a
movq %r13, %rdi
callq 0x10f66
movq %r13, %r12
decl %r14d
jne 0x115ea
movq 0x8(%rsp), %rax
movl 0x8(%rax), %eax
movq 0x20(%rsp), %r15
movl 0x14(%rsp), %edx
movq 0x18(%rsp), %rsi
addq $0x4, %r15
incq %rsi
movl %eax, %ecx
cmpq %rcx, %rsi
jb 0x115c0
movb $0x1, %al
movq 0x8(%rsp), %rcx
cmpl 0x18(%rcx), %edx
jne 0x116c2
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x732b
xorl %eax, %eax
jmp 0x116b0
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x20a32
jmp 0x116ec
movq %rax, %rbx
jmp 0x116ec
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x1119a
leaq 0x40(%rsp), %rdi
callq 0x10f66
movq %rbx, %rdi
callq 0x6670