// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/png/deflate.c
// Function: deflateInit2_
int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
                  version, stream_size)
    z_streamp strm;
    int  level;
    int  method;
    int  windowBits;
    int  memLevel;
    int  strategy;
    const char *version;
    int stream_size;
{
    deflate_state *s;
    int wrap = 1;
    static const char my_version[] = ZLIB_VERSION;

    ushf *overlay;
    /* We overlay pending_buf and d_buf+l_buf. This works since the average
     * output size for (length,distance) codes is <= 24 bits.
     */

    if (version == Z_NULL || version[0] != my_version[0] ||
        stream_size != sizeof(z_stream)) {
        return Z_VERSION_ERROR;
    }
    if (strm == Z_NULL) return Z_STREAM_ERROR;

    strm->msg = Z_NULL;
    if (strm->zalloc == (alloc_func)0) {
        strm->zalloc = zcalloc;
        strm->opaque = (voidpf)0;
    }
    if (strm->zfree == (free_func)0) strm->zfree = zcfree;

#ifdef FASTEST
    if (level != 0) level = 1;
#else
    if (level == Z_DEFAULT_COMPRESSION) level = 6;
#endif

    if (windowBits < 0) { /* suppress zlib wrapper */
        wrap = 0;
        windowBits = -windowBits;
    }
#ifdef GZIP
    else if (windowBits > 15) {
        wrap = 2;       /* write gzip wrapper instead */
        windowBits -= 16;
    }
#endif
    if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
        windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
        strategy < 0 || strategy > Z_FIXED) {
        return Z_STREAM_ERROR;
    }
    if (windowBits == 8) windowBits = 9;  /* until 256-byte window bug fixed */
    s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
    if (s == Z_NULL) return Z_MEM_ERROR;
    strm->state = (struct internal_state FAR *)s;
    s->strm = strm;

    s->wrap = wrap;
    s->gzhead = Z_NULL;
    s->w_bits = windowBits;
    s->w_size = 1 << s->w_bits;
    s->w_mask = s->w_size - 1;

    s->hash_bits = memLevel + 7;
    s->hash_size = 1 << s->hash_bits;
    s->hash_mask = s->hash_size - 1;
    s->hash_shift =  ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);

    s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
    s->prev   = (Posf *)  ZALLOC(strm, s->w_size, sizeof(Pos));
    s->head   = (Posf *)  ZALLOC(strm, s->hash_size, sizeof(Pos));

    s->high_water = 0;      /* nothing written to s->window yet */

    s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */

    overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
    s->pending_buf = (uchf *) overlay;
    s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);

    if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
        s->pending_buf == Z_NULL) {
        s->status = FINISH_STATE;
        strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
        deflateEnd (strm);
        return Z_MEM_ERROR;
    }
    s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
    s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;

    s->level = level;
    s->strategy = strategy;
    s->method = (Byte)method;

    return deflateReset(strm);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x40(%rsp), %rax
movl $0xfffffffa, %ebx       # imm = 0xFFFFFFFA
testq %rax, %rax
je 0x92a32
cmpl $0x70, 0x48(%rsp)
jne 0x92a32
cmpb $0x31, (%rax)
jne 0x92a32
movq %rdi, %r14
movl $0xfffffffe, %ebx       # imm = 0xFFFFFFFE
testq %rdi, %rdi
je 0x92a32
movl %r8d, %r15d
movl %ecx, %r13d
movq $0x0, 0x30(%r14)
movq 0x40(%r14), %rax
testq %rax, %rax
jne 0x92860
leaq 0x715b(%rip), %rax      # 0x999af
movq %rax, 0x40(%r14)
movq $0x0, 0x50(%r14)
cmpq $0x0, 0x48(%r14)
jne 0x92872
leaq 0x714b(%rip), %rcx      # 0x999b9
movq %rcx, 0x48(%r14)
cmpl $-0x1, %esi
movl $0x6, %edi
cmovnel %esi, %edi
testl %r13d, %r13d
js 0x9289b
leal -0x10(%r13), %ecx
cmpl $0x10, %r13d
cmovbl %r13d, %ecx
movl $0x1, %ebp
sbbl $-0x1, %ebp
movl %ecx, %r13d
jmp 0x928a0
negl %r13d
xorl %ebp, %ebp
cmpl $0x4, %r9d
ja 0x92a32
cmpl $0x9, %edi
ja 0x92a32
cmpl $0x8, %edx
jne 0x92a32
leal -0xa(%r15), %ecx
cmpl $-0x9, %ecx
jb 0x92a32
leal -0x10(%r13), %ecx
cmpl $-0x8, %ecx
jb 0x92a32
movl %edi, (%rsp)
movl %r9d, 0x4(%rsp)
movq 0x50(%r14), %rdi
movl $0x1, %esi
movl $0x1730, %edx           # imm = 0x1730
callq *%rax
movl $0xfffffffc, %ebx       # imm = 0xFFFFFFFC
testq %rax, %rax
je 0x92a32
movq %rax, %r12
cmpl $0x8, %r13d
movl $0x9, %ecx
cmovnel %r13d, %ecx
movq %rax, 0x38(%r14)
movq %r14, (%rax)
movl %ebp, 0x2c(%rax)
xorl %r13d, %r13d
movq %r13, 0x30(%rax)
movl $0x1, %esi
shll %cl, %esi
movl %ecx, 0x48(%rax)
movl %esi, 0x44(%rax)
leal -0x1(%rsi), %eax
movl %eax, 0x4c(%r12)
leal 0x7(%r15), %eax
movl %eax, 0x78(%r12)
movl $0x80, %eax
movl %r15d, %ecx
shll %cl, %eax
movl %eax, 0x74(%r12)
decl %eax
movl %eax, 0x7c(%r12)
leal 0x9(%r15), %eax
movzbl %al, %eax
imull $0xab, %eax, %eax
shrl $0x9, %eax
movl %eax, 0x80(%r12)
movq 0x50(%r14), %rdi
movl $0x2, %edx
callq *0x40(%r14)
movq %rax, 0x50(%r12)
movq 0x50(%r14), %rdi
movl 0x44(%r12), %esi
movl $0x2, %edx
callq *0x40(%r14)
movq %rax, 0x60(%r12)
movq 0x50(%r14), %rdi
movl 0x74(%r12), %esi
movl $0x2, %edx
callq *0x40(%r14)
movl $0x40, %esi
movl %r15d, %ecx
shll %cl, %esi
movq %rax, 0x68(%r12)
movq %r13, 0x1728(%r12)
movl %esi, 0x16f8(%r12)
movq 0x50(%r14), %rdi
movl $0x4, %edx
callq *0x40(%r14)
movq %rax, 0x10(%r12)
movl 0x16f8(%r12), %ecx
leaq (,%rcx,4), %rdx
movq %rdx, 0x18(%r12)
cmpq %r13, 0x50(%r12)
je 0x92a12
cmpq $0x0, 0x60(%r12)
je 0x92a12
cmpq $0x0, 0x68(%r12)
sete %dl
testq %rax, %rax
sete %sil
orb %dl, %sil
cmpb $0x1, %sil
jne 0x92a43
movl $0x29a, 0x8(%r12)       # imm = 0x29A
leaq 0x522ae(%rip), %rax     # 0xe4cd0
movq 0x30(%rax), %rax
movq %rax, 0x30(%r14)
movq %r14, %rdi
callq 0x92a95
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ecx, %edx
andl $-0x2, %edx
addq %rax, %rdx
movq %rdx, 0x1700(%r12)
leaq (%rcx,%rcx,2), %rcx
addq %rax, %rcx
movq %rcx, 0x16f0(%r12)
movl (%rsp), %eax
movl %eax, 0xb4(%r12)
movl 0x4(%rsp), %eax
movl %eax, 0xb8(%r12)
movb $0x8, 0x3c(%r12)
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x92b77