// File: /workspace/github_c_makefile_star2_O2/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 0x7ac96
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 0x7adb8
movl %edx, %r15d
movq %rsi, %rbx
movl 0x74(%r14), %eax
testl %eax, %eax
je 0x7accb
cmpl $-0x5, %eax
jne 0x7adb8
cmpl $0x0, 0x70(%r14)
je 0x7acf8
andl $0x0, 0x70(%r14)
movq 0x68(%r14), %rsi
movq %r14, %rdi
callq 0x7ac10
cmpl $-0x1, %eax
sete %al
decl %r15d
sete %cl
orb %al, %cl
je 0x7ad01
jmp 0x7adb8
decl %r15d
je 0x7adb8
movq %r14, (%rsp)
movl (%r14), %r13d
movq %rbx, 0x8(%rsp)
movq %rbx, %r14
movq (%rsp), %rbp
testl %r13d, %r13d
jne 0x7ad36
movq (%rsp), %rbx
movq %rbx, %rdi
callq 0x7adc9
cmpl $-0x1, %eax
je 0x7adb8
movl (%rbx), %r13d
testl %r13d, %r13d
je 0x7ad9b
cmpl %r15d, %r13d
cmovael %r15d, %r13d
movq 0x8(%rbp), %rbx
movq %rbx, %rdi
pushq $0xa
popq %rsi
movq %r13, %rdx
callq 0xb710
movq %rax, 0x10(%rsp)
movl %eax, %r12d
subl %ebx, %r12d
incl %r12d
testq %rax, %rax
cmovel %r13d, %r12d
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0xb520
movl (%rbp), %r13d
addq %r12, 0x8(%rbp)
addq %r12, 0x10(%rbp)
subl %r12d, %r13d
addq %r12, %r14
movl %r13d, (%rbp)
cmpq $0x0, 0x10(%rsp)
jne 0x7ada6
subl %r12d, %r15d
jne 0x7ad14
jmp 0x7ada6
movq (%rsp), %rax
movl $0x1, 0x54(%rax)
cmpq 0x8(%rsp), %r14
je 0x7adb8
movb $0x0, (%r14)
movq 0x8(%rsp), %rax
jmp 0x7adba
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq