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

    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.
         * At this point we have always match_length < MIN_MATCH
         */
        if (hash_head != NIL && 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 >= MIN_MATCH) {
            check_match(s, s->strstart, s->match_start, s->match_length);

            _tr_tally_dist(s, s->strstart - s->match_start,
                           s->match_length - MIN_MATCH, bflush);

            s->lookahead -= s->match_length;

            /* Insert new strings in the hash table only if the match length
             * is not too large. This saves time but degrades compression.
             */
#ifndef FASTEST
            if (s->match_length <= s->max_insert_length &&
                s->lookahead >= MIN_MATCH) {
                s->match_length--; /* string at strstart already in table */
                do {
                    s->strstart++;
                    INSERT_STRING(s, s->strstart, hash_head);
                    /* strstart never exceeds WSIZE-MAX_MATCH, so there are
                     * always MIN_MATCH bytes ahead.
                     */
                } while (--s->match_length != 0);
                s->strstart++;
            } else
#endif
            {
                s->strstart += s->match_length;
                s->match_length = 0;
                s->ins_h = s->window[s->strstart];
                UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
#if MIN_MATCH != 3
                Call UPDATE_HASH() MIN_MATCH-3 more times
#endif
                /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
                 * matter since it will be recomputed at next deflate call.
                 */
            }
        } else {
            /* No match, output a literal byte */
            Tracevv((stderr,"%c", s->window[s->strstart]));
            _tr_tally_lit (s, s->window[s->strstart], bflush);
            s->lookahead--;
            s->strstart++;
        }
        if (bflush) FLUSH_BLOCK(s, 0);
    }
    FLUSH_BLOCK(s, flush == Z_FINISH);
    return flush == Z_FINISH ? finish_done : block_done;
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
movl %esi, 0x44(%rsp)
movq 0x48(%rsp), %rax
cmpl $0x106, 0xa4(%rax)      # imm = 0x106
jae 0x118392
movq 0x48(%rsp), %rdi
callq 0x1193a0
movq 0x48(%rsp), %rax
cmpl $0x106, 0xa4(%rax)      # imm = 0x106
jae 0x11837d
cmpl $0x0, 0x44(%rsp)
jne 0x11837d
movl $0x0, 0x54(%rsp)
jmp 0x118a46
movq 0x48(%rsp), %rax
cmpl $0x0, 0xa4(%rax)
jne 0x118390
jmp 0x11896e
jmp 0x118392
movl $0x0, 0x40(%rsp)
movq 0x48(%rsp), %rax
cmpl $0x3, 0xa4(%rax)
jb 0x118453
movq 0x48(%rsp), %rax
movl 0x70(%rax), %eax
movq 0x48(%rsp), %rcx
movl 0x80(%rcx), %ecx
shll %cl, %eax
movl %eax, %ecx
movq 0x48(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x48(%rsp), %rdx
movl 0x9c(%rdx), %edx
addl $0x2, %edx
movl %edx, %edx
movzbl (%rax,%rdx), %eax
xorl %eax, %ecx
movq 0x48(%rsp), %rax
andl 0x7c(%rax), %ecx
movq 0x48(%rsp), %rax
movl %ecx, 0x70(%rax)
movq 0x48(%rsp), %rax
movq 0x68(%rax), %rax
movq 0x48(%rsp), %rcx
movl 0x70(%rcx), %ecx
movw (%rax,%rcx,2), %ax
movq 0x48(%rsp), %rcx
movq 0x60(%rcx), %rcx
movq 0x48(%rsp), %rdx
movl 0x9c(%rdx), %edx
movq 0x48(%rsp), %rsi
andl 0x4c(%rsi), %edx
movl %edx, %edx
movw %ax, (%rcx,%rdx,2)
movzwl %ax, %eax
movl %eax, 0x40(%rsp)
movq 0x48(%rsp), %rax
movl 0x9c(%rax), %eax
movw %ax, %dx
movq 0x48(%rsp), %rax
movq 0x68(%rax), %rax
movq 0x48(%rsp), %rcx
movl 0x70(%rcx), %ecx
movw %dx, (%rax,%rcx,2)
cmpl $0x0, 0x40(%rsp)
je 0x118496
movq 0x48(%rsp), %rax
movl 0x9c(%rax), %eax
subl 0x40(%rsp), %eax
movq 0x48(%rsp), %rcx
movl 0x44(%rcx), %ecx
subl $0x106, %ecx            # imm = 0x106
cmpl %ecx, %eax
ja 0x118496
movq 0x48(%rsp), %rdi
movl 0x40(%rsp), %esi
callq 0x119910
movl %eax, %ecx
movq 0x48(%rsp), %rax
movl %ecx, 0x90(%rax)
movq 0x48(%rsp), %rax
cmpl $0x3, 0x90(%rax)
jb 0x1187de
movq 0x48(%rsp), %rax
movl 0x90(%rax), %eax
subl $0x3, %eax
movb %al, 0x3b(%rsp)
movq 0x48(%rsp), %rax
movl 0x9c(%rax), %eax
movq 0x48(%rsp), %rcx
subl 0xa0(%rcx), %eax
movw %ax, 0x38(%rsp)
movw 0x38(%rsp), %dx
movq 0x48(%rsp), %rax
movq 0x1700(%rax), %rax
movq 0x48(%rsp), %rcx
movl 0x16fc(%rcx), %ecx
movw %dx, (%rax,%rcx,2)
movb 0x3b(%rsp), %dl
movq 0x48(%rsp), %rax
movq 0x16f0(%rax), %rax
movq 0x48(%rsp), %rsi
movl 0x16fc(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x16fc(%rsi)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movw 0x38(%rsp), %ax
addw $-0x1, %ax
movw %ax, 0x38(%rsp)
movq 0x48(%rsp), %rax
movzbl 0x3b(%rsp), %ecx
movl %ecx, %edx
leaq 0x261ff(%rip), %rcx     # 0x13e740
movzbl (%rcx,%rdx), %ecx
addl $0x100, %ecx            # imm = 0x100
addl $0x1, %ecx
movslq %ecx, %rcx
movw 0xc4(%rax,%rcx,4), %dx
addw $0x1, %dx
movw %dx, 0xc4(%rax,%rcx,4)
movq 0x48(%rsp), %rax
addq $0x9b8, %rax            # imm = 0x9B8
movq %rax, 0x28(%rsp)
movzwl 0x38(%rsp), %eax
cmpl $0x100, %eax            # imm = 0x100
jge 0x118599
movzwl 0x38(%rsp), %eax
movl %eax, %ecx
leaq 0x25fb1(%rip), %rax     # 0x13e540
movzbl (%rax,%rcx), %eax
movl %eax, 0x24(%rsp)
jmp 0x1185b8
movzwl 0x38(%rsp), %eax
sarl $0x7, %eax
addl $0x100, %eax            # imm = 0x100
movslq %eax, %rcx
leaq 0x25f90(%rip), %rax     # 0x13e540
movzbl (%rax,%rcx), %eax
movl %eax, 0x24(%rsp)
movq 0x28(%rsp), %rax
movl 0x24(%rsp), %ecx
movslq %ecx, %rcx
movw (%rax,%rcx,4), %dx
addw $0x1, %dx
movw %dx, (%rax,%rcx,4)
movq 0x48(%rsp), %rax
movl 0x16fc(%rax), %eax
movq 0x48(%rsp), %rcx
movl 0x16f8(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x3c(%rsp)
movq 0x48(%rsp), %rax
movl 0x90(%rax), %edx
movq 0x48(%rsp), %rax
movl 0xa4(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0xa4(%rax)
movq 0x48(%rsp), %rax
movl 0x90(%rax), %eax
movq 0x48(%rsp), %rcx
cmpl 0xb0(%rcx), %eax
ja 0x118748
movq 0x48(%rsp), %rax
cmpl $0x3, 0xa4(%rax)
jb 0x118748
movq 0x48(%rsp), %rax
movl 0x90(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x90(%rax)
movq 0x48(%rsp), %rax
movl 0x9c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x9c(%rax)
movq 0x48(%rsp), %rax
movl 0x70(%rax), %eax
movq 0x48(%rsp), %rcx
movl 0x80(%rcx), %ecx
shll %cl, %eax
movl %eax, %ecx
movq 0x48(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x48(%rsp), %rdx
movl 0x9c(%rdx), %edx
addl $0x2, %edx
movl %edx, %edx
movzbl (%rax,%rdx), %eax
xorl %eax, %ecx
movq 0x48(%rsp), %rax
andl 0x7c(%rax), %ecx
movq 0x48(%rsp), %rax
movl %ecx, 0x70(%rax)
movq 0x48(%rsp), %rax
movq 0x68(%rax), %rax
movq 0x48(%rsp), %rcx
movl 0x70(%rcx), %ecx
movw (%rax,%rcx,2), %ax
movq 0x48(%rsp), %rcx
movq 0x60(%rcx), %rcx
movq 0x48(%rsp), %rdx
movl 0x9c(%rdx), %edx
movq 0x48(%rsp), %rsi
andl 0x4c(%rsi), %edx
movl %edx, %edx
movw %ax, (%rcx,%rdx,2)
movzwl %ax, %eax
movl %eax, 0x40(%rsp)
movq 0x48(%rsp), %rax
movl 0x9c(%rax), %eax
movw %ax, %dx
movq 0x48(%rsp), %rax
movq 0x68(%rax), %rax
movq 0x48(%rsp), %rcx
movl 0x70(%rcx), %ecx
movw %dx, (%rax,%rcx,2)
movq 0x48(%rsp), %rcx
movl 0x90(%rcx), %eax
addl $-0x1, %eax
movl %eax, 0x90(%rcx)
cmpl $0x0, %eax
jne 0x118657
movq 0x48(%rsp), %rax
movl 0x9c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x9c(%rax)
jmp 0x1187d9
movq 0x48(%rsp), %rax
movl 0x90(%rax), %ecx
movq 0x48(%rsp), %rax
addl 0x9c(%rax), %ecx
movl %ecx, 0x9c(%rax)
movq 0x48(%rsp), %rax
movl $0x0, 0x90(%rax)
movq 0x48(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x48(%rsp), %rcx
movl 0x9c(%rcx), %ecx
movzbl (%rax,%rcx), %ecx
movq 0x48(%rsp), %rax
movl %ecx, 0x70(%rax)
movq 0x48(%rsp), %rax
movl 0x70(%rax), %eax
movq 0x48(%rsp), %rcx
movl 0x80(%rcx), %ecx
shll %cl, %eax
movl %eax, %ecx
movq 0x48(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x48(%rsp), %rdx
movl 0x9c(%rdx), %edx
addl $0x1, %edx
movl %edx, %edx
movzbl (%rax,%rdx), %eax
xorl %eax, %ecx
movq 0x48(%rsp), %rax
andl 0x7c(%rax), %ecx
movq 0x48(%rsp), %rax
movl %ecx, 0x70(%rax)
jmp 0x1188ae
movq 0x48(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x48(%rsp), %rcx
movl 0x9c(%rcx), %ecx
movb (%rax,%rcx), %al
movb %al, 0x37(%rsp)
movq 0x48(%rsp), %rax
movq 0x1700(%rax), %rax
movq 0x48(%rsp), %rcx
movl 0x16fc(%rcx), %ecx
movw $0x0, (%rax,%rcx,2)
movb 0x37(%rsp), %dl
movq 0x48(%rsp), %rax
movq 0x16f0(%rax), %rax
movq 0x48(%rsp), %rsi
movl 0x16fc(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x16fc(%rsi)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq 0x48(%rsp), %rax
movzbl 0x37(%rsp), %ecx
movw 0xc4(%rax,%rcx,4), %dx
addw $0x1, %dx
movw %dx, 0xc4(%rax,%rcx,4)
movq 0x48(%rsp), %rax
movl 0x16fc(%rax), %eax
movq 0x48(%rsp), %rcx
movl 0x16f8(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x3c(%rsp)
movq 0x48(%rsp), %rax
movl 0xa4(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0xa4(%rax)
movq 0x48(%rsp), %rax
movl 0x9c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x9c(%rax)
cmpl $0x0, 0x3c(%rsp)
je 0x118969
movq 0x48(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x48(%rsp), %rax
cmpq $0x0, 0x88(%rax)
jl 0x1188f3
movq 0x48(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x48(%rsp), %rcx
movq 0x88(%rcx), %rcx
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
jmp 0x1188fc
xorl %eax, %eax
movq %rax, 0x10(%rsp)
jmp 0x1188fc
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x48(%rsp), %rax
movl 0x9c(%rax), %eax
movl %eax, %edx
movq 0x48(%rsp), %rax
subq 0x88(%rax), %rdx
xorl %ecx, %ecx
callq 0x11f710
movq 0x48(%rsp), %rax
movl 0x9c(%rax), %eax
movl %eax, %ecx
movq 0x48(%rsp), %rax
movq %rcx, 0x88(%rax)
movq 0x48(%rsp), %rax
movq (%rax), %rdi
callq 0x117190
movq 0x48(%rsp), %rax
movq (%rax), %rax
cmpl $0x0, 0x20(%rax)
jne 0x118967
movl $0x0, 0x54(%rsp)
jmp 0x118a46
jmp 0x118969
jmp 0x11833d
movq 0x48(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x48(%rsp), %rax
cmpq $0x0, 0x88(%rax)
jl 0x1189a7
movq 0x48(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x48(%rsp), %rcx
movq 0x88(%rcx), %rcx
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, (%rsp)
jmp 0x1189af
xorl %eax, %eax
movq %rax, (%rsp)
jmp 0x1189af
movq 0x8(%rsp), %rdi
movq (%rsp), %rsi
movq 0x48(%rsp), %rax
movl 0x9c(%rax), %eax
movl %eax, %edx
movq 0x48(%rsp), %rax
subq 0x88(%rax), %rdx
cmpl $0x4, 0x44(%rsp)
sete %al
andb $0x1, %al
movzbl %al, %ecx
callq 0x11f710
movq 0x48(%rsp), %rax
movl 0x9c(%rax), %eax
movl %eax, %ecx
movq 0x48(%rsp), %rax
movq %rcx, 0x88(%rax)
movq 0x48(%rsp), %rax
movq (%rax), %rdi
callq 0x117190
movq 0x48(%rsp), %rax
movq (%rax), %rax
cmpl $0x0, 0x20(%rax)
jne 0x118a2e
movl 0x44(%rsp), %edx
xorl %eax, %eax
movl $0x2, %ecx
cmpl $0x4, %edx
cmovel %ecx, %eax
movl %eax, 0x54(%rsp)
jmp 0x118a46
movl 0x44(%rsp), %edx
movl $0x1, %eax
movl $0x3, %ecx
cmpl $0x4, %edx
cmovel %ecx, %eax
movl %eax, 0x54(%rsp)
movl 0x54(%rsp), %eax
addq $0x58, %rsp
retq
nop