// File: zeeev[P]DASVC/bamtools/src/api/internal/index/BamToolsIndex_p.cpp
// Function: BamTools::Internal::BamToolsIndex::WriteHeader()
void BamToolsIndex::WriteHeader(void) {

    int64_t numBytesWritten = 0 ;

    // write BTI index format 'magic number'
    numBytesWritten += m_resources.Device->Write(BamToolsIndex::BTI_MAGIC, 4);

    // write BTI index format version
    int32_t currentVersion = (int32_t)m_outputVersion;
    if ( m_isBigEndian ) SwapEndian_32(currentVersion);
    numBytesWritten += m_resources.Device->Write((const char*)&currentVersion, sizeof(currentVersion));

    // write block size
    uint32_t blockSize = m_blockSize;
    if ( m_isBigEndian ) SwapEndian_32(blockSize);
    numBytesWritten += m_resources.Device->Write((const char*)&blockSize, sizeof(blockSize));

    // write number of references
    int32_t numReferences = m_indexFileSummary.size();
    if ( m_isBigEndian ) SwapEndian_32(numReferences);
    numBytesWritten += m_resources.Device->Write((const char*)&numReferences, sizeof(numReferences));

    // check header written ok
    const int expectedBytes = 4 +
                              sizeof(currentVersion) +
                              sizeof(blockSize) +
                              sizeof(numReferences);
    if ( numBytesWritten != expectedBytes )
        throw BamException("BamToolsIndex::WriteHeader", "could not write BTI header");
}

// Assembly:
subq $0xa8, %rsp
movq %rdi, 0xa0(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x20(%rsp)
movq $0x0, 0x98(%rsp)
movq 0x60(%rax), %rdi
movq (%rdi), %rax
leaq 0x298bb(%rip), %rsi     # 0xeb6e1
movl $0x4, %edx
callq *0x40(%rax)
movq %rax, %rcx
movq 0x20(%rsp), %rax
addq 0x98(%rsp), %rcx
movq %rcx, 0x98(%rsp)
movl 0x58(%rax), %ecx
movl %ecx, 0x94(%rsp)
testb $0x1, 0x30(%rax)
je 0xc1e63
leaq 0x94(%rsp), %rdi
callq 0x75b80
movq 0x20(%rsp), %rax
movq 0x60(%rax), %rdi
movq (%rdi), %rax
leaq 0x94(%rsp), %rsi
movl $0x4, %edx
callq *0x40(%rax)
movq %rax, %rcx
movq 0x20(%rsp), %rax
addq 0x98(%rsp), %rcx
movq %rcx, 0x98(%rsp)
movl 0x50(%rax), %ecx
movl %ecx, 0x90(%rsp)
testb $0x1, 0x30(%rax)
je 0xc1eb4
leaq 0x90(%rsp), %rdi
callq 0x77400
movq 0x20(%rsp), %rax
movq 0x60(%rax), %rdi
movq (%rdi), %rax
leaq 0x90(%rsp), %rsi
movl $0x4, %edx
callq *0x40(%rax)
movq 0x20(%rsp), %rdi
addq 0x98(%rsp), %rax
movq %rax, 0x98(%rsp)
addq $0x38, %rdi
callq 0x72c30
movq %rax, %rcx
movq 0x20(%rsp), %rax
movl %ecx, 0x8c(%rsp)
testb $0x1, 0x30(%rax)
je 0xc1f10
leaq 0x8c(%rsp), %rdi
callq 0x75b80
movq 0x20(%rsp), %rax
movq 0x60(%rax), %rdi
movq (%rdi), %rax
leaq 0x8c(%rsp), %rsi
movl $0x4, %edx
callq *0x40(%rax)
addq 0x98(%rsp), %rax
movq %rax, 0x98(%rsp)
movl $0x10, 0x88(%rsp)
cmpq $0x10, 0x98(%rsp)
je 0xc2063
movb $0x1, 0x2e(%rsp)
movl $0x28, %edi
callq 0x737c0
movq %rax, 0x10(%rsp)
leaq 0x67(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x7b5f0
movq 0x18(%rsp), %rdx
leaq 0x29b31(%rip), %rsi     # 0xebab6
leaq 0x68(%rsp), %rdi
callq 0x78e70
jmp 0xc1f91
leaq 0x2f(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x7b5f0
movq 0x8(%rsp), %rdx
leaq 0x29b25(%rip), %rsi     # 0xebad1
leaq 0x30(%rsp), %rdi
callq 0x78e70
jmp 0xc1fb8
movq 0x10(%rsp), %rdi
leaq 0x68(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x79cd0
jmp 0xc1fce
movq 0x10(%rsp), %rdi
movb $0x0, 0x2e(%rsp)
movq 0x4ff31(%rip), %rsi     # 0x111f10
movq 0x4ff7a(%rip), %rdx     # 0x111f60
callq 0x7b010
jmp 0xc207d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
jmp 0xc2044
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
jmp 0xc202c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x7cce8
jmp 0xc202a
jmp 0xc202c
leaq 0x2f(%rsp), %rdi
callq 0x76f80
leaq 0x68(%rsp), %rdi
callq 0x7cce8
jmp 0xc2042
jmp 0xc2044
leaq 0x67(%rsp), %rdi
callq 0x76f80
testb $0x1, 0x2e(%rsp)
jne 0xc2057
jmp 0xc2061
movq 0x10(%rsp), %rdi
callq 0x74e00
jmp 0xc206b
addq $0xa8, %rsp
retq
movq 0x58(%rsp), %rdi
callq 0x7b550
movq %rax, %rdi
callq 0x88ef0
nopl (%rax)