// File: sisong[P]ApkDiffPatch/zlib1.3.1/deflate.c
// Function: deflateInit2_
int ZEXPORT deflateInit2_(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;

    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) {
#ifdef Z_SOLO
        return Z_STREAM_ERROR;
#else
        strm->zalloc = zcalloc;
        strm->opaque = (voidpf)0;
#endif
    }
    if (strm->zfree == (free_func)0)
#ifdef Z_SOLO
        return Z_STREAM_ERROR;
#else
        strm->zfree = zcfree;
#endif

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

    if (windowBits < 0) { /* suppress zlib wrapper */
        wrap = 0;
        if (windowBits < -15)
            return Z_STREAM_ERROR;
        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 || (windowBits == 8 && wrap != 1)) {
        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->status = INIT_STATE;     /* to pass state test in deflateReset() */

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

    s->hash_bits = (uInt)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 */

    /* We overlay pending_buf and sym_buf. This works since the average size
     * for length/distance pairs over any compressed block is assured to be 31
     * bits or less.
     *
     * Analysis: The longest fixed codes are a length code of 8 bits plus 5
     * extra bits, for lengths 131 to 257. The longest fixed distance codes are
     * 5 bits plus 13 extra bits, for distances 16385 to 32768. The longest
     * possible fixed-codes length/distance pair is then 31 bits total.
     *
     * sym_buf starts one-fourth of the way into pending_buf. So there are
     * three bytes in sym_buf for every four bytes in pending_buf. Each symbol
     * in sym_buf is three bytes -- two for the distance and one for the
     * literal/length. As each symbol is consumed, the pointer to the next
     * sym_buf value to read moves forward three bytes. From that symbol, up to
     * 31 bits are written to pending_buf. The closest the written pending_buf
     * bits gets to the next sym_buf symbol to read is just before the last
     * code is written. At that time, 31*(n - 2) bits have been written, just
     * after 24*(n - 2) bits have been consumed from sym_buf. sym_buf starts at
     * 8*n bits into pending_buf. (Note that the symbol buffer fills when n - 1
     * symbols are written.) The closest the writing gets to what is unread is
     * then n + 14 bits. Here n is lit_bufsize, which is 16384 by default, and
     * can range from 128 to 32768.
     *
     * Therefore, at a minimum, there are 142 bits of space between what is
     * written and what is read in the overlain buffers, so the symbols cannot
     * be overwritten by the compressed data. That space is actually 139 bits,
     * due to the three-bit fixed-code block header.
     *
     * That covers the case where either Z_FIXED is specified, forcing fixed
     * codes, or when the use of fixed codes is chosen, because that choice
     * results in a smaller compressed block than dynamic codes. That latter
     * condition then assures that the above analysis also covers all dynamic
     * blocks. A dynamic-code block will only be chosen to be emitted if it has
     * fewer bits than a fixed-code block would for the same set of symbols.
     * Therefore its average symbol length is assured to be less than 31. So
     * the compressed data for a dynamic block also cannot overwrite the
     * symbols from which it is being constructed.
     */

    s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, LIT_BUFS);
    s->pending_buf_size = (ulg)s->lit_bufsize * 4;

    if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
        s->pending_buf == Z_NULL) {
        s->status = FINISH_STATE;
        strm->msg = ERR_MSG(Z_MEM_ERROR);
        deflateEnd (strm);
        return Z_MEM_ERROR;
    }
#ifdef LIT_MEM
    s->d_buf = (ushf *)(s->pending_buf + (s->lit_bufsize << 1));
    s->l_buf = s->pending_buf + (s->lit_bufsize << 2);
    s->sym_end = s->lit_bufsize - 1;
#else
    s->sym_buf = s->pending_buf + s->lit_bufsize;
    s->sym_end = (s->lit_bufsize - 1) * 3;
#endif
    /* We avoid equality with lit_bufsize*3 because of wraparound at 64K
     * on 16 bit machines and because stored blocks are restricted to
     * 64K-1 bytes.
     */

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

    return deflateReset(strm);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
movl $0x1, -0x34(%rbp)
cmpq $0x0, 0x10(%rbp)
je 0x92cde
movq 0x10(%rbp), %rax
movsbl (%rax), %eax
movsbl 0x29eb4(%rip), %ecx     # 0xbcb84
cmpl %ecx, %eax
jne 0x92cde
movslq 0x18(%rbp), %rax
cmpq $0x70, %rax
je 0x92cea
movl $0xfffffffa, -0x4(%rbp) # imm = 0xFFFFFFFA
jmp 0x930aa
cmpq $0x0, -0x10(%rbp)
jne 0x92cfd
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x930aa
movq -0x10(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x40(%rax)
jne 0x92d2f
movq -0x10(%rbp), %rax
leaq 0xf681(%rip), %rcx      # 0xa23a0
movq %rcx, 0x40(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x50(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x48(%rax)
jne 0x92d49
movq -0x10(%rbp), %rax
leaq 0xf68b(%rip), %rcx      # 0xa23d0
movq %rcx, 0x48(%rax)
cmpl $-0x1, -0x14(%rbp)
jne 0x92d56
movl $0x6, -0x14(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x92d7f
movl $0x0, -0x34(%rbp)
cmpl $-0xf, -0x1c(%rbp)
jge 0x92d75
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x930aa
xorl %eax, %eax
subl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x92d97
cmpl $0xf, -0x1c(%rbp)
jle 0x92d95
movl $0x2, -0x34(%rbp)
movl -0x1c(%rbp), %eax
subl $0x10, %eax
movl %eax, -0x1c(%rbp)
jmp 0x92d97
cmpl $0x1, -0x20(%rbp)
jl 0x92dd9
cmpl $0x9, -0x20(%rbp)
jg 0x92dd9
cmpl $0x8, -0x18(%rbp)
jne 0x92dd9
cmpl $0x8, -0x1c(%rbp)
jl 0x92dd9
cmpl $0xf, -0x1c(%rbp)
jg 0x92dd9
cmpl $0x0, -0x14(%rbp)
jl 0x92dd9
cmpl $0x9, -0x14(%rbp)
jg 0x92dd9
cmpl $0x0, -0x24(%rbp)
jl 0x92dd9
cmpl $0x4, -0x24(%rbp)
jg 0x92dd9
cmpl $0x8, -0x1c(%rbp)
jne 0x92de5
cmpl $0x1, -0x34(%rbp)
je 0x92de5
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x930aa
cmpl $0x8, -0x1c(%rbp)
jne 0x92df2
movl $0x9, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x50(%rcx), %rdi
movl $0x1, %esi
movl $0x1740, %edx           # imm = 0x1740
callq *%rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x92e25
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0x930aa
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movl $0x2a, 0x8(%rax)
movl -0x34(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x38(%rax)
movl -0x1c(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x54(%rax)
movq -0x30(%rbp), %rax
movl 0x54(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x50(%rax)
movq -0x30(%rbp), %rax
movl 0x50(%rax), %ecx
subl $0x1, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x58(%rax)
movl -0x20(%rbp), %ecx
addl $0x7, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x88(%rax)
movq -0x30(%rbp), %rax
movl 0x88(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x84(%rax)
movq -0x30(%rbp), %rax
movl 0x84(%rax), %ecx
subl $0x1, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x8c(%rax)
movq -0x30(%rbp), %rax
movl 0x88(%rax), %eax
addl $0x3, %eax
subl $0x1, %eax
movl $0x3, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x90(%rax)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x50(%rcx), %rdi
movq -0x30(%rbp), %rcx
movl 0x50(%rcx), %esi
movl $0x2, %edx
callq *%rax
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x50(%rcx), %rdi
movq -0x30(%rbp), %rcx
movl 0x50(%rcx), %esi
movl $0x2, %edx
callq *%rax
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x50(%rcx), %rdi
movq -0x30(%rbp), %rcx
movl 0x84(%rcx), %esi
movl $0x2, %edx
callq *%rax
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x78(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x1738(%rax)
movl -0x20(%rbp), %ecx
addl $0x6, %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x1708(%rax)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x50(%rcx), %rdi
movq -0x30(%rbp), %rcx
movl 0x1708(%rcx), %esi
movl $0x4, %edx
callq *%rax
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rax
movl 0x1708(%rax), %eax
movl %eax, %ecx
shlq $0x2, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x30(%rbp), %rax
cmpq $0x0, 0x60(%rax)
je 0x9300e
movq -0x30(%rbp), %rax
cmpq $0x0, 0x70(%rax)
je 0x9300e
movq -0x30(%rbp), %rax
cmpq $0x0, 0x78(%rax)
je 0x9300e
movq -0x30(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x9303e
movq -0x30(%rbp), %rax
movl $0x29a, 0x8(%rax)       # imm = 0x29A
leaq 0x52d20(%rip), %rax     # 0xe5d40
movq 0x30(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rdi
callq 0x930c0
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0x930aa
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x30(%rbp), %rax
movl 0x1708(%rax), %eax
addq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x1700(%rax)
movq -0x30(%rbp), %rax
movl 0x1708(%rax), %eax
subl $0x1, %eax
imull $0x3, %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x1710(%rax)
movl -0x14(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0xc4(%rax)
movl -0x24(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0xc8(%rax)
movl -0x18(%rbp), %eax
movb %al, %cl
movq -0x30(%rbp), %rax
movb %cl, 0x48(%rax)
movq -0x10(%rbp), %rdi
callq 0x931f0
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)