// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/zlib-1.3.0.1/gzread.c
// Function: gz_look
local int gz_look(gz_statep state) {
    z_streamp strm = &(state->strm);

    /* allocate read buffers and inflate memory */
    if (state->size == 0) {
        /* allocate buffers */
        state->in = (unsigned char *)malloc(state->want);
        state->out = (unsigned char *)malloc(state->want << 1);
        if (state->in == NULL || state->out == NULL) {
            free(state->out);
            free(state->in);
            gz_error(state, Z_MEM_ERROR, "out of memory");
            return -1;
        }
        state->size = state->want;

        /* allocate inflate memory */
        state->strm.zalloc = Z_NULL;
        state->strm.zfree = Z_NULL;
        state->strm.opaque = Z_NULL;
        state->strm.avail_in = 0;
        state->strm.next_in = Z_NULL;
        if (inflateInit2(&(state->strm), 15 + 16) != Z_OK) {    /* gunzip */
            free(state->out);
            free(state->in);
            state->size = 0;
            gz_error(state, Z_MEM_ERROR, "out of memory");
            return -1;
        }
    }

    /* get at least the magic bytes in the input buffer */
    if (strm->avail_in < 2) {
        if (gz_avail(state) == -1)
            return -1;
        if (strm->avail_in == 0)
            return 0;
    }

    /* look for gzip magic bytes -- if there, do gzip decoding (note: there is
       a logical dilemma here when considering the case of a partially written
       gzip file, to wit, if a single 31 byte is written, then we cannot tell
       whether this is a single-byte file, or just a partially written gzip
       file -- for here we assume that if a gzip file is being written, then
       the header will be written in a single operation, so that reading a
       single byte is sufficient indication that it is not a gzip file) */
    if (strm->avail_in > 1 &&
            strm->next_in[0] == 31 && strm->next_in[1] == 139) {
        inflateReset(strm);
        state->how = GZIP;
        state->direct = 0;
        return 0;
    }

    /* no gzip header -- if we were decoding gzip before, then this is trailing
       garbage.  Ignore the trailing garbage and finish. */
    if (state->direct == 0) {
        strm->avail_in = 0;
        state->eof = 1;
        state->x.have = 0;
        return 0;
    }

    /* doing raw i/o, copy any leftover input to output -- this assumes that
       the output buffer is larger than the input buffer, which also assures
       space for gzungetc() */
    state->x.next = state->out;
    memcpy(state->x.next, strm->next_in, strm->avail_in);
    state->x.have = strm->avail_in;
    strm->avail_in = 0;
    state->how = COPY;
    state->direct = 1;
    return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x80(%rdi), %r14
cmpl $0x0, 0x28(%rdi)
je 0x7ab40
movl 0x88(%rbx), %eax
cmpl $0x1, %eax
ja 0x7aadc
movq %rbx, %rdi
callq 0x7b09a
cmpl $-0x1, %eax
je 0x7abec
movl 0x88(%rbx), %eax
testl %eax, %eax
je 0x7ac04
cmpl $0x1, %eax
je 0x7aafe
movq (%r14), %rcx
cmpb $0x1f, (%rcx)
jne 0x7aafe
cmpb $-0x75, 0x1(%rcx)
jne 0x7aafe
movq %r14, %rdi
callq 0x80386
movabsq $0x200000000, %rax      # imm = 0x200000000
jmp 0x7ab37
cmpl $0x0, 0x40(%rbx)
je 0x7abf1
movq 0x38(%rbx), %rdi
movq 0x80(%rbx), %rsi
movq %rdi, 0x8(%rbx)
movl %eax, %edx
callq 0xb520
movl 0x88(%rbx), %eax
movl %eax, (%rbx)
andl $0x0, 0x88(%rbx)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x40(%rbx)
jmp 0x7ac02
movl 0x2c(%rbx), %r12d
movq %r12, %rdi
callq 0xbce8
movq %rax, %r15
movq %rax, 0x30(%rbx)
leal (%r12,%r12), %edi
callq 0xbce8
movq %rax, 0x38(%rbx)
testq %r15, %r15
setne %cl
testq %rax, %rax
setne %dl
testb %dl, %cl
jne 0x7ab82
movq %rax, %rdi
callq 0xb790
movq %r15, %rdi
callq 0xb790
jmp 0x7abda
movl %r12d, 0x28(%rbx)
andl $0x0, 0x88(%rbx)
andq $0x0, 0x80(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0xc0(%rbx)
andq $0x0, 0xd0(%rbx)
leaq 0x66615(%rip), %rdx     # 0xe11c3
pushq $0x1f
popq %rsi
pushq $0x70
popq %rcx
movq %r14, %rdi
callq 0x8043f
testl %eax, %eax
je 0x7aaad
movq 0x38(%rbx), %rdi
callq 0xb790
movq 0x30(%rbx), %rdi
callq 0xb790
andl $0x0, 0x28(%rbx)
leaq 0x621a9(%rip), %rdx     # 0xdcd8a
pushq $-0x4
popq %rsi
movq %rbx, %rdi
callq 0x7a532
pushq $-0x1
popq %rax
jmp 0x7ac04
andl $0x0, 0x88(%rbx)
movl $0x1, 0x50(%rbx)
andl $0x0, (%rbx)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq