// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movl 0x38(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x8(%rbp), %rcx
movl 0xbc(%rcx), %ecx
subq %rcx, %rax
movq -0x8(%rbp), %rcx
movl 0xb4(%rcx), %ecx
subq %rcx, %rax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x51a6
movq -0x8(%rbp), %rax
cmpl $0x0, 0xb4(%rax)
jne 0x51a6
movq -0x8(%rbp), %rax
cmpl $0x0, 0xbc(%rax)
jne 0x51a6
movl -0x20(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x532f
cmpl $-0x1, -0x1c(%rbp)
jne 0x51ba
movl -0x1c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x532d
movq -0x8(%rbp), %rax
movl 0xb4(%rax), %eax
movl -0x20(%rbp), %ecx
movq -0x8(%rbp), %rdx
movl 0x38(%rdx), %edx
subl $0x1006, %edx           # imm = 0x1006
addl %edx, %ecx
cmpl %ecx, %eax
jb 0x532b
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rsi
movl -0x20(%rbp), %eax
addq %rax, %rsi
movl -0x20(%rbp), %eax
movl %eax, %edx
callq 0x10d0
movq -0x8(%rbp), %rax
cmpl $0x2, 0xc0(%rax)
jne 0x5220
movl -0x20(%rbp), %edx
movq -0x8(%rbp), %rax
movl 0xb8(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0xb8(%rax)
movl -0x20(%rbp), %edx
movq -0x8(%rbp), %rax
movl 0xb4(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0xb4(%rax)
movl -0x20(%rbp), %eax
movl %eax, %edx
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0xa0(%rax)
movq -0x8(%rbp), %rax
movl 0x90(%rax), %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq 0x78(%rax), %rax
movl -0xc(%rbp), %ecx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $-0x2, %rcx
movq %rcx, -0x18(%rbp)
movzwl -0x2(%rax), %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl -0x20(%rbp), %eax
jb 0x529a
movl -0x10(%rbp), %eax
subl -0x20(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x52a1
xorl %eax, %eax
movl %eax, -0x24(%rbp)
jmp 0x52a1
movl -0x24(%rbp), %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, (%rax)
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
cmpl $0x0, %eax
jne 0x5271
movl -0x20(%rbp), %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rax
movl -0xc(%rbp), %ecx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $-0x2, %rcx
movq %rcx, -0x18(%rbp)
movzwl -0x2(%rax), %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl -0x20(%rbp), %eax
jb 0x5300
movl -0x10(%rbp), %eax
subl -0x20(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x5307
xorl %eax, %eax
movl %eax, -0x28(%rbp)
jmp 0x5307
movl -0x28(%rbp), %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, (%rax)
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
cmpl $0x0, %eax
jne 0x52d7
movl -0x20(%rbp), %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x532d
jmp 0x532f
movq -0x8(%rbp), %rax
movq (%rax), %rax
cmpl $0x0, 0x8(%rax)
jne 0x5341
jmp 0x5431
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rsi
movq -0x8(%rbp), %rax
movl 0xb4(%rax), %eax
addq %rax, %rsi
movq -0x8(%rbp), %rax
movl 0xbc(%rax), %eax
addq %rax, %rsi
movl -0x1c(%rbp), %edx
callq 0x5440
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
addl 0xbc(%rax), %ecx
movl %ecx, 0xbc(%rax)
movq -0x8(%rbp), %rax
cmpl $0x3, 0xbc(%rax)
jb 0x53fe
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x8(%rbp), %rcx
movl 0xb4(%rcx), %ecx
movzbl (%rax,%rcx), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x88(%rax)
movq -0x8(%rbp), %rax
movl 0x88(%rax), %eax
movq -0x8(%rbp), %rcx
movl 0x9c(%rcx), %ecx
shll %cl, %eax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x8(%rbp), %rdx
movl 0xb4(%rdx), %edx
addl $0x1, %edx
movl %edx, %edx
movzbl (%rax,%rdx), %eax
xorl %eax, %ecx
movq -0x8(%rbp), %rax
andl 0x98(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x88(%rax)
jmp 0x5400
movq -0x8(%rbp), %rcx
xorl %eax, %eax
cmpl $0x1006, 0xbc(%rcx)     # imm = 0x1006
movb %al, -0x29(%rbp)
jae 0x5426
movq -0x8(%rbp), %rax
movq (%rax), %rax
cmpl $0x0, 0x8(%rax)
setne %al
movb %al, -0x29(%rbp)
movb -0x29(%rbp), %al
testb $0x1, %al
jne 0x5156
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)