// File: /workspace/github_cpp_makefile_star2_O1/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 $0x48, %rsp
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r14
movq %rdx, %rsi
callq 0x27890
movq 0x8(%rbx), %rax
subq (%rbx), %rax
shrq $0x3, %rax
movl %eax, 0x4(%rsp)
cmpb $0x1, 0x30(%r14)
jne 0x4140b
movl %eax, %ecx
sarl $0x18, %ecx
movl %eax, %edx
shll $0x8, %edx
andl $0xff0000, %edx         # imm = 0xFF0000
movl %eax, %esi
shrl $0x8, %esi
andl $0xff00, %esi           # imm = 0xFF00
shll $0x18, %eax
orl %ecx, %eax
orl %edx, %eax
orl %esi, %eax
movl %eax, 0x4(%rsp)
movq 0x58(%r14), %rdi
movq (%rdi), %rax
leaq 0x4(%rsp), %rsi
movl $0x4, %edx
callq *0x40(%rax)
movq 0x8(%rbx), %rcx
subq (%rbx), %rcx
movq %rax, %r15
shrq $0x3, %rcx
leaq 0x8(%rsp), %rdx
movl %ecx, (%rdx)
movq %r14, %rdi
movq %r12, %rsi
callq 0x277c0
movq (%rbx), %r13
movq 0x8(%rbx), %rbp
cmpq %rbp, %r13
je 0x41486
leaq 0x8(%rsp), %r12
movq (%r13), %rax
movq %rax, 0x8(%rsp)
cmpb $0x1, 0x30(%r14)
jne 0x41468
bswapq %rax
movq %rax, 0x8(%rsp)
movq 0x58(%r14), %rdi
movq (%rdi), %rax
movq %r12, %rsi
movl $0x8, %edx
callq *0x40(%rax)
addq %rax, %r15
addq $0x8, %r13
cmpq %rbp, %r13
jne 0x41450
movq 0x8(%rbx), %rax
subq (%rbx), %rax
addq $0x4, %rax
cmpq %rax, %r15
jne 0x414a5
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x28, %edi
callq 0x269d0
movq %rax, %rbx
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x14f2c(%rip), %rsi     # 0x563ee
leaq 0x14f49(%rip), %rdx     # 0x56412
leaq 0x8(%rsp), %rdi
callq 0x26750
leaq 0x38(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x14f2f(%rip), %rsi     # 0x56413
leaq 0x14f4a(%rip), %rdx     # 0x56435
leaq 0x28(%rsp), %rdi
callq 0x26750
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
leaq 0x28(%rsp), %rdx
movq %rbx, %rdi
callq 0x28490
xorl %ebp, %ebp
movq 0x29a25(%rip), %rsi     # 0x6af38
movq 0x29a5e(%rip), %rdx     # 0x6af78
movq %rbx, %rdi
callq 0x28a30
movq %rax, %r14
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0x4153c
callq 0x27560
jmp 0x4153c
movq %rax, %r14
movb $0x1, %bpl
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x41553
callq 0x27560
jmp 0x41553
movq %rax, %r14
movb $0x1, %bpl
testb %bpl, %bpl
je 0x41560
movq %rbx, %rdi
callq 0x27070
movq %r14, %rdi
callq 0x28c20