// File: /workspace/github_cpp_makefile_star2_O3/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 %r12
pushq %rbx
subq $0x80, %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 0x20(%rsp), %rsi
movl $0x12, %edx
callq *0x28(%rax)
testq %rax, %rax
js 0x49d56
cmpq $0x12, %rax
je 0x49c7e
testq %rax, %rax
jne 0x49e8b
movl $0x0, (%rbx)
jmp 0x49d46
cmpb $0x1f, 0x20(%rsp)
jne 0x49e0d
cmpb $-0x75, 0x21(%rsp)
jne 0x49e0d
cmpb $0x8, 0x22(%rsp)
jne 0x49e0d
testb $0x4, 0x23(%rsp)
je 0x49e0d
cmpw $0x6, 0x2a(%rsp)
jne 0x49e0d
cmpb $0x42, 0x2c(%rsp)
jne 0x49e0d
cmpb $0x43, 0x2d(%rsp)
jne 0x49e0d
cmpw $0x2, 0x2e(%rsp)
jne 0x49e0d
movzwl 0x30(%rsp), %r15d
leaq 0x1(%r15), %rax
movq %rax, 0x58(%rsp)
movq 0x30(%rbx), %rax
movzwl 0x30(%rsp), %ecx
movw %cx, 0x10(%rax)
movaps 0x20(%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 0x49f09
cmpq %r15, %rax
jne 0x49fbd
leaq 0x58(%rsp), %rsi
movq %rbx, %rdi
callq 0x27a50
cmpl $0x0, (%rbx)
je 0x49d40
movl $0x0, 0x4(%rbx)
movq %r14, 0x8(%rbx)
movl %eax, (%rbx)
addq $0x80, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xd045(%rip), %rsi      # 0x56dab
leaq 0xd04c(%rip), %rdx      # 0x56db9
movq %rsp, %rdi
callq 0x26750
movq 0x18(%rbx), %rsi
movq (%rsi), %rax
leaq 0x60(%rsp), %rdi
callq *0x48(%rax)
leaq 0x38(%rsp), %rdi
movq %rsp, %rsi
leaq 0x60(%rsp), %rdx
callq 0x29120
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x49da9
callq 0x27560
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x49db7
callq 0x27560
movl $0x28, %edi
callq 0x269d0
movq %rax, %r14
movq %rsp, %rdi
movq %r15, (%rdi)
leaq 0xd0c2(%rip), %rsi      # 0x56e93
leaq 0xd0d0(%rip), %rdx      # 0x56ea8
callq 0x26750
movb $0x1, %bpl
movq %rsp, %rsi
leaq 0x38(%rsp), %rdx
movq %r14, %rdi
callq 0x28480
xorl %ebp, %ebp
movq 0x2113f(%rip), %rsi     # 0x6af38
movq 0x21178(%rip), %rdx     # 0x6af78
movq %r14, %rdi
callq 0x28a20
jmp 0x4a036
movl $0x28, %edi
callq 0x269d0
movq %rax, %r14
leaq 0x48(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xd069(%rip), %rsi      # 0x56e93
leaq 0xd077(%rip), %rdx      # 0x56ea8
leaq 0x38(%rsp), %rdi
callq 0x26750
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0xd077(%rip), %rsi      # 0x56ec3
leaq 0xd08d(%rip), %rdx      # 0x56ee0
movq %rsp, %rdi
callq 0x26750
movb $0x1, %bpl
leaq 0x38(%rsp), %rsi
movq %rsp, %rdx
movq %r14, %rdi
callq 0x28480
xorl %ebp, %ebp
movq 0x210c1(%rip), %rsi     # 0x6af38
movq 0x210fa(%rip), %rdx     # 0x6af78
movq %r14, %rdi
callq 0x28a20
jmp 0x4a036
movl $0x28, %edi
callq 0x269d0
movq %rax, %r14
leaq 0x48(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xcfeb(%rip), %rsi      # 0x56e93
leaq 0xcff9(%rip), %rdx      # 0x56ea8
leaq 0x38(%rsp), %rdi
callq 0x26750
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0xcfdf(%rip), %rsi      # 0x56ea9
leaq 0xcff1(%rip), %rdx      # 0x56ec2
movq %rsp, %rdi
callq 0x26750
movb $0x1, %bpl
leaq 0x38(%rsp), %rsi
movq %rsp, %rdx
movq %r14, %rdi
callq 0x28480
xorl %ebp, %ebp
movq 0x21043(%rip), %rsi     # 0x6af38
movq 0x2107c(%rip), %rdx     # 0x6af78
movq %r14, %rdi
callq 0x28a20
jmp 0x4a036
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xce92(%rip), %rsi      # 0x56dab
leaq 0xce99(%rip), %rdx      # 0x56db9
movq %rsp, %rdi
callq 0x26750
movq 0x18(%rbx), %rsi
movq (%rsi), %rax
leaq 0x60(%rsp), %rdi
callq *0x48(%rax)
leaq 0x38(%rsp), %rdi
movq %rsp, %rsi
leaq 0x60(%rsp), %rdx
callq 0x29120
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x49f5c
callq 0x27560
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x49f6a
callq 0x27560
movl $0x28, %edi
callq 0x269d0
movq %rax, %r14
movq %rsp, %rdi
movq %r15, (%rdi)
leaq 0xcf0f(%rip), %rsi      # 0x56e93
leaq 0xcf1d(%rip), %rdx      # 0x56ea8
callq 0x26750
movb $0x1, %bpl
movq %rsp, %rsi
leaq 0x38(%rsp), %rdx
movq %r14, %rdi
callq 0x28480
xorl %ebp, %ebp
movq 0x20f8c(%rip), %rsi     # 0x6af38
movq 0x20fc5(%rip), %rdx     # 0x6af78
movq %r14, %rdi
callq 0x28a20
jmp 0x4a036
movl $0x28, %edi
callq 0x269d0
movq %rax, %r14
leaq 0x48(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xceb9(%rip), %rsi      # 0x56e93
leaq 0xcec7(%rip), %rdx      # 0x56ea8
leaq 0x38(%rsp), %rdi
callq 0x26750
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0xcee5(%rip), %rsi      # 0x56ee1
leaq 0xcefc(%rip), %rdx      # 0x56eff
movq %rsp, %rdi
callq 0x26750
movb $0x1, %bpl
leaq 0x38(%rsp), %rsi
movq %rsp, %rdx
movq %r14, %rdi
callq 0x28480
xorl %ebp, %ebp
movq 0x20f11(%rip), %rsi     # 0x6af38
movq 0x20f4a(%rip), %rdx     # 0x6af78
movq %r14, %rdi
callq 0x28a20
jmp 0x4a03c
jmp 0x4a054
jmp 0x4a07c
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x4a04d
callq 0x27560
testb %bpl, %bpl
jne 0x4a057
jmp 0x4a05f
movq %rax, %rbx
movq %r14, %rdi
callq 0x27070
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x4a0e1
jmp 0x4a0f8
jmp 0x4a098
jmp 0x4a0bf
jmp 0x4a0d5
jmp 0x4a098
jmp 0x4a0bf
movq %rax, %rbx
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4a0d8
callq 0x27560
jmp 0x4a0d8
jmp 0x4a0e8
jmp 0x4a0f5
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x4a0a9
callq 0x27560
movq 0x38(%rsp), %rdi
cmpq %r15, %rdi
je 0x4a0b8
callq 0x27560
testb %bpl, %bpl
jne 0x4a0eb
jmp 0x4a0f8
movq %rax, %rbx
movq 0x38(%rsp), %rdi
cmpq %r15, %rdi
je 0x4a0eb
callq 0x27560
jmp 0x4a0eb
jmp 0x4a0e8
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x4a0f8
callq 0x27560
jmp 0x4a0f8
movq %rax, %rbx
movq %r14, %rdi
callq 0x27070
jmp 0x4a0f8
movq %rax, %rbx
movq %rbx, %rdi
callq 0x28c10