// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/bgzf.c
// Function: inflate_gzip_block
static int inflate_gzip_block(BGZF *fp)
{
    // we will set this to true when we detect EOF, so we don't bang against the EOF more than once per call
    int input_eof = 0;

    // write to the part of the output buffer after block_offset
    fp->gz_stream->next_out = (Bytef*)fp->uncompressed_block + fp->block_offset;
    fp->gz_stream->avail_out = BGZF_MAX_BLOCK_SIZE - fp->block_offset;

    while ( fp->gz_stream->avail_out != 0 ) {
        // until we fill the output buffer (or hit EOF)

        if ( !input_eof && fp->gz_stream->avail_in == 0 ) {
            // we are out of input data in the buffer. Get more.
            fp->gz_stream->next_in = fp->compressed_block;
            int ret = hread(fp->fp, fp->compressed_block, BGZF_BLOCK_SIZE);
            if ( ret < 0 ) {
                // hread had an error. Pass it on.
                return ret;
            }
            fp->gz_stream->avail_in = ret;
            if ( fp->gz_stream->avail_in < BGZF_BLOCK_SIZE ) {
                // we have reached EOF but the decompressor hasn't necessarily
                input_eof = 1;
            }
        }

        fp->gz_stream->msg = NULL;
        // decompress as much data as we can
        int ret = inflate(fp->gz_stream, Z_SYNC_FLUSH);

        if ( (ret < 0 && ret != Z_BUF_ERROR) || ret == Z_NEED_DICT ) {
            // an error occurred, other than running out of space
            hts_log_error("Inflate operation failed: %s", bgzf_zerr(ret, ret == Z_DATA_ERROR ? fp->gz_stream : NULL));
            fp->errcode |= BGZF_ERR_ZLIB;
            return -1;
        } else if ( ret == Z_STREAM_END ) {
            // we finished a GZIP member

            // scratch for peeking to see if the file is over
            char c;
            if (fp->gz_stream->avail_in > 0 || hpeek(fp->fp, &c, 1) == 1) {
                // there is more data; try and read another GZIP member in the remaining data
                int reset_ret = inflateReset(fp->gz_stream);
                if (reset_ret != Z_OK) {
                    hts_log_error("Call to inflateReset failed: %s", bgzf_zerr(reset_ret, NULL));
                    fp->errcode |= BGZF_ERR_ZLIB;
                    return -1;
                }
            } else {
                // we consumed all the input data and hit Z_STREAM_END
                // so stop looping, even if we never fill the output buffer
                break;
            }
        } else if ( ret == Z_BUF_ERROR && input_eof && fp->gz_stream->avail_out > 0 ) {
            // the gzip file has ended prematurely
            hts_log_error("Gzip file truncated");
            fp->errcode |= BGZF_ERR_IO;
            return -1;
        }
    }

    // when we get here, the buffer is full or there is an EOF after a complete gzip member
    return BGZF_MAX_BLOCK_SIZE - fp->gz_stream->avail_out;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movslq 0x10(%rdi), %rax
movl $0x10000, %ecx          # imm = 0x10000
subl %eax, %ecx
addq 0x28(%rdi), %rax
movq 0x60(%rdi), %rdx
movq %rax, 0x18(%rdx)
movl %ecx, 0x20(%rdx)
leaq 0x7(%rsp), %r12
leaq 0x899c0(%rip), %r13     # 0x9524c
leaq 0x899e9(%rip), %rbp     # 0x9527c
xorl %r14d, %r14d
movq 0x60(%rbx), %rdi
cmpl $0x0, 0x20(%rdi)
je 0xba28
testl %r14d, %r14d
je 0xb8b4
movl $0x1, %r14d
jmp 0xb951
xorl %r14d, %r14d
cmpl $0x0, 0x8(%rdi)
jne 0xb951
movq %r12, %rbp
movq 0x30(%rbx), %r14
movq %r14, (%rdi)
movq 0x40(%rbx), %r15
movq 0x8(%r15), %rsi
movq 0x10(%r15), %r12
subq %rsi, %r12
movl $0xff00, %eax           # imm = 0xFF00
cmpq %rax, %r12
movl $0xff00, %r13d          # imm = 0xFF00
cmovbq %r12, %r13
movq %r14, %rdi
movq %r13, %rdx
callq 0x43c0
addq %r13, 0x8(%r15)
cmpq $0xfeff, %r12           # imm = 0xFEFF
ja 0xb921
testb $0x2, 0x30(%r15)
je 0xb921
movl $0xff00, %edx           # imm = 0xFF00
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rcx
callq 0xf129
movq %rax, %r13
testl %r13d, %r13d
js 0xbaab
movq 0x60(%rbx), %rdi
movl %r13d, 0x8(%rdi)
xorl %r14d, %r14d
cmpl $0xff00, %r13d          # imm = 0xFF00
setb %r14b
movq %rbp, %r12
leaq 0x89902(%rip), %r13     # 0x9524c
leaq 0x8992b(%rip), %rbp     # 0x9527c
movq $0x0, 0x30(%rdi)
movl $0x2, %esi
callq 0x4380
testl %eax, %eax
sets %cl
cmpl $-0x5, %eax
setne %dl
cmpl $0x2, %eax
je 0xba2f
andb %dl, %cl
jne 0xba2f
cmpl $0x1, %eax
jne 0xb9e1
movq 0x60(%rbx), %rdi
cmpl $0x0, 0x8(%rdi)
jne 0xb9af
movq 0x40(%rbx), %rdi
movl $0x1, %edx
movq %r12, %rsi
callq 0xf0a9
movl $0x3, %r15d
cmpq $0x1, %rax
jne 0xba06
movq 0x60(%rbx), %rdi
callq 0x46e0
testl %eax, %eax
je 0xba03
movl %eax, %edi
xorl %esi, %esi
callq 0xadc9
movl $0x1, %r15d
movl $0x1, %edi
movq %r13, %rsi
movq %rbp, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x13de5
orb $0x1, (%rbx)
jmp 0xba06
cmpl $-0x5, %eax
setne %al
testl %r14d, %r14d
sete %cl
xorl %r15d, %r15d
orb %al, %cl
jne 0xba06
movq 0x60(%rbx), %rax
cmpl $0x0, 0x20(%rax)
je 0xba06
jmp 0xba8c
xorl %r15d, %r15d
testl %r15d, %r15d
je 0xb896
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $0x3, %r15d
jne 0xba7d
movq 0x60(%rbx), %rcx
movl $0x10000, %eax          # imm = 0x10000
subl 0x20(%rcx), %eax
jmp 0xba7d
movl $0x10000, %eax          # imm = 0x10000
jmp 0xba7d
cmpl $-0x3, %eax
jne 0xba4f
movq 0x60(%rbx), %rax
testq %rax, %rax
je 0xba46
movq 0x30(%rax), %rcx
testq %rcx, %rcx
jne 0xba5b
leaq 0x89749(%rip), %rcx     # 0x95196
jmp 0xba5b
movl %eax, %edi
xorl %esi, %esi
callq 0xadc9
movq %rax, %rcx
leaq 0x897ea(%rip), %rsi     # 0x9524c
leaq 0x897f6(%rip), %rdx     # 0x9525f
movl $0x1, %edi
xorl %eax, %eax
callq 0x13de5
orb $0x1, (%rbx)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x897b9(%rip), %rsi     # 0x9524c
leaq 0x89802(%rip), %rdx     # 0x9529c
movl $0x1, %edi
xorl %eax, %eax
callq 0x13de5
orb $0x4, (%rbx)
jmp 0xba78
movl %r13d, %eax
jmp 0xba7d