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

    //Copy TS
    int64_t time_len = KVTime::SizeOf();
    lastTime_->Update();
    time_t t = lastTime_->GetTime();
    memcpy((void *)buf_ptr, (const void*)&t, time_len);
    buf_ptr += time_len;
    __DEBUG("memcpy timestamp: %s at %p, at %ld", KVTime::ToChar(*lastTime_), (void *)buf_ptr, (int64_t)(buf_ptr-buff));

    //Copy Counter Table
    __DEBUG("memcpy Counter at %p, at %ld", (void *)buf_ptr, (int64_t)(buf_ptr-buff));
    for (uint32_t i = 0; i < htSize_; i++) {
        int counter = hashtable_[i].entryList_->get_size();
        memcpy((void *)buf_ptr, (const void*)&counter, sizeof(int));
        buf_ptr += sizeof(int);
    }

    //Copy Index
    __DEBUG("memcpy Index at %p, at %ld", (void *)buf_ptr, (int64_t)(buf_ptr-buff));
    uint64_t entry_len = IndexManager::SizeOfHashEntryOnDisk();
    for (uint32_t i = 0; i < htSize_; i++) {
        int slot_num = hashtable_[i].entryList_->get_size();
        if (slot_num > 0) {
            vector<HashEntry> tmp_vec = hashtable_[i].entryList_->get();
            for (vector<HashEntry>::iterator iter = tmp_vec.begin(); iter != tmp_vec.end(); iter++) {
                memcpy((void *)buf_ptr, (const void*)&(iter->GetEntryOnDisk()), entry_len);
                buf_ptr += entry_len;
            }
        }
    }

    __DEBUG("memcpy complete at %p, at %ld", (void *)buf_ptr, (int64_t)(buf_ptr-buff));

    return true;
}

// Assembly:
subq $0xa8, %rsp
movq %rdi, 0x98(%rsp)
movq %rsi, 0x90(%rsp)
movq %rdx, 0x88(%rsp)
movq 0x98(%rsp), %rcx
movq %rcx, 0x10(%rsp)
movq 0x88(%rsp), %rax
cmpq 0x10(%rcx), %rax
je 0x258f7
movb $0x0, 0xa7(%rsp)
jmp 0x25b07
movq 0x90(%rsp), %rax
movq %rax, 0x80(%rsp)
callq 0x116e0
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x78(%rsp)
movq 0x40(%rax), %rdi
callq 0x50710
movq 0x10(%rsp), %rax
movq 0x40(%rax), %rdi
callq 0x506e0
movq %rax, 0x70(%rsp)
movq 0x80(%rsp), %rdi
movq 0x78(%rsp), %rdx
leaq 0x70(%rsp), %rsi
callq 0x8410
movq 0x78(%rsp), %rax
addq 0x80(%rsp), %rax
movq %rax, 0x80(%rsp)
movl $0x0, 0x6c(%rsp)
movq 0x10(%rsp), %rcx
movl 0x6c(%rsp), %eax
cmpl 0x8(%rcx), %eax
jae 0x259c5
movq 0x10(%rsp), %rax
movq (%rax), %rax
movl 0x6c(%rsp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x277a0
movl %eax, 0x68(%rsp)
movq 0x80(%rsp), %rax
movl 0x68(%rsp), %ecx
movl %ecx, (%rax)
movq 0x80(%rsp), %rax
addq $0x4, %rax
movq %rax, 0x80(%rsp)
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
jmp 0x25969
callq 0x166b0
movq %rax, 0x60(%rsp)
movl $0x0, 0x5c(%rsp)
movq 0x10(%rsp), %rcx
movl 0x5c(%rsp), %eax
cmpl 0x8(%rcx), %eax
jae 0x25aff
movq 0x10(%rsp), %rax
movq (%rax), %rax
movl 0x5c(%rsp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x277a0
movl %eax, 0x58(%rsp)
cmpl $0x0, 0x58(%rsp)
jle 0x25aed
movq 0x10(%rsp), %rax
movq (%rax), %rax
movl 0x5c(%rsp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rsi
leaq 0x40(%rsp), %rdi
callq 0x277b0
leaq 0x40(%rsp), %rdi
callq 0x27870
movq %rax, 0x38(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x278e0
movq %rax, 0x30(%rsp)
leaq 0x38(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x278a0
testb $0x1, %al
jne 0x25a66
jmp 0x25ae3
movq 0x80(%rsp), %rax
movq %rax, (%rsp)
leaq 0x38(%rsp), %rdi
callq 0x27910
movq %rax, %rdi
callq 0x27920
movq %rax, 0x8(%rsp)
jmp 0x25a8b
movq 0x8(%rsp), %rsi
movq (%rsp), %rdi
movq 0x60(%rsp), %rdx
callq 0x8410
movq 0x60(%rsp), %rax
addq 0x80(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x38(%rsp), %rdi
xorl %esi, %esi
callq 0x27930
movq %rax, 0x18(%rsp)
jmp 0x25a42
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x28(%rsp)
movl %eax, 0x24(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x27970
jmp 0x25b18
leaq 0x40(%rsp), %rdi
callq 0x27970
jmp 0x25aef
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
jmp 0x259d7
movb $0x1, 0xa7(%rsp)
movb 0xa7(%rsp), %al
andb $0x1, %al
addq $0xa8, %rsp
retq
movq 0x28(%rsp), %rdi
callq 0x8820
nopw %cs:(%rax,%rax)