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

    uint32_t offset_begin = 0;
    uint32_t offset_end = segSize_;

    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());
        offset_begin += IndexManager::SizeOfDataHeader();
        memcpy(&(dataBuf_[offset_begin]), key, key_len);
        offset_begin += key_len;

        if (slice->IsAlignedData()) {
            offset_end -= data_len;
            memcpy(&(dataBuf_[offset_end]), data, data_len);
            __DEBUG("write key = %s, data position: %u", slice->GetKey(), offset_end);
        } else {
            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;
    uint32_t checksum_length = 0;
    SegHeaderOnDisk seg_header(timestamp, trx_id, trx_segs, checksum_data, checksum_length, keyNum_);
    memcpy(dataBuf_, &seg_header, SegBase::SizeOfSegOnDisk());

    //set 0 to free data buffer
    memset(&(dataBuf_[offset_begin]), 0, (offset_end - offset_begin));
}

// Assembly:
subq $0xe8, %rsp
movq %rdi, 0xe0(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, 0x30(%rsp)
movq $0x0, 0xd8(%rsp)
movq 0x8(%rax), %rdi
movl (%rax), %esi
leaq 0xd8(%rsp), %rdx
callq 0x23960
movq 0x30(%rsp), %rax
movl $0x0, 0xd4(%rsp)
movl 0x10(%rax), %eax
movl %eax, 0xd0(%rsp)
callq 0x166a0
movq 0x30(%rsp), %rdi
movq %rax, %rcx
movl 0xd4(%rsp), %eax
addq %rcx, %rax
movl %eax, 0xd4(%rsp)
addq $0x28, %rdi
callq 0x16410
movq %rax, 0xc8(%rsp)
movq 0x30(%rsp), %rdi
addq $0x28, %rdi
callq 0x16460
movq %rax, 0xc0(%rsp)
leaq 0xc8(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x16440
testb $0x1, %al
jne 0x42438
jmp 0x42616
leaq 0xc8(%rsp), %rdi
callq 0x16490
movq (%rax), %rax
movq %rax, 0xb8(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x116b0
movq %rax, %rdi
callq 0x27920
movq %rax, %rdi
callq 0x442f0
movq %rax, 0xb0(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x23a40
movq %rax, 0xa8(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x163a0
movw %ax, 0xa6(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x23a30
movq %rax, 0x98(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x44260
movw %ax, %cx
movq 0x30(%rsp), %rax
movw %cx, 0x96(%rsp)
movq 0x40(%rax), %rax
movl 0xd4(%rsp), %ecx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0x28(%rsp)
callq 0x238d0
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq %rax, %rdx
callq 0x8410
callq 0x238d0
movq %rax, %rdx
movq 0x30(%rsp), %rax
movl 0xd4(%rsp), %ecx
addq %rdx, %rcx
movl %ecx, 0xd4(%rsp)
movq 0x40(%rax), %rdi
movl 0xd4(%rsp), %eax
addq %rax, %rdi
movq 0x98(%rsp), %rsi
movzwl 0x96(%rsp), %eax
movl %eax, %edx
callq 0x8410
movzwl 0x96(%rsp), %eax
addl 0xd4(%rsp), %eax
movl %eax, 0xd4(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x442d0
testb $0x1, %al
jne 0x42574
jmp 0x425b8
movq 0x30(%rsp), %rax
movzwl 0xa6(%rsp), %edx
movl 0xd0(%rsp), %ecx
subl %edx, %ecx
movl %ecx, 0xd0(%rsp)
movq 0x40(%rax), %rdi
movl 0xd0(%rsp), %eax
addq %rax, %rdi
movq 0xa8(%rsp), %rsi
movzwl 0xa6(%rsp), %eax
movl %eax, %edx
callq 0x8410
jmp 0x425f8
movq 0x30(%rsp), %rax
movq 0x40(%rax), %rdi
movl 0xd4(%rsp), %eax
addq %rax, %rdi
movq 0xa8(%rsp), %rsi
movzwl 0xa6(%rsp), %eax
movl %eax, %edx
callq 0x8410
movzwl 0xa6(%rsp), %eax
addl 0xd4(%rsp), %eax
movl %eax, 0xd4(%rsp)
jmp 0x425fa
leaq 0xc8(%rsp), %rdi
xorl %esi, %esi
callq 0x164c0
movq %rax, 0x88(%rsp)
jmp 0x42404
callq 0x50670
movq %rax, %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x80(%rsp)
movq $0x0, 0x78(%rsp)
movl $0x0, 0x74(%rsp)
movl $0x0, 0x70(%rsp)
movl $0x0, 0x6c(%rsp)
movq 0x80(%rsp), %rsi
movq 0x78(%rsp), %rdx
movl 0x74(%rsp), %ecx
movl 0x70(%rsp), %r8d
movl 0x6c(%rsp), %r9d
movl 0x1c(%rax), %edi
movq %rsp, %rax
movl %edi, (%rax)
leaq 0x48(%rsp), %rdi
callq 0x40b90
movq 0x30(%rsp), %rax
movq 0x40(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x166a0
movq %rax, 0x18(%rsp)
jmp 0x42693
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x8410
movq 0x30(%rsp), %rax
movq 0x40(%rax), %rdi
movl 0xd4(%rsp), %eax
addq %rax, %rdi
movl 0xd0(%rsp), %eax
subl 0xd4(%rsp), %eax
movl %eax, %eax
movl %eax, %edx
xorl %esi, %esi
callq 0x8280
leaq 0x48(%rsp), %rdi
callq 0x40ac0
addq $0xe8, %rsp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x40(%rsp)
movl %eax, 0x3c(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x40ac0
movq 0x40(%rsp), %rdi
callq 0x8820
nopw (%rax,%rax)