// File: /workspace/github_cpp_makefile_star2_O1/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 0x40(%rsp), %rsi
movl $0x12, %edx
callq *0x28(%rax)
testq %rax, %rax
js 0x49d5c
cmpq $0x12, %rax
je 0x49ccc
testq %rax, %rax
jne 0x49e13
movl $0x0, (%rbx)
jmp 0x49d4c
leaq 0x40(%rsp), %rdi
callq 0x27b40
testb %al, %al
je 0x49e91
movzwl 0x50(%rsp), %r15d
leaq 0x1(%r15), %rax
movq %rax, 0x58(%rsp)
movq 0x30(%rbx), %rax
movzwl 0x50(%rsp), %ecx
movw %cx, 0x10(%rax)
movaps 0x40(%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 0x49f0f
cmpq %r15, %rax
jne 0x49fc3
leaq 0x58(%rsp), %rsi
movq %rbx, %rdi
callq 0x27a50
cmpl $0x0, (%rbx)
je 0x49d46
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 0xd03f(%rip), %rsi      # 0x56dab
leaq 0xd046(%rip), %rdx      # 0x56db9
movq %rsp, %rdi
callq 0x26750
movq 0x18(%rbx), %rsi
movq (%rsi), %rax
leaq 0x60(%rsp), %rdi
callq *0x48(%rax)
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
leaq 0x60(%rsp), %rdx
callq 0x29130
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x49daf
callq 0x27560
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x49dbd
callq 0x27560
movl $0x28, %edi
callq 0x269d0
movq %rax, %r14
movq %rsp, %rdi
movq %r15, (%rdi)
leaq 0xd0bc(%rip), %rsi      # 0x56e93
leaq 0xd0ca(%rip), %rdx      # 0x56ea8
callq 0x26750
movb $0x1, %bpl
movq %rsp, %rsi
leaq 0x20(%rsp), %rdx
movq %r14, %rdi
callq 0x28490
xorl %ebp, %ebp
movq 0x21139(%rip), %rsi     # 0x6af38
movq 0x21172(%rip), %rdx     # 0x6af78
movq %r14, %rdi
callq 0x28a30
jmp 0x4a03c
movl $0x28, %edi
callq 0x269d0
movq %rax, %r14
leaq 0x30(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xd063(%rip), %rsi      # 0x56e93
leaq 0xd071(%rip), %rdx      # 0x56ea8
leaq 0x20(%rsp), %rdi
callq 0x26750
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0xd057(%rip), %rsi      # 0x56ea9
leaq 0xd069(%rip), %rdx      # 0x56ec2
movq %rsp, %rdi
callq 0x26750
movb $0x1, %bpl
leaq 0x20(%rsp), %rsi
movq %rsp, %rdx
movq %r14, %rdi
callq 0x28490
xorl %ebp, %ebp
movq 0x210bb(%rip), %rsi     # 0x6af38
movq 0x210f4(%rip), %rdx     # 0x6af78
movq %r14, %rdi
callq 0x28a30
jmp 0x4a03c
movl $0x28, %edi
callq 0x269d0
movq %rax, %r14
leaq 0x30(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xcfe5(%rip), %rsi      # 0x56e93
leaq 0xcff3(%rip), %rdx      # 0x56ea8
leaq 0x20(%rsp), %rdi
callq 0x26750
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0xcff3(%rip), %rsi      # 0x56ec3
leaq 0xd009(%rip), %rdx      # 0x56ee0
movq %rsp, %rdi
callq 0x26750
movb $0x1, %bpl
leaq 0x20(%rsp), %rsi
movq %rsp, %rdx
movq %r14, %rdi
callq 0x28490
xorl %ebp, %ebp
movq 0x2103d(%rip), %rsi     # 0x6af38
movq 0x21076(%rip), %rdx     # 0x6af78
movq %r14, %rdi
callq 0x28a30
jmp 0x4a03c
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xce8c(%rip), %rsi      # 0x56dab
leaq 0xce93(%rip), %rdx      # 0x56db9
movq %rsp, %rdi
callq 0x26750
movq 0x18(%rbx), %rsi
movq (%rsi), %rax
leaq 0x60(%rsp), %rdi
callq *0x48(%rax)
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
leaq 0x60(%rsp), %rdx
callq 0x29130
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x49f62
callq 0x27560
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x49f70
callq 0x27560
movl $0x28, %edi
callq 0x269d0
movq %rax, %r14
movq %rsp, %rdi
movq %r15, (%rdi)
leaq 0xcf09(%rip), %rsi      # 0x56e93
leaq 0xcf17(%rip), %rdx      # 0x56ea8
callq 0x26750
movb $0x1, %bpl
movq %rsp, %rsi
leaq 0x20(%rsp), %rdx
movq %r14, %rdi
callq 0x28490
xorl %ebp, %ebp
movq 0x20f86(%rip), %rsi     # 0x6af38
movq 0x20fbf(%rip), %rdx     # 0x6af78
movq %r14, %rdi
callq 0x28a30
jmp 0x4a03c
movl $0x28, %edi
callq 0x269d0
movq %rax, %r14
leaq 0x30(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xceb3(%rip), %rsi      # 0x56e93
leaq 0xcec1(%rip), %rdx      # 0x56ea8
leaq 0x20(%rsp), %rdi
callq 0x26750
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0xcedf(%rip), %rsi      # 0x56ee1
leaq 0xcef6(%rip), %rdx      # 0x56eff
movq %rsp, %rdi
callq 0x26750
movb $0x1, %bpl
leaq 0x20(%rsp), %rsi
movq %rsp, %rdx
movq %r14, %rdi
callq 0x28490
xorl %ebp, %ebp
movq 0x20f0b(%rip), %rsi     # 0x6af38
movq 0x20f44(%rip), %rdx     # 0x6af78
movq %r14, %rdi
callq 0x28a30
jmp 0x4a042
jmp 0x4a055
jmp 0x4a0ac
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x4a05b
callq 0x27560
jmp 0x4a05b
movq %rax, %rbx
movb $0x1, %bpl
testb %bpl, %bpl
je 0x4a068
movq %r14, %rdi
callq 0x27070
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x4a0eb
jmp 0x4a0f5
jmp 0x4a082
jmp 0x4a095
jmp 0x4a0df
jmp 0x4a082
jmp 0x4a095
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x4a09b
callq 0x27560
jmp 0x4a09b
movq %rax, %rbx
movb $0x1, %bpl
movq 0x20(%rsp), %rdi
cmpq %r15, %rdi
je 0x4a0d0
callq 0x27560
jmp 0x4a0d0
movq %rax, %rbx
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4a0e2
callq 0x27560
jmp 0x4a0e2
jmp 0x4a0ca
jmp 0x4a0f2
jmp 0x4a0ca
movq %rax, %rbx
movb $0x1, %bpl
testb %bpl, %bpl
je 0x4a0f5
movq %r14, %rdi
callq 0x27070
jmp 0x4a0f5
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x4a0f5
callq 0x27560
jmp 0x4a0f5
movq %rax, %rbx
movq %rbx, %rdi
callq 0x28c20
nop