// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x88, %rsp
movq %rdi, %rbx
movq 0x18(%rdi), %rdi
movq (%rdi), %rax
callq *0x38(%rax)
movq %rax, %r14
movq 0x18(%rbx), %rdi
movq (%rdi), %rax
leaq 0x70(%rsp), %rsi
pushq $0x12
popq %rdx
callq *0x28(%rax)
testq %rax, %rax
js 0x510dc
cmpq $0x12, %rax
je 0x5104b
testq %rax, %rax
jne 0x5117c
andl $0x0, (%rbx)
jmp 0x510ce
leaq 0x70(%rsp), %rdi
callq 0x337e0
testb %al, %al
je 0x511e5
movzwl 0x80(%rsp), %r15d
leaq 0x1(%r15), %rax
movq %rax, 0x28(%rsp)
movq 0x30(%rbx), %rax
movzwl 0x80(%rsp), %ecx
movw %cx, 0x10(%rax)
movaps 0x70(%rsp), %xmm0
movups %xmm0, (%rax)
addq $-0x11, %r15
movq 0x18(%rbx), %rdi
movq 0x30(%rbx), %rsi
addq $0x12, %rsi
movq (%rdi), %rax
movl %r15d, %edx
callq *0x28(%rax)
testq %rax, %rax
js 0x5124e
cmpq %r15, %rax
jne 0x512eb
leaq 0x28(%rsp), %rsi
movq %rbx, %rdi
callq 0x33620
cmpl $0x0, (%rbx)
je 0x510c8
andl $0x0, 0x4(%rbx)
movq %r14, 0x8(%rbx)
movl %eax, (%rbx)
addq $0x88, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0xbcf7(%rip), %rsi      # 0x5cdda
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x31b30
movq 0x18(%rbx), %rsi
movq (%rsi), %rax
leaq 0x50(%rsp), %rdi
callq *0x48(%rax)
leaq 0x30(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0x50(%rsp), %rdx
callq 0x355e0
leaq 0x50(%rsp), %rdi
callq 0x33a00
leaq 0x8(%rsp), %rdi
callq 0x33a00
pushq $0x28
popq %rdi
callq 0x31e70
movq %rax, %r14
leaq 0xbd87(%rip), %rsi      # 0x5cec2
leaq 0x8(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x31b30
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
leaq 0x30(%rsp), %rdx
movq %r14, %rdi
callq 0x344c0
xorl %ebp, %ebp
movq 0x23dd0(%rip), %rsi     # 0x74f38
movq 0x23e09(%rip), %rdx     # 0x74f78
movq %r14, %rdi
callq 0x34c90
jmp 0x5134f
pushq $0x28
popq %rdi
callq 0x31e70
movq %rax, %r14
leaq 0xbd34(%rip), %rsi      # 0x5cec2
leaq 0x30(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x31b30
leaq 0xbd34(%rip), %rsi      # 0x5ced8
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x31b30
movb $0x1, %bpl
leaq 0x30(%rsp), %rsi
leaq 0x8(%rsp), %rdx
movq %r14, %rdi
callq 0x344c0
xorl %ebp, %ebp
movq 0x23d67(%rip), %rsi     # 0x74f38
movq 0x23da0(%rip), %rdx     # 0x74f78
movq %r14, %rdi
callq 0x34c90
jmp 0x5134f
pushq $0x28
popq %rdi
callq 0x31e70
movq %rax, %r14
leaq 0xbccb(%rip), %rsi      # 0x5cec2
leaq 0x30(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x31b30
leaq 0xbce5(%rip), %rsi      # 0x5cef2
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x31b30
movb $0x1, %bpl
leaq 0x30(%rsp), %rsi
leaq 0x8(%rsp), %rdx
movq %r14, %rdi
callq 0x344c0
xorl %ebp, %ebp
movq 0x23cfe(%rip), %rsi     # 0x74f38
movq 0x23d37(%rip), %rdx     # 0x74f78
movq %r14, %rdi
callq 0x34c90
jmp 0x5134f
leaq 0xbb85(%rip), %rsi      # 0x5cdda
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x31b30
movq 0x18(%rbx), %rsi
movq (%rsi), %rax
leaq 0x50(%rsp), %rdi
callq *0x48(%rax)
leaq 0x30(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0x50(%rsp), %rdx
callq 0x355e0
leaq 0x50(%rsp), %rdi
callq 0x33a00
leaq 0x8(%rsp), %rdi
callq 0x33a00
pushq $0x28
popq %rdi
callq 0x31e70
movq %rax, %r14
leaq 0xbc15(%rip), %rsi      # 0x5cec2
leaq 0x8(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x31b30
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
leaq 0x30(%rsp), %rdx
movq %r14, %rdi
callq 0x344c0
xorl %ebp, %ebp
movq 0x23c5e(%rip), %rsi     # 0x74f38
movq 0x23c97(%rip), %rdx     # 0x74f78
movq %r14, %rdi
callq 0x34c90
jmp 0x5134f
pushq $0x28
popq %rdi
callq 0x31e70
movq %rax, %r14
leaq 0xbbc5(%rip), %rsi      # 0x5cec2
leaq 0x30(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x31b30
leaq 0xbbfd(%rip), %rsi      # 0x5cf10
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x31b30
movb $0x1, %bpl
leaq 0x30(%rsp), %rsi
leaq 0x8(%rsp), %rdx
movq %r14, %rdi
callq 0x344c0
xorl %ebp, %ebp
movq 0x23bf8(%rip), %rsi     # 0x74f38
movq 0x23c31(%rip), %rdx     # 0x74f78
movq %r14, %rdi
callq 0x34c90
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x33a00
testb %bpl, %bpl
jne 0x51366
jmp 0x5136e
movq %rax, %rbx
movq %r14, %rdi
callq 0x327c0
leaq 0x30(%rsp), %rdi
callq 0x33a00
jmp 0x51465
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x33a00
testb %bpl, %bpl
jne 0x51394
jmp 0x5139c
movq %rax, %rbx
movq %r14, %rdi
callq 0x327c0
leaq 0x30(%rsp), %rdi
callq 0x33a00
jmp 0x51465
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x33a00
jmp 0x51434
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x33a00
jmp 0x513cf
movq %rax, %rbx
movb $0x1, %bpl
leaq 0x30(%rsp), %rdi
callq 0x33a00
jmp 0x5141b
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x33a00
jmp 0x513f0
movq %rax, %rbx
movb $0x1, %bpl
leaq 0x30(%rsp), %rdi
callq 0x33a00
jmp 0x5141b
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x33a00
jmp 0x51411
movq %rax, %rbx
movb $0x1, %bpl
leaq 0x30(%rsp), %rdi
callq 0x33a00
testb %bpl, %bpl
jne 0x51447
jmp 0x51465
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x33a00
jmp 0x51456
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x33a00
jmp 0x51465
jmp 0x51444
jmp 0x51444
movq %rax, %rbx
movq %r14, %rdi
callq 0x327c0
jmp 0x51465
jmp 0x51462
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x33a00
jmp 0x51465
movq %rax, %rbx
movq %rbx, %rdi
callq 0x34ed0
movq %rax, %rdi
callq 0x39b2f
nop