// File: yangwanyuan[P]HLKVDS/src/Segment.cc
// Function: hlkvds::SegBase::fillEntryToSlice()
void SegBase::fillEntryToSlice() {
    uint32_t head_pos = SegBase::SizeOfSegOnDisk();
    uint32_t tail_pos = segSize_;
    int vol_id = vol_->GetId();
    for (list<KVSlice *>::iterator iter = sliceList_.begin(); iter
            != sliceList_.end(); iter++) {

        KVSlice *slice = *iter;
        slice->SetSegId(segId_);
        if (slice->IsAlignedData()) {
            uint32_t data_offset = tail_pos - ALIGNED_SIZE;
            uint32_t next_offset = head_pos + IndexManager::SizeOfDataHeader() + slice->GetKeyLen();
            DataHeader data_header(slice->GetDigest(), slice->GetKeyLen(), slice->GetDataLen(),
                                   data_offset, next_offset);

            uint64_t seg_offset = 0;
            vol_->CalcSegOffsetFromId(segId_, seg_offset);
            uint64_t header_offset = seg_offset + head_pos;

            DataHeaderAddress addrs(vol_id, header_offset);
            HashEntry hash_entry(data_header, addrs, NULL);
            slice->SetHashEntry(&hash_entry);

            head_pos += IndexManager::SizeOfDataHeader() + slice->GetKeyLen();
            tail_pos -= ALIGNED_SIZE;
            __DEBUG("SegmentSlice: key=%s, data_offset=%u, header_offset=%lu, seg_id=%u, head_pos=%u, tail_pos = %u", slice->GetKey(), data_offset, header_offset, segId_, head_pos, tail_pos);
        } else {
            uint32_t data_offset = head_pos + IndexManager::SizeOfDataHeader() + slice->GetKeyLen();
            uint32_t next_offset = head_pos + IndexManager::SizeOfDataHeader()
                    + slice->GetKeyLen() + slice->GetDataLen();

            DataHeader data_header(slice->GetDigest(), slice->GetKeyLen(), slice->GetDataLen(),
                                   data_offset, next_offset);
            uint64_t seg_offset = 0;
            vol_->CalcSegOffsetFromId(segId_, seg_offset);
            uint64_t header_offset = seg_offset + head_pos;

            DataHeaderAddress addrs(vol_id, header_offset);
            HashEntry hash_entry(data_header, addrs, NULL);
            slice->SetHashEntry(&hash_entry);

            head_pos += IndexManager::SizeOfDataHeader() + slice->GetKeyLen() + slice->GetDataLen();
            __DEBUG("SegmentSlice: key=%s, data_offset=%u, header_offset=%lu, seg_id=%u, head_pos=%u, tail_pos = %u", slice->GetKey(), data_offset, header_offset, segId_, head_pos, tail_pos);

        }
    }
    if (head_pos != headPos_ || tail_pos != tailPos_) {
        __ERROR("Segment fillEntryToSlice  Failed!!! head_pos= %u, headPos_=%u, tail_pos= %u, tailPos_ = %u", head_pos, headPos_, tail_pos, tailPos_);
    }
}

// Assembly:
subq $0x178, %rsp            # imm = 0x178
movq %rdi, 0x170(%rsp)
movq 0x170(%rsp), %rax
movq %rax, 0x68(%rsp)
callq 0x166a0
movq %rax, %rcx
movq 0x68(%rsp), %rax
movl %ecx, 0x16c(%rsp)
movl 0x10(%rax), %ecx
movl %ecx, 0x168(%rsp)
movq 0x8(%rax), %rdi
callq 0x238c0
movq 0x68(%rsp), %rdi
movl %eax, 0x164(%rsp)
addq $0x28, %rdi
callq 0x16410
movq %rax, 0x158(%rsp)
movq 0x68(%rsp), %rdi
addq $0x28, %rdi
callq 0x16460
movq %rax, 0x150(%rsp)
leaq 0x158(%rsp), %rdi
leaq 0x150(%rsp), %rsi
callq 0x16440
testb $0x1, %al
jne 0x41d04
jmp 0x42218
leaq 0x158(%rsp), %rdi
callq 0x16490
movq %rax, %rcx
movq 0x68(%rsp), %rax
movq (%rcx), %rcx
movq %rcx, 0x148(%rsp)
movq 0x148(%rsp), %rdi
movl (%rax), %esi
callq 0x413f0
movq 0x148(%rsp), %rdi
callq 0x442d0
testb $0x1, %al
jne 0x41d49
jmp 0x41f7c
movl 0x168(%rsp), %eax
addl $0xfffff000, %eax       # imm = 0xFFFFF000
movl %eax, 0x144(%rsp)
movl 0x16c(%rsp), %eax
movl %eax, 0x54(%rsp)
callq 0x238d0
movq %rax, %rcx
movl 0x54(%rsp), %eax
addl %ecx, %eax
movl %eax, 0x58(%rsp)
movq 0x148(%rsp), %rdi
callq 0x44260
movw %ax, %cx
movl 0x58(%rsp), %eax
movzwl %cx, %ecx
addl %ecx, %eax
movl %eax, 0x140(%rsp)
movq 0x148(%rsp), %rdi
callq 0x16d90
movq %rax, 0x60(%rsp)
movq 0x148(%rsp), %rdi
callq 0x44260
movw %ax, 0x5e(%rsp)
movq 0x148(%rsp), %rdi
callq 0x163a0
movw 0x5e(%rsp), %cx
movq 0x60(%rsp), %rsi
movl 0x144(%rsp), %r8d
movl 0x140(%rsp), %r9d
movzwl %cx, %edx
movzwl %ax, %ecx
leaq 0x120(%rsp), %rdi
callq 0x24d90
movq 0x68(%rsp), %rax
movq $0x0, 0x118(%rsp)
movq 0x8(%rax), %rdi
movl (%rax), %esi
leaq 0x118(%rsp), %rdx
callq 0x23960
jmp 0x41e1d
movq 0x118(%rsp), %rax
movl 0x16c(%rsp), %ecx
addq %rcx, %rax
movq %rax, 0x100(%rsp)
movzwl 0x164(%rsp), %esi
movq 0x100(%rsp), %rdx
leaq 0xf6(%rsp), %rdi
callq 0x238e0
jmp 0x41e56
xorl %eax, %eax
movl %eax, %ecx
leaq 0xd8(%rsp), %rdi
leaq 0x120(%rsp), %rsi
leaq 0xf6(%rsp), %rdx
callq 0x25210
jmp 0x41e79
movq 0x148(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x41310
jmp 0x41e90
callq 0x238d0
movq %rax, 0x48(%rsp)
jmp 0x41e9c
movq 0x148(%rsp), %rdi
callq 0x44260
movw %ax, 0x46(%rsp)
jmp 0x41eb0
movq 0x48(%rsp), %rcx
movw 0x46(%rsp), %ax
movzwl %ax, %eax
addq %rax, %rcx
movl 0x16c(%rsp), %eax
addq %rcx, %rax
movl %eax, 0x16c(%rsp)
movl 0x168(%rsp), %eax
subl $0x1000, %eax           # imm = 0x1000
movl %eax, 0x168(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x253b0
leaq 0xf6(%rsp), %rdi
callq 0x24e40
leaq 0x120(%rsp), %rdi
callq 0x24e00
jmp 0x421fd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
jmp 0x41f6a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
jmp 0x41f5d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x253b0
leaq 0xf6(%rsp), %rdi
callq 0x24e40
leaq 0x120(%rsp), %rdi
callq 0x24e00
jmp 0x422d1
movl 0x16c(%rsp), %eax
movl %eax, 0x20(%rsp)
callq 0x238d0
movq %rax, %rcx
movl 0x20(%rsp), %eax
addl %ecx, %eax
movl %eax, 0x24(%rsp)
movq 0x148(%rsp), %rdi
callq 0x44260
movw %ax, %cx
movl 0x24(%rsp), %eax
movzwl %cx, %ecx
addl %ecx, %eax
movl %eax, 0xd4(%rsp)
movl 0x16c(%rsp), %eax
movl %eax, 0x28(%rsp)
callq 0x238d0
movq %rax, %rcx
movl 0x28(%rsp), %eax
addl %ecx, %eax
movl %eax, 0x2c(%rsp)
movq 0x148(%rsp), %rdi
callq 0x44260
movw %ax, %cx
movl 0x2c(%rsp), %eax
movzwl %cx, %ecx
addl %ecx, %eax
movl %eax, 0x30(%rsp)
movq 0x148(%rsp), %rdi
callq 0x163a0
movw %ax, %cx
movl 0x30(%rsp), %eax
movzwl %cx, %ecx
addl %ecx, %eax
movl %eax, 0xd0(%rsp)
movq 0x148(%rsp), %rdi
callq 0x16d90
movq %rax, 0x38(%rsp)
movq 0x148(%rsp), %rdi
callq 0x44260
movw %ax, 0x36(%rsp)
movq 0x148(%rsp), %rdi
callq 0x163a0
movw 0x36(%rsp), %cx
movq 0x38(%rsp), %rsi
movl 0xd4(%rsp), %r8d
movl 0xd0(%rsp), %r9d
movzwl %cx, %edx
movzwl %ax, %ecx
leaq 0xb0(%rsp), %rdi
callq 0x24d90
movq 0x68(%rsp), %rax
movq $0x0, 0xa8(%rsp)
movq 0x8(%rax), %rdi
movl (%rax), %esi
leaq 0xa8(%rsp), %rdx
callq 0x23960
jmp 0x42097
movq 0xa8(%rsp), %rax
movl 0x16c(%rsp), %ecx
addq %rcx, %rax
movq %rax, 0xa0(%rsp)
movzwl 0x164(%rsp), %esi
movq 0xa0(%rsp), %rdx
leaq 0x96(%rsp), %rdi
callq 0x238e0
jmp 0x420d0
xorl %eax, %eax
movl %eax, %ecx
leaq 0x78(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
leaq 0x96(%rsp), %rdx
callq 0x25210
jmp 0x420f0
movq 0x148(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x41310
jmp 0x42104
callq 0x238d0
movq %rax, 0x18(%rsp)
jmp 0x42110
movq 0x148(%rsp), %rdi
callq 0x44260
movw %ax, 0x16(%rsp)
jmp 0x42124
movq 0x18(%rsp), %rax
movw 0x16(%rsp), %cx
movzwl %cx, %ecx
addq %rcx, %rax
movq %rax, 0x8(%rsp)
movq 0x148(%rsp), %rdi
callq 0x163a0
movw %ax, 0x14(%rsp)
jmp 0x4214d
movq 0x8(%rsp), %rcx
movw 0x14(%rsp), %ax
movzwl %ax, %eax
addq %rax, %rcx
movl 0x16c(%rsp), %eax
addq %rcx, %rax
movl %eax, 0x16c(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x253b0
leaq 0x96(%rsp), %rdi
callq 0x24e40
leaq 0xb0(%rsp), %rdi
callq 0x24e00
jmp 0x421fd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
jmp 0x421eb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
jmp 0x421de
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x253b0
leaq 0x96(%rsp), %rdi
callq 0x24e40
leaq 0xb0(%rsp), %rdi
callq 0x24e00
jmp 0x422d1
jmp 0x421ff
leaq 0x158(%rsp), %rdi
xorl %esi, %esi
callq 0x164c0
movq %rax, 0x70(%rsp)
jmp 0x41cd0
movq 0x68(%rsp), %rcx
movl 0x16c(%rsp), %eax
cmpl 0x14(%rcx), %eax
jne 0x4223e
movq 0x68(%rsp), %rcx
movl 0x168(%rsp), %eax
cmpl 0x18(%rcx), %eax
je 0x422c9
jmp 0x42240
movq 0x2ed91(%rip), %rax     # 0x70fd8
movq (%rax), %rax
movq %rax, (%rsp)
callq 0x8480
movq (%rsp), %rdi
movq %rax, %rdx
leaq 0x10250(%rip), %rsi     # 0x524b1
leaq 0x11f61(%rip), %rcx     # 0x541c9
leaq 0x11f31(%rip), %r8      # 0x541a0
movl $0x14c, %r9d            # imm = 0x14C
movb $0x0, %al
callq 0x86f0
movq 0x68(%rsp), %rax
movq 0x2ed50(%rip), %rcx     # 0x70fd8
movq (%rcx), %rdi
movl 0x16c(%rsp), %edx
movl 0x14(%rax), %ecx
movl 0x168(%rsp), %r8d
movl 0x18(%rax), %r9d
leaq 0x11f32(%rip), %rsi     # 0x541da
movb $0x0, %al
callq 0x86f0
movq 0x2ed22(%rip), %rax     # 0x70fd8
movq (%rax), %rdi
leaq 0x10b05(%rip), %rsi     # 0x52dc5
movb $0x0, %al
callq 0x86f0
jmp 0x422c9
addq $0x178, %rsp            # imm = 0x178
retq
movq 0x110(%rsp), %rdi
callq 0x8820
nop