// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $-0x6
popq %rbx
testq %rax, %rax
je 0x85248
cmpl $0x70, 0x48(%rsp)
jne 0x85248
cmpb $0x31, (%rax)
jne 0x85248
movq %rdi, %r14
pushq $-0x2
popq %rbx
testq %rdi, %rdi
je 0x85248
movl %r8d, %r15d
movl %ecx, %r13d
andq $0x0, 0x30(%r14)
movq 0x40(%r14), %rax
testq %rax, %rax
jne 0x85089
leaq 0x651d(%rip), %rax      # 0x8b59d
movq %rax, 0x40(%r14)
andq $0x0, 0x50(%r14)
cmpq $0x0, 0x48(%r14)
jne 0x8509b
leaq 0x6510(%rip), %rcx      # 0x8b5a7
movq %rcx, 0x48(%r14)
cmpl $-0x1, %esi
pushq $0x6
popq %rdi
cmovnel %esi, %edi
testl %r13d, %r13d
js 0x850c0
leal -0x10(%r13), %ecx
cmpl $0x10, %r13d
cmovbl %r13d, %ecx
pushq $0x1
popq %rbp
sbbl $-0x1, %ebp
movl %ecx, %r13d
jmp 0x850c5
negl %r13d
xorl %ebp, %ebp
cmpl $0x4, %r9d
ja 0x85248
cmpl $0x9, %edi
ja 0x85248
cmpl $0x8, %edx
jne 0x85248
leal -0xa(%r15), %ecx
cmpl $-0x9, %ecx
jb 0x85248
leal -0x10(%r13), %ecx
cmpl $-0x8, %ecx
jb 0x85248
movl %edi, (%rsp)
movl %r9d, 0x4(%rsp)
movq 0x50(%r14), %rdi
pushq $0x1
popq %rsi
movl $0x1730, %edx           # imm = 0x1730
callq *%rax
pushq $-0x4
popq %rbx
testq %rax, %rax
je 0x85248
movq %rax, %r12
cmpl $0x8, %r13d
pushq $0x9
popq %rcx
cmovnel %r13d, %ecx
movq %rax, 0x38(%r14)
movq %r14, (%rax)
movl %ebp, 0x2c(%rax)
andq $0x0, 0x30(%rax)
pushq $0x1
popq %rsi
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
movb $0x3, %cl
divb %cl
movzbl %al, %eax
movl %eax, 0x80(%r12)
movq 0x50(%r14), %rdi
pushq $0x2
popq %r13
movl %r13d, %edx
callq *0x40(%r14)
movq %rax, 0x50(%r12)
movq 0x50(%r14), %rdi
movl 0x44(%r12), %esi
movl %r13d, %edx
callq *0x40(%r14)
movq %rax, 0x60(%r12)
movq 0x50(%r14), %rdi
movl 0x74(%r12), %esi
movl %r13d, %edx
callq *0x40(%r14)
movq %rax, 0x68(%r12)
andq $0x0, 0x1728(%r12)
pushq $0x40
popq %rsi
movl %r15d, %ecx
shll %cl, %esi
movl %esi, 0x16f8(%r12)
movq 0x50(%r14), %rdi
pushq $0x4
popq %rdx
callq *0x40(%r14)
movq %rax, 0x10(%r12)
movl 0x16f8(%r12), %ecx
leaq (,%rcx,4), %rdx
movq %rdx, 0x18(%r12)
xorl %edx, %edx
cmpq %rdx, 0x50(%r12)
je 0x85228
cmpq $0x0, 0x60(%r12)
je 0x85228
cmpq $0x0, 0x68(%r12)
sete %dl
testq %rax, %rax
sete %sil
orb %dl, %sil
cmpb $0x1, %sil
jne 0x85259
movl $0x29a, 0x8(%r12)       # imm = 0x29A
leaq 0x54aa8(%rip), %rax     # 0xd9ce0
movq 0x30(%rax), %rax
movq %rax, 0x30(%r14)
movq %r14, %rdi
callq 0x852ab
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 0x85384