// File: /workspace/github_c_makefile_star2_O3/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
je 0x9a5fb
xorl %eax, %eax
retq
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r14
cmpl $0x1c4f, 0x18(%rdi)     # imm = 0x1C4F
jne 0x9a722
movl %edx, %r15d
movq %rsi, %rbx
movl 0x74(%r14), %eax
testl %eax, %eax
je 0x9a630
cmpl $-0x5, %eax
jne 0x9a722
cmpl $0x0, 0x70(%r14)
je 0x9a660
movl $0x0, 0x70(%r14)
movq 0x68(%r14), %rsi
movq %r14, %rdi
callq 0x9a57a
cmpl $-0x1, %eax
sete %al
decl %r15d
sete %cl
orb %al, %cl
je 0x9a669
jmp 0x9a722
decl %r15d
je 0x9a722
movq %r14, (%rsp)
movl (%r14), %r12d
movq %rbx, 0x8(%rsp)
movq %rbx, %r14
movq (%rsp), %rbp
testl %r12d, %r12d
jne 0x9a69e
movq (%rsp), %rbx
movq %rbx, %rdi
callq 0x9a733
cmpl $-0x1, %eax
je 0x9a722
movl (%rbx), %r12d
testl %r12d, %r12d
je 0x9a705
cmpl %r15d, %r12d
cmovael %r15d, %r12d
movq 0x8(%rbp), %rbx
movq %rbx, %rdi
movl $0xa, %esi
movq %r12, %rdx
callq 0xb710
movq %rax, 0x10(%rsp)
movl %eax, %r13d
subl %ebx, %r13d
incl %r13d
testq %rax, %rax
cmovel %r12d, %r13d
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0xb520
movl (%rbp), %r12d
addq %r13, 0x8(%rbp)
addq %r13, 0x10(%rbp)
subl %r13d, %r12d
addq %r13, %r14
movl %r12d, (%rbp)
cmpq $0x0, 0x10(%rsp)
jne 0x9a710
subl %r13d, %r15d
jne 0x9a67c
jmp 0x9a710
movq (%rsp), %rax
movl $0x1, 0x54(%rax)
cmpq 0x8(%rsp), %r14
je 0x9a722
movb $0x0, (%r14)
movq 0x8(%rsp), %rax
jmp 0x9a724
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq