// File: /workspace/github_c_makefile_star2_O3/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 0x9a49e
movl 0x88(%rbx), %eax
cmpl $0x1, %eax
ja 0x9a435
movq %rbx, %rdi
callq 0x9aa17
cmpl $-0x1, %eax
je 0x9a556
movl 0x88(%rbx), %eax
testl %eax, %eax
je 0x9a56e
cmpl $0x1, %eax
je 0x9a457
movq (%r14), %rcx
cmpb $0x1f, (%rcx)
jne 0x9a457
cmpb $-0x75, 0x1(%rcx)
jne 0x9a457
movq %r14, %rdi
callq 0xa0941
movabsq $0x200000000, %rax      # imm = 0x200000000
jmp 0x9a493
cmpl $0x0, 0x40(%rbx)
je 0x9a55d
movq 0x38(%rbx), %rdi
movq 0x80(%rbx), %rsi
movq %rdi, 0x8(%rbx)
movl %eax, %edx
callq 0xb520
movl 0x88(%rbx), %eax
movl %eax, (%rbx)
movl $0x0, 0x88(%rbx)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x40(%rbx)
xorl %eax, %eax
jmp 0x9a56e
movl 0x2c(%rbx), %r12d
movq %r12, %rdi
callq 0xb810
movq %rax, %r15
movq %rax, 0x30(%rbx)
leal (%r12,%r12), %edi
callq 0xb810
movq %rax, 0x38(%rbx)
testq %r15, %r15
setne %cl
testq %rax, %rax
setne %dl
testb %dl, %cl
jne 0x9a4e0
movq %rax, %rdi
callq 0xb790
movq %r15, %rdi
callq 0xb790
jmp 0x9a542
movl %r12d, 0x28(%rbx)
movl $0x0, 0x88(%rbx)
xorl %eax, %eax
movq %rax, 0x80(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0xc0(%rbx)
movq %rax, 0xd0(%rbx)
leaq 0x5d93c(%rip), %rdx     # 0xf7e4b
movq %r14, %rdi
movl $0x1f, %esi
movl $0x70, %ecx
callq 0xa0a12
testl %eax, %eax
je 0x9a406
movq 0x38(%rbx), %rdi
callq 0xb790
movq 0x30(%rbx), %rdi
callq 0xb790
movl $0x0, 0x28(%rbx)
leaq 0x594e1(%rip), %rdx     # 0xf3a2a
movq %rbx, %rdi
movl $0xfffffffc, %esi       # imm = 0xFFFFFFFC
callq 0x99e17
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x9a56e
xorl %eax, %eax
movl %eax, 0x88(%rbx)
movl $0x1, 0x50(%rbx)
movl %eax, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq