// File: /workspace/github_cpp_makefile_star2_O2/sisong[P]ApkDiffPatch/zlib1.3.1/deflate.c
// Function: fill_window
local void fill_window(deflate_state *s) {
    unsigned n;
    unsigned more;    /* Amount of free space at the end of the window. */
    uInt wsize = s->w_size;

    Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");

    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 - more);
            s->match_start -= wsize;
            s->strstart    -= wsize; /* we now have strstart >= MAX_DIST */
            s->block_start -= (long) wsize;
            if (s->insert > s->strstart)
                s->insert = s->strstart;
            slide_hash(s);
            more += wsize;
        }
        if (s->strm->avail_in == 0) break;

        /* 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 + s->insert >= MIN_MATCH) {
            uInt str = s->strstart - s->insert;
            s->ins_h = s->window[str];
            UPDATE_HASH(s, s->ins_h, s->window[str + 1]);
#if MIN_MATCH != 3
            Call UPDATE_HASH() MIN_MATCH-3 more times
#endif
            while (s->insert) {
                UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]);
#ifndef FASTEST
                s->prev[str & s->w_mask] = s->head[s->ins_h];
#endif
                s->head[s->ins_h] = (Pos)str;
                str++;
                s->insert--;
                if (s->lookahead + s->insert < MIN_MATCH)
                    break;
            }
        }
        /* 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;
        }
    }

    Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
           "not enough room for search");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movl 0x50(%rdi), %r14d
movl 0xb4(%rdi), %eax
movd %r14d, %xmm0
leal -0x106(%r14), %r15d
pshufd $0x50, %xmm0, %xmm0     # xmm0 = xmm0[0,0,1,1]
movdqa %xmm0, (%rsp)
movl 0x68(%rbx), %ebp
movl 0xac(%rbx), %ecx
addl %ecx, %eax
subl %eax, %ebp
movl 0x50(%rbx), %eax
addl %r15d, %eax
cmpl %eax, %ecx
jb 0x40d71
movq 0x60(%rbx), %rdi
leaq (%rdi,%r14), %rsi
movl %r14d, %edx
subl %ebp, %edx
callq 0x42c0
movq 0xac(%rbx), %xmm0
psubd (%rsp), %xmm0
movq %xmm0, 0xac(%rbx)
subq %r14, 0x98(%rbx)
movd %xmm0, %eax
cmpl %eax, 0x172c(%rbx)
jbe 0x40d66
movl %eax, 0x172c(%rbx)
movq %rbx, %rdi
callq 0x421d8
addl %r14d, %ebp
movq (%rbx), %rdi
cmpl $0x0, 0x8(%rdi)
je 0x40e59
movl 0xac(%rbx), %eax
movl 0xb4(%rbx), %esi
addq 0x60(%rbx), %rax
addq %rax, %rsi
movl %ebp, %edx
callq 0x42a3a
addl 0xb4(%rbx), %eax
movl %eax, 0xb4(%rbx)
movl 0x172c(%rbx), %edx
leal (%rdx,%rax), %ecx
cmpl $0x3, %ecx
jb 0x40e45
movl 0xac(%rbx), %esi
subl %edx, %esi
movq 0x60(%rbx), %rdi
movzbl (%rdi,%rsi), %r8d
movl %r8d, 0x80(%rbx)
movl 0x90(%rbx), %ecx
shll %cl, %r8d
leal 0x1(%rsi), %r9d
movzbl (%rdi,%r9), %r9d
xorl %r8d, %r9d
movl 0x8c(%rbx), %r8d
andl %r8d, %r9d
movl %r9d, 0x80(%rbx)
subl $0x1, %edx
jb 0x40e45
shll %cl, %r9d
leal 0x2(%rsi), %r10d
movzbl (%rdi,%r10), %r10d
xorl %r9d, %r10d
andl %r8d, %r10d
movl %r10d, 0x80(%rbx)
movq 0x70(%rbx), %r9
movq 0x78(%rbx), %r11
movzwl (%r11,%r10,2), %ebp
movl 0x58(%rbx), %r12d
andl %esi, %r12d
movw %bp, (%r9,%r12,2)
movw %si, (%r11,%r10,2)
incl %esi
movl %edx, 0x172c(%rbx)
leal (%rax,%rdx), %r11d
movl %r10d, %r9d
cmpl $0x2, %r11d
ja 0x40df4
cmpl $0x105, %eax            # imm = 0x105
ja 0x40e59
movq (%rbx), %rcx
cmpl $0x0, 0x8(%rcx)
jne 0x40d0f
movq 0x1738(%rbx), %rdi
movq 0x68(%rbx), %r14
movq %r14, %r15
subq %rdi, %r15
jbe 0x40ed8
movl 0xac(%rbx), %eax
movl 0xb4(%rbx), %r12d
addq %rax, %r12
cmpq %r12, %rdi
jae 0x40ea6
subq %r12, %r14
movl $0x102, %eax            # imm = 0x102
cmpq %rax, %r14
cmovaeq %rax, %r14
movq 0x60(%rbx), %rdi
addq %r12, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x41f0
addq %r12, %r14
jmp 0x40ed1
addq $0x102, %r12            # imm = 0x102
subq %rdi, %r12
jbe 0x40ed8
cmpq %r15, %r12
cmovbq %r12, %r15
addq 0x60(%rbx), %rdi
movl %r15d, %edx
xorl %esi, %esi
callq 0x41f0
addq 0x1738(%rbx), %r15
movq %r15, %r14
movq %r14, 0x1738(%rbx)
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq