// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/zlib-1.3.0.1/gzwrite.c
// Function: gz_write
local z_size_t gz_write(gz_statep state, voidpc buf, z_size_t len) {
    z_size_t put = len;

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

    /* allocate memory if this is the first time through */
    if (state->size == 0 && gz_init(state) == -1)
        return 0;

    /* check for seek request */
    if (state->seek) {
        state->seek = 0;
        if (gz_zero(state, state->skip) == -1)
            return 0;
    }

    /* for small len, copy to input buffer, otherwise compress directly */
    if (len < state->size) {
        /* copy to input buffer, compress when full */
        do {
            unsigned have, copy;

            if (state->strm.avail_in == 0)
                state->strm.next_in = state->in;
            have = (unsigned)((state->strm.next_in + state->strm.avail_in) -
                              state->in);
            copy = state->size - have;
            if (copy > len)
                copy = (unsigned)len;
            memcpy(state->in + have, buf, copy);
            state->strm.avail_in += copy;
            state->x.pos += copy;
            buf = (const char *)buf + copy;
            len -= copy;
            if (len && gz_comp(state, Z_NO_FLUSH) == -1)
                return 0;
        } while (len);
    }
    else {
        /* consume whatever's left in the input buffer */
        if (state->strm.avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
            return 0;

        /* directly compress user buffer to file */
        state->strm.next_in = (z_const Bytef *)buf;
        do {
            unsigned n = (unsigned)-1;
            if (n > len)
                n = (unsigned)len;
            state->strm.avail_in = n;
            state->x.pos += n;
            if (gz_comp(state, Z_NO_FLUSH) == -1)
                return 0;
            len -= n;
        } while (len);
    }

    /* input was all buffered or compressed */
    return put;
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x18(%rsp)
jne 0xcec23
movq $0x0, 0x30(%rsp)
jmp 0xcee78
movq 0x28(%rsp), %rax
cmpl $0x0, 0x28(%rax)
jne 0xcec4b
movq 0x28(%rsp), %rdi
callq 0xcf5b0
cmpl $-0x1, %eax
jne 0xcec4b
movq $0x0, 0x30(%rsp)
jmp 0xcee78
movq 0x28(%rsp), %rax
cmpl $0x0, 0x70(%rax)
je 0xcec8a
movq 0x28(%rsp), %rax
movl $0x0, 0x70(%rax)
movq 0x28(%rsp), %rdi
movq 0x28(%rsp), %rax
movq 0x68(%rax), %rsi
callq 0xcf120
cmpl $-0x1, %eax
jne 0xcec88
movq $0x0, 0x30(%rsp)
jmp 0xcee78
jmp 0xcec8a
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
movl 0x28(%rcx), %ecx
cmpq %rcx, %rax
jae 0xcedb9
jmp 0xceca2
movq 0x28(%rsp), %rax
cmpl $0x0, 0x88(%rax)
jne 0xcecc5
movq 0x28(%rsp), %rax
movq 0x30(%rax), %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x80(%rax)
movq 0x28(%rsp), %rax
movq 0x80(%rax), %rax
movq 0x28(%rsp), %rcx
movl 0x88(%rcx), %ecx
addq %rcx, %rax
movq 0x28(%rsp), %rcx
movq 0x30(%rcx), %rcx
subq %rcx, %rax
movl %eax, 0xc(%rsp)
movq 0x28(%rsp), %rax
movl 0x28(%rax), %eax
subl 0xc(%rsp), %eax
movl %eax, 0x8(%rsp)
movl 0x8(%rsp), %eax
cmpq 0x18(%rsp), %rax
jbe 0xced13
movq 0x18(%rsp), %rax
movl %eax, 0x8(%rsp)
movq 0x28(%rsp), %rax
movq 0x30(%rax), %rdi
movl 0xc(%rsp), %eax
addq %rax, %rdi
movq 0x20(%rsp), %rsi
movl 0x8(%rsp), %eax
movl %eax, %edx
callq 0xb500
movl 0x8(%rsp), %ecx
movq 0x28(%rsp), %rax
addl 0x88(%rax), %ecx
movl %ecx, 0x88(%rax)
movl 0x8(%rsp), %eax
movl %eax, %ecx
movq 0x28(%rsp), %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq 0x20(%rsp), %rax
movl 0x8(%rsp), %ecx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movl 0x8(%rsp), %eax
movl %eax, %ecx
movq 0x18(%rsp), %rax
subq %rcx, %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
je 0xceda6
movq 0x28(%rsp), %rdi
xorl %esi, %esi
callq 0xcf7a0
cmpl $-0x1, %eax
jne 0xceda6
movq $0x0, 0x30(%rsp)
jmp 0xcee78
jmp 0xceda8
cmpq $0x0, 0x18(%rsp)
jne 0xceca2
jmp 0xcee6e
movq 0x28(%rsp), %rax
cmpl $0x0, 0x88(%rax)
je 0xcede6
movq 0x28(%rsp), %rdi
xorl %esi, %esi
callq 0xcf7a0
cmpl $-0x1, %eax
jne 0xcede6
movq $0x0, 0x30(%rsp)
jmp 0xcee78
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x80(%rax)
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
movl 0x4(%rsp), %eax
cmpq 0x18(%rsp), %rax
jbe 0xcee13
movq 0x18(%rsp), %rax
movl %eax, 0x4(%rsp)
movl 0x4(%rsp), %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0x88(%rax)
movl 0x4(%rsp), %eax
movl %eax, %ecx
movq 0x28(%rsp), %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq 0x28(%rsp), %rdi
xorl %esi, %esi
callq 0xcf7a0
cmpl $-0x1, %eax
jne 0xcee51
movq $0x0, 0x30(%rsp)
jmp 0xcee78
movl 0x4(%rsp), %eax
movl %eax, %ecx
movq 0x18(%rsp), %rax
subq %rcx, %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
jne 0xcedf7
jmp 0xcee6e
movq 0x10(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)