// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x10(%rbp), %rax
movslq 0x10(%rax), %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movl $0x10000, %ecx          # imm = 0x10000
subl 0x10(%rax), %ecx
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movl %ecx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
cmpl $0x0, 0x20(%rax)
je 0xe144
cmpl $0x0, -0x14(%rbp)
jne 0xdf88
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
cmpl $0x0, 0x8(%rax)
jne 0xdf88
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rcx
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rsi
movl $0xff00, %edx           # imm = 0xFF00
callq 0xde00
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jge 0xdf60
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xe157
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
cmpl $0xff00, 0x8(%rax)      # imm = 0xFF00
jae 0xdf86
movl $0x1, -0x14(%rbp)
jmp 0xdf88
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq $0x0, 0x30(%rax)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
movl $0x2, %esi
callq 0x4370
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0xdfb9
cmpl $-0x5, -0x1c(%rbp)
jne 0xdfbf
cmpl $0x2, -0x1c(%rbp)
jne 0xe037
movl -0x1c(%rbp), %eax
movl %eax, -0x28(%rbp)
cmpl $-0x3, -0x1c(%rbp)
jne 0xdfd9
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0xdfe1
xorl %eax, %eax
movq %rax, -0x30(%rbp)
jmp 0xdfe1
movl -0x28(%rbp), %edi
movq -0x30(%rbp), %rsi
callq 0xcd40
movq %rax, %rcx
movl $0x1, %edi
leaq 0xe141a(%rip), %rsi     # 0xef416
leaq 0xe1426(%rip), %rdx     # 0xef429
movb $0x0, %al
callq 0x1b030
movq -0x10(%rbp), %rax
movl (%rax), %edx
andl $0xffff, %edx           # imm = 0xFFFF
orl $0x1, %edx
movl (%rax), %ecx
andl $0xffff, %edx           # imm = 0xFFFF
andl $0xffff0000, %ecx       # imm = 0xFFFF0000
orl %edx, %ecx
movl %ecx, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xe157
cmpl $0x1, -0x1c(%rbp)
jne 0xe0dd
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
cmpl $0x0, 0x8(%rax)
ja 0xe06b
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
leaq -0x1d(%rbp), %rsi
movl $0x1, %edx
callq 0x140b0
cmpq $0x1, %rax
jne 0xe0d9
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x46b0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0xe0d7
movl -0x24(%rbp), %edi
xorl %eax, %eax
movl %eax, %esi
callq 0xcd40
movq %rax, %rcx
movl $0x1, %edi
leaq 0xe137a(%rip), %rsi     # 0xef416
leaq 0xe13a3(%rip), %rdx     # 0xef446
movb $0x0, %al
callq 0x1b030
movq -0x10(%rbp), %rax
movl (%rax), %edx
andl $0xffff, %edx           # imm = 0xFFFF
orl $0x1, %edx
movl (%rax), %ecx
andl $0xffff, %edx           # imm = 0xFFFF
andl $0xffff0000, %ecx       # imm = 0xFFFF0000
orl %edx, %ecx
movl %ecx, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xe157
jmp 0xe0db
jmp 0xe144
jmp 0xe13d
cmpl $-0x5, -0x1c(%rbp)
jne 0xe13b
cmpl $0x0, -0x14(%rbp)
je 0xe13b
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
cmpl $0x0, 0x20(%rax)
jbe 0xe13b
movl $0x1, %edi
leaq 0xe1313(%rip), %rsi     # 0xef416
leaq 0xe135c(%rip), %rdx     # 0xef466
movb $0x0, %al
callq 0x1b030
movq -0x10(%rbp), %rax
movl (%rax), %edx
andl $0xffff, %edx           # imm = 0xFFFF
orl $0x4, %edx
movl (%rax), %ecx
andl $0xffff, %edx           # imm = 0xFFFF
andl $0xffff0000, %ecx       # imm = 0xFFFF0000
orl %edx, %ecx
movl %ecx, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xe157
jmp 0xe13d
jmp 0xe13f
jmp 0xdef9
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rcx
movl $0x10000, %eax          # imm = 0x10000
subl 0x20(%rcx), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq