// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/external/zlib-1.3.0.1/gzwrite.c
// Function: gzvprintf
int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) {
    int len;
    unsigned left;
    char *next;
    gz_statep state;
    z_streamp strm;

    /* get internal structure */
    if (file == NULL)
        return Z_STREAM_ERROR;
    state = (gz_statep)file;
    strm = &(state->strm);

    /* check that we're writing and that there's no error */
    if (state->mode != GZ_WRITE || state->err != Z_OK)
        return Z_STREAM_ERROR;

    /* make sure we have some buffer space */
    if (state->size == 0 && gz_init(state) == -1)
        return state->err;

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

    /* do the printf() into the input buffer, put length in len -- the input
       buffer is double-sized just for this function, so there is guaranteed to
       be state->size bytes available after the current contents */
    if (strm->avail_in == 0)
        strm->next_in = state->in;
    next = (char *)(state->in + (strm->next_in - state->in) + strm->avail_in);
    next[state->size - 1] = 0;
#ifdef NO_vsnprintf
#  ifdef HAS_vsprintf_void
    (void)vsprintf(next, format, va);
    for (len = 0; len < state->size; len++)
        if (next[len] == 0) break;
#  else
    len = vsprintf(next, format, va);
#  endif
#else
#  ifdef HAS_vsnprintf_void
    (void)vsnprintf(next, state->size, format, va);
    len = strlen(next);
#  else
    len = vsnprintf(next, state->size, format, va);
#  endif
#endif

    /* check that printf() results fit in buffer */
    if (len == 0 || (unsigned)len >= state->size || next[state->size - 1] != 0)
        return 0;

    /* update buffer and position, compress first half if past that */
    strm->avail_in += (unsigned)len;
    state->x.pos += len;
    if (strm->avail_in >= state->size) {
        left = strm->avail_in - state->size;
        strm->avail_in = state->size;
        if (gz_comp(state, Z_NO_FLUSH) == -1)
            return state->err;
        memmove(state->in, state->in + state->size, left);
        strm->next_in = state->in;
        strm->avail_in = left;
    }
    return len;
}

// Assembly:
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
testq %rdi, %rdi
je 0x9ae83
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
cmpl $0x79b1, 0x18(%rdi)     # imm = 0x79B1
jne 0x9ae7b
cmpl $0x0, 0x74(%rbx)
je 0x9ae84
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %r14
movq %rsi, %r15
cmpl $0x0, 0x28(%rbx)
jne 0x9aea1
movq %rbx, %rdi
callq 0x9af8a
cmpl $-0x1, %eax
je 0x9af82
cmpl $0x0, 0x70(%rbx)
je 0x9aec3
movl $0x0, 0x70(%rbx)
movq 0x68(%rbx), %rsi
movq %rbx, %rdi
callq 0x9ad51
cmpl $-0x1, %eax
je 0x9af82
movl 0x88(%rbx), %eax
testq %rax, %rax
je 0x9aed7
movq 0x80(%rbx), %r12
jmp 0x9aee2
movq 0x30(%rbx), %r12
movq %r12, 0x80(%rbx)
addq %rax, %r12
movl 0x28(%rbx), %eax
decl %eax
movb $0x0, (%rax,%r12)
movl 0x28(%rbx), %esi
movq %r12, %rdi
movq %r15, %rdx
movq %r14, %rcx
callq 0xb3b0
movl %eax, %ebp
xorl %eax, %eax
testl %ebp, %ebp
je 0x9ae7b
movl 0x28(%rbx), %ecx
cmpl %ecx, %ebp
jae 0x9ae7b
leal -0x1(%rcx), %edx
cmpb $0x0, (%r12,%rdx)
jne 0x9ae7b
movl 0x88(%rbx), %r14d
addl %ebp, %r14d
movl %r14d, 0x88(%rbx)
movslq %ebp, %rax
addq %rax, 0x10(%rbx)
subl %ecx, %r14d
jb 0x9af7b
movl %ecx, 0x88(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x9b081
cmpl $-0x1, %eax
je 0x9af82
movq 0x30(%rbx), %rdi
movl 0x28(%rbx), %esi
addq %rdi, %rsi
movq %r14, %rdx
callq 0xba60
movq 0x30(%rbx), %rax
movq %rax, 0x80(%rbx)
movl %r14d, 0x88(%rbx)
movl %ebp, %eax
jmp 0x9ae7b
movl 0x74(%rbx), %eax
jmp 0x9ae7b