// File: 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:
subq $0xe8, %rsp
movq %rdi, 0xe0(%rsp)
movq %rsi, 0xd8(%rsp)
movq %rdx, 0xd0(%rsp)
movq 0xe0(%rsp), %rdi
movq %rdi, 0x30(%rsp)
movq 0xd0(%rsp), %rsi
callq 0x76df0
movq $0x0, 0xc8(%rsp)
movq 0xd0(%rsp), %rdi
callq 0x79820
movq %rax, %rcx
movq 0x30(%rsp), %rax
movl %ecx, 0xc4(%rsp)
testb $0x1, 0x30(%rax)
je 0xb6004
leaq 0xc4(%rsp), %rdi
callq 0x75b80
movq 0x30(%rsp), %rax
movq 0x58(%rax), %rdi
movq (%rdi), %rax
leaq 0xc4(%rsp), %rsi
movl $0x4, %edx
callq *0x40(%rax)
addq 0xc8(%rsp), %rax
movq %rax, 0xc8(%rsp)
movq 0xd8(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0xd0(%rsp), %rdi
callq 0x79820
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl %eax, 0xc0(%rsp)
leaq 0xc0(%rsp), %rdx
callq 0x76bd0
movq 0xd0(%rsp), %rdi
callq 0x715a0
movq %rax, 0xb0(%rsp)
leaq 0xb8(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x71d40
movq 0xd0(%rsp), %rdi
callq 0x7c880
movq %rax, 0xa0(%rsp)
leaq 0xa8(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x71d40
leaq 0xb8(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x74590
testb $0x1, %al
jne 0xb60d7
jmp 0xb6148
leaq 0xb8(%rsp), %rdi
callq 0x74460
movq %rax, %rcx
movq 0x30(%rsp), %rax
movq (%rcx), %rcx
movq %rcx, 0x98(%rsp)
testb $0x1, 0x30(%rax)
je 0xb610a
leaq 0x98(%rsp), %rdi
callq 0x72ec0
movq 0x30(%rsp), %rax
movq 0x58(%rax), %rdi
movq (%rdi), %rax
leaq 0x98(%rsp), %rsi
movl $0x8, %edx
callq *0x40(%rax)
addq 0xc8(%rsp), %rax
movq %rax, 0xc8(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x77a10
jmp 0xb60bc
movq 0xc8(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0xd0(%rsp), %rdi
callq 0x79820
movq %rax, %rcx
movq 0x20(%rsp), %rax
shlq $0x3, %rcx
addq $0x4, %rcx
cmpq %rcx, %rax
je 0xb6288
movb $0x1, 0x3e(%rsp)
movl $0x28, %edi
callq 0x737c0
movq %rax, 0x10(%rsp)
leaq 0x77(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x7b5f0
movq 0x18(%rsp), %rdx
leaq 0x35491(%rip), %rsi     # 0xeb63b
leaq 0x78(%rsp), %rdi
callq 0x78e70
jmp 0xb61b6
leaq 0x3f(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x7b5f0
movq 0x8(%rsp), %rdx
leaq 0x3548f(%rip), %rsi     # 0xeb660
leaq 0x40(%rsp), %rdi
callq 0x78e70
jmp 0xb61dd
movq 0x10(%rsp), %rdi
leaq 0x78(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x79cd0
jmp 0xb61f3
movq 0x10(%rsp), %rdi
movb $0x0, 0x3e(%rsp)
movq 0x5bd0c(%rip), %rsi     # 0x111f10
movq 0x5bd55(%rip), %rdx     # 0x111f60
callq 0x7b010
jmp 0xb62a2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
jmp 0xb6269
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
jmp 0xb6251
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x7cce8
jmp 0xb624f
jmp 0xb6251
leaq 0x3f(%rsp), %rdi
callq 0x76f80
leaq 0x78(%rsp), %rdi
callq 0x7cce8
jmp 0xb6267
jmp 0xb6269
leaq 0x77(%rsp), %rdi
callq 0x76f80
testb $0x1, 0x3e(%rsp)
jne 0xb627c
jmp 0xb6286
movq 0x10(%rsp), %rdi
callq 0x74e00
jmp 0xb6290
addq $0xe8, %rsp
retq
movq 0x68(%rsp), %rdi
callq 0x7b550
movq %rax, %rdi
callq 0x88ef0
nopw %cs:(%rax,%rax)
nopl (%rax)