// File: /workspace/github_c_makefile_star2_O2/snej[P]zdelta/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 (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
       * and lookahead == 1 (input done one 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.
       */
    } else if (s->strstart >= wsize+MAX_DIST(s)) {

      zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
      /* the match may be in the refference window; dont change it always */
      if(s->match_ptr == ZD_TARP) 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);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0x38(%rdi), %r14d
movl 0xbc(%rdi), %eax
leal -0x1006(%r14), %r15d
leaq -0x2(,%r14,2), %r12
xorl %r13d, %r13d
movl 0x58(%rbx), %ebp
movl 0xb4(%rbx), %ecx
subl %eax, %ebp
subl %ecx, %ebp
orl %ecx, %eax
orl %ebp, %eax
je 0x35be
cmpl $-0x1, %ebp
je 0x35c3
movl 0x38(%rbx), %eax
addl %r15d, %eax
cmpl %eax, %ecx
jb 0x35c6
movq 0x48(%rbx), %rdi
leaq (%rdi,%r14), %rsi
movq %r14, %rdx
callq 0x10f0
cmpl $0x2, 0xc0(%rbx)
jne 0x355d
subl %r14d, 0xb8(%rbx)
movl 0xb4(%rbx), %ecx
subl %r14d, %ecx
movl %ecx, 0xb4(%rbx)
subq %r14, 0xa0(%rbx)
movl 0x90(%rbx), %eax
movq 0x78(%rbx), %rdx
leaq (%rdx,%rax,2), %rdx
addq $-0x2, %rdx
movzwl (%rdx), %esi
subl %r14d, %esi
cmovbl %r13d, %esi
movw %si, (%rdx)
addq $-0x2, %rdx
decl %eax
jne 0x3585
movq 0x68(%rbx), %rax
addq %r12, %rax
movl %r14d, %edx
movzwl (%rax), %esi
subl %r14d, %esi
cmovbl %r13d, %esi
movw %si, (%rax)
addq $-0x2, %rax
decl %edx
jne 0x35a4
addl %r14d, %ebp
jmp 0x35c6
movl %r14d, %ebp
jmp 0x35c6
pushq $-0x2
popq %rbp
movq (%rbx), %rdi
cmpl $0x0, 0x8(%rdi)
je 0x363b
movl %ecx, %eax
addq 0x48(%rbx), %rax
movl 0xbc(%rbx), %esi
addq %rax, %rsi
movl %ebp, %edx
callq 0x364a
addl 0xbc(%rbx), %eax
movl %eax, 0xbc(%rbx)
cmpl $0x3, %eax
jb 0x362e
movq 0x48(%rbx), %rdx
movl 0xb4(%rbx), %esi
movzbl (%rdx,%rsi), %edi
movl %edi, 0x88(%rbx)
movb 0x9c(%rbx), %cl
shll %cl, %edi
leal 0x1(%rsi), %ecx
movzbl (%rdx,%rcx), %ecx
xorl %edi, %ecx
andl 0x98(%rbx), %ecx
movl %ecx, 0x88(%rbx)
cmpl $0x1005, %eax           # imm = 0x1005
ja 0x363b
movq (%rbx), %rcx
cmpl $0x0, 0x8(%rcx)
jne 0x350f
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq