// File: yangwanyuan[P]HLKVDS/src/Segment.cc
// Function: hlkvds::SegLatencyFriendly::copyToDataBuf()
void SegLatencyFriendly::copyToDataBuf() {
    uint64_t offset = 0;
    vol_->CalcSegOffsetFromId(segId_, offset);

    uint32_t offset_begin = 0;

    offset_begin += SegBase::SizeOfSegOnDisk();

    //aggregate iovec
    for (list<KVSlice *>::iterator iter = sliceList_.begin(); iter
            != sliceList_.end(); iter++) {
        KVSlice *slice = *iter;
        DataHeader *header =
                &slice->GetHashEntry().GetEntryOnDisk().GetDataHeader();
        char *data = (char *) slice->GetData();
        uint16_t data_len = slice->GetDataLen();

        char *key = (char *) slice->GetKey();
        uint16_t key_len = slice->GetKeyLen();
        memcpy(&(dataBuf_[offset_begin]), header, IndexManager::SizeOfDataHeader());
        __DEBUG("write key = %s, seg_id: %u, header offset: %u", slice->GetKey(), segId_, offset_begin);
        offset_begin += IndexManager::SizeOfDataHeader();
        memcpy(&(dataBuf_[offset_begin]), key, key_len);
        __DEBUG("write key = %s, key offset: %u", slice->GetKey(), offset_begin);
        offset_begin += key_len;
        memcpy(&(dataBuf_[offset_begin]), data, data_len);
        __DEBUG("write key = %s, data position: %u", slice->GetKey(), offset_begin);
        offset_begin += data_len;
    }

    // Generate SegHeaderOnDisk
    uint64_t timestamp = KVTime::GetNow();
    uint64_t trx_id = 0;
    uint32_t trx_segs = 0;
    uint32_t checksum_data = 0;
    SegHeaderOnDisk seg_header(timestamp, trx_id, trx_segs, checksum_data, checksumSize_, keyNum_);
    memcpy(dataBuf_, &seg_header, SegBase::SizeOfSegOnDisk());

}

// Assembly:
subq $0xd8, %rsp
movq %rdi, 0xd0(%rsp)
movq 0xd0(%rsp), %rax
movq %rax, 0x28(%rsp)
movq $0x0, 0xc8(%rsp)
movq (%rax), %rdi
movl 0x10(%rax), %esi
leaq 0xc8(%rsp), %rdx
callq 0x23960
movl $0x0, 0xc4(%rsp)
callq 0x166a0
movq 0x28(%rsp), %rdi
movq %rax, %rcx
movl 0xc4(%rsp), %eax
addq %rcx, %rax
movl %eax, 0xc4(%rsp)
addq $0x28, %rdi
callq 0x16410
movq %rax, 0xb8(%rsp)
movq 0x28(%rsp), %rdi
addq $0x28, %rdi
callq 0x16460
movq %rax, 0xb0(%rsp)
leaq 0xb8(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x16440
testb $0x1, %al
jne 0x43f49
jmp 0x440cb
leaq 0xb8(%rsp), %rdi
callq 0x16490
movq (%rax), %rax
movq %rax, 0xa8(%rsp)
movq 0xa8(%rsp), %rdi
callq 0x116b0
movq %rax, %rdi
callq 0x27920
movq %rax, %rdi
callq 0x442f0
movq %rax, 0xa0(%rsp)
movq 0xa8(%rsp), %rdi
callq 0x23a40
movq %rax, 0x98(%rsp)
movq 0xa8(%rsp), %rdi
callq 0x163a0
movw %ax, 0x96(%rsp)
movq 0xa8(%rsp), %rdi
callq 0x23a30
movq %rax, 0x88(%rsp)
movq 0xa8(%rsp), %rdi
callq 0x44260
movw %ax, %cx
movq 0x28(%rsp), %rax
movw %cx, 0x86(%rsp)
movq 0x40(%rax), %rax
movl 0xc4(%rsp), %ecx
addq %rcx, %rax
movq %rax, 0x18(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x20(%rsp)
callq 0x238d0
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq %rax, %rdx
callq 0x8410
callq 0x238d0
movq %rax, %rdx
movq 0x28(%rsp), %rax
movl 0xc4(%rsp), %ecx
addq %rdx, %rcx
movl %ecx, 0xc4(%rsp)
movq 0x40(%rax), %rdi
movl 0xc4(%rsp), %eax
addq %rax, %rdi
movq 0x88(%rsp), %rsi
movzwl 0x86(%rsp), %eax
movl %eax, %edx
callq 0x8410
movq 0x28(%rsp), %rax
movzwl 0x86(%rsp), %ecx
addl 0xc4(%rsp), %ecx
movl %ecx, 0xc4(%rsp)
movq 0x40(%rax), %rdi
movl 0xc4(%rsp), %eax
addq %rax, %rdi
movq 0x98(%rsp), %rsi
movzwl 0x96(%rsp), %eax
movl %eax, %edx
callq 0x8410
movzwl 0x96(%rsp), %eax
addl 0xc4(%rsp), %eax
movl %eax, 0xc4(%rsp)
leaq 0xb8(%rsp), %rdi
xorl %esi, %esi
callq 0x164c0
movq %rax, 0x78(%rsp)
jmp 0x43f15
callq 0x50670
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x70(%rsp)
movq $0x0, 0x68(%rsp)
movl $0x0, 0x64(%rsp)
movl $0x0, 0x60(%rsp)
movq 0x70(%rsp), %rsi
movq 0x68(%rsp), %rdx
movl 0x64(%rsp), %ecx
movl 0x60(%rsp), %r8d
movl 0x1c(%rax), %edi
movl 0x20(%rax), %r9d
movq %rsp, %rax
movl %edi, (%rax)
leaq 0x40(%rsp), %rdi
callq 0x40b90
movq 0x28(%rsp), %rax
movq 0x40(%rax), %rax
movq %rax, 0x8(%rsp)
callq 0x166a0
movq %rax, 0x10(%rsp)
jmp 0x44139
movq 0x10(%rsp), %rdx
movq 0x8(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x8410
leaq 0x40(%rsp), %rdi
callq 0x40ac0
addq $0xd8, %rsp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x38(%rsp)
movl %eax, 0x34(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x40ac0
movq 0x38(%rsp), %rdi
callq 0x8820
nopw %cs:(%rax,%rax)