// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/png/deflate.c
// Function: fill_window
local void fill_window(s)
    deflate_state *s;
{
    register unsigned n, m;
    register Posf *p;
    unsigned more;    /* Amount of free space at the end of the window. */
    uInt wsize = s->w_size;

    do {
        more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);

        /* Deal with !@#$% 64K limit: */
        if (sizeof(int) <= 2) {
            if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
                more = wsize;

            } else if (more == (unsigned)(-1)) {
                /* Very unlikely, but possible on 16 bit machine if
                 * strstart == 0 && lookahead == 1 (input done a byte at time)
                 */
                more--;
            }
        }

        /* If the window is almost full and there is insufficient lookahead,
         * move the upper half to the lower one to make room in the upper half.
         */
        if (s->strstart >= wsize+MAX_DIST(s)) {

            zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
            s->match_start -= wsize;
            s->strstart    -= wsize; /* we now have strstart >= MAX_DIST */
            s->block_start -= (long) wsize;

            /* Slide the hash table (could be avoided with 32 bit values
               at the expense of memory usage). We slide even when level == 0
               to keep the hash table consistent if we switch back to level > 0
               later. (Using level 0 permanently is not an optimal usage of
               zlib, so we don't care about this pathological case.)
             */
            n = s->hash_size;
            p = &s->head[n];
            do {
                m = *--p;
                *p = (Pos)(m >= wsize ? m-wsize : NIL);
            } while (--n);

            n = wsize;
#ifndef FASTEST
            p = &s->prev[n];
            do {
                m = *--p;
                *p = (Pos)(m >= wsize ? m-wsize : NIL);
                /* If n is not on any hash chain, prev[n] is garbage but
                 * its value will never be used.
                 */
            } while (--n);
#endif
            more += wsize;
        }
        if (s->strm->avail_in == 0) return;

        /* If there was no sliding:
         *    strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
         *    more == window_size - lookahead - strstart
         * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
         * => more >= window_size - 2*WSIZE + 2
         * In the BIG_MEM or MMAP case (not yet supported),
         *   window_size == input_size + MIN_LOOKAHEAD  &&
         *   strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
         * Otherwise, window_size == 2*WSIZE so more >= 2.
         * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
         */
        Assert(more >= 2, "more < 2");

        n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
        s->lookahead += n;

        /* Initialize the hash value now that we have some input: */
        if (s->lookahead >= MIN_MATCH) {
            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 the whole input has less than MIN_MATCH bytes, ins_h is garbage,
         * but this is not important since only literal bytes will be emitted.
         */

    } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);

    /* If the WIN_INIT bytes after the end of the current data have never been
     * written, then zero those bytes in order to avoid memory check reports of
     * the use of uninitialized (or uninitialised as Julian writes) bytes by
     * the longest match routines.  Update the high water mark for the next
     * time through here.  WIN_INIT is set to MAX_MATCH since the longest match
     * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
     */
    if (s->high_water < s->window_size) {
        ulg curr = s->strstart + (ulg)(s->lookahead);
        ulg init;

        if (s->high_water < curr) {
            /* Previous high water mark below current data -- zero WIN_INIT
             * bytes or up to end of window, whichever is less.
             */
            init = s->window_size - curr;
            if (init > WIN_INIT)
                init = WIN_INIT;
            zmemzero(s->window + curr, (unsigned)init);
            s->high_water = curr + init;
        }
        else if (s->high_water < (ulg)curr + WIN_INIT) {
            /* High water mark at or above current data, but below current data
             * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
             * to end of window, whichever is less.
             */
            init = (ulg)curr + WIN_INIT - s->high_water;
            if (init > s->window_size - s->high_water)
                init = s->window_size - s->high_water;
            zmemzero(s->window + s->high_water, (unsigned)init);
            s->high_water += init;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r12
movl 0x44(%rdi), %r14d
leal -0x106(%r14), %eax
movl %eax, 0xc(%rsp)
movd %r14d, %xmm0
pshufd $0x50, %xmm0, %xmm0     # xmm0 = xmm0[0,0,1,1]
movdqa %xmm0, 0x20(%rsp)
leaq -0x2(,%r14,2), %rax
movq %rax, 0x10(%rsp)
xorl %r13d, %r13d
movq %rdi, 0x18(%rsp)
movl 0x58(%r12), %r15d
movl 0x9c(%r12), %eax
movl 0xa4(%r12), %ecx
addl %eax, %ecx
subl %ecx, %r15d
movl 0x44(%r12), %ecx
addl 0xc(%rsp), %ecx
cmpl %ecx, %eax
jb 0x95837
movq 0x50(%r12), %rdi
leaq (%rdi,%r14), %rsi
movq %r14, %rdx
callq 0xe370
movq 0x9c(%r12), %xmm0
psubd 0x20(%rsp), %xmm0
movq %xmm0, 0x9c(%r12)
subq %r14, 0x88(%r12)
movl 0x74(%r12), %eax
movq 0x68(%r12), %rcx
leaq (%rcx,%rax,2), %rcx
addq $-0x2, %rcx
movzwl (%rcx), %edx
subl %r14d, %edx
cmovbl %r13d, %edx
movw %dx, (%rcx)
addq $-0x2, %rcx
decl %eax
jne 0x957fd
movq 0x60(%r12), %rax
addq 0x10(%rsp), %rax
movl %r14d, %ecx
movzwl (%rax), %edx
subl %r14d, %edx
cmovbl %r13d, %edx
movw %dx, (%rax)
addq $-0x2, %rax
decl %ecx
jne 0x9581f
addl %r14d, %r15d
movq (%r12), %rbx
movl 0x8(%rbx), %eax
testl %eax, %eax
je 0x959a7
cmpl %r15d, %eax
movl %r15d, %ebp
cmovbl %eax, %ebp
testl %r15d, %r15d
je 0x95891
movl 0x9c(%r12), %r15d
movq %r12, %rcx
movl 0xa4(%r12), %r12d
addq 0x50(%rcx), %r15
subl %ebp, %eax
movl %eax, 0x8(%rbx)
movq 0x38(%rbx), %rax
movl 0x2c(%rax), %eax
cmpl $0x2, %eax
je 0x95895
cmpl $0x1, %eax
jne 0x958a7
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
movl %ebp, %edx
callq 0xa1570
jmp 0x958a3
xorl %ebp, %ebp
jmp 0x958c7
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
movl %ebp, %edx
callq 0x93034
movq %rax, 0x60(%rbx)
addq %r12, %r15
movq (%rbx), %rsi
movl %ebp, %r12d
movq %r15, %rdi
movq %r12, %rdx
callq 0xe370
addq %r12, (%rbx)
addq %r12, 0x10(%rbx)
movq 0x18(%rsp), %r12
addl 0xa4(%r12), %ebp
movl %ebp, 0xa4(%r12)
cmpl $0x3, %ebp
jb 0x9590f
movq 0x50(%r12), %rax
movl 0x9c(%r12), %edx
movzbl (%rax,%rdx), %esi
movl %esi, 0x70(%r12)
movb 0x80(%r12), %cl
shll %cl, %esi
leal 0x1(%rdx), %ecx
movzbl (%rax,%rcx), %eax
xorl %esi, %eax
andl 0x7c(%r12), %eax
movl %eax, 0x70(%r12)
cmpl $0x105, %ebp            # imm = 0x105
ja 0x95925
movq (%r12), %rax
cmpl $0x0, 0x8(%rax)
jne 0x95791
movq 0x1728(%r12), %rdi
movq 0x58(%r12), %r14
movq %r14, %rbx
subq %rdi, %rbx
jbe 0x959a7
movl 0x9c(%r12), %eax
movl %ebp, %r15d
addq %rax, %r15
cmpq %r15, %rdi
jae 0x95973
subq %r15, %r14
movl $0x102, %eax            # imm = 0x102
cmpq %rax, %r14
cmovaeq %rax, %r14
movq 0x50(%r12), %rdi
addq %r15, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0xe260
addq %r15, %r14
jmp 0x9599f
addq $0x102, %r15            # imm = 0x102
subq %rdi, %r15
jbe 0x959a7
cmpq %rbx, %r15
cmovbq %r15, %rbx
addq 0x50(%r12), %rdi
movl %ebx, %edx
xorl %esi, %esi
callq 0xe260
addq 0x1728(%r12), %rbx
movq %rbx, %r14
movq %r14, 0x1728(%r12)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq