// File: /workspace/github_c_makefile_star2_O1/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
leaq (%rcx,%rdx), %rsi
addq $-0x1002, %rsi          # imm = 0xEFFE
imulq %rax, %rsi
addq %rsi, 0x3e88(%rbx,%r13,8)
movslq 0x3e98(%rbx,%r13,4), %rdi
imulq $0x1f40, %r13, %rcx     # imm = 0x1F40
leaq (%rbx,%rcx), %rdx
movq %rax, (%rdx,%rdi,8)
leaq (%rbx,%rcx), %r8
addq $0x1f40, %r8            # imm = 0x1F40
leal 0x1(%rdi), %r9d
xorl %eax, %eax
cmpl $0x3e8, %r9d            # imm = 0x3E8
cmovel %eax, %r9d
movq %rsi, (%r8,%rdi,8)
movl %r9d, 0x3e98(%rbx,%r13,4)
movslq 0x3e9c(%rbx,%r13,4), %rsi
cmpl %esi, %r9d
je 0x3fbb
cmpq $0x1389, 0x3e80(%rbx,%r13,8) # imm = 0x1389
jb 0x3ff1
movq (%rdx,%rsi,8), %rdx
subq %rdx, 0x3e80(%rbx,%r13,8)
leaq 0x1f40(%rbx), %rdx
addq %rcx, %rdx
movq (%rdx,%rsi,8), %rcx
subq %rcx, 0x3e88(%rbx,%r13,8)
leal 0x1(%rsi), %ecx
cmpl $0x3e8, %ecx            # imm = 0x3E8
cmovnel %ecx, %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 0x4204
movl $0x0, 0x3ea0(%rbx,%r13,4)
movq 0x3e88(%rbx,%r13,8), %rax
xorl %edx, %edx
divq 0x3e80(%rbx,%r13,8)
movq %rax, 0x3e90(%rbx)
cmpq $0x55ef, %rax           # imm = 0x55EF
ja 0x4204
cmpq $0x7d1, 0x3e80(%rbx,%r13,8) # imm = 0x7D1
jb 0x4204
addl %ebp, %ebp
movslq %ebp, %rcx
movslq 0x38(%r14), %r15
cmpq %r15, 0x1a78(%r14,%rcx,8)
jg 0x4077
movl %ebp, %eax
orl $0x1, %eax
cltq
cmpq %r15, 0x1a78(%r14,%rax,8)
jle 0x4204
movq %rcx, 0x20(%rsp)
movq 0x50(%r14,%r13,8), %rdi
movl %r15d, %edx
leaq (%rdi,%rdx), %rsi
movq %rdx, 0x8(%rsp)
callq 0x10f0
movq (%r14), %rcx
movq 0x40(%rcx,%r13,8), %rax
cmpl %r15d, %eax
movl %r15d, %r12d
cmovbl %eax, %r12d
testl %r12d, %r12d
je 0x40e8
movq 0x50(%r14,%r13,8), %rdi
addq 0x8(%rsp), %rdi
movl %r12d, %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)
jmp 0x40eb
xorl %r12d, %r12d
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 0x4118
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 0x413a
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 0x41aa
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
nop