// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x38, %rsp
movq %rdi, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
jne 0xcd7b9
movq $0x0, 0x30(%rsp)
jmp 0xcd9d4
movq 0x28(%rsp), %rax
cmpl $0x0, 0x70(%rax)
je 0xcd7f8
movq 0x28(%rsp), %rax
movl $0x0, 0x70(%rax)
movq 0x28(%rsp), %rdi
movq 0x28(%rsp), %rax
movq 0x68(%rax), %rsi
callq 0xce130
cmpl $-0x1, %eax
jne 0xcd7f6
movq $0x0, 0x30(%rsp)
jmp 0xcd9d4
jmp 0xcd7f8
movq $0x0, 0x10(%rsp)
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movl 0xc(%rsp), %eax
cmpq 0x18(%rsp), %rax
jbe 0xcd81d
movq 0x18(%rsp), %rax
movl %eax, 0xc(%rsp)
movq 0x28(%rsp), %rax
cmpl $0x0, (%rax)
je 0xcd882
movq 0x28(%rsp), %rax
movl (%rax), %eax
cmpl 0xc(%rsp), %eax
jae 0xcd83f
movq 0x28(%rsp), %rax
movl (%rax), %eax
movl %eax, 0xc(%rsp)
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rsi
movl 0xc(%rsp), %eax
movl %eax, %edx
callq 0xb500
movl 0xc(%rsp), %edx
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rcx
movl %edx, %edx
addq %rdx, %rcx
movq %rcx, 0x8(%rax)
movl 0xc(%rsp), %edx
movq 0x28(%rsp), %rax
movl (%rax), %ecx
subl %edx, %ecx
movl %ecx, (%rax)
jmp 0xcd979
movq 0x28(%rsp), %rax
cmpl $0x0, 0x50(%rax)
je 0xcd8ac
movq 0x28(%rsp), %rax
cmpl $0x0, 0x88(%rax)
jne 0xcd8ac
movq 0x28(%rsp), %rax
movl $0x1, 0x54(%rax)
jmp 0xcd9ca
movq 0x28(%rsp), %rax
cmpl $0x0, 0x44(%rax)
je 0xcd8c9
movl 0xc(%rsp), %eax
movq 0x28(%rsp), %rcx
movl 0x28(%rcx), %ecx
shll %ecx
cmpl %ecx, %eax
jae 0xcd8eb
movq 0x28(%rsp), %rdi
callq 0xce470
cmpl $-0x1, %eax
jne 0xcd8e6
movq $0x0, 0x30(%rsp)
jmp 0xcd9d4
jmp 0xcd9be
movq 0x28(%rsp), %rax
cmpl $0x1, 0x44(%rax)
jne 0xcd923
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl 0xc(%rsp), %edx
leaq 0xc(%rsp), %rcx
callq 0xce750
cmpl $-0x1, %eax
jne 0xcd921
movq $0x0, 0x30(%rsp)
jmp 0xcd9d4
jmp 0xcd973
movl 0xc(%rsp), %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0xa0(%rax)
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x98(%rax)
movq 0x28(%rsp), %rdi
callq 0xce850
cmpl $-0x1, %eax
jne 0xcd95d
movq $0x0, 0x30(%rsp)
jmp 0xcd9d4
movq 0x28(%rsp), %rax
movl (%rax), %eax
movl %eax, 0xc(%rsp)
movq 0x28(%rsp), %rax
movl $0x0, (%rax)
jmp 0xcd975
jmp 0xcd977
jmp 0xcd979
movl 0xc(%rsp), %eax
movl %eax, %ecx
movq 0x18(%rsp), %rax
subq %rcx, %rax
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rax
movl 0xc(%rsp), %ecx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movl 0xc(%rsp), %eax
addq 0x10(%rsp), %rax
movq %rax, 0x10(%rsp)
movl 0xc(%rsp), %eax
movl %eax, %ecx
movq 0x28(%rsp), %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
cmpq $0x0, 0x18(%rsp)
jne 0xcd801
movq 0x10(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
addq $0x38, %rsp
retq
nop