// File: yangwanyuan[P]HLKVDS/src/MetaStor.cc
// Function: hlkvds::MetaStor::PersistIndexToDevice()
bool MetaStor::PersistIndexToDevice() {
    int ret = false;
    char *align_buf;
    uint64_t length = sbMgr_->GetIndexRegionLength();
    ret = posix_memalign((void **)&align_buf, 4096, length);
    if (ret < 0) {
        __ERROR("Can't allocate memory for Index, Persist Failed!");
        return false;
    }
    memset(align_buf, 0, length);

    if (!idxMgr_->Get(align_buf, length)) {
        __ERROR("Can't Get Index, Persist Failed!");
        free(align_buf);
        return false;
    }

    if ((uint64_t) metaDev_->pWrite(align_buf, length, idxOff_) != length) {
        __ERROR("Could not write Index at position %ld\n", idxOff_);
        free(align_buf);
        return false;
    }

    free(align_buf);

    idxMgr_->UpdateMetaToSB();
    return true;
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x18(%rsp)
movl $0x0, 0x34(%rsp)
movq 0x18(%rax), %rdi
callq 0x36260
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rdx
leaq 0x28(%rsp), %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0x8230
movl %eax, 0x34(%rsp)
cmpl $0x0, 0x34(%rsp)
jge 0x35ab2
jmp 0x35a3a
movq 0x3b597(%rip), %rax     # 0x70fd8
movq (%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x8480
movq 0x10(%rsp), %rdi
movq %rax, %rdx
leaq 0x1ca54(%rip), %rsi     # 0x524b1
leaq 0x1daf8(%rip), %rcx     # 0x5355c
leaq 0x1d7e2(%rip), %r8      # 0x5324d
movl $0x149, %r9d            # imm = 0x149
movb $0x0, %al
callq 0x86f0
movq 0x3b559(%rip), %rax     # 0x70fd8
movq (%rax), %rdi
leaq 0x1dae8(%rip), %rsi     # 0x53571
movb $0x0, %al
callq 0x86f0
movq 0x3b541(%rip), %rax     # 0x70fd8
movq (%rax), %rdi
leaq 0x1d324(%rip), %rsi     # 0x52dc5
movb $0x0, %al
callq 0x86f0
movb $0x0, 0x47(%rsp)
jmp 0x35c34
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rdx
xorl %esi, %esi
callq 0x8280
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rdi
movq 0x28(%rsp), %rsi
movq 0x20(%rsp), %rdx
callq 0x258b0
testb $0x1, %al
jne 0x35b67
jmp 0x35ae5
movq 0x3b4ec(%rip), %rax     # 0x70fd8
movq (%rax), %rax
movq %rax, 0x8(%rsp)
callq 0x8480
movq 0x8(%rsp), %rdi
movq %rax, %rdx
leaq 0x1c9a9(%rip), %rsi     # 0x524b1
leaq 0x1da4d(%rip), %rcx     # 0x5355c
leaq 0x1d737(%rip), %r8      # 0x5324d
movl $0x14f, %r9d            # imm = 0x14F
movb $0x0, %al
callq 0x86f0
movq 0x3b4ae(%rip), %rax     # 0x70fd8
movq (%rax), %rdi
leaq 0x1da6e(%rip), %rsi     # 0x535a2
movb $0x0, %al
callq 0x86f0
movq 0x3b496(%rip), %rax     # 0x70fd8
movq (%rax), %rdi
leaq 0x1d279(%rip), %rsi     # 0x52dc5
movb $0x0, %al
callq 0x86f0
movq 0x28(%rsp), %rdi
callq 0x85b0
movb $0x0, 0x47(%rsp)
jmp 0x35c34
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x28(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq 0x40(%rax), %rcx
movq (%rdi), %rax
callq *0x48(%rax)
cmpq 0x20(%rsp), %rax
je 0x35c17
jmp 0x35b91
movq 0x3b440(%rip), %rax     # 0x70fd8
movq (%rax), %rax
movq %rax, (%rsp)
callq 0x8480
movq (%rsp), %rdi
movq %rax, %rdx
leaq 0x1c8ff(%rip), %rsi     # 0x524b1
leaq 0x1d9a3(%rip), %rcx     # 0x5355c
leaq 0x1d68d(%rip), %r8      # 0x5324d
movl $0x155, %r9d            # imm = 0x155
movb $0x0, %al
callq 0x86f0
movq 0x18(%rsp), %rax
movq 0x3b3ff(%rip), %rcx     # 0x70fd8
movq (%rcx), %rdi
movq 0x40(%rax), %rdx
leaq 0x1d9dc(%rip), %rsi     # 0x535c3
movb $0x0, %al
callq 0x86f0
movq 0x3b3e3(%rip), %rax     # 0x70fd8
movq (%rax), %rdi
leaq 0x1d1c6(%rip), %rsi     # 0x52dc5
movb $0x0, %al
callq 0x86f0
movq 0x28(%rsp), %rdi
callq 0x85b0
movb $0x0, 0x47(%rsp)
jmp 0x35c34
movq 0x28(%rsp), %rdi
callq 0x85b0
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0x25870
movb $0x1, 0x47(%rsp)
movb 0x47(%rsp), %al
andb $0x1, %al
addq $0x48, %rsp
retq
nop