// File: /workspace/github_c_makefile_star2_O1/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 0x9aee9
cmpl $0x1, 0x88(%rbx)
ja 0x9ae76
movq %rbx, %rdi
callq 0x9b442
cmpl $-0x1, %eax
je 0x9afa1
cmpl $0x0, 0x88(%rbx)
je 0x9aee2
movl 0x88(%rbx), %edx
cmpq $0x2, %rdx
jb 0x9aea4
movq (%r14), %rax
cmpb $0x1f, (%rax)
jne 0x9aea4
cmpb $-0x75, 0x1(%rax)
jne 0x9aea4
movq %r14, %rdi
callq 0xa1371
movabsq $0x200000000, %rax      # imm = 0x200000000
jmp 0x9aede
cmpl $0x0, 0x40(%rbx)
je 0x9afa8
movq 0x38(%rbx), %rdi
movq 0x80(%rbx), %rsi
movq %rdi, 0x8(%rbx)
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 0x9afb9
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 0x9af2b
movq %rax, %rdi
callq 0xb790
movq %r15, %rdi
callq 0xb790
jmp 0x9af8d
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 0x5cf89(%rip), %rdx     # 0xf7ee3
movq %r14, %rdi
movl $0x1f, %esi
movl $0x70, %ecx
callq 0xa1442
testl %eax, %eax
je 0x9ae53
movq 0x38(%rbx), %rdi
callq 0xb790
movq 0x30(%rbx), %rdi
callq 0xb790
movl $0x0, 0x28(%rbx)
leaq 0x58af6(%rip), %rdx     # 0xf3a8a
movq %rbx, %rdi
movl $0xfffffffc, %esi       # imm = 0xFFFFFFFC
callq 0x9a863
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x9afb9
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