// File: zeeev[P]DASVC/bamtools/src/api/internal/io/BgzfStream_p.cpp
// Function: BamTools::Internal::BgzfStream::FlushBlock()
void BgzfStream::FlushBlock(void) {

    BT_ASSERT_X( m_device, "BgzfStream::FlushBlock() - attempting to flush to null device" );

    // flush all of the remaining blocks
    while ( m_blockOffset > 0 ) {

        // compress the data block
        const size_t blockLength = DeflateBlock(m_blockOffset);

        // flush the data to our output device
        const int64_t numBytesWritten = m_device->Write(m_compressedBlock.Buffer, blockLength);

        // check for device error
        if ( numBytesWritten < 0 ) {
            const string message = string("device error: ") + m_device->GetErrorString();
            throw BamException("BgzfStream::FlushBlock", message);
        }

        // check that we wrote expected numBytes
        if ( numBytesWritten != static_cast<int64_t>(blockLength) ) {
            stringstream s("");
            s << "expected to write " << blockLength
              << " bytes during flushing, but wrote " << numBytesWritten;
            throw BamException("BgzfStream::FlushBlock", s.str());
        }

        // update block data
        m_blockAddress += blockLength;
    }
}

// Assembly:
subq $0x318, %rsp            # imm = 0x318
movq %rdi, 0x310(%rsp)
movq 0x310(%rsp), %rax
movq %rax, 0x58(%rsp)
callq 0x761a0
movq 0x58(%rsp), %rax
cmpl $0x0, 0x4(%rax)
jle 0xcd76b
movq 0x58(%rsp), %rdi
movl 0x4(%rdi), %esi
callq 0x72790
movq %rax, %rcx
movq 0x58(%rsp), %rax
movq %rcx, 0x308(%rsp)
movq 0x18(%rax), %rdi
movq 0x30(%rax), %rsi
movq 0x308(%rsp), %rax
movl %eax, %edx
movq (%rdi), %rax
callq *0x40(%rax)
movq %rax, 0x300(%rsp)
cmpq $0x0, 0x300(%rsp)
jge 0xcd4da
leaq 0x2bf(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x7b5f0
movq 0x50(%rsp), %rdx
leaq 0x1ed3e(%rip), %rsi     # 0xec038
leaq 0x2c0(%rsp), %rdi
callq 0x78e70
jmp 0xcd309
movq 0x58(%rsp), %rax
movq 0x18(%rax), %rsi
movq (%rsi), %rax
movq 0x48(%rax), %rax
leaq 0x288(%rsp), %rdi
callq *%rax
jmp 0xcd325
leaq 0x2e0(%rsp), %rdi
leaq 0x2c0(%rsp), %rsi
leaq 0x288(%rsp), %rdx
callq 0x7c720
jmp 0xcd344
leaq 0x288(%rsp), %rdi
callq 0x7cce8
jmp 0xcd353
leaq 0x2c0(%rsp), %rdi
callq 0x7cce8
jmp 0xcd362
leaq 0x2bf(%rsp), %rdi
callq 0x76f80
movb $0x1, 0x266(%rsp)
movl $0x28, %edi
callq 0x737c0
movq %rax, 0x40(%rsp)
leaq 0x267(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x7b5f0
movq 0x48(%rsp), %rdx
leaq 0x1eca3(%rip), %rsi     # 0xec047
leaq 0x268(%rsp), %rdi
callq 0x78e70
jmp 0xcd3b3
movq 0x40(%rsp), %rdi
leaq 0x268(%rsp), %rsi
leaq 0x2e0(%rsp), %rdx
callq 0x79cd0
jmp 0xcd3cf
movq 0x40(%rsp), %rdi
movb $0x0, 0x266(%rsp)
movq 0x44b2d(%rip), %rsi     # 0x111f10
movq 0x44b76(%rip), %rdx     # 0x111f60
callq 0x7b010
jmp 0xcd788
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0xcd456
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0xcd445
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
leaq 0x288(%rsp), %rdi
callq 0x7cce8
jmp 0xcd443
jmp 0xcd445
leaq 0x2c0(%rsp), %rdi
callq 0x7cce8
jmp 0xcd454
jmp 0xcd456
leaq 0x2bf(%rsp), %rdi
callq 0x76f80
jmp 0xcd773
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0xcd4a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
leaq 0x268(%rsp), %rdi
callq 0x7cce8
jmp 0xcd4a1
jmp 0xcd4a3
leaq 0x267(%rsp), %rdi
callq 0x76f80
testb $0x1, 0x266(%rsp)
jne 0xcd4bc
jmp 0xcd4c6
movq 0x40(%rsp), %rdi
callq 0x74e00
leaq 0x2e0(%rsp), %rdi
callq 0x7cce8
jmp 0xcd4d5
jmp 0xcd773
movq 0x300(%rsp), %rax
cmpq 0x308(%rsp), %rax
je 0xcd751
leaq 0xb7(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x7b5f0
movq 0x38(%rsp), %rdx
leaq 0x1dbce(%rip), %rsi     # 0xeb0dc
leaq 0xb8(%rsp), %rdi
callq 0x78e70
jmp 0xcd51d
movl $0x10, %edi
movl $0x8, %esi
callq 0x7b8d0
movl %eax, 0x34(%rsp)
jmp 0xcd532
movl 0x34(%rsp), %edx
leaq 0xd8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x7a4b0
jmp 0xcd54d
leaq 0xb8(%rsp), %rdi
callq 0x7cce8
jmp 0xcd55c
leaq 0xb7(%rsp), %rdi
callq 0x76f80
leaq 0xe8(%rsp), %rdi
leaq 0x1eae6(%rip), %rsi     # 0xec05e
callq 0x768e0
movq %rax, 0x28(%rsp)
jmp 0xcd584
movq 0x28(%rsp), %rdi
movq 0x308(%rsp), %rsi
callq 0x720a0
movq %rax, 0x20(%rsp)
jmp 0xcd59d
movq 0x20(%rsp), %rdi
leaq 0x1eac8(%rip), %rsi     # 0xec071
callq 0x768e0
movq %rax, 0x18(%rsp)
jmp 0xcd5b5
movq 0x18(%rsp), %rdi
movq 0x300(%rsp), %rsi
callq 0x7ba30
jmp 0xcd5c9
movb $0x1, 0x67(%rsp)
movl $0x28, %edi
callq 0x737c0
movq %rax, 0x8(%rsp)
leaq 0x8f(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x7b5f0
movq 0x10(%rsp), %rdx
leaq 0x1ea4c(%rip), %rsi     # 0xec047
leaq 0x90(%rsp), %rdi
callq 0x78e70
jmp 0xcd60a
leaq 0x68(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x76880
jmp 0xcd61e
movq 0x8(%rsp), %rdi
leaq 0x90(%rsp), %rsi
leaq 0x68(%rsp), %rdx
callq 0x79cd0
jmp 0xcd637
movq 0x8(%rsp), %rdi
movb $0x0, 0x67(%rsp)
movq 0x448c8(%rip), %rsi     # 0x111f10
movq 0x44911(%rip), %rdx     # 0x111f60
callq 0x7b010
jmp 0xcd788
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0xcd694
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x7cce8
jmp 0xcd692
jmp 0xcd694
leaq 0xb7(%rsp), %rdi
callq 0x76f80
jmp 0xcd773
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0xcd740
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0xcd71e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0xcd70d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x7cce8
jmp 0xcd70b
jmp 0xcd70d
leaq 0x90(%rsp), %rdi
callq 0x7cce8
jmp 0xcd71c
jmp 0xcd71e
leaq 0x8f(%rsp), %rdi
callq 0x76f80
testb $0x1, 0x67(%rsp)
jne 0xcd734
jmp 0xcd73e
movq 0x8(%rsp), %rdi
callq 0x74e00
jmp 0xcd740
leaq 0xd8(%rsp), %rdi
callq 0x74f60
jmp 0xcd74f
jmp 0xcd773
movq 0x58(%rsp), %rax
movq 0x308(%rsp), %rcx
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
jmp 0xcd281
addq $0x318, %rsp            # imm = 0x318
retq
movq 0x2b0(%rsp), %rdi
callq 0x7b550
movq %rax, %rdi
callq 0x88ef0
nopl (%rax,%rax)