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

    BT_ASSERT_X( m_device, "BgzfStream::ReadBlock() - trying to read from null IO device");

    // store block's starting address
    const int64_t blockAddress = m_device->Tell();

    // read block header from file
    char header[Constants::BGZF_BLOCK_HEADER_LENGTH];
    int64_t numBytesRead = m_device->Read(header, Constants::BGZF_BLOCK_HEADER_LENGTH);

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

    // if block header empty
    if ( numBytesRead == 0 ) {
        m_blockLength = 0;
        return;
    }

    // if block header invalid size
    if ( numBytesRead != static_cast<int8_t>(Constants::BGZF_BLOCK_HEADER_LENGTH) )
        throw BamException("BgzfStream::ReadBlock", "invalid block header size");

    // validate block header contents
    if ( !BgzfStream::CheckBlockHeader(header) )
        throw BamException("BgzfStream::ReadBlock", "invalid block header contents");

    // copy header contents to compressed buffer
    const size_t blockLength = BamTools::UnpackUnsignedShort(&header[16]) + 1;
    memcpy(m_compressedBlock.Buffer, header, Constants::BGZF_BLOCK_HEADER_LENGTH);

    // read remainder of block
    const size_t remaining = blockLength - Constants::BGZF_BLOCK_HEADER_LENGTH;
    numBytesRead = m_device->Read(&m_compressedBlock.Buffer[Constants::BGZF_BLOCK_HEADER_LENGTH], remaining);

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

    // check that we read in expected numBytes
    if ( numBytesRead != static_cast<int64_t>(remaining) )
        throw BamException("BgzfStream::ReadBlock", "could not read data from block");

    // decompress block data
    const size_t newBlockLength = InflateBlock(blockLength);

    // update block data
    if ( m_blockLength != 0 )
        m_blockOffset = 0;
    m_blockAddress = blockAddress;
    m_blockLength  = newBlockLength;
}

// Assembly:
subq $0x2e8, %rsp            # imm = 0x2E8
movq %rdi, 0x2e0(%rsp)
movq 0x2e0(%rsp), %rax
movq %rax, 0x78(%rsp)
callq 0x761a0
movq 0x78(%rsp), %rax
movq 0x18(%rax), %rdi
movq (%rdi), %rax
callq *0x38(%rax)
movq %rax, %rcx
movq 0x78(%rsp), %rax
movq %rcx, 0x2d8(%rsp)
movq 0x18(%rax), %rdi
leaq 0x2c0(%rsp), %rsi
movq (%rdi), %rax
movl $0x12, %edx
callq *0x28(%rax)
movq %rax, 0x2b8(%rsp)
cmpq $0x0, 0x2b8(%rsp)
jge 0xcee4c
leaq 0x277(%rsp), %rdi
movq %rdi, 0x70(%rsp)
callq 0x7b5f0
movq 0x70(%rsp), %rdx
leaq 0x1d3cc(%rip), %rsi     # 0xec038
leaq 0x278(%rsp), %rdi
callq 0x78e70
jmp 0xcec7b
movq 0x78(%rsp), %rax
movq 0x18(%rax), %rsi
movq (%rsi), %rax
movq 0x48(%rax), %rax
leaq 0x240(%rsp), %rdi
callq *%rax
jmp 0xcec97
leaq 0x298(%rsp), %rdi
leaq 0x278(%rsp), %rsi
leaq 0x240(%rsp), %rdx
callq 0x7c720
jmp 0xcecb6
leaq 0x240(%rsp), %rdi
callq 0x7cce8
jmp 0xcecc5
leaq 0x278(%rsp), %rdi
callq 0x7cce8
jmp 0xcecd4
leaq 0x277(%rsp), %rdi
callq 0x76f80
movb $0x1, 0x21e(%rsp)
movl $0x28, %edi
callq 0x737c0
movq %rax, 0x60(%rsp)
leaq 0x21f(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x7b5f0
movq 0x68(%rsp), %rdx
leaq 0x1d40a(%rip), %rsi     # 0xec120
leaq 0x220(%rsp), %rdi
callq 0x78e70
jmp 0xced25
movq 0x60(%rsp), %rdi
leaq 0x220(%rsp), %rsi
leaq 0x298(%rsp), %rdx
callq 0x79cd0
jmp 0xced41
movq 0x60(%rsp), %rdi
movb $0x0, 0x21e(%rsp)
movq 0x431bb(%rip), %rsi     # 0x111f10
movq 0x43204(%rip), %rdx     # 0x111f60
callq 0x7b010
jmp 0xcf578
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
jmp 0xcedc8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
jmp 0xcedb7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
leaq 0x240(%rsp), %rdi
callq 0x7cce8
jmp 0xcedb5
jmp 0xcedb7
leaq 0x278(%rsp), %rdi
callq 0x7cce8
jmp 0xcedc6
jmp 0xcedc8
leaq 0x277(%rsp), %rdi
callq 0x76f80
jmp 0xcf563
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
jmp 0xcee15
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
leaq 0x220(%rsp), %rdi
callq 0x7cce8
jmp 0xcee13
jmp 0xcee15
leaq 0x21f(%rsp), %rdi
callq 0x76f80
testb $0x1, 0x21e(%rsp)
jne 0xcee2e
jmp 0xcee38
movq 0x60(%rsp), %rdi
callq 0x74e00
leaq 0x298(%rsp), %rdi
callq 0x7cce8
jmp 0xcee47
jmp 0xcf563
cmpq $0x0, 0x2b8(%rsp)
jne 0xcee67
movq 0x78(%rsp), %rax
movl $0x0, (%rax)
jmp 0xcf55b
cmpq $0x12, 0x2b8(%rsp)
je 0xcefbf
movb $0x1, 0x1ce(%rsp)
movl $0x28, %edi
callq 0x737c0
movq %rax, 0x50(%rsp)
leaq 0x1f7(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0x7b5f0
movq 0x58(%rsp), %rdx
leaq 0x1d275(%rip), %rsi     # 0xec120
leaq 0x1f8(%rsp), %rdi
callq 0x78e70
jmp 0xceeba
leaq 0x1cf(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x7b5f0
movq 0x48(%rsp), %rdx
leaq 0x1d25e(%rip), %rsi     # 0xec136
leaq 0x1d0(%rsp), %rdi
callq 0x78e70
jmp 0xceee7
movq 0x50(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
leaq 0x1d0(%rsp), %rdx
callq 0x79cd0
jmp 0xcef03
movq 0x50(%rsp), %rdi
movb $0x0, 0x1ce(%rsp)
movq 0x42ff9(%rip), %rsi     # 0x111f10
movq 0x43042(%rip), %rdx     # 0x111f60
callq 0x7b010
jmp 0xcf578
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
jmp 0xcef97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
jmp 0xcef79
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
leaq 0x1d0(%rsp), %rdi
callq 0x7cce8
jmp 0xcef77
jmp 0xcef79
leaq 0x1cf(%rsp), %rdi
callq 0x76f80
leaq 0x1f8(%rsp), %rdi
callq 0x7cce8
jmp 0xcef95
jmp 0xcef97
leaq 0x1f7(%rsp), %rdi
callq 0x76f80
testb $0x1, 0x1ce(%rsp)
jne 0xcefb0
jmp 0xcefba
movq 0x50(%rsp), %rdi
callq 0x74e00
jmp 0xcf563
leaq 0x2c0(%rsp), %rdi
callq 0x77a00
testb $0x1, %al
jne 0xcf11d
movb $0x1, 0x17e(%rsp)
movl $0x28, %edi
callq 0x737c0
movq %rax, 0x38(%rsp)
leaq 0x1a7(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0x7b5f0
movq 0x40(%rsp), %rdx
leaq 0x1d117(%rip), %rsi     # 0xec120
leaq 0x1a8(%rsp), %rdi
callq 0x78e70
jmp 0xcf018
leaq 0x17f(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x7b5f0
movq 0x30(%rsp), %rdx
leaq 0x1d11a(%rip), %rsi     # 0xec150
leaq 0x180(%rsp), %rdi
callq 0x78e70
jmp 0xcf045
movq 0x38(%rsp), %rdi
leaq 0x1a8(%rsp), %rsi
leaq 0x180(%rsp), %rdx
callq 0x79cd0
jmp 0xcf061
movq 0x38(%rsp), %rdi
movb $0x0, 0x17e(%rsp)
movq 0x42e9b(%rip), %rsi     # 0x111f10
movq 0x42ee4(%rip), %rdx     # 0x111f60
callq 0x7b010
jmp 0xcf578
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
jmp 0xcf0f5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
jmp 0xcf0d7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
leaq 0x180(%rsp), %rdi
callq 0x7cce8
jmp 0xcf0d5
jmp 0xcf0d7
leaq 0x17f(%rsp), %rdi
callq 0x76f80
leaq 0x1a8(%rsp), %rdi
callq 0x7cce8
jmp 0xcf0f3
jmp 0xcf0f5
leaq 0x1a7(%rsp), %rdi
callq 0x76f80
testb $0x1, 0x17e(%rsp)
jne 0xcf10e
jmp 0xcf118
movq 0x38(%rsp), %rdi
callq 0x74e00
jmp 0xcf563
leaq 0x2c0(%rsp), %rdi
addq $0x10, %rdi
callq 0x71680
movw %ax, %cx
movq 0x78(%rsp), %rax
movzwl %cx, %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq %rcx, 0x170(%rsp)
movq 0x30(%rax), %rcx
movq 0x2c0(%rsp), %rdx
movq %rdx, (%rcx)
movq 0x2c8(%rsp), %rdx
movq %rdx, 0x8(%rcx)
movw 0x2d0(%rsp), %dx
movw %dx, 0x10(%rcx)
movq 0x170(%rsp), %rcx
subq $0x12, %rcx
movq %rcx, 0x168(%rsp)
movq 0x18(%rax), %rdi
movq 0x30(%rax), %rsi
addq $0x12, %rsi
movq 0x168(%rsp), %rax
movl %eax, %edx
movq (%rdi), %rax
callq *0x28(%rax)
movq %rax, 0x2b8(%rsp)
cmpq $0x0, 0x2b8(%rsp)
jge 0xcf3b3
leaq 0x127(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x7b5f0
movq 0x28(%rsp), %rdx
leaq 0x1ce65(%rip), %rsi     # 0xec038
leaq 0x128(%rsp), %rdi
callq 0x78e70
jmp 0xcf1e2
movq 0x78(%rsp), %rax
movq 0x18(%rax), %rsi
movq (%rsi), %rax
movq 0x48(%rax), %rax
leaq 0x100(%rsp), %rdi
callq *%rax
jmp 0xcf1fe
leaq 0x148(%rsp), %rdi
leaq 0x128(%rsp), %rsi
leaq 0x100(%rsp), %rdx
callq 0x7c720
jmp 0xcf21d
leaq 0x100(%rsp), %rdi
callq 0x7cce8
jmp 0xcf22c
leaq 0x128(%rsp), %rdi
callq 0x7cce8
jmp 0xcf23b
leaq 0x127(%rsp), %rdi
callq 0x76f80
movb $0x1, 0xde(%rsp)
movl $0x28, %edi
callq 0x737c0
movq %rax, 0x18(%rsp)
leaq 0xdf(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x7b5f0
movq 0x20(%rsp), %rdx
leaq 0x1cea3(%rip), %rsi     # 0xec120
leaq 0xe0(%rsp), %rdi
callq 0x78e70
jmp 0xcf28c
movq 0x18(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
leaq 0x148(%rsp), %rdx
callq 0x79cd0
jmp 0xcf2a8
movq 0x18(%rsp), %rdi
movb $0x0, 0xde(%rsp)
movq 0x42c54(%rip), %rsi     # 0x111f10
movq 0x42c9d(%rip), %rdx     # 0x111f60
callq 0x7b010
jmp 0xcf578
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
jmp 0xcf32f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
jmp 0xcf31e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x7cce8
jmp 0xcf31c
jmp 0xcf31e
leaq 0x128(%rsp), %rdi
callq 0x7cce8
jmp 0xcf32d
jmp 0xcf32f
leaq 0x127(%rsp), %rdi
callq 0x76f80
jmp 0xcf563
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
jmp 0xcf37c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x7cce8
jmp 0xcf37a
jmp 0xcf37c
leaq 0xdf(%rsp), %rdi
callq 0x76f80
testb $0x1, 0xde(%rsp)
jne 0xcf395
jmp 0xcf39f
movq 0x18(%rsp), %rdi
callq 0x74e00
leaq 0x148(%rsp), %rdi
callq 0x7cce8
jmp 0xcf3ae
jmp 0xcf563
movq 0x2b8(%rsp), %rax
cmpq 0x168(%rsp), %rax
je 0xcf50d
movb $0x1, 0x8e(%rsp)
movl $0x28, %edi
callq 0x737c0
movq %rax, 0x8(%rsp)
leaq 0xb7(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x7b5f0
movq 0x10(%rsp), %rdx
leaq 0x1cd22(%rip), %rsi     # 0xec120
leaq 0xb8(%rsp), %rdi
callq 0x78e70
jmp 0xcf40d
leaq 0x8f(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x7b5f0
movq (%rsp), %rdx
leaq 0x1cd45(%rip), %rsi     # 0xec16e
leaq 0x90(%rsp), %rdi
callq 0x78e70
jmp 0xcf438
movq 0x8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
leaq 0x90(%rsp), %rdx
callq 0x79cd0
jmp 0xcf454
movq 0x8(%rsp), %rdi
movb $0x0, 0x8e(%rsp)
movq 0x42aa8(%rip), %rsi     # 0x111f10
movq 0x42af1(%rip), %rdx     # 0x111f60
callq 0x7b010
jmp 0xcf578
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
jmp 0xcf4e8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
jmp 0xcf4ca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x7cce8
jmp 0xcf4c8
jmp 0xcf4ca
leaq 0x8f(%rsp), %rdi
callq 0x76f80
leaq 0xb8(%rsp), %rdi
callq 0x7cce8
jmp 0xcf4e6
jmp 0xcf4e8
leaq 0xb7(%rsp), %rdi
callq 0x76f80
testb $0x1, 0x8e(%rsp)
jne 0xcf501
jmp 0xcf50b
movq 0x8(%rsp), %rdi
callq 0x74e00
jmp 0xcf563
movq 0x78(%rsp), %rdi
leaq 0x170(%rsp), %rsi
callq 0x77620
movq %rax, %rcx
movq 0x78(%rsp), %rax
movq %rcx, 0x80(%rsp)
cmpl $0x0, (%rax)
je 0xcf540
movq 0x78(%rsp), %rax
movl $0x0, 0x4(%rax)
movq 0x78(%rsp), %rax
movq 0x2d8(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x80(%rsp), %rcx
movl %ecx, (%rax)
addq $0x2e8, %rsp            # imm = 0x2E8
retq
movq 0x268(%rsp), %rdi
callq 0x7b550
movq %rax, %rdi
callq 0x88ef0
nopl (%rax,%rax)