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

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

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

    free(align_buf);

    uint64_t reserved_region_length = SuperBlockManager::ReservedRegionLength();

    char *reserved_content = new char[reserved_region_length];
    if ( !dataStor_->GetSBReservedContent(reserved_content, reserved_region_length) ) {
        delete[] reserved_content;
        return false;
    }

    if ( !sbMgr_->SetReservedContent(reserved_content, reserved_region_length) ) {
        delete[] reserved_content;
        return false;
    }

    delete[] reserved_content;
    return true;
}

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x68(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x38(%rsp)
movl $0x0, 0x64(%rsp)
movq 0x18(%rax), %rdi
callq 0x167b0
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rdx
leaq 0x58(%rsp), %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0x8230
movl %eax, 0x64(%rsp)
cmpl $0x0, 0x64(%rsp)
jge 0x35d02
jmp 0x35c8a
movq 0x3b347(%rip), %rax     # 0x70fd8
movq (%rax), %rax
movq %rax, 0x30(%rsp)
callq 0x8480
movq 0x30(%rsp), %rdi
movq %rax, %rdx
leaq 0x1c804(%rip), %rsi     # 0x524b1
leaq 0x1d9fc(%rip), %rcx     # 0x536b0
leaq 0x1d592(%rip), %r8      # 0x5324d
movl $0x1a1, %r9d            # imm = 0x1A1
movb $0x0, %al
callq 0x86f0
movq 0x3b309(%rip), %rax     # 0x70fd8
movq (%rax), %rdi
leaq 0x1d655(%rip), %rsi     # 0x5332e
movb $0x0, %al
callq 0x86f0
movq 0x3b2f1(%rip), %rax     # 0x70fd8
movq (%rax), %rdi
leaq 0x1d0d4(%rip), %rsi     # 0x52dc5
movb $0x0, %al
callq 0x86f0
movb $0x0, 0x77(%rsp)
jmp 0x35f2d
movq 0x58(%rsp), %rdi
movq 0x50(%rsp), %rdx
xorl %esi, %esi
callq 0x8280
movq 0x38(%rsp), %rax
movq 0x28(%rax), %rdi
movq 0x58(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq (%rdi), %rax
callq *0x70(%rax)
testb $0x1, %al
jne 0x35db8
jmp 0x35d36
movq 0x3b29b(%rip), %rax     # 0x70fd8
movq (%rax), %rax
movq %rax, 0x28(%rsp)
callq 0x8480
movq 0x28(%rsp), %rdi
movq %rax, %rdx
leaq 0x1c758(%rip), %rsi     # 0x524b1
leaq 0x1d950(%rip), %rcx     # 0x536b0
leaq 0x1d4e6(%rip), %r8      # 0x5324d
movl $0x1a7, %r9d            # imm = 0x1A7
movb $0x0, %al
callq 0x86f0
movq 0x3b25d(%rip), %rax     # 0x70fd8
movq (%rax), %rdi
leaq 0x1d93f(%rip), %rsi     # 0x536c4
movb $0x0, %al
callq 0x86f0
movq 0x3b245(%rip), %rax     # 0x70fd8
movq (%rax), %rdi
leaq 0x1d028(%rip), %rsi     # 0x52dc5
movb $0x0, %al
callq 0x86f0
movq 0x58(%rsp), %rdi
callq 0x85b0
movb $0x0, 0x77(%rsp)
jmp 0x35f2d
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x58(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq 0x48(%rax), %rcx
movq (%rdi), %rax
callq *0x48(%rax)
cmpq 0x50(%rsp), %rax
je 0x35e6d
jmp 0x35de2
movq 0x3b1ef(%rip), %rax     # 0x70fd8
movq (%rax), %rax
movq %rax, 0x20(%rsp)
callq 0x8480
movq 0x20(%rsp), %rdi
movq %rax, %rdx
leaq 0x1c6ac(%rip), %rsi     # 0x524b1
leaq 0x1d8a4(%rip), %rcx     # 0x536b0
leaq 0x1d43a(%rip), %r8      # 0x5324d
movl $0x1ad, %r9d            # imm = 0x1AD
movb $0x0, %al
callq 0x86f0
movq 0x38(%rsp), %rax
movq 0x3b1ac(%rip), %rcx     # 0x70fd8
movq (%rcx), %rdi
movq 0x48(%rax), %rdx
leaq 0x1d8aa(%rip), %rsi     # 0x536e4
movb $0x0, %al
callq 0x86f0
movq 0x3b190(%rip), %rax     # 0x70fd8
movq (%rax), %rdi
leaq 0x1cf73(%rip), %rsi     # 0x52dc5
movb $0x0, %al
callq 0x86f0
movq 0x58(%rsp), %rdi
callq 0x85b0
movb $0x0, 0x77(%rsp)
jmp 0x35f2d
movq 0x58(%rsp), %rdi
callq 0x85b0
callq 0x116c0
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rdi
callq 0x8040
movq %rax, %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x40(%rsp)
movq 0x28(%rax), %rdi
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
movq (%rdi), %rax
callq *0x60(%rax)
testb $0x1, %al
jne 0x35ed1
movq 0x40(%rsp), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, %rax
je 0x35eca
movq 0x18(%rsp), %rdi
callq 0x8610
movb $0x0, 0x77(%rsp)
jmp 0x35f2d
movq 0x38(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
callq 0x497c0
testb $0x1, %al
jne 0x35f0e
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x35f07
movq 0x10(%rsp), %rdi
callq 0x8610
movb $0x0, 0x77(%rsp)
jmp 0x35f2d
movq 0x40(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x35f28
movq 0x8(%rsp), %rdi
callq 0x8610
movb $0x1, 0x77(%rsp)
movb 0x77(%rsp), %al
andb $0x1, %al
addq $0x78, %rsp
retq
nopl (%rax,%rax)