// File: /workspace/github_c_makefile_star2_O1/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 0x9ac33
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
cmpl $0x0, 0x70(%rdi)
je 0x9ab52
movl $0x0, 0x70(%r14)
movq 0x68(%r14), %rsi
movq %r14, %rdi
callq 0x9afc5
cmpl $-0x1, %eax
je 0x9ac33
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
leaq 0x4(%rsp), %r13
xorl %r12d, %r12d
cmpq %rbp, %rbx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmovbq %rbx, %rdx
movl %edx, 0x4(%rsp)
movl (%r14), %eax
testl %eax, %eax
je 0x9abb1
cmpl %edx, %eax
jae 0x9ab7e
movl %eax, 0x4(%rsp)
movq 0x8(%r14), %rsi
movl 0x4(%rsp), %edx
movq %r15, %rdi
callq 0xb520
movl 0x4(%rsp), %ecx
addq %rcx, 0x8(%r14)
movl (%r14), %eax
subl %ecx, %eax
movl %eax, (%r14)
movl 0x4(%rsp), %eax
subq %rax, %rbx
addq %rax, %r15
addq %rax, %r12
addq %rax, 0x10(%r14)
jmp 0x9abe5
cmpl $0x0, 0x50(%r14)
je 0x9abc6
cmpl $0x0, 0x88(%r14)
je 0x9ac48
movl 0x44(%r14), %eax
testl %eax, %eax
je 0x9abd8
movl 0x28(%r14), %ecx
addl %ecx, %ecx
cmpl %edx, %ecx
jbe 0x9abf0
movq %r14, %rdi
callq 0x9b160
cmpl $-0x1, %eax
je 0x9ac33
testq %rbx, %rbx
jne 0x9ab5f
jmp 0x9ac36
cmpl $0x1, %eax
jne 0x9ac0a
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rcx
callq 0x9b2b3
cmpl $-0x1, %eax
jne 0x9ab9e
jmp 0x9ac33
movl %edx, 0xa0(%r14)
movq %r15, 0x98(%r14)
movq %r14, %rdi
callq 0x9b33a
cmpl $-0x1, %eax
je 0x9ac33
movl (%r14), %eax
movl %eax, 0x4(%rsp)
xorl %eax, %eax
jmp 0x9ab9b
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 0x9ac36