// File: yangwanyuan[P]HLKVDS/src/Tier.cc
// Function: hlkvds::MediumTier::SetSBReservedContent(char*, unsigned long)
bool MediumTier::SetSBReservedContent(char* buf, uint64_t length) {
    char* buf_ptr = buf;
    uint64_t medium_tier_header_size = sizeof(MultiTierDS_SB_Reserved_MediumTier_Header);
    memcpy((void*)&sbResMediumTierHeader_, (const void *)buf_ptr, medium_tier_header_size);
    __DEBUG("MultiTierDS_SB_Reserved_MediumTier_Header: segment_size = %d, volume_num = %d",
            sbResMediumTierHeader_.segment_size, sbResMediumTierHeader_.volume_num);
    buf_ptr += medium_tier_header_size;

    uint64_t except_length = sizeof(MultiTierDS_SB_Reserved_MediumTier_Header) +
                            sbResMediumTierHeader_.volume_num * sizeof(MultiTierDS_SB_Reserved_MediumTier_Content);
    if (length != except_length) {
        __INFO("!!!!!length = %ld, except_length = %ld, volNum_ = %d", length, except_length, volNum_);
        return false;
    }

    //Get sbResVolVec_
    uint64_t sb_res_item_size = sizeof(MultiTierDS_SB_Reserved_MediumTier_Content);
    for (uint32_t i = 0; i < sbResMediumTierHeader_.volume_num; i++) {
        MultiTierDS_SB_Reserved_MediumTier_Content sb_res_item;
        memcpy((void*)&sb_res_item, (const void*)buf_ptr, sb_res_item_size);
        sbResMediumTierVolVec_.push_back(sb_res_item);
        buf_ptr += sb_res_item_size;
        __DEBUG("MultiTierDS_SB_Reserved_MediumTier_Content[%d]: device_path = %s, segment_num = %d, current_seg_id = %d",
            i, sbResMediumTierVolVec_[i].dev_path, sbResMediumTierVolVec_[i].segment_num,
            sbResMediumTierVolVec_[i].cur_seg_id);
    }
    return true;
}

// Assembly:
subq $0x168, %rsp            # imm = 0x168
movq %rdi, 0x158(%rsp)
movq %rsi, 0x150(%rsp)
movq %rdx, 0x148(%rsp)
movq 0x158(%rsp), %rdi
movq %rdi, 0x10(%rsp)
movq 0x150(%rsp), %rax
movq %rax, 0x140(%rsp)
movq $0x8, 0x138(%rsp)
addq $0x18, %rdi
movq 0x140(%rsp), %rsi
movq 0x138(%rsp), %rdx
callq 0x8410
movq 0x10(%rsp), %rax
movq 0x138(%rsp), %rcx
addq 0x140(%rsp), %rcx
movq %rcx, 0x140(%rsp)
movl 0x1c(%rax), %eax
imulq $0x108, %rax, %rax      # imm = 0x108
addq $0x8, %rax
movq %rax, 0x130(%rsp)
movq 0x148(%rsp), %rax
cmpq 0x130(%rsp), %rax
je 0x4d3d0
jmp 0x4d33c
movq 0x23c95(%rip), %rax     # 0x70fd8
movq (%rax), %rax
movq %rax, 0x8(%rsp)
callq 0x8480
movq 0x8(%rsp), %rdi
movq %rax, %rdx
leaq 0x505d(%rip), %rsi      # 0x523bc
leaq 0x7345(%rip), %rcx      # 0x546ab
leaq 0x7175(%rip), %r8       # 0x544e2
movl $0x2bc, %r9d            # imm = 0x2BC
movb $0x0, %al
callq 0x86f0
movq 0x10(%rsp), %rax
movq 0x23c52(%rip), %rcx     # 0x70fd8
movq (%rcx), %rdi
movq 0x148(%rsp), %rdx
movq 0x130(%rsp), %rcx
movl 0x40(%rax), %r8d
leaq 0x731c(%rip), %rsi      # 0x546c0
movb $0x0, %al
callq 0x86f0
movq 0x23c26(%rip), %rax     # 0x70fd8
movq (%rax), %rdi
leaq 0x5a09(%rip), %rsi      # 0x52dc5
movb $0x0, %al
callq 0x86f0
movb $0x0, 0x167(%rsp)
jmp 0x4d462
movq $0x108, 0x128(%rsp) # imm = 0x108
movl $0x0, 0x124(%rsp)
movq 0x10(%rsp), %rcx
movl 0x124(%rsp), %eax
cmpl 0x1c(%rcx), %eax
jae 0x4d45a
leaq 0x1c(%rsp), %rdi
callq 0x4ecc0
movq 0x140(%rsp), %rsi
movq 0x128(%rsp), %rdx
leaq 0x1c(%rsp), %rdi
callq 0x8410
movq 0x10(%rsp), %rdi
addq $0x20, %rdi
leaq 0x1c(%rsp), %rsi
callq 0x4ecf0
movq 0x128(%rsp), %rax
addq 0x140(%rsp), %rax
movq %rax, 0x140(%rsp)
movl 0x124(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x124(%rsp)
jmp 0x4d3e7
movb $0x1, 0x167(%rsp)
movb 0x167(%rsp), %al
andb $0x1, %al
addq $0x168, %rsp            # imm = 0x168
retq
nopw %cs:(%rax,%rax)