// File: /workspace/github_cpp_makefile_star2_O2/yangwanyuan[P]HLKVDS/src/DS_MultiVolume_Impl.cc
// Function: hlkvds::DS_MultiVolume_Impl::writeDataImmediately(hlkvds::KVSlice&)
Status DS_MultiVolume_Impl::writeDataImmediately(KVSlice& slice) {
    uint32_t seg_id = 0;
    bool ret = false;

    int vol_id = pickVol();
    Volume *vol = volMap_[vol_id];

    //TODO: use GcSegment first, need abstract segment.
    while (!vol->Alloc(seg_id)) {
        ret = vol->ForeGC();
        if (!ret) {
            __ERROR("Cann't get a new Empty Segment.\n");
            return Status::Aborted("Can't allocate a Empty Segment.");
        }
    }

    SegLatencyFriendly *seg = new SegLatencyFriendly(vol, idxMgr_);
    seg->Put(&slice);
    seg->SegSegId(seg_id);
    ret = seg->WriteSegToDevice();
    if(!ret) {
        __ERROR("Write batch segment to device failed");
        vol->FreeForFailed(seg_id);
        delete seg;
        return Status::IOError("could not write batch segment to device ");
    }
    uint32_t free_size = seg->GetFreeSize();
    vol->Use(seg_id, free_size);
    seg->UpdateToIndex();
    delete seg;
    return Status::OK();
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %rbx
leaq 0x8(%rsp), %r14
andl $0x0, (%r14)
movq %rsi, %rdi
callq 0x9292
leaq 0xc(%rsp), %rsi
movl %eax, (%rsi)
leaq 0x28(%r13), %rdi
callq 0xaf64
movq (%rax), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x1dde4
testb %al, %al
jne 0x99d1
movq %r15, %rdi
callq 0x1df8c
testb %al, %al
jne 0x994e
movq 0x28668(%rip), %r15     # 0x31fd8
movq (%r15), %r14
callq 0x63c0
leaq 0x15926(%rip), %rsi     # 0x1f2a5
leaq 0x15d1f(%rip), %rcx     # 0x1f6a5
leaq 0x159d3(%rip), %r8      # 0x1f360
movq %r14, %rdi
movq %rax, %rdx
movl $0x1d2, %r9d            # imm = 0x1D2
xorl %eax, %eax
callq 0x6580
movq (%r15), %rcx
leaq 0x15b2c(%rip), %rdi     # 0x1f4d6
pushq $0x20
popq %rsi
pushq $0x1
popq %rdx
callq 0x6750
movq (%r15), %rsi
pushq $0xa
popq %rdi
callq 0x64b0
leaq 0x15b30(%rip), %rsi     # 0x1f4f7
movq %rbx, %rdi
callq 0xb30a
jmp 0x9a41
pushq $0x48
popq %rdi
callq 0x6410
movq %rax, %r14
movq 0x20(%r13), %rdx
movq %rax, %rdi
movq %r15, %rsi
callq 0x1954e
movq %r14, %rdi
movq %r12, %rsi
callq 0x1959a
movl 0x8(%rsp), %eax
movl %eax, 0x10(%r14)
movq %r14, %rdi
callq 0x19636
testb %al, %al
je 0x9a52
movl 0x14(%r14), %edx
subl 0x20(%r14), %edx
addl $-0x20, %edx
movl 0x8(%rsp), %esi
movq %r15, %rdi
callq 0x1df82
movq %r14, %rdi
callq 0x199a2
movq %r14, %rdi
callq 0x1950a
movq %r14, %rdi
callq 0x63f0
andl $0x0, (%rbx)
andq $0x0, 0x8(%rbx)
movq %rbx, %rax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq 0x2857f(%rip), %r13     # 0x31fd8
movq (%r13), %r12
callq 0x63c0
leaq 0x1583c(%rip), %rsi     # 0x1f2a5
leaq 0x15c35(%rip), %rcx     # 0x1f6a5
leaq 0x158e9(%rip), %r8      # 0x1f360
movq %r12, %rdi
movq %rax, %rdx
movl $0x1dc, %r9d            # imm = 0x1DC
xorl %eax, %eax
callq 0x6580
movq (%r13), %rcx
leaq 0x15ac7(%rip), %rdi     # 0x1f55c
pushq $0x24
popq %rsi
pushq $0x1
popq %rdx
callq 0x6750
movq (%r13), %rsi
pushq $0xa
popq %rdi
callq 0x64b0
movl 0x8(%rsp), %esi
movq %r15, %rdi
callq 0x1df6e
movq %r14, %rdi
callq 0x1950a
movq %r14, %rdi
callq 0x63f0
leaq 0x15ab2(%rip), %rsi     # 0x1f581
movq %rbx, %rdi
callq 0xb31e
jmp 0x9a41
movq %rax, %rbx
movq %r14, %rdi
callq 0x63f0
movq %rbx, %rdi
callq 0x6680
nop