// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/external/zlib-1.3.0.1/gzread.c
// Function: gzgets
char * ZEXPORT gzgets(gzFile file, char *buf, int len) {
    unsigned left, n;
    char *str;
    unsigned char *eol;
    gz_statep state;

    /* check parameters and get internal structure */
    if (file == NULL || buf == NULL || len < 1)
        return NULL;
    state = (gz_statep)file;

    /* check that we're reading and that there's no (serious) error */
    if (state->mode != GZ_READ ||
        (state->err != Z_OK && state->err != Z_BUF_ERROR))
        return NULL;

    /* process a skip request */
    if (state->seek) {
        state->seek = 0;
        if (gz_skip(state, state->skip) == -1)
            return NULL;
    }

    /* copy output bytes up to new line or len - 1, whichever comes first --
       append a terminating zero to the string (we don't check for a zero in
       the contents, let the user worry about that) */
    str = buf;
    left = (unsigned)len - 1;
    if (left) do {
        /* assure that something is in the output buffer */
        if (state->x.have == 0 && gz_fetch(state) == -1)
            return NULL;                /* error */
        if (state->x.have == 0) {       /* end of file */
            state->past = 1;            /* read past end */
            break;                      /* return what we have */
        }

        /* look for end-of-line in current output buffer */
        n = state->x.have > left ? left : state->x.have;
        eol = (unsigned char *)memchr(state->x.next, '\n', n);
        if (eol != NULL)
            n = (unsigned)(eol - state->x.next) + 1;

        /* copy through end-of-line, or remainder if not found */
        memcpy(buf, state->x.next, n);
        state->x.have -= n;
        state->x.next += n;
        state->x.pos += n;
        left -= n;
        buf += n;
    } while (left && eol == NULL);

    /* return terminated string, or if nothing, end of file */
    if (buf == str)
        return NULL;
    buf[0] = 0;
    return str;
}

// Assembly:
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
orb %al, %cl
testl %edx, %edx
setle %al
orb %cl, %al
jne 0x9b133
cmpl $0x1c4f, 0x18(%rdi)     # imm = 0x1C4F
jne 0x9b133
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %ebp
movq %rsi, %r15
movl 0x74(%rdi), %eax
testl %eax, %eax
je 0x9b077
cmpl $-0x5, %eax
jne 0x9b14f
cmpl $0x0, 0x70(%rdi)
movq %rdi, 0x8(%rsp)
je 0x9b0a5
movl $0x0, 0x70(%rdi)
movq 0x68(%rdi), %rsi
movq 0x8(%rsp), %rdi
callq 0x9afc5
movq 0x8(%rsp), %rdi
cmpl $-0x1, %eax
je 0x9b14f
movq %r15, 0x10(%rsp)
decl %ebp
je 0x9b13d
movq 0x10(%rsp), %r15
cmpl $0x0, (%rdi)
jne 0x9b0d0
movq 0x8(%rsp), %rdi
callq 0x9b160
movq 0x8(%rsp), %rdi
cmpl $-0x1, %eax
je 0x9b14f
movl (%rdi), %r12d
testl %r12d, %r12d
je 0x9b136
cmpl %ebp, %r12d
cmovael %ebp, %r12d
movq 0x8(%rdi), %rbx
movq %rbx, %rdi
movl $0xa, %esi
movq %r12, %rdx
callq 0xb710
movq %rax, %r14
movl %r14d, %r13d
subl %ebx, %r13d
incl %r13d
testq %rax, %rax
cmovel %r12d, %r13d
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0xb520
movq 0x8(%rsp), %rdi
subl %r13d, (%rdi)
addq %r13, 0x8(%rdi)
addq %r13, 0x10(%rdi)
addq %r13, %r15
testq %r14, %r14
jne 0x9b13d
subl %r13d, %ebp
jne 0x9b0b7
jmp 0x9b13d
xorl %eax, %eax
retq
movl $0x1, 0x54(%rdi)
cmpq 0x10(%rsp), %r15
je 0x9b14f
movb $0x0, (%r15)
movq 0x10(%rsp), %rax
jmp 0x9b151
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq