// File: /workspace/github_cpp_makefile_star2_O1/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, %r12d          # imm = 0xFFFF
movl $0x100, %r13d           # imm = 0x100
movl $0xfffffefa, %r15d      # imm = 0xFFFFFEFA
cmpl $0x105, 0xa4(%r14) # imm = 0x105
ja 0x952f4
testl %ebx, %ebx
sete %bpl
movq %r14, %rdi
callq 0x9574c
movl 0xa4(%r14), %eax
cmpl $0x106, %eax            # imm = 0x106
setb %cl
testb %cl, %bpl
jne 0x95672
testl %eax, %eax
je 0x95679
xorl %esi, %esi
cmpl $0x3, 0xa4(%r14)
jb 0x95345
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), %eax
movl 0xa0(%r14), %ecx
movl %eax, 0xa8(%r14)
movl %ecx, 0x94(%r14)
movl $0x2, 0x90(%r14)
testl %esi, %esi
je 0x953d2
cmpl 0xb0(%r14), %eax
jae 0x953d2
movl 0x9c(%r14), %eax
subl %esi, %eax
movl 0x44(%r14), %ecx
addl %r15d, %ecx
cmpl %ecx, %eax
ja 0x953d2
movq %r14, %rdi
callq 0x959b6
movl %eax, 0x90(%r14)
cmpl $0x5, %eax
ja 0x953d2
cmpl $0x1, 0xb8(%r14)
jne 0x953b8
movl $0x2, 0x90(%r14)
jmp 0x953d2
cmpl $0x3, %eax
jne 0x953d2
movl 0x9c(%r14), %eax
subl 0xa0(%r14), %eax
cmpl $0x1001, %eax           # imm = 0x1001
jae 0x953ab
movl 0xa8(%r14), %eax
cmpl $0x3, %eax
jb 0x953eb
cmpl %eax, 0x90(%r14)
jbe 0x95486
cmpl $0x0, 0x98(%r14)
je 0x95468
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 0x9561a
movq 0x88(%r14), %rax
testq %rax, %rax
js 0x955ee
movl %eax, %esi
addq 0x50(%r14), %rsi
jmp 0x955f0
movl $0x1, 0x98(%r14)
incl 0x9c(%r14)
decl 0xa4(%r14)
jmp 0x952b9
movl 0x94(%r14), %ecx
movl 0x9c(%r14), %esi
movl 0xa4(%r14), %edx
addb $-0x3, %al
notl %ecx
movl %esi, %edi
addl %ecx, %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 %al, (%rdi,%r9)
movzbl %al, %eax
leaq 0x1c9aa(%rip), %rdi     # 0xb1e80
movzbl (%rdi,%rax), %eax
incw 0x4c8(%r14,%rax,4)
addl %esi, %edx
addl $-0x3, %edx
leal (%rsi,%rcx), %eax
decl %eax
movl %eax, %ecx
andl %r12d, %ecx
movl %ecx, %esi
shrl $0x7, %esi
addl %r13d, %esi
cmpl %r13d, %ecx
cmovbl %eax, %esi
andl %r12d, %esi
leaq 0x1c776(%rip), %rax     # 0xb1c80
movzbl (%rax,%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 0x955a6
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 0x95559
movl $0x0, 0x98(%r14)
movl $0x2, 0x90(%r14)
movl %eax, 0x9c(%r14)
cmpl %edi, %esi
jne 0x952b9
movq 0x88(%r14), %rcx
testq %rcx, %rcx
js 0x95637
movl %ecx, %esi
addq 0x50(%r14), %rsi
jmp 0x95639
xorl %esi, %esi
movl 0x9c(%r14), %edx
subq %rax, %rdx
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x988ce
movl 0x9c(%r14), %eax
movq %rax, 0x88(%r14)
movq (%r14), %rdi
callq 0x9469d
incl 0x9c(%r14)
decl 0xa4(%r14)
movq (%r14), %rax
cmpl $0x0, 0x20(%rax)
jne 0x952b9
jmp 0x95672
xorl %esi, %esi
movl %eax, %edx
subq %rcx, %rdx
xorl %ebp, %ebp
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x988ce
movl 0x9c(%r14), %eax
movq %rax, 0x88(%r14)
movq (%r14), %rdi
callq 0x9469d
movq (%r14), %rax
cmpl $0x0, 0x20(%rax)
jne 0x952b9
jmp 0x9573b
xorl %ebp, %ebp
jmp 0x9573b
cmpl $0x0, 0x98(%r14)
je 0x956d0
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 0x956e4
movl %eax, %esi
addq 0x50(%r14), %rsi
jmp 0x956e6
xorl %esi, %esi
movl 0x9c(%r14), %edx
subq %rax, %rdx
xorl %ecx, %ecx
cmpl $0x4, %ebx
sete %cl
movq %r14, %rdi
callq 0x988ce
movl 0x9c(%r14), %eax
movq %rax, 0x88(%r14)
movq (%r14), %rdi
callq 0x9469d
movq (%r14), %rax
cmpl $0x0, 0x20(%rax)
je 0x95730
xorl %eax, %eax
cmpl $0x4, %ebx
sete %al
leal 0x1(,%rax,2), %ebp
jmp 0x9573b
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