// File: /workspace/github_cpp_makefile_star2_O2/zeeev[P]DASVC/bamtools/src/api/internal/index/BamStandardIndex_p.cpp
// Function: BamTools::Internal::BamStandardIndex::WriteLinearOffsets(int const&, std::vector<unsigned long, std::allocator<unsigned long>>&)
void BamStandardIndex::WriteLinearOffsets(const int& refId, BaiLinearOffsetVector& linearOffsets) {

    // make sure linear offsets are sorted before writing & saving summary
    SortLinearOffsets(linearOffsets);

    int64_t numBytesWritten = 0;

    // write number of linear offsets
    int32_t offsetCount = linearOffsets.size();
    if ( m_isBigEndian ) SwapEndian_32(offsetCount);
    numBytesWritten += m_resources.Device->Write((const char*)&offsetCount, sizeof(offsetCount));

    // save summary for reference's linear offsets
    SaveLinearOffsetsSummary(refId, linearOffsets.size());

    // iterate over linear offsets
    BaiLinearOffsetVector::const_iterator offsetIter = linearOffsets.begin();
    BaiLinearOffsetVector::const_iterator offsetEnd  = linearOffsets.end();
    for ( ; offsetIter != offsetEnd; ++offsetIter ) {

        // write linear offset
        uint64_t linearOffset = (*offsetIter);
        if ( m_isBigEndian ) SwapEndian_64(linearOffset);
        numBytesWritten += m_resources.Device->Write((const char*)&linearOffset, sizeof(linearOffset));
    }

    if ( numBytesWritten != (sizeof(offsetCount) + linearOffsets.size()*sizeof(uint64_t)) )
        throw BamException("BamStandardIndex::WriteLinearOffsets", "could not write BAI linear offsets");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r14
movq %rdx, %rsi
callq 0x33360
movq 0x8(%rbx), %rax
subq (%rbx), %rax
shrq $0x3, %rax
movl %eax, 0xc(%rsp)
cmpb $0x1, 0x30(%r14)
jne 0x495d9
leaq 0xc(%rsp), %rdi
callq 0x32c90
movq 0x58(%r14), %rdi
movq (%rdi), %rax
leaq 0xc(%rsp), %rsi
pushq $0x4
popq %rdx
callq *0x40(%rax)
movq 0x8(%rbx), %rcx
subq (%rbx), %rcx
movq %rax, %r15
shrq $0x3, %rcx
leaq 0x18(%rsp), %r13
movl %ecx, (%r13)
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x33260
movq (%rbx), %r12
movq %rbx, 0x10(%rsp)
movq 0x8(%rbx), %rbx
pushq $0x8
popq %rbp
cmpq %rbx, %r12
je 0x49654
movq (%r12), %rax
movq %rax, 0x18(%rsp)
cmpb $0x1, 0x30(%r14)
jne 0x4963c
bswapq %rax
movq %rax, 0x18(%rsp)
movq 0x58(%r14), %rdi
movq (%rdi), %rax
movq %r13, %rsi
movl %ebp, %edx
callq *0x40(%rax)
addq %rax, %r15
addq $0x8, %r12
jmp 0x4961f
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
addq $0x4, %rax
cmpq %rax, %r15
jne 0x49678
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x28
popq %rdi
callq 0x31e70
movq %rax, %rbx
leaq 0x12d39(%rip), %rsi     # 0x5c3c3
leaq 0x18(%rsp), %rdi
leaq 0xb(%rsp), %rdx
callq 0x31b30
leaq 0x12d48(%rip), %rsi     # 0x5c3e8
leaq 0x38(%rsp), %rdi
leaq 0xa(%rsp), %rdx
callq 0x31b30
movb $0x1, %bpl
leaq 0x18(%rsp), %rsi
leaq 0x38(%rsp), %rdx
movq %rbx, %rdi
callq 0x344c0
xorl %ebp, %ebp
movq 0x2b86b(%rip), %rsi     # 0x74f38
movq 0x2b8a4(%rip), %rdx     # 0x74f78
movq %rbx, %rdi
callq 0x34c90
movq %rax, %r14
leaq 0x38(%rsp), %rdi
callq 0x33a00
jmp 0x496f1
movq %rax, %r14
movb $0x1, %bpl
leaq 0x18(%rsp), %rdi
callq 0x33a00
testb %bpl, %bpl
jne 0x4970d
jmp 0x49715
movq %rax, %rdi
callq 0x39b2f
movq %rax, %r14
movq %rbx, %rdi
callq 0x327c0
movq %r14, %rdi
callq 0x34ed0
nop