// File: zeeev[P]DASVC/bamtools/src/api/internal/index/BamStandardIndex_p.cpp
// Function: BamTools::Internal::BamStandardIndex::WriteBins(int const&, std::map<unsigned int, std::vector<BamTools::Internal::BaiAlignmentChunk, std::allocator<BamTools::Internal::BaiAlignmentChunk>>, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, std::vector<BamTools::Internal::BaiAlignmentChunk, std::allocator<BamTools::Internal::BaiAlignmentChunk>>>>>&)
void BamStandardIndex::WriteBins(const int& refId, BaiBinMap& bins) {

    // write number of bins
    int32_t binCount = bins.size();
    if ( m_isBigEndian ) SwapEndian_32(binCount);
    const int64_t numBytesWritten = m_resources.Device->Write((const char*)&binCount, sizeof(binCount));
    if ( numBytesWritten != sizeof(binCount) )
        throw BamException("BamStandardIndex::WriteBins", "could not write bin count");

    // save summary for reference's bins
    SaveBinsSummary(refId, bins.size());

    // iterate over bins
    BaiBinMap::iterator binIter = bins.begin();
    BaiBinMap::iterator binEnd  = bins.end();
    for ( ; binIter != binEnd; ++binIter )
        WriteBin( (*binIter).first, (*binIter).second );
}

// Assembly:
subq $0xc8, %rsp
movq %rdi, 0xc0(%rsp)
movq %rsi, 0xb8(%rsp)
movq %rdx, 0xb0(%rsp)
movq 0xc0(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0xb0(%rsp), %rdi
callq 0x7c3e0
movq %rax, %rcx
movq 0x28(%rsp), %rax
movl %ecx, 0xac(%rsp)
testb $0x1, 0x30(%rax)
je 0xb5d7b
leaq 0xac(%rsp), %rdi
callq 0x75b80
movq 0x28(%rsp), %rax
movq 0x58(%rax), %rdi
movq (%rdi), %rax
leaq 0xac(%rsp), %rsi
movl $0x4, %edx
callq *0x40(%rax)
movq %rax, 0xa0(%rsp)
cmpq $0x4, 0xa0(%rsp)
je 0xb5ec7
movb $0x1, 0x46(%rsp)
movl $0x28, %edi
callq 0x737c0
movq %rax, 0x18(%rsp)
leaq 0x7f(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x7b5f0
movq 0x20(%rsp), %rdx
leaq 0x357ef(%rip), %rsi     # 0xeb5cc
leaq 0x80(%rsp), %rdi
callq 0x78e70
jmp 0xb5dec
leaq 0x47(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x7b5f0
movq 0x10(%rsp), %rdx
leaq 0x357e1(%rip), %rsi     # 0xeb5e8
leaq 0x48(%rsp), %rdi
callq 0x78e70
jmp 0xb5e13
movq 0x18(%rsp), %rdi
leaq 0x80(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0x79cd0
jmp 0xb5e2c
movq 0x18(%rsp), %rdi
movb $0x0, 0x46(%rsp)
movq 0x5c0d3(%rip), %rsi     # 0x111f10
movq 0x5c11c(%rip), %rdx     # 0x111f60
callq 0x7b010
jmp 0xb5f85
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
jmp 0xb5ea5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
jmp 0xb5e8a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x7cce8
jmp 0xb5e88
jmp 0xb5e8a
leaq 0x47(%rsp), %rdi
callq 0x76f80
leaq 0x80(%rsp), %rdi
callq 0x7cce8
jmp 0xb5ea3
jmp 0xb5ea5
leaq 0x7f(%rsp), %rdi
callq 0x76f80
testb $0x1, 0x46(%rsp)
jne 0xb5eb8
jmp 0xb5ec2
movq 0x18(%rsp), %rdi
callq 0x74e00
jmp 0xb5f73
movq 0xb8(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0xb0(%rsp), %rdi
callq 0x7c3e0
movq 0x28(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl %eax, 0x40(%rsp)
leaq 0x40(%rsp), %rdx
callq 0x71b70
movq 0xb0(%rsp), %rdi
callq 0x76070
movq %rax, 0x38(%rsp)
movq 0xb0(%rsp), %rdi
callq 0x76fc0
movq %rax, 0x30(%rsp)
leaq 0x38(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x72d50
testb $0x1, %al
jne 0xb5f32
jmp 0xb5f6b
leaq 0x38(%rsp), %rdi
callq 0x7b3d0
movq %rax, (%rsp)
leaq 0x38(%rsp), %rdi
callq 0x7b3d0
movq 0x28(%rsp), %rdi
movq (%rsp), %rsi
movq %rax, %rdx
addq $0x8, %rdx
callq 0x79bb0
leaq 0x38(%rsp), %rdi
callq 0x71df0
jmp 0xb5f1d
addq $0xc8, %rsp
retq
movq 0x70(%rsp), %rdi
callq 0x7b550
movq %rax, %rdi
callq 0x88ef0
nopw %cs:(%rax,%rax)