// File: /workspace/github_c_makefile_star2_O1/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
leal -0x1006(%r14), %ebp
leaq -0x2(,%r14,2), %r15
xorl %r12d, %r12d
movl 0xbc(%rbx), %ecx
movl 0x58(%rbx), %r13d
movl 0xb4(%rbx), %eax
subl %ecx, %r13d
subl %eax, %r13d
orl %eax, %ecx
orl %r13d, %ecx
movl %r14d, %edx
je 0x37a9
cmpl $-0x1, %r13d
je 0x37a4
movl 0x38(%rbx), %ecx
addl %ebp, %ecx
cmpl %ecx, %eax
jb 0x379f
movq 0x48(%rbx), %rdi
leaq (%rdi,%r14), %rsi
movq %r14, %rdx
callq 0x10f0
cmpl $0x2, 0xc0(%rbx)
jne 0x3748
subl %r14d, 0xb8(%rbx)
subl %r14d, 0xb4(%rbx)
subq %r14, 0xa0(%rbx)
movl 0x90(%rbx), %eax
movq 0x78(%rbx), %rcx
leaq (%rcx,%rax,2), %rcx
addq $-0x2, %rcx
movzwl (%rcx), %edx
subl %r14d, %edx
cmovbl %r12d, %edx
movw %dx, (%rcx)
addq $-0x2, %rcx
decl %eax
jne 0x3768
movq 0x68(%rbx), %rax
addq %r15, %rax
movl %r14d, %ecx
movzwl (%rax), %edx
subl %r14d, %edx
cmovbl %r12d, %edx
movw %dx, (%rax)
addq $-0x2, %rax
decl %ecx
jne 0x3787
addl %r14d, %r13d
movl %r13d, %edx
jmp 0x37a9
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
movq (%rbx), %rdi
cmpl $0x0, 0x8(%rdi)
je 0x3820
movl 0xb4(%rbx), %eax
movl 0xbc(%rbx), %esi
addq 0x48(%rbx), %rax
addq %rax, %rsi
callq 0x382f
addl 0xbc(%rbx), %eax
movl %eax, 0xbc(%rbx)
cmpl $0x3, %eax
jb 0x380c
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 0x3820
movq (%rbx), %rax
cmpl $0x0, 0x8(%rax)
jne 0x36f1
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq