// File: /workspace/github_cpp_makefile_star2_O3/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
movl $0xffff, %r13d          # imm = 0xFFFF
movl $0x100, %r15d           # imm = 0x100
leaq 0x1d6e1(%rip), %r12     # 0xb1cd0
cmpl $0x106, 0xa4(%r14) # imm = 0x106
jae 0x9465c
testl %ebx, %ebx
sete %bpl
movq %r14, %rdi
callq 0x94ab7
movl 0xa4(%r14), %ecx
cmpl $0x106, %ecx            # imm = 0x106
setb %al
testb %al, %bpl
jne 0x949dd
testl %ecx, %ecx
je 0x949e4
movl 0x90(%r14), %edx
movl 0xa0(%r14), %eax
cmpl $0x2, %ecx
ja 0x9466a
movl %edx, 0xa8(%r14)
movl %eax, 0x94(%r14)
movl $0x2, 0x90(%r14)
jmp 0x9471e
movl 0x90(%r14), %edx
movl 0xa0(%r14), %eax
movl 0x70(%r14), %esi
movb 0x80(%r14), %cl
shll %cl, %esi
movl 0x9c(%r14), %ecx
leal 0x2(%rcx), %edi
movq 0x50(%r14), %r8
movzbl (%r8,%rdi), %edi
xorl %esi, %edi
andl 0x7c(%r14), %edi
movq 0x60(%r14), %r8
movl %edi, 0x70(%r14)
movq 0x68(%r14), %r9
movzwl (%r9,%rdi,2), %esi
movl 0x4c(%r14), %r10d
andl %ecx, %r10d
movw %si, (%r8,%r10,2)
movw %cx, (%r9,%rdi,2)
movl %edx, 0xa8(%r14)
movl %eax, 0x94(%r14)
movl $0x2, 0x90(%r14)
testl %esi, %esi
je 0x9471e
movl $0x2, %eax
cmpl 0xb0(%r14), %edx
jae 0x94745
subl %esi, %ecx
movl 0x44(%r14), %edx
movl $0xfffffefa, %edi       # imm = 0xFFFFFEFA
addl %edi, %edx
cmpl %edx, %ecx
ja 0x94745
movq %r14, %rdi
callq 0x94d15
movl %eax, 0x90(%r14)
cmpl $0x5, %eax
ja 0x94745
cmpl $0x1, 0xb8(%r14)
jne 0x94725
movl $0x2, 0x90(%r14)
movl $0x2, %eax
jmp 0x94745
movl $0x2, %eax
jmp 0x9474c
cmpl $0x3, %eax
jne 0x94745
movl 0x9c(%r14), %ecx
subl 0xa0(%r14), %ecx
movl $0x3, %eax
cmpl $0x1001, %ecx           # imm = 0x1001
jae 0x9470c
movl 0xa8(%r14), %edx
cmpl $0x3, %edx
jb 0x948c7
cmpl %edx, %eax
ja 0x948c7
movl 0x94(%r14), %eax
movl 0x9c(%r14), %ecx
movl 0xa4(%r14), %esi
addb $-0x3, %dl
notl %eax
movl %ecx, %edi
addl %eax, %edi
movq 0x1700(%r14), %r8
movl 0x16fc(%r14), %r9d
movw %di, (%r8,%r9,2)
movq 0x16f0(%r14), %rdi
leal 0x1(%r9), %r8d
movl %r8d, 0x16fc(%r14)
movb %dl, (%rdi,%r9)
movzbl %dl, %edx
leaq 0x1d722(%rip), %rdi     # 0xb1ed0
movzbl (%rdi,%rdx), %edx
incw 0x4c8(%r14,%rdx,4)
leal (%rcx,%rsi), %edx
addl $-0x3, %edx
addl %ecx, %eax
decl %eax
movl %eax, %ecx
andl %r13d, %ecx
movl %ecx, %esi
shrl $0x7, %esi
addl %r15d, %esi
cmpl %r15d, %ecx
cmovbl %eax, %esi
andl %r13d, %esi
movzbl (%r12,%rsi), %eax
incw 0x9b8(%r14,%rax,4)
movl 0x16fc(%r14), %esi
movl 0x16f8(%r14), %edi
decl %edi
movl 0xa8(%r14), %r8d
movl 0x9c(%r14), %eax
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 %eax
movl %eax, 0x9c(%r14)
cmpl %edx, %eax
ja 0x94878
movl 0x70(%r14), %r9d
movb 0x80(%r14), %cl
shll %cl, %r9d
leal 0x2(%rax), %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 %eax, %ebp
movw %r11w, (%r9,%rbp,2)
movw %ax, (%r10,%rcx,2)
movl %r8d, 0xa8(%r14)
incl %eax
addl $-0x1, %r8d
jb 0x9482b
movl $0x0, 0x98(%r14)
movl $0x2, 0x90(%r14)
movl %eax, 0x9c(%r14)
cmpl %edi, %esi
jne 0x945ef
movq 0x88(%r14), %rcx
testq %rcx, %rcx
js 0x9495b
movl %ecx, %esi
addq 0x50(%r14), %rsi
jmp 0x9495d
cmpl $0x0, 0x98(%r14)
je 0x9493d
movq 0x50(%r14), %rax
movl 0x9c(%r14), %ecx
decl %ecx
movzbl (%rax,%rcx), %eax
movq 0x1700(%r14), %rcx
movl 0x16fc(%r14), %edx
movw $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 0x949c2
movq 0x88(%r14), %rax
testq %rax, %rax
js 0x94996
movl %eax, %esi
addq 0x50(%r14), %rsi
jmp 0x94998
movl $0x1, 0x98(%r14)
incl 0x9c(%r14)
decl 0xa4(%r14)
jmp 0x945ef
xorl %esi, %esi
movl %eax, %edx
subq %rcx, %rdx
xorl %ebp, %ebp
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x97fbc
movl 0x9c(%r14), %eax
movq %rax, 0x88(%r14)
movq (%r14), %rdi
callq 0x9399f
movq (%r14), %rax
cmpl $0x0, 0x20(%rax)
jne 0x945ef
jmp 0x94aa6
xorl %esi, %esi
movl 0x9c(%r14), %edx
subq %rax, %rdx
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x97fbc
movl 0x9c(%r14), %eax
movq %rax, 0x88(%r14)
movq (%r14), %rdi
callq 0x9399f
incl 0x9c(%r14)
decl 0xa4(%r14)
movq (%r14), %rax
cmpl $0x0, 0x20(%rax)
jne 0x945ef
xorl %ebp, %ebp
jmp 0x94aa6
cmpl $0x0, 0x98(%r14)
je 0x94a3b
movq 0x50(%r14), %rax
movl 0x9c(%r14), %ecx
decl %ecx
movzbl (%rax,%rcx), %eax
movq 0x1700(%r14), %rcx
movl 0x16fc(%r14), %edx
movw $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 $0x0, 0x98(%r14)
movq 0x88(%r14), %rax
testq %rax, %rax
js 0x94a4f
movl %eax, %esi
addq 0x50(%r14), %rsi
jmp 0x94a51
xorl %esi, %esi
movl 0x9c(%r14), %edx
subq %rax, %rdx
xorl %ecx, %ecx
cmpl $0x4, %ebx
sete %cl
movq %r14, %rdi
callq 0x97fbc
movl 0x9c(%r14), %eax
movq %rax, 0x88(%r14)
movq (%r14), %rdi
callq 0x9399f
movq (%r14), %rax
cmpl $0x0, 0x20(%rax)
je 0x94a9b
xorl %eax, %eax
cmpl $0x4, %ebx
sete %al
leal 0x1(,%rax,2), %ebp
jmp 0x94aa6
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