// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/zlib-1.3.0.1/gzwrite.c
// Function: gz_init
local int gz_init(gz_statep state) {
    int ret;
    z_streamp strm = &(state->strm);

    /* allocate input buffer (double size for gzprintf) */
    state->in = (unsigned char *)malloc(state->want << 1);
    if (state->in == NULL) {
        gz_error(state, Z_MEM_ERROR, "out of memory");
        return -1;
    }

    /* only need output buffer and deflate state if compressing */
    if (!state->direct) {
        /* allocate output buffer */
        state->out = (unsigned char *)malloc(state->want);
        if (state->out == NULL) {
            free(state->in);
            gz_error(state, Z_MEM_ERROR, "out of memory");
            return -1;
        }

        /* allocate deflate memory, set up for gzip compression */
        strm->zalloc = Z_NULL;
        strm->zfree = Z_NULL;
        strm->opaque = Z_NULL;
        ret = deflateInit2(strm, state->level, Z_DEFLATED,
                           MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy);
        if (ret != Z_OK) {
            free(state->out);
            free(state->in);
            gz_error(state, Z_MEM_ERROR, "out of memory");
            return -1;
        }
        strm->next_in = NULL;
    }

    /* mark state as initialized */
    state->size = state->want;

    /* initialize write buffer if compressing */
    if (!state->direct) {
        strm->avail_out = state->size;
        strm->next_out = state->out;
        state->x.next = strm->next_out;
    }
    return 0;
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x28(%rsp)
movq 0x28(%rsp), %rax
addq $0x80, %rax
movq %rax, 0x18(%rsp)
movq 0x28(%rsp), %rax
movl 0x2c(%rax), %eax
shll %eax
movl %eax, %eax
movl %eax, %edi
callq 0xbcb8
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x30(%rax)
movq 0x28(%rsp), %rax
cmpq $0x0, 0x30(%rax)
jne 0xcf617
movq 0x28(%rsp), %rdi
movl $0xfffffffc, %esi       # imm = 0xFFFFFFFC
leaq 0xa2639(%rip), %rdx     # 0x171c3e
callq 0xcd150
movl $0xffffffff, 0x34(%rsp) # imm = 0xFFFFFFFF
jmp 0xcf78b
movq 0x28(%rsp), %rax
cmpl $0x0, 0x40(%rax)
jne 0xcf734
movq 0x28(%rsp), %rax
movl 0x2c(%rax), %eax
movl %eax, %edi
callq 0xbcb8
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x38(%rax)
movq 0x28(%rsp), %rax
cmpq $0x0, 0x38(%rax)
jne 0xcf67e
movq 0x28(%rsp), %rax
movq 0x30(%rax), %rdi
callq 0xb760
movq 0x28(%rsp), %rdi
movl $0xfffffffc, %esi       # imm = 0xFFFFFFFC
leaq 0xa25d2(%rip), %rdx     # 0x171c3e
callq 0xcd150
movl $0xffffffff, 0x34(%rsp) # imm = 0xFFFFFFFF
jmp 0xcf78b
movq 0x18(%rsp), %rax
movq $0x0, 0x40(%rax)
movq 0x18(%rsp), %rax
movq $0x0, 0x48(%rax)
movq 0x18(%rsp), %rax
movq $0x0, 0x50(%rax)
movq 0x18(%rsp), %rdi
movq 0x28(%rsp), %rax
movl 0x58(%rax), %esi
movq 0x28(%rsp), %rax
movl 0x5c(%rax), %r9d
movl $0x8, %r8d
movl $0x1f, %ecx
leaq 0xa6c0d(%rip), %rax     # 0x1762da
movl %r8d, %edx
movq %rax, (%rsp)
movl $0x70, 0x8(%rsp)
callq 0xcff60
movl %eax, 0x24(%rsp)
cmpl $0x0, 0x24(%rsp)
je 0xcf728
movq 0x28(%rsp), %rax
movq 0x38(%rax), %rdi
callq 0xb760
movq 0x28(%rsp), %rax
movq 0x30(%rax), %rdi
callq 0xb760
movq 0x28(%rsp), %rdi
movl $0xfffffffc, %esi       # imm = 0xFFFFFFFC
leaq 0xa2525(%rip), %rdx     # 0x171c3e
callq 0xcd150
movl $0xffffffff, 0x34(%rsp) # imm = 0xFFFFFFFF
jmp 0xcf78b
movq 0x18(%rsp), %rax
movq $0x0, (%rax)
movq 0x28(%rsp), %rax
movl 0x2c(%rax), %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0x28(%rax)
movq 0x28(%rsp), %rax
cmpl $0x0, 0x40(%rax)
jne 0xcf783
movq 0x28(%rsp), %rax
movl 0x28(%rax), %ecx
movq 0x18(%rsp), %rax
movl %ecx, 0x20(%rax)
movq 0x28(%rsp), %rax
movq 0x38(%rax), %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x8(%rax)
movl $0x0, 0x34(%rsp)
movl 0x34(%rsp), %eax
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)