// File: /workspace/github_cpp_makefile_star2_O3/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)
leaq 0x28(%rdi), %rax
movq 0x28(%rdi), %r13
movq %rax, 0x28(%rsp)
cmpq %rax, %r13
je 0x1c0f7
movq 0x8(%r14), %rax
movzwl 0x28(%rax), %eax
movw %ax, 0xe(%rsp)
movl $0x20, %ebx
leaq 0x50(%rsp), %r12
movq %r14, 0x20(%rsp)
movq 0x10(%r13), %rbp
movl (%r14), %eax
movl %eax, 0x30(%rbp)
movzwl 0x18(%rbp), %ecx
movl %ebx, %r15d
cmpq $0x1000, %rcx           # imm = 0x1000
jne 0x1c00a
movl 0x10(%rsp), %r8d
addl $0xfffff000, %r8d       # imm = 0xFFFFF000
movzwl 0x8(%rbp), %edx
leal (%rbx,%rdx), %r9d
addl $0x20, %r9d
movq 0x20(%rbp), %rsi
leaq 0x30(%rsp), %rdi
movl $0x1000, %ecx           # imm = 0x1000
movl %r8d, 0x10(%rsp)
callq 0x10e5a
movq 0x8(%r14), %rcx
movl (%r14), %eax
cmpl %eax, 0x3c(%rcx)
jbe 0x1c040
movb 0x40(%rcx), %cl
shlq %cl, %rax
jmp 0x1c042
movzwl 0x8(%rbp), %edx
leal (%rbx,%rdx), %eax
leal (%rbx,%rdx), %r8d
addl $0x20, %r8d
leal 0x20(%rcx,%rax), %r9d
movq 0x20(%rbp), %rsi
leaq 0x30(%rsp), %rdi
callq 0x10e5a
movq 0x8(%r14), %rcx
movl (%r14), %eax
cmpl %eax, 0x3c(%rcx)
jbe 0x1c07f
movb 0x40(%rcx), %cl
shlq %cl, %rax
jmp 0x1c081
xorl %eax, %eax
addq %rax, %r15
movzwl 0xe(%rsp), %eax
movw %ax, 0x16(%rsp)
movq %r15, 0x18(%rsp)
movq %r12, %rdi
leaq 0x30(%rsp), %rsi
leaq 0x16(%rsp), %r14
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x110c0
movq %rbp, %rdi
movq %r12, %rsi
callq 0x1bade
movzwl 0x8(%rbp), %ebp
addl $0x20, %ebp
jmp 0x1c0c3
xorl %eax, %eax
addq %rax, %r15
movzwl 0xe(%rsp), %eax
movw %ax, 0x16(%rsp)
movq %r15, 0x18(%rsp)
movq %r12, %rdi
leaq 0x30(%rsp), %rsi
leaq 0x16(%rsp), %r14
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x110c0
movq %rbp, %rdi
movq %r12, %rsi
callq 0x1bade
movzwl 0x8(%rbp), %eax
movzwl 0x18(%rbp), %ecx
leal (%rax,%rcx), %ebp
addl $0x20, %ebp
movq %r12, %rdi
callq 0x1119a
movq %r14, %rdi
callq 0x10ea2
leaq 0x30(%rsp), %rdi
callq 0x10e96
addl %ebx, %ebp
movq (%r13), %r13
movl %ebp, %ebx
cmpq 0x28(%rsp), %r13
movq 0x20(%rsp), %r14
jne 0x1bfac
jmp 0x1c0fc
movl $0x20, %ebp
cmpl 0x14(%r14), %ebp
movl 0x10(%rsp), %ecx
jne 0x1c11b
cmpl 0x18(%r14), %ecx
jne 0x1c11b
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x14(%r14), %rdi
addq $0x18, %r14
movq %r14, %rsi
movl %ebp, %edx
callq 0x87ca
jmp 0x1c10c
jmp 0x1c131
movq %rax, %rbx
jmp 0x1c145
jmp 0x1c138
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x1119a
leaq 0x16(%rsp), %rdi
callq 0x10ea2
leaq 0x30(%rsp), %rdi
callq 0x10e96
movq %rbx, %rdi
callq 0x6670
nop