// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
movl %esi, 0x44(%rsp)
movl $0x40000000, 0x30(%rsp) # imm = 0x40000000
movq 0x48(%rsp), %rax
addq $0x80, %rax
movq %rax, 0x28(%rsp)
movq 0x48(%rsp), %rax
cmpl $0x0, 0x28(%rax)
jne 0xcf7ec
movq 0x48(%rsp), %rdi
callq 0xcf5b0
cmpl $-0x1, %eax
jne 0xcf7ec
movl $0xffffffff, 0x54(%rsp) # imm = 0xFFFFFFFF
jmp 0xcface
movq 0x48(%rsp), %rax
cmpl $0x0, 0x40(%rax)
je 0xcf8cb
jmp 0xcf7fd
movq 0x28(%rsp), %rax
cmpl $0x0, 0x8(%rax)
je 0xcf8be
movq 0x28(%rsp), %rax
movl 0x8(%rax), %eax
cmpl 0x30(%rsp), %eax
jbe 0xcf824
movl 0x30(%rsp), %eax
movl %eax, 0x24(%rsp)
jmp 0xcf830
movq 0x28(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0x24(%rsp)
movl 0x24(%rsp), %eax
movl %eax, 0x34(%rsp)
movq 0x48(%rsp), %rax
movl 0x1c(%rax), %edi
movq 0x28(%rsp), %rax
movq (%rax), %rsi
movl 0x34(%rsp), %eax
movl %eax, %edx
callq 0xb1e0
movl %eax, 0x3c(%rsp)
cmpl $0x0, 0x3c(%rsp)
jge 0xcf893
movq 0x48(%rsp), %rax
movq %rax, 0x18(%rsp)
callq 0xb060
movl (%rax), %edi
callq 0xb1b0
movq 0x18(%rsp), %rdi
movq %rax, %rdx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xcd150
movl $0xffffffff, 0x54(%rsp) # imm = 0xFFFFFFFF
jmp 0xcface
movl 0x3c(%rsp), %edx
movq 0x28(%rsp), %rax
movl 0x8(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x8(%rax)
movl 0x3c(%rsp), %edx
movq 0x28(%rsp), %rax
movq (%rax), %rcx
movslq %edx, %rdx
addq %rdx, %rcx
movq %rcx, (%rax)
jmp 0xcf7fd
movl $0x0, 0x54(%rsp)
jmp 0xcface
movq 0x48(%rsp), %rax
cmpl $0x0, 0x60(%rax)
je 0xcf904
movq 0x28(%rsp), %rax
cmpl $0x0, 0x8(%rax)
jne 0xcf8ee
movl $0x0, 0x54(%rsp)
jmp 0xcface
movq 0x28(%rsp), %rdi
callq 0xd0550
movq 0x48(%rsp), %rax
movl $0x0, 0x60(%rax)
movl $0x0, 0x40(%rsp)
movq 0x28(%rsp), %rax
cmpl $0x0, 0x20(%rax)
je 0xcf934
cmpl $0x0, 0x44(%rsp)
je 0xcfa51
cmpl $0x4, 0x44(%rsp)
jne 0xcf934
cmpl $0x1, 0x40(%rsp)
jne 0xcfa51
jmp 0xcf936
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x48(%rsp), %rcx
cmpq 0x8(%rcx), %rax
jbe 0xcfa10
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x48(%rsp), %rcx
movq 0x8(%rcx), %rcx
subq %rcx, %rax
movslq 0x30(%rsp), %rcx
cmpq %rcx, %rax
jle 0xcf977
movl 0x30(%rsp), %eax
movl %eax, 0x14(%rsp)
jmp 0xcf990
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x48(%rsp), %rcx
movq 0x8(%rcx), %rcx
subq %rcx, %rax
movl %eax, 0x14(%rsp)
movl 0x14(%rsp), %eax
movl %eax, 0x34(%rsp)
movq 0x48(%rsp), %rax
movl 0x1c(%rax), %edi
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rsi
movl 0x34(%rsp), %eax
movl %eax, %edx
callq 0xb1e0
movl %eax, 0x3c(%rsp)
cmpl $0x0, 0x3c(%rsp)
jge 0xcf9f4
movq 0x48(%rsp), %rax
movq %rax, 0x8(%rsp)
callq 0xb060
movl (%rax), %edi
callq 0xb1b0
movq 0x8(%rsp), %rdi
movq %rax, %rdx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xcd150
movl $0xffffffff, 0x54(%rsp) # imm = 0xFFFFFFFF
jmp 0xcface
movl 0x3c(%rsp), %edx
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rcx
movslq %edx, %rdx
addq %rdx, %rcx
movq %rcx, 0x8(%rax)
jmp 0xcf936
movq 0x28(%rsp), %rax
cmpl $0x0, 0x20(%rax)
jne 0xcfa4f
movq 0x48(%rsp), %rax
movl 0x28(%rax), %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0x20(%rax)
movq 0x48(%rsp), %rax
movq 0x38(%rax), %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x48(%rsp), %rax
movq 0x38(%rax), %rcx
movq 0x48(%rsp), %rax
movq %rcx, 0x8(%rax)
jmp 0xcfa51
movq 0x28(%rsp), %rax
movl 0x20(%rax), %eax
movl %eax, 0x38(%rsp)
movq 0x28(%rsp), %rdi
movl 0x44(%rsp), %esi
callq 0xd16e0
movl %eax, 0x40(%rsp)
cmpl $-0x2, 0x40(%rsp)
jne 0xcfa96
movq 0x48(%rsp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
leaq 0xa68a9(%rip), %rdx     # 0x176330
callq 0xcd150
movl $0xffffffff, 0x54(%rsp) # imm = 0xFFFFFFFF
jmp 0xcface
movq 0x28(%rsp), %rax
movl 0x20(%rax), %ecx
movl 0x38(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x38(%rsp)
cmpl $0x0, 0x38(%rsp)
jne 0xcf90c
cmpl $0x4, 0x44(%rsp)
jne 0xcfac6
movq 0x48(%rsp), %rax
movl $0x1, 0x60(%rax)
movl $0x0, 0x54(%rsp)
movl 0x54(%rsp), %eax
addq $0x58, %rsp
retq
nopw (%rax,%rax)