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

    // copy entry data
    int32_t maxEndPosition = block.MaxEndPosition;
    int64_t startOffset    = block.StartOffset;
    int32_t startPosition  = block.StartPosition;

    // swap endian-ness if necessary
    if ( m_isBigEndian ) {
        SwapEndian_32(maxEndPosition);
        SwapEndian_64(startOffset);
        SwapEndian_32(startPosition);
    }

    // write the reference index entry
    int64_t numBytesWritten = 0;
    numBytesWritten += m_resources.Device->Write((const char*)&maxEndPosition, sizeof(maxEndPosition));
    numBytesWritten += m_resources.Device->Write((const char*)&startOffset,    sizeof(startOffset));
    numBytesWritten += m_resources.Device->Write((const char*)&startPosition,  sizeof(startPosition));

    // check block written ok
    const int expectedBytes = sizeof(maxEndPosition) +
                              sizeof(startOffset) +
                              sizeof(startPosition);
    if ( numBytesWritten != expectedBytes )
        throw BamException("BamToolsIndex::WriteBlock", "could not write BTI block");
}

// Assembly:
subq $0xb8, %rsp
movq %rdi, 0xb0(%rsp)
movq %rsi, 0xa8(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0xa8(%rsp), %rcx
movl (%rcx), %ecx
movl %ecx, 0xa4(%rsp)
movq 0xa8(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, 0x98(%rsp)
movq 0xa8(%rsp), %rcx
movl 0x10(%rcx), %ecx
movl %ecx, 0x94(%rsp)
testb $0x1, 0x30(%rax)
je 0xc3a18
leaq 0xa4(%rsp), %rdi
callq 0x75b80
leaq 0x98(%rsp), %rdi
callq 0x7a460
leaq 0x94(%rsp), %rdi
callq 0x75b80
movq 0x18(%rsp), %rax
movq $0x0, 0x88(%rsp)
movq 0x60(%rax), %rdi
movq (%rdi), %rax
leaq 0xa4(%rsp), %rsi
movl $0x4, %edx
callq *0x40(%rax)
movq %rax, %rcx
movq 0x18(%rsp), %rax
addq 0x88(%rsp), %rcx
movq %rcx, 0x88(%rsp)
movq 0x60(%rax), %rdi
movq (%rdi), %rax
leaq 0x98(%rsp), %rsi
movl $0x8, %edx
callq *0x40(%rax)
movq %rax, %rcx
movq 0x18(%rsp), %rax
addq 0x88(%rsp), %rcx
movq %rcx, 0x88(%rsp)
movq 0x60(%rax), %rdi
movq (%rdi), %rax
leaq 0x94(%rsp), %rsi
movl $0x4, %edx
callq *0x40(%rax)
addq 0x88(%rsp), %rax
movq %rax, 0x88(%rsp)
movl $0x10, 0x84(%rsp)
cmpq $0x10, 0x88(%rsp)
je 0xc3bd3
movb $0x1, 0x26(%rsp)
movl $0x28, %edi
callq 0x737c0
movq %rax, 0x8(%rsp)
leaq 0x5f(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x7b5f0
movq 0x10(%rsp), %rdx
leaq 0x27f8b(%rip), %rsi     # 0xeba82
leaq 0x60(%rsp), %rdi
callq 0x78e70
jmp 0xc3b03
leaq 0x27(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x7b5f0
movq (%rsp), %rdx
leaq 0x27f80(%rip), %rsi     # 0xeba9c
leaq 0x28(%rsp), %rdi
callq 0x78e70
jmp 0xc3b28
movq 0x8(%rsp), %rdi
leaq 0x60(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0x79cd0
jmp 0xc3b3e
movq 0x8(%rsp), %rdi
movb $0x0, 0x26(%rsp)
movq 0x4e3c1(%rip), %rsi     # 0x111f10
movq 0x4e40a(%rip), %rdx     # 0x111f60
callq 0x7b010
jmp 0xc3bed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x50(%rsp)
movl %eax, 0x4c(%rsp)
jmp 0xc3bb4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x50(%rsp)
movl %eax, 0x4c(%rsp)
jmp 0xc3b9c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x50(%rsp)
movl %eax, 0x4c(%rsp)
leaq 0x28(%rsp), %rdi
callq 0x7cce8
jmp 0xc3b9a
jmp 0xc3b9c
leaq 0x27(%rsp), %rdi
callq 0x76f80
leaq 0x60(%rsp), %rdi
callq 0x7cce8
jmp 0xc3bb2
jmp 0xc3bb4
leaq 0x5f(%rsp), %rdi
callq 0x76f80
testb $0x1, 0x26(%rsp)
jne 0xc3bc7
jmp 0xc3bd1
movq 0x8(%rsp), %rdi
callq 0x74e00
jmp 0xc3bdb
addq $0xb8, %rsp
retq
movq 0x50(%rsp), %rdi
callq 0x7b550
movq %rax, %rdi
callq 0x88ef0
nopl (%rax)