// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/external/zlib-1.3.0.1/gzread.c
// Function: gz_read
local z_size_t gz_read(gz_statep state, voidp buf, z_size_t len) {
    z_size_t got;
    unsigned n;

    /* if len is zero, avoid unnecessary operations */
    if (len == 0)
        return 0;

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

    /* get len bytes to buf, or less than len if at the end */
    got = 0;
    do {
        /* set n to the maximum amount of len that fits in an unsigned int */
        n = (unsigned)-1;
        if (n > len)
            n = (unsigned)len;

        /* first just try copying data from the output buffer */
        if (state->x.have) {
            if (state->x.have < n)
                n = state->x.have;
            memcpy(buf, state->x.next, n);
            state->x.next += n;
            state->x.have -= n;
        }

        /* output buffer empty -- return if we're at the end of the input */
        else if (state->eof && state->strm.avail_in == 0) {
            state->past = 1;        /* tried to read past end */
            break;
        }

        /* need output data -- for small len or new stream load up our output
           buffer */
        else if (state->how == LOOK || n < (state->size << 1)) {
            /* get more output, looking for header if required */
            if (gz_fetch(state) == -1)
                return 0;
            continue;       /* no progress yet -- go back to copy above */
            /* the copy above assures that we will leave with space in the
               output buffer, allowing at least one gzungetc() to succeed */
        }

        /* large len -- read directly into user buffer */
        else if (state->how == COPY) {      /* read directly */
            if (gz_load(state, (unsigned char *)buf, n, &n) == -1)
                return 0;
        }

        /* large len -- decompress directly into user buffer */
        else {  /* state->how == GZIP */
            state->strm.avail_out = n;
            state->strm.next_out = (unsigned char *)buf;
            if (gz_decomp(state) == -1)
                return 0;
            n = state->x.have;
            state->x.have = 0;
        }

        /* update progress */
        len -= n;
        buf = (char *)buf + n;
        got += n;
        state->x.pos += n;
    } while (len);

    /* return number of bytes read into user buffer */
    return got;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rdx, %rdx
je 0x9a1e8
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
cmpl $0x0, 0x70(%rdi)
je 0x9a106
movl $0x0, 0x70(%r14)
movq 0x68(%r14), %rsi
movq %r14, %rdi
callq 0x9a57a
cmpl $-0x1, %eax
je 0x9a1e8
xorl %r12d, %r12d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %rbx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmovbq %rbx, %rbp
movl %ebp, 0x4(%rsp)
movl (%r14), %eax
testl %eax, %eax
je 0x9a159
cmpl %ebp, %eax
jae 0x9a12f
movl %eax, 0x4(%rsp)
movl %eax, %ebp
movq 0x8(%r14), %rsi
movl %ebp, %r13d
movq %r15, %rdi
movq %r13, %rdx
callq 0xb520
addq %r13, 0x8(%r14)
subl %ebp, (%r14)
movl %ebp, %eax
subq %rax, %rbx
addq %rax, %r15
addq %rax, %r12
addq %rax, 0x10(%r14)
jmp 0x9a18d
cmpl $0x0, 0x50(%r14)
je 0x9a16e
cmpl $0x0, 0x88(%r14)
je 0x9a1fd
movl 0x44(%r14), %eax
testl %eax, %eax
je 0x9a180
movl 0x28(%r14), %ecx
addl %ecx, %ecx
cmpl %ebp, %ecx
jbe 0x9a198
movq %r14, %rdi
callq 0x9a733
cmpl $-0x1, %eax
je 0x9a1e8
testq %rbx, %rbx
jne 0x9a109
jmp 0x9a1eb
cmpl $0x1, %eax
jne 0x9a1ba
movq %r14, %rdi
movq %r15, %rsi
movl %ebp, %edx
leaq 0x4(%rsp), %rcx
callq 0x9a886
cmpl $-0x1, %eax
je 0x9a1e8
movl 0x4(%rsp), %ebp
jmp 0x9a148
movl %ebp, 0xa0(%r14)
movq %r15, 0x98(%r14)
movq %r14, %rdi
callq 0x9a908
cmpl $-0x1, %eax
je 0x9a1e8
movl (%r14), %ebp
movl %ebp, 0x4(%rsp)
movl $0x0, (%r14)
jmp 0x9a148
xorl %r12d, %r12d
movq %r12, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, 0x54(%r14)
jmp 0x9a1eb