// File: /workspace/github_cpp_makefile_star2_O2/yangwanyuan[P]HLKVDS/src/DS_MultiVolume_Impl.cc
// Function: hlkvds::DS_MultiVolume_Impl::WriteBatchData(hlkvds::WriteBatch*)
Status DS_MultiVolume_Impl::WriteBatchData(WriteBatch *batch) {
    uint32_t seg_id = 0;
    bool ret;

    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.");
        }
    }

    SegForSlice *seg = new SegForSlice(vol, idxMgr_);
    for (std::list<KVSlice *>::iterator iter = batch->batch_.begin();
            iter != batch->batch_.end(); iter++) {
        if (seg->TryPut(*iter)) {
            seg->Put(*iter);
        }
        else {
            __ERROR("The Batch is too large, can't put in one segment");
            delete seg;
            return Status::Aborted("Batch is too large.");
        }
    }

    seg->SetSegId(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 0x9ba6
movq %r15, %rdi
callq 0x1df8c
testb %al, %al
jne 0x9b2a
movq 0x2848c(%rip), %r15     # 0x31fd8
movq (%r15), %r14
callq 0x63c0
leaq 0x1574a(%rip), %rsi     # 0x1f2a5
leaq 0x15965(%rip), %rcx     # 0x1f4c7
leaq 0x157f7(%rip), %r8      # 0x1f360
pushq $0x7c
popq %r9
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x6580
movq (%r15), %rcx
leaq 0x15952(%rip), %rdi     # 0x1f4d6
pushq $0x20
popq %rsi
pushq $0x1
popq %rdx
callq 0x6750
movq (%r15), %rsi
pushq $0xa
popq %rdi
callq 0x64b0
leaq 0x15956(%rip), %rsi     # 0x1f4f7
jmp 0x9cb7
pushq $0x50
popq %rdi
callq 0x6410
movq %rax, %r14
movq 0x20(%r13), %rdx
movq %rax, %rdi
movq %r15, %rsi
callq 0x19436
movq %r12, %r13
movq (%r13), %r13
cmpq %r12, %r13
je 0x9bea
movq 0x10(%r13), %rsi
movq %r14, %rdi
callq 0x18962
testb %al, %al
je 0x9c46
movq 0x10(%r13), %rsi
movq %r14, %rdi
callq 0x1897c
jmp 0x9bc3
movl 0x8(%rsp), %eax
movl %eax, (%r14)
movq %r14, %rdi
callq 0x18a22
testb %al, %al
je 0x9cc4
movl 0x18(%r14), %edx
subl 0x14(%r14), %edx
movl 0x8(%rsp), %esi
movq %r15, %rdi
callq 0x1df82
movq %r14, %rdi
callq 0x19452
movq %r14, %rdi
callq 0x18894
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 0x2838b(%rip), %r12     # 0x31fd8
movq (%r12), %r15
callq 0x63c0
leaq 0x15648(%rip), %rsi     # 0x1f2a5
leaq 0x15863(%rip), %rcx     # 0x1f4c7
leaq 0x156f5(%rip), %r8      # 0x1f360
movq %r15, %rdi
movq %rax, %rdx
movl $0x88, %r9d
xorl %eax, %eax
callq 0x6580
movq (%r12), %rcx
leaq 0x1588e(%rip), %rdi     # 0x1f517
pushq $0x30
popq %rsi
pushq $0x1
popq %rdx
callq 0x6750
movq (%r12), %rsi
pushq $0xa
popq %rdi
callq 0x64b0
movq %r14, %rdi
callq 0x18894
movq %r14, %rdi
callq 0x63f0
leaq 0x15891(%rip), %rsi     # 0x1f548
movq %rbx, %rdi
callq 0xb30a
jmp 0x9c35
movq 0x2830d(%rip), %r13     # 0x31fd8
movq (%r13), %r12
callq 0x63c0
leaq 0x155ca(%rip), %rsi     # 0x1f2a5
leaq 0x157e5(%rip), %rcx     # 0x1f4c7
leaq 0x15677(%rip), %r8      # 0x1f360
movq %r12, %rdi
movq %rax, %rdx
movl $0x91, %r9d
xorl %eax, %eax
callq 0x6580
movq (%r13), %rcx
leaq 0x15855(%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 0x18894
movq %r14, %rdi
callq 0x63f0
leaq 0x15840(%rip), %rsi     # 0x1f581
movq %rbx, %rdi
callq 0xb31e
jmp 0x9c35
movq %rax, %rbx
movq %r14, %rdi
callq 0x63f0
movq %rbx, %rdi
callq 0x6680
nop