// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %r14
movl 0x10(%rdi), %eax
movl %eax, 0x10(%rsp)
movq 0x8(%rdi), %rax
movzwl 0x28(%rax), %eax
movw %ax, 0xe(%rsp)
leaq 0x28(%rdi), %rbx
pushq $0x20
popq %r15
leaq 0x50(%rsp), %r13
movq %rbx, 0x28(%rsp)
movq %rdi, 0x20(%rsp)
movq (%rbx), %rbx
cmpq 0x28(%rsp), %rbx
je 0x18c30
movq 0x10(%rbx), %rbp
movl (%r14), %eax
movl %eax, 0x30(%rbp)
movzwl 0x18(%rbp), %ecx
movl %r15d, %r12d
cmpq $0x1000, %rcx           # imm = 0x1000
jne 0x18b4c
movl 0x10(%rsp), %r8d
addl $0xfffff000, %r8d       # imm = 0xFFFFF000
movzwl 0x8(%rbp), %edx
leal (%r15,%rdx), %r9d
addl $0x20, %r9d
movq 0x20(%rbp), %rsi
leaq 0x30(%rsp), %rdi
movl $0x1000, %ecx           # imm = 0x1000
movl %r8d, 0x10(%rsp)
callq 0xe350
movq 0x8(%r14), %rcx
movl (%r14), %eax
cmpl %eax, 0x3c(%rcx)
jbe 0x18b83
movb 0x40(%rcx), %cl
shlq %cl, %rax
jmp 0x18b85
movzwl 0x8(%rbp), %edx
leal (%r15,%rdx), %eax
leal (%r15,%rdx), %r8d
addl $0x20, %r8d
leal 0x20(%rcx,%rax), %r9d
movq 0x20(%rbp), %rsi
leaq 0x30(%rsp), %rdi
callq 0xe350
movq 0x8(%r14), %rcx
movl (%r14), %eax
cmpl %eax, 0x3c(%rcx)
jbe 0x18bc2
movb 0x40(%rcx), %cl
shlq %cl, %rax
jmp 0x18bc4
xorl %eax, %eax
addq %rax, %r12
movzwl 0xe(%rsp), %eax
movw %ax, 0x16(%rsp)
movq %r12, 0x18(%rsp)
movq %r13, %rdi
leaq 0x30(%rsp), %rsi
leaq 0x16(%rsp), %r14
movq %r14, %rdx
xorl %ecx, %ecx
callq 0xe56a
movq %rbp, %rdi
movq %r13, %rsi
callq 0x1867e
movzwl 0x8(%rbp), %ebp
addl $0x20, %ebp
jmp 0x18c06
xorl %eax, %eax
addq %rax, %r12
movzwl 0xe(%rsp), %eax
movw %ax, 0x16(%rsp)
movq %r12, 0x18(%rsp)
movq %r13, %rdi
leaq 0x30(%rsp), %rsi
leaq 0x16(%rsp), %r14
movq %r14, %rdx
xorl %ecx, %ecx
callq 0xe56a
movq %rbp, %rdi
movq %r13, %rsi
callq 0x1867e
movzwl 0x8(%rbp), %eax
movzwl 0x18(%rbp), %ecx
leal (%rax,%rcx), %ebp
addl $0x20, %ebp
movq %r13, %rdi
callq 0xe636
movq %r14, %rdi
callq 0xe398
leaq 0x30(%rsp), %rdi
callq 0xe38c
addl %r15d, %ebp
movl %ebp, %r15d
movq 0x20(%rsp), %r14
jmp 0x18ae0
cmpl 0x14(%r14), %r15d
movl 0x10(%rsp), %ebp
jne 0x18c4f
cmpl 0x18(%r14), %ebp
jne 0x18c4f
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x19382(%rip), %rbx     # 0x31fd8
movq (%rbx), %r12
callq 0x63c0
leaq 0x6640(%rip), %rsi      # 0x1f2a5
leaq 0x840e(%rip), %rcx      # 0x2107a
leaq 0x83de(%rip), %r8       # 0x21051
movq %r12, %rdi
movq %rax, %rdx
movl $0x14c, %r9d            # imm = 0x14C
xorl %eax, %eax
callq 0x6580
movq (%rbx), %rdi
movl 0x14(%r14), %ecx
movl 0x18(%r14), %r9d
leaq 0x83f3(%rip), %rsi      # 0x2108b
movl %r15d, %edx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x6580
movq (%rbx), %rsi
pushq $0xa
popq %rdi
callq 0x64b0
jmp 0x18c40
jmp 0x18cb4
movq %rax, %rbx
jmp 0x18cc8
jmp 0x18cbb
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0xe636
leaq 0x16(%rsp), %rdi
callq 0xe398
leaq 0x30(%rsp), %rdi
callq 0xe38c
movq %rbx, %rdi
callq 0x6680