// File: /workspace/github_cpp_makefile_star2_O2/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, %r15d
cmpq %rdx, 0x10(%rdi)
jne 0xeb21
movq %rsi, %r14
movq %rdi, %rbx
movq $0x0, 0x10(%rsp)
movq (%rsi), %rsi
movq 0x40(%rdi), %rdi
callq 0x1daec
movq %rbx, 0x8(%rsp)
movl 0x8(%rbx), %eax
leaq (%r14,%rax,4), %rbp
addq $0x8, %rbp
addq $0x8, %r14
leaq 0x40(%rsp), %r12
leaq 0x70(%rsp), %r15
movq %r14, %rdx
xorl %esi, %esi
movl %eax, %ecx
cmpq %rcx, %rsi
jae 0xeb0f
movq %rsi, 0x18(%rsp)
movl (%rdx), %r14d
testl %r14d, %r14d
jle 0xeafe
movq %rdx, 0x20(%rsp)
movq 0x10(%rsp), %rax
addl %r14d, %eax
movq %rax, 0x10(%rsp)
imulq $0x30, 0x18(%rsp), %rax
movq %rax, 0x28(%rsp)
subl $0x1, %r14d
jb 0xeaf1
movq %r12, %rdi
callq 0xe39a
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), %rbx
movq %rbx, %rdi
callq 0x1db12
movq %r15, %rdi
movq %r12, %r13
movq %r12, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0xe4d2
movq %rbx, %rdi
callq 0x1db90
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x28(%rsp), %rcx
movq (%rax,%rcx), %rdi
movq %r15, %rsi
callq 0xf6c4
addq $0x2a, %rbp
movq %r15, %rdi
callq 0xe636
movq %r13, %rdi
callq 0xe434
movq %r13, %r12
jmp 0xea5e
movq 0x8(%rsp), %rax
movl 0x8(%rax), %eax
movq 0x20(%rsp), %rdx
addq $0x4, %rdx
movq 0x18(%rsp), %rsi
incq %rsi
jmp 0xea25
movb $0x1, %r15b
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
cmpl 0x18(%rcx), %eax
jne 0xeb36
movl %r15d, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2349b(%rip), %r14     # 0x31fd8
movq (%r14), %rbx
callq 0x63c0
leaq 0x10759(%rip), %rsi     # 0x1f2a5
leaq 0x10fa1(%rip), %rcx     # 0x1faf4
leaq 0x10efb(%rip), %r8      # 0x1fa55
xorl %r15d, %r15d
movq %rbx, %rdi
movq %rax, %rdx
movl $0xee, %r9d
xorl %eax, %eax
callq 0x6580
movq (%r14), %rcx
leaq 0x10f7e(%rip), %rdi     # 0x1faf8
pushq $0x3b
popq %rsi
pushq $0x1
popq %rdx
callq 0x6750
movq (%r14), %rsi
pushq $0xa
popq %rdi
callq 0x64b0
jmp 0xeb21
movq %rax, %rbx
jmp 0xebb3
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x1db90
jmp 0xebb3
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0xe636
leaq 0x40(%rsp), %rdi
callq 0xe434
movq %rbx, %rdi
callq 0x6680
nop