// File: /workspace/github_c_makefile_star2_O2/snej[P]zdelta/deflate.c
// Function: slide_ref_window
local void slide_ref_window(deflate_state *s, pointer_history *h, 
			    int rw, int len, int match_start){
  ulg ptr_val;
  h->sum_len[rw] += len;       /* cumm. copy length */
  ptr_val = (s->ref_window_size[rw] - match_start - MAX_MATCH) * len;
  h->sum_ptr[rw] += ptr_val;              /* pointer average */
  h->len_hist[rw][h->front_ptr[rw]] = len;
  h->ptr_hist[rw][h->front_ptr[rw]] = ptr_val;
  h->front_ptr[rw] = ZD_GET_NEXT_POS(h->front_ptr[rw]);
  
  if ((h->front_ptr[rw] == h->back_ptr[rw]) || (h->sum_len[rw] > 5000)){
    h->sum_len[rw] -= h->len_hist[rw][h->back_ptr[rw]];
    h->sum_ptr[rw] -= h->ptr_hist[rw][h->back_ptr[rw]];
    h->back_ptr[rw] = ZD_GET_NEXT_POS(h->back_ptr[rw]);
  }
  
  /* check if base window should be slided*/
  if((++(h->ch_flag[rw])) == ZD_TIME_TO_CHECK){
    h->ch_flag[rw] = 0;
    h->avg_pos = h->sum_ptr[rw] / h->sum_len[rw];
    
    if((h->avg_pos < 22000) && (h->sum_len[rw] > 2000) && 
       (s->rwptr[2*rw]>(int)s->w_size ||
	s->rwptr[2*rw+1]>(int)s->w_size)) 
    { 
      fill_ref_window(s, rw);         /* slide */
      h->sum_ptr[rw]   = 0;
      h->sum_len[rw]   = 0;
      h->front_ptr[rw] = 0;
      h->back_ptr[rw]  = 0;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %r15d
movq %rsi, %rbx
movq %rdi, %r14
movslq %ecx, %rax
movslq %edx, %rbp
addq %rax, 0x3e80(%rsi,%rbp,8)
movq 0x60(%rdi,%rbp,8), %rcx
movslq %r8d, %rdx
negq %rdx
addq %rdx, %rcx
addq $-0x1002, %rcx          # imm = 0xEFFE
imulq %rax, %rcx
addq %rcx, 0x3e88(%rsi,%rbp,8)
movslq 0x3e98(%rsi,%rbp,4), %rdi
imulq $0x1f40, %rbp, %rdx     # imm = 0x1F40
addq %rdx, %rsi
movq %rax, (%rsi,%rdi,8)
leaq (%rbx,%rdx), %rax
addq $0x1f40, %rax           # imm = 0x1F40
movq %rcx, (%rax,%rdi,8)
leal 0x1(%rdi), %ecx
xorl %eax, %eax
cmpl $0x3e8, %ecx            # imm = 0x3E8
cmovel %eax, %ecx
movl %ecx, 0x3e98(%rbx,%rbp,4)
movslq 0x3e9c(%rbx,%rbp,4), %rdi
cmpl %edi, %ecx
sete %r8b
movq 0x3e80(%rbx,%rbp,8), %rcx
cmpq $0x1389, %rcx           # imm = 0x1389
setae %r9b
orb %r8b, %r9b
cmpb $0x1, %r9b
jne 0x3e12
leaq 0x1f40(%rbx), %r8
movq (%rsi,%rdi,8), %rsi
subq %rsi, %rcx
movq %rcx, 0x3e80(%rbx,%rbp,8)
addq %rdx, %r8
movq (%r8,%rdi,8), %rdx
subq %rdx, 0x3e88(%rbx,%rbp,8)
leal 0x1(%rdi), %edx
cmpl $0x3e8, %edx            # imm = 0x3E8
cmovnel %edx, %eax
movl %eax, 0x3e9c(%rbx,%rbp,4)
movl 0x3ea0(%rbx,%rbp,4), %eax
incl %eax
movl %eax, 0x3ea0(%rbx,%rbp,4)
cmpl $0x2, %eax
jne 0x3fde
andl $0x0, 0x3ea0(%rbx,%rbp,4)
movq 0x3e88(%rbx,%rbp,8), %rax
xorl %edx, %edx
divq %rcx
movq %rax, 0x3e90(%rbx)
cmpq $0x55ef, %rax           # imm = 0x55EF
ja 0x3fde
cmpq $0x7d1, 0x3e80(%rbx,%rbp,8) # imm = 0x7D1
jb 0x3fde
leal (%r15,%r15), %edx
movslq %edx, %rcx
movslq 0x38(%r14), %r13
cmpq %r13, 0x1a78(%r14,%rcx,8)
jg 0x3e8f
movl %edx, %eax
orl $0x1, %eax
cltq
cmpq %r13, 0x1a78(%r14,%rax,8)
jle 0x3fde
movl %edx, 0x4(%rsp)
movq 0x50(%r14,%rbp,8), %rdi
movl %r13d, %r12d
leaq (%rdi,%r12), %rsi
movq %r12, %rdx
movq %rcx, 0x10(%rsp)
callq 0x10f0
movq (%r14), %rdi
movq 0x50(%r14,%rbp,8), %rsi
movq %r12, 0x8(%rsp)
addq %r12, %rsi
movl %r13d, %edx
movl %r15d, %ecx
callq 0x3fed
movq 0x10(%rsp), %rcx
addl %r13d, %eax
movq %rax, 0x60(%r14,%rbp,8)
movq 0x1a78(%r14,%rcx,8), %rax
cmpq $-0x7fff, %rax          # imm = 0x8001
jl 0x3ef1
subq 0x8(%rsp), %rax
movq %rax, 0x1a78(%r14,%rcx,8)
movl 0x4(%rsp), %eax
orl $0x1, %eax
cltq
movq 0x1a78(%r14,%rax,8), %rcx
cmpq $-0x7fff, %rcx          # imm = 0x8001
jl 0x3f18
subq 0x8(%rsp), %rcx
movq %rcx, 0x1a78(%r14,%rax,8)
movq 0x80(%r14,%rbp,8), %rdi
movl 0x90(%r14), %edx
decl %edx
andw $0x0, (%rdi,%rdx,2)
addq %rdx, %rdx
xorl %r15d, %r15d
xorl %esi, %esi
callq 0x1090
movq 0x50(%r14,%rbp,8), %rax
movzbl (%rax), %esi
movl %esi, 0x8c(%r14)
movl 0x9c(%r14), %ecx
shll %cl, %esi
movl 0x98(%r14), %edx
movzbl 0x1(%rax), %edi
xorl %esi, %edi
andl %edx, %edi
movl %edi, 0x8c(%r14)
movq 0x60(%r14,%rbp,8), %rsi
addq $-0x3, %rsi
movl %r15d, %r8d
cmpq %r8, %rsi
jb 0x3fc1
shll %cl, %edi
leal 0x2(%r15), %r8d
movzbl (%rax,%r8), %r8d
xorl %edi, %r8d
andl %edx, %r8d
movl %r8d, 0x8c(%r14)
movq 0x70(%r14,%rbp,8), %rdi
movq 0x80(%r14,%rbp,8), %r9
movzwl (%r9,%r8,2), %r10d
movl 0x44(%r14), %r11d
andl %r15d, %r11d
movzwl %r11w, %r11d
movw %r10w, (%rdi,%r11,2)
movw %r15w, (%r9,%r8,2)
incl %r15d
movl %r8d, %edi
jmp 0x3f72
movb $0x0, 0x1aa8(%r14,%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x3e80(%rbx,%rbp,8)
andq $0x0, 0x3e98(%rbx,%rbp,4)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq