// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/png/deflate.c
// Function: deflate_slow
local block_state deflate_slow(s, flush)
    deflate_state *s;
    int flush;
{
    IPos hash_head;          /* head of hash chain */
    int bflush;              /* set if current block must be flushed */

    /* Process the input block. */
    for (;;) {
        /* Make sure that we always have enough lookahead, except
         * at the end of the input file. We need MAX_MATCH bytes
         * for the next match, plus MIN_MATCH bytes to insert the
         * string following the next match.
         */
        if (s->lookahead < MIN_LOOKAHEAD) {
            fill_window(s);
            if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
                return need_more;
            }
            if (s->lookahead == 0) break; /* flush the current block */
        }

        /* Insert the string window[strstart .. strstart+2] in the
         * dictionary, and set hash_head to the head of the hash chain:
         */
        hash_head = NIL;
        if (s->lookahead >= MIN_MATCH) {
            INSERT_STRING(s, s->strstart, hash_head);
        }

        /* Find the longest match, discarding those <= prev_length.
         */
        s->prev_length = s->match_length, s->prev_match = s->match_start;
        s->match_length = MIN_MATCH-1;

        if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
            s->strstart - hash_head <= MAX_DIST(s)) {
            /* To simplify the code, we prevent matches with the string
             * of window index 0 (in particular we have to avoid a match
             * of the string with itself at the start of the input file).
             */
            s->match_length = longest_match (s, hash_head);
            /* longest_match() sets match_start */

            if (s->match_length <= 5 && (s->strategy == Z_FILTERED
#if TOO_FAR <= 32767
                || (s->match_length == MIN_MATCH &&
                    s->strstart - s->match_start > TOO_FAR)
#endif
                )) {

                /* If prev_match is also MIN_MATCH, match_start is garbage
                 * but we will ignore the current match anyway.
                 */
                s->match_length = MIN_MATCH-1;
            }
        }
        /* If there was a match at the previous step and the current
         * match is not better, output the previous match:
         */
        if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
            uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
            /* Do not insert strings in hash table beyond this. */

            check_match(s, s->strstart-1, s->prev_match, s->prev_length);

            _tr_tally_dist(s, s->strstart -1 - s->prev_match,
                           s->prev_length - MIN_MATCH, bflush);

            /* Insert in hash table all strings up to the end of the match.
             * strstart-1 and strstart are already inserted. If there is not
             * enough lookahead, the last two strings are not inserted in
             * the hash table.
             */
            s->lookahead -= s->prev_length-1;
            s->prev_length -= 2;
            do {
                if (++s->strstart <= max_insert) {
                    INSERT_STRING(s, s->strstart, hash_head);
                }
            } while (--s->prev_length != 0);
            s->match_available = 0;
            s->match_length = MIN_MATCH-1;
            s->strstart++;

            if (bflush) FLUSH_BLOCK(s, 0);

        } else if (s->match_available) {
            /* If there was no match at the previous position, output a
             * single literal. If there was a match but the current match
             * is longer, truncate the previous match to a single literal.
             */
            Tracevv((stderr,"%c", s->window[s->strstart-1]));
            _tr_tally_lit(s, s->window[s->strstart-1], bflush);
            if (bflush) {
                FLUSH_BLOCK_ONLY(s, 0);
            }
            s->strstart++;
            s->lookahead--;
            if (s->strm->avail_out == 0) return need_more;
        } else {
            /* There is no previous match to compare with, wait for
             * the next step to decide.
             */
            s->match_available = 1;
            s->strstart++;
            s->lookahead--;
        }
    }
    Assert (flush != Z_NO_FLUSH, "no flush?");
    if (s->match_available) {
        Tracevv((stderr,"%c", s->window[s->strstart-1]));
        _tr_tally_lit(s, s->window[s->strstart-1], bflush);
        s->match_available = 0;
    }
    FLUSH_BLOCK(s, flush == Z_FINISH);
    return flush == Z_FINISH ? finish_done : block_done;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
pushq $0x2
popq %r15
movl $0xffff, %r12d          # imm = 0xFFFF
leaq 0x1bc9b(%rip), %r13     # 0xa2980
cmpl $0x105, 0xa4(%r14) # imm = 0x105
ja 0x86d27
testl %ebx, %ebx
sete %bpl
movq %r14, %rdi
callq 0x87176
movl 0xa4(%r14), %eax
cmpl $0x106, %eax            # imm = 0x106
setb %cl
testb %cl, %bpl
jne 0x870a0
testl %eax, %eax
je 0x870a7
xorl %esi, %esi
cmpl $0x3, %eax
jb 0x86d6c
movl 0x70(%r14), %eax
movb 0x80(%r14), %cl
shll %cl, %eax
movl 0x9c(%r14), %ecx
leal 0x2(%rcx), %edx
movq 0x50(%r14), %rsi
movzbl (%rsi,%rdx), %edx
xorl %eax, %edx
andl 0x7c(%r14), %edx
movq 0x60(%r14), %rax
movl %edx, 0x70(%r14)
movq 0x68(%r14), %rdi
movzwl (%rdi,%rdx,2), %esi
movl 0x4c(%r14), %r8d
andl %ecx, %r8d
movw %si, (%rax,%r8,2)
movw %cx, (%rdi,%rdx,2)
movl 0x90(%r14), %ecx
movl 0xa0(%r14), %eax
movl %ecx, 0xa8(%r14)
movl %eax, 0x94(%r14)
movl $0x2, 0x90(%r14)
movl %r15d, %eax
testl %esi, %esi
je 0x86e11
cmpl 0xb0(%r14), %ecx
jae 0x86e0a
movl 0x9c(%r14), %ecx
subl %esi, %ecx
movl 0x44(%r14), %edx
movl $0xfffffefa, %eax       # imm = 0xFFFFFEFA
addl %eax, %edx
movl %r15d, %eax
cmpl %edx, %ecx
ja 0x86e0a
movq %r14, %rdi
callq 0x873d4
movl %eax, 0x90(%r14)
cmpl $0x5, %eax
ja 0x86e0a
cmpl $0x1, 0xb8(%r14)
jne 0x86dec
movl $0x2, 0x90(%r14)
movl %r15d, %eax
jmp 0x86e0a
cmpl $0x3, %eax
jne 0x86e0a
movl 0x9c(%r14), %ecx
subl 0xa0(%r14), %ecx
pushq $0x3
popq %rax
cmpl $0x1001, %ecx           # imm = 0x1001
jae 0x86ddc
movl 0xa8(%r14), %ecx
cmpl $0x3, %ecx
jb 0x86f8b
cmpl %ecx, %eax
ja 0x86f8b
movl 0x94(%r14), %edx
movl 0x9c(%r14), %esi
movl 0xa4(%r14), %eax
addl %esi, %eax
addl $-0x3, %eax
addb $-0x3, %cl
notl %edx
leal (%rsi,%rdx), %edi
decl %edi
addl %edx, %esi
movq 0x1700(%r14), %rdx
movl 0x16fc(%r14), %r8d
movw %si, (%rdx,%r8,2)
movq 0x16f0(%r14), %rdx
leal 0x1(%r8), %esi
movl %esi, 0x16fc(%r14)
movb %cl, (%rdx,%r8)
movl %edi, %edx
movzbl %cl, %ecx
leaq 0x1bd03(%rip), %rsi     # 0xa2b80
movzbl (%rsi,%rcx), %ecx
incw 0x4c8(%r14,%rcx,4)
andl %r12d, %edx
shrl $0x7, %edx
addl $0x100, %edx            # imm = 0x100
cmpw $0x100, %di             # imm = 0x100
cmovbl %edi, %edx
andl %r12d, %edx
movzbl (%r13,%rdx), %ecx
incw 0x9b8(%r14,%rcx,4)
movl 0x16fc(%r14), %esi
movl 0x16f8(%r14), %edi
decl %edi
movl 0xa8(%r14), %r8d
movl 0x9c(%r14), %edx
movl 0xa4(%r14), %ecx
subl %r8d, %ecx
incl %ecx
movl %ecx, 0xa4(%r14)
leal -0x2(%r8), %ecx
movl %ecx, 0xa8(%r14)
addl $-0x3, %r8d
incl %edx
movl %edx, 0x9c(%r14)
cmpl %eax, %edx
ja 0x86f3f
movl 0x70(%r14), %r9d
movb 0x80(%r14), %cl
shll %cl, %r9d
leal 0x2(%rdx), %ecx
movq 0x50(%r14), %r10
movzbl (%r10,%rcx), %ecx
xorl %r9d, %ecx
andl 0x7c(%r14), %ecx
movq 0x60(%r14), %r9
movl %ecx, 0x70(%r14)
movq 0x68(%r14), %r10
movzwl (%r10,%rcx,2), %r11d
movl 0x4c(%r14), %ebp
andl %edx, %ebp
movw %r11w, (%r9,%rbp,2)
movw %dx, (%r10,%rcx,2)
movl %r8d, 0xa8(%r14)
incl %edx
addl $-0x1, %r8d
jb 0x86ef2
andl $0x0, 0x98(%r14)
movl $0x2, 0x90(%r14)
movl %edx, 0x9c(%r14)
cmpl %edi, %esi
jne 0x86ce5
movq 0x88(%r14), %rax
testq %rax, %rax
js 0x8701e
movl %eax, %esi
addq 0x50(%r14), %rsi
jmp 0x87020
cmpl $0x0, 0x98(%r14)
je 0x87000
movq 0x50(%r14), %rax
movl 0x9c(%r14), %ecx
decl %ecx
movzbl (%rax,%rcx), %eax
movq 0x1700(%r14), %rcx
movl 0x16fc(%r14), %edx
andw $0x0, (%rcx,%rdx,2)
movq 0x16f0(%r14), %rcx
leal 0x1(%rdx), %esi
movl %esi, 0x16fc(%r14)
movb %al, (%rcx,%rdx)
incw 0xc4(%r14,%rax,4)
movl 0x16f8(%r14), %eax
decl %eax
cmpl %eax, 0x16fc(%r14)
jne 0x87085
movq 0x88(%r14), %rax
testq %rax, %rax
js 0x87059
movl %eax, %esi
addq 0x50(%r14), %rsi
jmp 0x8705b
movl $0x1, 0x98(%r14)
incl 0x9c(%r14)
decl 0xa4(%r14)
jmp 0x86ce5
xorl %esi, %esi
movl %edx, %edx
subq %rax, %rdx
xorl %ebp, %ebp
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x8a0ca
movl 0x9c(%r14), %eax
movq %rax, 0x88(%r14)
movq (%r14), %rdi
callq 0x86561
movq (%r14), %rax
cmpl $0x0, 0x20(%rax)
jne 0x86ce5
jmp 0x87165
xorl %esi, %esi
movl 0x9c(%r14), %edx
subq %rax, %rdx
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x8a0ca
movl 0x9c(%r14), %eax
movq %rax, 0x88(%r14)
movq (%r14), %rdi
callq 0x86561
incl 0x9c(%r14)
decl 0xa4(%r14)
movq (%r14), %rax
cmpl $0x0, 0x20(%rax)
jne 0x86ce5
xorl %ebp, %ebp
jmp 0x87165
cmpl $0x0, 0x98(%r14)
je 0x870fa
movq 0x50(%r14), %rax
movl 0x9c(%r14), %ecx
decl %ecx
movzbl (%rax,%rcx), %eax
movq 0x1700(%r14), %rcx
movl 0x16fc(%r14), %edx
andw $0x0, (%rcx,%rdx,2)
movq 0x16f0(%r14), %rcx
leal 0x1(%rdx), %esi
movl %esi, 0x16fc(%r14)
movb %al, (%rcx,%rdx)
incw 0xc4(%r14,%rax,4)
andl $0x0, 0x98(%r14)
movq 0x88(%r14), %rax
testq %rax, %rax
js 0x8710e
movl %eax, %esi
addq 0x50(%r14), %rsi
jmp 0x87110
xorl %esi, %esi
movl 0x9c(%r14), %edx
subq %rax, %rdx
xorl %ecx, %ecx
cmpl $0x4, %ebx
sete %cl
movq %r14, %rdi
callq 0x8a0ca
movl 0x9c(%r14), %eax
movq %rax, 0x88(%r14)
movq (%r14), %rdi
callq 0x86561
movq (%r14), %rax
cmpl $0x0, 0x20(%rax)
je 0x8715a
xorl %eax, %eax
cmpl $0x4, %ebx
sete %al
leal 0x1(,%rax,2), %ebp
jmp 0x87165
xorl %ebp, %ebp
cmpl $0x4, %ebx
sete %bpl
addl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq