// File: /workspace/github_cpp_makefile_star2_O2/sisong[P]ApkDiffPatch/zlib1.3.1/deflate.c
// Function: deflateSetDictionary
int ZEXPORT deflateSetDictionary(z_streamp strm, const Bytef *dictionary,
                                 uInt  dictLength) {
    deflate_state *s;
    uInt str, n;
    int wrap;
    unsigned avail;
    z_const unsigned char *next;

    if (deflateStateCheck(strm) || dictionary == Z_NULL)
        return Z_STREAM_ERROR;
    s = strm->state;
    wrap = s->wrap;
    if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead)
        return Z_STREAM_ERROR;

    /* when using zlib wrappers, compute Adler-32 for provided dictionary */
    if (wrap == 1)
        strm->adler = adler32(strm->adler, dictionary, dictLength);
    s->wrap = 0;                    /* avoid computing Adler-32 in read_buf */

    /* if dictionary would fill window, just replace the history */
    if (dictLength >= s->w_size) {
        if (wrap == 0) {            /* already empty otherwise */
            CLEAR_HASH(s);
            s->strstart = 0;
            s->block_start = 0L;
            s->insert = 0;
        }
        dictionary += dictLength - s->w_size;  /* use the tail */
        dictLength = s->w_size;
    }

    /* insert dictionary into window and hash */
    avail = strm->avail_in;
    next = strm->next_in;
    strm->avail_in = dictLength;
    strm->next_in = (z_const Bytef *)dictionary;
    fill_window(s);
    while (s->lookahead >= MIN_MATCH) {
        str = s->strstart;
        n = s->lookahead - (MIN_MATCH-1);
        do {
            UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
#ifndef FASTEST
            s->prev[str & s->w_mask] = s->head[s->ins_h];
#endif
            s->head[s->ins_h] = (Pos)str;
            str++;
        } while (--n);
        s->strstart = str;
        s->lookahead = MIN_MATCH-1;
        fill_window(s);
    }
    s->strstart += s->lookahead;
    s->block_start = (long)s->strstart;
    s->insert = s->lookahead;
    s->lookahead = 0;
    s->match_length = s->prev_length = MIN_MATCH-1;
    s->match_available = 0;
    strm->next_in = next;
    strm->avail_in = avail;
    s->wrap = wrap;
    return Z_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %r12d
movq %rsi, %r15
movq %rdi, %rbx
callq 0x40c8e
movl %eax, %ecx
pushq $-0x2
popq %rax
testq %r15, %r15
je 0x40c7f
testl %ecx, %ecx
jne 0x40c7f
movq 0x38(%rbx), %r14
movl 0x30(%r14), %ebp
cmpl $0x2, %ebp
je 0x40c7f
cmpl $0x1, %ebp
jne 0x40b31
cmpl $0x2a, 0x8(%r14)
jne 0x40c7f
cmpl $0x0, 0xb4(%r14)
jne 0x40c7f
movq 0x60(%rbx), %rdi
movq %r15, %rsi
movl %r12d, %edx
callq 0x400c8
movq %rax, 0x60(%rbx)
jmp 0x40b3f
cmpl $0x0, 0xb4(%r14)
jne 0x40c7f
andl $0x0, 0x30(%r14)
movl 0x50(%r14), %eax
cmpl %r12d, %eax
ja 0x40b92
testl %ebp, %ebp
jne 0x40b89
movq 0x78(%r14), %rdi
movl 0x84(%r14), %edx
decl %edx
andw $0x0, (%rdi,%rdx,2)
addq %rdx, %rdx
xorl %esi, %esi
callq 0x41f0
andl $0x0, 0xac(%r14)
andq $0x0, 0x98(%r14)
andl $0x0, 0x172c(%r14)
movl 0x50(%r14), %eax
subl %eax, %r12d
addq %r12, %r15
movl %eax, %r12d
movl 0x8(%rbx), %eax
movl %eax, 0x4(%rsp)
movq (%rbx), %r13
movl %r12d, 0x8(%rbx)
movq %r15, (%rbx)
movq %r14, %rdi
callq 0x40ce0
movl 0xac(%r14), %eax
movl 0xb4(%r14), %edx
cmpl $0x3, %edx
jb 0x40c34
addl $-0x2, %edx
movl 0x90(%r14), %ecx
movq 0x60(%r14), %rsi
movl 0x8c(%r14), %edi
movq 0x78(%r14), %r8
movq 0x70(%r14), %r9
movl 0x58(%r14), %r10d
movl 0x80(%r14), %r11d
shll %cl, %r11d
leal 0x2(%rax), %r15d
movzbl (%rsi,%r15), %r15d
xorl %r11d, %r15d
andl %edi, %r15d
movl %r15d, 0x80(%r14)
movzwl (%r8,%r15,2), %r11d
movl %r10d, %r12d
andl %eax, %r12d
movw %r11w, (%r9,%r12,2)
movw %ax, (%r8,%r15,2)
incl %eax
movl %r15d, %r11d
decl %edx
jne 0x40be6
movl %eax, 0xac(%r14)
movl $0x2, 0xb4(%r14)
jmp 0x40ba3
addl %edx, %eax
movl %eax, 0xac(%r14)
movq %rax, 0x98(%r14)
movl %edx, 0x172c(%r14)
movabsq $0x200000000, %rax      # imm = 0x200000000
movq %rax, 0xb4(%r14)
movl $0x2, 0xa0(%r14)
andl $0x0, 0xa8(%r14)
movq %r13, (%rbx)
movl 0x4(%rsp), %eax
movl %eax, 0x8(%rbx)
movl %ebp, 0x30(%r14)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq