// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/zlib-1.3.0.1/gzwrite.c
// Function: gz_comp
local int gz_comp(gz_statep state, int flush) {
    int ret, writ;
    unsigned have, put, max = ((unsigned)-1 >> 2) + 1;
    z_streamp strm = &(state->strm);

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

    /* write directly if requested */
    if (state->direct) {
        while (strm->avail_in) {
            put = strm->avail_in > max ? max : strm->avail_in;
            writ = write(state->fd, strm->next_in, put);
            if (writ < 0) {
                gz_error(state, Z_ERRNO, zstrerror());
                return -1;
            }
            strm->avail_in -= (unsigned)writ;
            strm->next_in += writ;
        }
        return 0;
    }

    /* check for a pending reset */
    if (state->reset) {
        /* don't start a new gzip member unless there is data to write */
        if (strm->avail_in == 0)
            return 0;
        deflateReset(strm);
        state->reset = 0;
    }

    /* run deflate() on provided input until it produces no more output */
    ret = Z_OK;
    do {
        /* write out current buffer contents if full, or if flushing, but if
           doing Z_FINISH then don't write until we get to Z_STREAM_END */
        if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
            (flush != Z_FINISH || ret == Z_STREAM_END))) {
            while (strm->next_out > state->x.next) {
                put = strm->next_out - state->x.next > (int)max ? max :
                      (unsigned)(strm->next_out - state->x.next);
                writ = write(state->fd, state->x.next, put);
                if (writ < 0) {
                    gz_error(state, Z_ERRNO, zstrerror());
                    return -1;
                }
                state->x.next += writ;
            }
            if (strm->avail_out == 0) {
                strm->avail_out = state->size;
                strm->next_out = state->out;
                state->x.next = state->out;
            }
        }

        /* compress */
        have = strm->avail_out;
        ret = deflate(strm, flush);
        if (ret == Z_STREAM_ERROR) {
            gz_error(state, Z_STREAM_ERROR,
                      "internal error: deflate stream corrupt");
            return -1;
        }
        have -= strm->avail_out;
    } while (have);

    /* if that completed a deflate stream, allow another to start */
    if (flush == Z_FINISH)
        state->reset = 1;

    /* all done, no errors */
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebp
movq %rdi, %r14
cmpl $0x0, 0x28(%rdi)
pushq $-0x1
popq %rbx
jne 0x7b6fa
movq %r14, %rdi
callq 0x7b5ee
cmpl $-0x1, %eax
je 0x7b864
cmpl $0x0, 0x40(%r14)
je 0x7b750
movl 0x88(%r14), %edx
movl $0x40000000, %ebp       # imm = 0x40000000
testl %edx, %edx
je 0x7b836
cmpl %ebp, %edx
cmovael %ebp, %edx
movl 0x1c(%r14), %edi
movq 0x80(%r14), %rsi
callq 0xb200
testl %eax, %eax
js 0x7b83a
movl 0x88(%r14), %edx
subl %eax, %edx
movl %edx, 0x88(%r14)
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addq %rax, 0x80(%r14)
jmp 0x7b70d
leaq 0x80(%r14), %r15
cmpl $0x0, 0x60(%r14)
je 0x7b779
cmpl $0x0, 0x88(%r14)
je 0x7b836
movq %r15, %rdi
callq 0x7be16
andl $0x0, 0x60(%r14)
movl 0xa0(%r14), %r13d
xorl %eax, %eax
movl $0x40000000, %r12d      # imm = 0x40000000
testl %r13d, %r13d
je 0x7b7a1
cmpl $0x4, %ebp
setne %cl
cmpl $0x1, %eax
sete %al
testl %ebp, %ebp
je 0x7b803
orb %al, %cl
je 0x7b803
movq 0x8(%r14), %rax
movq 0x98(%r14), %rcx
subq %rax, %rcx
jbe 0x7b7dd
cmpq $0x40000001, %rcx       # imm = 0x40000001
movl %ecx, %edx
cmovgeq %r12, %rdx
movl 0x1c(%r14), %edi
movq %rax, %rsi
callq 0xb200
testl %eax, %eax
js 0x7b848
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addq 0x8(%r14), %rax
movq %rax, 0x8(%r14)
jmp 0x7b7a5
movl 0xa0(%r14), %r13d
testl %r13d, %r13d
jne 0x7b803
movl 0x28(%r14), %r13d
movl %r13d, 0xa0(%r14)
movq 0x38(%r14), %rax
movq %rax, 0x98(%r14)
movq %rax, 0x8(%r14)
movq %r15, %rdi
movl %ebp, %esi
callq 0x7c68a
cmpl $-0x2, %eax
je 0x7b875
movl 0xa0(%r14), %ecx
cmpl %ecx, %r13d
movl %ecx, %r13d
jne 0x7b788
xorl %ebx, %ebx
cmpl $0x4, %ebp
jne 0x7b864
movl $0x1, 0x60(%r14)
jmp 0x7b864
xorl %ebx, %ebx
jmp 0x7b864
callq 0xb060
movl (%rax), %edi
callq 0xb1d0
jmp 0x7b857
callq 0xb060
movl (%rax), %edi
callq 0xb1d0
pushq $-0x1
popq %rbx
movq %r14, %rdi
movl %ebx, %esi
movq %rax, %rdx
callq 0x7a532
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6599d(%rip), %rdx     # 0xe1219
pushq $-0x2
popq %rsi
movq %r14, %rdi
jmp 0x7b85f