// File: /workspace/github_c_makefile_star2_O2/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)
pushq $0x1
popq %r12
pushq $0x2
popq %r15
leaq 0x6c95d(%rip), %r13     # 0x7722c
pushq $-0x1
popq %rbp
xorl %r14d, %r14d
movq 0x60(%rbx), %rdi
cmpl $0x0, 0x20(%rdi)
je 0xa9e8
testl %r14d, %r14d
je 0xa8ed
movl %r12d, %r14d
jmp 0xa926
xorl %r14d, %r14d
cmpl $0x0, 0x8(%rdi)
jne 0xa926
movq 0x30(%rbx), %rsi
movq %rsi, (%rdi)
movq 0x40(%rbx), %rdi
movl $0xff00, %edx           # imm = 0xFF00
callq 0xa82f
testl %eax, %eax
js 0xaa4f
movq 0x60(%rbx), %rdi
movl %eax, 0x8(%rdi)
xorl %r14d, %r14d
cmpl $0xff00, %eax           # imm = 0xFF00
setb %r14b
andq $0x0, 0x30(%rdi)
movl %r15d, %esi
callq 0x4380
testl %eax, %eax
sets %cl
cmpl $-0x5, %eax
setne %dl
cmpl $0x2, %eax
je 0xa9ef
andb %dl, %cl
jne 0xa9ef
cmpl $0x1, %eax
jne 0xa9ad
movq 0x60(%rbx), %rdi
cmpl $0x0, 0x8(%rdi)
jne 0xa97c
movq 0x40(%rbx), %rdi
leaq 0x7(%rsp), %rsi
pushq $0x1
popq %rdx
callq 0xd4e0
pushq $0x3
popq %rcx
cmpq $0x1, %rax
jne 0xa9cd
movq 0x60(%rbx), %rdi
callq 0x46e0
testl %eax, %eax
je 0xa9cb
movl %eax, %edi
xorl %esi, %esi
callq 0x9cf6
movl %r12d, %edi
leaq 0x6c864(%rip), %rsi     # 0x771fc
movq %r13, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x110c6
orb $0x1, (%rbx)
movl %r12d, %ecx
jmp 0xa9cd
cmpl $-0x5, %eax
setne %al
testl %r14d, %r14d
sete %dl
xorl %ecx, %ecx
orb %al, %dl
jne 0xa9cd
movq 0x60(%rbx), %rax
cmpl $0x0, 0x20(%rax)
je 0xa9cd
jmp 0xaa32
xorl %ecx, %ecx
testl %ecx, %ecx
je 0xa8d5
cmpl $0x3, %ecx
jne 0xaa21
movq 0x60(%rbx), %rax
movl $0x10000, %ebp          # imm = 0x10000
subl 0x20(%rax), %ebp
jmp 0xaa21
movl $0x10000, %ebp          # imm = 0x10000
jmp 0xaa21
cmpl $-0x3, %eax
jne 0xa9fa
movq 0x60(%rbx), %rsi
jmp 0xa9fc
xorl %esi, %esi
movl %eax, %edi
callq 0x9cf6
leaq 0x6c7f2(%rip), %rsi     # 0x771fc
leaq 0x6c7fe(%rip), %rdx     # 0x7720f
pushq $0x1
popq %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x110c6
orb $0x1, (%rbx)
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6c7c3(%rip), %rsi     # 0x771fc
leaq 0x6c80c(%rip), %rdx     # 0x7724c
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x110c6
orb $0x4, (%rbx)
jmp 0xaa21
movl %eax, %ebp
jmp 0xaa21