// File: /workspace/github_c_makefile_star2_O3/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 $0x28, %rsp
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
movslq %ecx, %rax
movslq %edx, %r13
addq %rax, 0x3e80(%rsi,%r13,8)
movq 0x60(%rdi,%r13,8), %rcx
movslq %r8d, %rdx
negq %rdx
addq %rdx, %rcx
addq $-0x1002, %rcx          # imm = 0xEFFE
imulq %rax, %rcx
addq %rcx, 0x3e88(%rsi,%r13,8)
movslq 0x3e98(%rsi,%r13,4), %rdi
imulq $0x1f40, %r13, %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,%r13,4)
movslq 0x3e9c(%rbx,%r13,4), %rdi
cmpl %edi, %ecx
sete %r8b
movq 0x3e80(%rbx,%r13,8), %rcx
cmpq $0x1389, %rcx           # imm = 0x1389
setae %r9b
orb %r8b, %r9b
cmpb $0x1, %r9b
jne 0x3f5d
leaq 0x1f40(%rbx), %r8
movq (%rsi,%rdi,8), %rsi
subq %rsi, %rcx
movq %rcx, 0x3e80(%rbx,%r13,8)
addq %rdx, %r8
movq (%r8,%rdi,8), %rdx
subq %rdx, 0x3e88(%rbx,%r13,8)
leal 0x1(%rdi), %edx
cmpl $0x3e8, %edx            # imm = 0x3E8
cmovnel %edx, %eax
movl %eax, 0x3e9c(%rbx,%r13,4)
movl 0x3ea0(%rbx,%r13,4), %eax
incl %eax
movl %eax, 0x3ea0(%rbx,%r13,4)
cmpl $0x2, %eax
jne 0x4166
movl $0x0, 0x3ea0(%rbx,%r13,4)
movq 0x3e88(%rbx,%r13,8), %rax
xorl %edx, %edx
divq %rcx
movq %rax, 0x3e90(%rbx)
cmpq $0x55ef, %rax           # imm = 0x55EF
ja 0x4166
cmpq $0x7d1, 0x3e80(%rbx,%r13,8) # imm = 0x7D1
jb 0x4166
addl %ebp, %ebp
movslq %ebp, %rcx
movslq 0x38(%r14), %r12
cmpq %r12, 0x1a78(%r14,%rcx,8)
jg 0x3fde
movl %ebp, %eax
orl $0x1, %eax
cltq
cmpq %r12, 0x1a78(%r14,%rax,8)
jle 0x4166
movq %rcx, 0x20(%rsp)
movq 0x50(%r14,%r13,8), %rdi
movl %r12d, %edx
leaq (%rdi,%rdx), %rsi
movq %rdx, 0x8(%rsp)
callq 0x10f0
movq (%r14), %rcx
movq 0x40(%rcx,%r13,8), %rax
cmpl %r12d, %eax
movl %r12d, %r15d
cmovbl %eax, %r15d
testl %r15d, %r15d
je 0x404d
movq 0x50(%r14,%r13,8), %rdi
addq 0x8(%rsp), %rdi
movl %r15d, %edx
movq %rdx, 0x18(%rsp)
subq %rdx, %rax
movq %rax, 0x40(%rcx,%r13,8)
movq 0x30(%rcx,%r13,8), %rsi
movq %rcx, 0x10(%rsp)
callq 0x10f0
movq 0x18(%rsp), %rax
movq 0x10(%rsp), %rcx
addq %rax, 0x30(%rcx,%r13,8)
addq %rax, 0x38(%rcx,%r13,8)
addl %r12d, %r15d
movq %r15, 0x60(%r14,%r13,8)
movq 0x20(%rsp), %rcx
movq 0x1a78(%r14,%rcx,8), %rax
cmpq $-0x7fff, %rax          # imm = 0x8001
movq 0x8(%rsp), %rdx
jl 0x407a
subq %rdx, %rax
movq %rax, 0x1a78(%r14,%rcx,8)
orl $0x1, %ebp
movslq %ebp, %rax
movq 0x1a78(%r14,%rax,8), %rcx
cmpq $-0x7fff, %rcx          # imm = 0x8001
jl 0x409c
subq %rdx, %rcx
movq %rcx, 0x1a78(%r14,%rax,8)
movq 0x80(%r14,%r13,8), %rdi
movl 0x90(%r14), %edx
decl %edx
movw $0x0, (%rdi,%rdx,2)
addq %rdx, %rdx
xorl %r15d, %r15d
xorl %esi, %esi
callq 0x1090
movq 0x50(%r14,%r13,8), %rax
movzbl (%rax), %esi
movl %esi, 0x8c(%r14)
movl 0x98(%r14), %edx
movl 0x9c(%r14), %ecx
shll %cl, %esi
movzbl 0x1(%rax), %r10d
xorl %esi, %r10d
andl %edx, %r10d
movl %r10d, 0x8c(%r14)
movq 0x60(%r14,%r13,8), %rsi
movq 0x70(%r14,%r13,8), %rdi
addq $-0x3, %rsi
movq 0x80(%r14,%r13,8), %r8
movzwl 0x44(%r14), %r9d
shll %cl, %r10d
leal 0x2(%r15), %r11d
movzbl (%rax,%r11), %r11d
xorl %r10d, %r11d
andl %edx, %r11d
movl %r11d, 0x8c(%r14)
movzwl (%r8,%r11,2), %r10d
movl %r9d, %r12d
andl %r15d, %r12d
movw %r10w, (%rdi,%r12,2)
movw %r15w, (%r8,%r11,2)
incl %r15d
movl %r11d, %r10d
cmpq %r15, %rsi
jae 0x410c
movb $0x0, 0x1aa8(%r14,%r13)
xorps %xmm0, %xmm0
movups %xmm0, 0x3e80(%rbx,%r13,8)
movq $0x0, 0x3e98(%rbx,%r13,4)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)