// File: /workspace/github_cpp_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0x50(%rdi), %r14d
leal -0x106(%r14), %r15d
xorl %r12d, %r12d
movl 0x68(%rbx), %ebp
movl 0xac(%rbx), %eax
movl 0xb4(%rbx), %ecx
addl %eax, %ecx
subl %ecx, %ebp
movl 0x50(%rbx), %ecx
addl %r15d, %ecx
cmpl %ecx, %eax
jb 0x4b256
movq 0x60(%rbx), %rdi
leaq (%rdi,%r14), %rsi
movl %r14d, %edx
subl %ebp, %edx
callq 0x4290
subl %r14d, 0xb0(%rbx)
movl 0xac(%rbx), %eax
subl %r14d, %eax
movl %eax, 0xac(%rbx)
subq %r14, 0x98(%rbx)
cmpl %eax, 0x172c(%rbx)
jbe 0x4b208
movl %eax, 0x172c(%rbx)
movl 0x50(%rbx), %eax
movl 0x84(%rbx), %ecx
movq 0x78(%rbx), %rdx
leaq (%rdx,%rcx,2), %rdx
addq $-0x2, %rdx
movzwl (%rdx), %esi
subl %eax, %esi
cmovbl %r12d, %esi
movw %si, (%rdx)
addq $-0x2, %rdx
decl %ecx
jne 0x4b21d
movq 0x70(%rbx), %rcx
leaq (%rcx,%rax,2), %rcx
addq $-0x2, %rcx
movl %eax, %edx
movzwl (%rcx), %esi
subl %eax, %esi
cmovbl %r12d, %esi
movw %si, (%rcx)
addq $-0x2, %rcx
decl %edx
jne 0x4b23f
addl %r14d, %ebp
movq (%rbx), %rdi
cmpl $0x0, 0x8(%rdi)
je 0x4b347
movl 0xac(%rbx), %eax
movl 0xb4(%rbx), %esi
addq 0x60(%rbx), %rax
addq %rax, %rsi
movl %ebp, %edx
callq 0x4d066
addl 0xb4(%rbx), %eax
movl %eax, 0xb4(%rbx)
movl 0x172c(%rbx), %ecx
leal (%rcx,%rax), %edx
cmpl $0x3, %edx
jb 0x4b333
movl 0xac(%rbx), %edx
subl %ecx, %edx
movq 0x60(%rbx), %rsi
movzbl (%rsi,%rdx), %edi
movl %edi, 0x80(%rbx)
movl 0x90(%rbx), %ecx
shll %cl, %edi
leal 0x1(%rdx), %r8d
movzbl (%rsi,%r8), %r8d
xorl %edi, %r8d
movl 0x8c(%rbx), %edi
andl %edi, %r8d
movl %r8d, 0x80(%rbx)
movl 0x172c(%rbx), %r8d
subl $0x1, %r8d
jb 0x4b333
movl 0x80(%rbx), %r9d
shll %cl, %r9d
leal 0x2(%rdx), %r10d
movzbl (%rsi,%r10), %r10d
xorl %r9d, %r10d
andl %edi, %r10d
movl %r10d, 0x80(%rbx)
movq 0x70(%rbx), %r9
movq 0x78(%rbx), %r11
movzwl (%r11,%r10,2), %ebp
movl 0x58(%rbx), %r13d
andl %edx, %r13d
movw %bp, (%r9,%r13,2)
movw %dx, (%r11,%r10,2)
incl %edx
movl %r8d, 0x172c(%rbx)
leal (%rax,%r8), %r9d
cmpl $0x2, %r9d
ja 0x4b2dc
cmpl $0x105, %eax            # imm = 0x105
ja 0x4b347
movq (%rbx), %rax
cmpl $0x0, 0x8(%rax)
jne 0x4b1aa
movq 0x1738(%rbx), %rdi
movq 0x68(%rbx), %r14
movq %r14, %r15
subq %rdi, %r15
jbe 0x4b3c6
movl 0xac(%rbx), %eax
movl 0xb4(%rbx), %r12d
addq %rax, %r12
cmpq %r12, %rdi
jae 0x4b394
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 0x41c0
addq %r12, %r14
jmp 0x4b3bf
addq $0x102, %r12            # imm = 0x102
subq %rdi, %r12
jbe 0x4b3c6
cmpq %r15, %r12
cmovbq %r12, %r15
addq 0x60(%rbx), %rdi
movl %r15d, %edx
xorl %esi, %esi
callq 0x41c0
addq 0x1738(%rbx), %r15
movq %r15, %r14
movq %r14, 0x1738(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq