// File: /workspace/github_c_makefile_star2_O1/snej[P]zdelta/deflate.c
// Function: delta_deflate_slow
local block_state delta_deflate_slow(deflate_state *s, int flush){

  IPos hash_head = NIL;
  int bflush;           /* set if current block must be flushed */
  zd_streamp strm = s->strm;
  int refnum = strm->refnum;
  int rw; 
  /* data structures containing statistics for the sliding reference window */
  pointer_history ph;

  for(rw=0; rw<refnum; ++rw){
    ph.sum_len[rw]   = ph.sum_ptr[rw]  = 0;
    ph.front_ptr[rw] = ph.back_ptr[rw] = ph.ch_flag[rw] = 0;
  }

  for (;;){

    if (s->lookahead < MIN_LOOKAHEAD) {
      fill_window(s);
      if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
	return need_more;
      }
      if (s->lookahead == 0) break; /* flush the current block */
    }
    
    s->prev_length    = s->match_length;
    s->prev_match     = s->match_start;
    s->prev_ptr       = s->match_ptr;
    s->prev_sign      = s->match_sign;
    s->prev_distance  = s->match_distance;
    s->prev_benefit   = s->match_benefit;
    s->match_length   = MIN_MATCH - 1;
    s->match_distance = ZD_UNREACHABLE;
    s->match_benefit  = 0;
    if (s->lookahead >= MIN_MATCH && s->strategy!=ZD_HUFFMAN_ONLY) {
      INSERT_STRING(s, s->strstart, hash_head);
    
      /* Find the match giving the greates benefit */
      /* search in the reference data    */
      for(rw=0; rw<refnum; ++rw){
	if (s->ref_head[rw][s->ins_h] != NIL && 
	    s->match_length < s->max_lazy_match) 
	{
	  /* To simplify the code, we prevent matches with the string
	   * of window index 0 (in particular we have to avoid a match
	   * of the string with itself at the start of the input file).
	   */
	  reference_longest_match (s, s->ref_head[rw][s->ins_h], rw);
	  /* reference_longest_match() sets match_start, match_ptr, match_sign,
	   * match_length, match_distance
	   */
	}
      }
      /* search in the target data       */
      if (hash_head != NIL &&  s->match_length < s->max_lazy_match && 
	  s->strstart - hash_head <= ZD_UNREACHABLE) {
	/* To simplify the code, we prevent matches with the string
	 * of window index 0 (in particular we have to avoid a match
	 * of the string with itself at the start of the input file).
	 */
	target_longest_match (s, hash_head);
	/* target_longest_match() sets s->match_start, s->match_ptr,
	 * s->match_sign, s->match_length,  s->match_distance
	 */
      }
    }
    /* write the match
     * the minimum length is MIN_MATCH, so we can substract it and we'll
     * still have a positive number
     */
    if(s->prev_benefit>0 && s->prev_benefit>=s->match_benefit){ 
      /* the previous match is better than the current */

      uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
      /* Do not insert strings in hash table beyond this. */

      /* update best_ptr, but only if it is a base copy */
      if(s->prev_ptr != ZD_TARP){

	rw = s->prev_ptr/2;
	/* output reference window match */
	_tr_tally_dist_ref(s, s->prev_distance, s->prev_length-3,
			   ZCODE(s->prev_sign,s->prev_ptr), bflush);
	/* update reference pointers */
	UPDATE_REF_POINTERS(s->prev_ptr, s->prev_match, 
			    s->prev_length, s->prev_distance);

	/* slide reference data here */
	if(strm->base_avail[rw] > 0) 
	  slide_ref_window(s, &ph, rw, s->prev_length, s->prev_match);
      }
      else{
	/* output target match */
	_tr_tally_dist_tar(s, s->prev_distance, s->prev_length-3, bflush);
      }
      /* Insert in hash table all strings up to the end of the match.
       * strstart-1 and strstart are already inserted. If there is not
       * enough lookahead, the last two strings are not inserted in
       * the hash table.
       */
      s->lookahead -= s->prev_length-1;
      s->prev_length -= 2;
      do {
	if (++s->strstart <= max_insert) {
	  INSERT_STRING(s, s->strstart, hash_head);
	}
      } while (--s->prev_length != 0);
      s->match_available = 0;
      s->match_length   = MIN_MATCH-1;
      s->match_distance = ZD_UNREACHABLE;
      s->match_benefit  = 0;
      s->strstart++; 
      if (bflush) FLUSH_BLOCK(s, 0);
    }
    else if(s->match_available){
      /* If there was no match at the previous position, output a
       * single literal. If there was a match but the current match
       * is longer, truncate the previous match to a single literal.
       */
      _tr_tally_lit(s, s->window[s->strstart-1], bflush);
      if (bflush) {
	FLUSH_BLOCK_ONLY(s, 0);
      }
      s->strstart++;
      s->lookahead--;
      if (s->strm->avail_out == 0) return need_more;
    }
    else{
      /* There is no previous match to compare with, wait for
       * the next step to decide.
       */
      s->match_available = 1;
      s->strstart++;
      s->lookahead--;
    }
  }

  if (s->match_available) {
    _tr_tally_lit(s, s->window[s->strstart-1], bflush);
    s->match_available = 0;
  }
  
  FLUSH_BLOCK(s, flush == ZD_FINISH);
  return flush == ZD_FINISH ? finish_done : block_done;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3ec8, %rsp           # imm = 0x3EC8
movl %esi, 0xc(%rsp)
movq %rdi, %r14
movq (%rdi), %rax
movq %rax, 0x18(%rsp)
movslq 0x48(%rax), %r15
testq %r15, %r15
jle 0x2f80
xorl %eax, %eax
xorps %xmm0, %xmm0
movups %xmm0, 0x3ea0(%rsp,%rax,8)
movl $0x0, 0x3ec0(%rsp,%rax,4)
movq $0x0, 0x3eb8(%rsp,%rax,4)
incq %rax
cmpq %rax, %r15
jne 0x2f59
movl %r15d, %r13d
movl $0x140, %eax            # imm = 0x140
leaq 0x6431(%rip), %rcx      # 0x93c0
addq %rax, %rcx
movq %rcx, 0x10(%rsp)
cmpl $0x1005, 0xbc(%r14) # imm = 0x1005
ja 0x2fd3
cmpl $0x0, 0xc(%rsp)
sete %bl
movq %r14, %rdi
callq 0x36cd
movl 0xbc(%r14), %eax
cmpl $0x1006, %eax           # imm = 0x1006
setb %cl
testb %cl, %bl
jne 0x35e6
testl %eax, %eax
je 0x35ed
movl 0xa8(%r14), %eax
movl 0xb8(%r14), %ecx
movl %eax, 0xe4(%r14)
movl %ecx, 0xac(%r14)
movl 0xc0(%r14), %eax
movl %eax, 0xc4(%r14)
movl 0xc8(%r14), %eax
movl %eax, 0xcc(%r14)
movq 0xd0(%r14), %rax
movq %rax, 0xd8(%r14)
movl 0xe0(%r14), %eax
movl %eax, 0xe8(%r14)
movl $0x2, 0xa8(%r14)
movq $0x8000, 0xd0(%r14) # imm = 0x8000
movl $0x0, 0xe0(%r14)
cmpl $0x3, 0xbc(%r14)
jb 0x3120
cmpl $0x0, 0xf8(%r14)
je 0x3120
movl 0x88(%r14), %eax
movb 0x9c(%r14), %cl
shll %cl, %eax
movl 0xb4(%r14), %ecx
leal 0x2(%rcx), %edx
movq 0x48(%r14), %rsi
movq 0x68(%r14), %rdi
movzbl (%rsi,%rdx), %edx
xorl %eax, %edx
andl 0x98(%r14), %edx
movl 0x40(%r14), %eax
andl %ecx, %eax
movl %edx, 0x88(%r14)
movq 0x78(%r14), %rsi
movzwl (%rsi,%rdx,2), %ebp
movw %bp, (%rdi,%rax,2)
movw %cx, (%rsi,%rdx,2)
testl %r15d, %r15d
jle 0x30f2
xorl %r12d, %r12d
movq 0x80(%r14,%r12,8), %rax
movl 0x88(%r14), %ecx
movzwl (%rax,%rcx,2), %esi
testl %esi, %esi
je 0x30ea
movl 0xa8(%r14), %eax
cmpl 0xf0(%r14), %eax
jae 0x30ea
movq %r14, %rdi
movl %r12d, %edx
callq 0x389c
incq %r12
cmpq %r12, %r13
jne 0x30b8
testl %ebp, %ebp
je 0x3120
movl 0xa8(%r14), %eax
cmpl 0xf0(%r14), %eax
jae 0x3120
movl 0xb4(%r14), %eax
subl %ebp, %eax
cmpl $0x8000, %eax           # imm = 0x8000
ja 0x3120
movq %r14, %rdi
movl %ebp, %esi
callq 0x3c72
movl 0xe8(%r14), %eax
testl %eax, %eax
jle 0x3138
cmpl 0xe0(%r14), %eax
jge 0x31bb
cmpl $0x0, 0xb0(%r14)
je 0x3241
movq 0x48(%r14), %rax
movl 0xb4(%r14), %ecx
decl %ecx
movzbl (%rax,%rcx), %eax
movq 0x1a50(%r14), %rcx
movl 0x1a44(%r14), %edx
movb $0x40, (%rcx,%rdx)
movq 0x1a48(%r14), %rcx
movl 0x1a44(%r14), %edx
leal 0x1(%rdx), %esi
movl %esi, 0x1a44(%r14)
movw %ax, (%rcx,%rdx,2)
incw 0x480(%r14,%rax,4)
movl 0x1a40(%r14), %eax
addl $-0x2, %eax
cmpl %eax, %edx
jne 0x32fa
movq 0xa0(%r14), %rax
testq %rax, %rax
js 0x32ce
movl %eax, %esi
addq 0x48(%r14), %rsi
jmp 0x32d0
movl 0xb4(%r14), %r12d
movl 0xbc(%r14), %ebp
movl 0xc4(%r14), %eax
cmpl $0x2, %eax
jne 0x325f
movl 0xe4(%r14), %edx
addl $-0x3, %edx
movq 0xd8(%r14), %rcx
movq 0x1a48(%r14), %rax
movl 0x1a44(%r14), %esi
movw %cx, (%rax,%rsi,2)
movq 0x1a50(%r14), %rax
movb $0x20, (%rax,%rsi)
movq 0x1a38(%r14), %rsi
movl 0x1a44(%r14), %eax
leal 0x1(%rax), %edi
movl %edi, 0x1a44(%r14)
movw %dx, (%rsi,%rax,2)
movzwl %dx, %edx
cmpl $0xff, %edx
ja 0x331a
addq 0xad7f(%rip), %rdx      # 0xdfb8
movq %rdx, %rsi
jmp 0x333b
movl $0x1, 0xb0(%r14)
incl 0xb4(%r14)
decl 0xbc(%r14)
jmp 0x2f97
movl 0xe4(%r14), %esi
addl $-0x3, %esi
movq 0xd8(%r14), %rdx
movq 0x1a48(%r14), %rcx
movl 0x1a44(%r14), %edi
movw %dx, (%rcx,%rdi,2)
movl 0xcc(%r14), %ecx
orl %eax, %ecx
movq 0x1a50(%r14), %r8
movb %cl, (%r8,%rdi)
movq 0x1a38(%r14), %rdi
movl 0x1a44(%r14), %ecx
leal 0x1(%rcx), %r8d
movl %r8d, 0x1a44(%r14)
movw %si, (%rdi,%rcx,2)
movzwl %si, %esi
cmpl $0xff, %esi
ja 0x3387
addq 0xacef(%rip), %rsi      # 0xdfb8
jmp 0x33b4
xorl %esi, %esi
movl 0xb4(%r14), %edx
subq %rax, %rdx
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x4c16
movl 0xb4(%r14), %eax
movq %rax, 0xa0(%r14)
movq (%r14), %rdi
callq 0x267b
incl 0xb4(%r14)
decl 0xbc(%r14)
movq (%r14), %rax
cmpl $0x0, 0x20(%rax)
jne 0x2f97
jmp 0x35e6
movq 0x10(%rsp), %rsi
cmpl $0xfff, %edx            # imm = 0xFFF
je 0x333b
shrl $0x6, %edx
leaq 0x608f(%rip), %rsi      # 0x93c0
addq %rdx, %rsi
addq $0x100, %rsi            # imm = 0x100
movzbl (%rsi), %edx
incw 0x104(%r14,%rdx,4)
movzwl %cx, %edx
movl %edx, %esi
shrl $0x7, %esi
movl $0x100, %edi            # imm = 0x100
addl %edi, %esi
cmpl %edi, %edx
movzwl %cx, %ecx
cmovbq %rcx, %rsi
leaq 0x5e5a(%rip), %rcx      # 0x91c0
movzbl (%rcx,%rsi), %ecx
incw 0x884(%r14,%rcx,4)
movl 0x1a40(%r14), %ecx
addl $-0x2, %ecx
cmpl %ecx, %eax
sete %bl
jmp 0x34c9
cmpl $0xfff, %esi            # imm = 0xFFF
jne 0x33a0
leaq 0x602a(%rip), %rsi      # 0x93c0
movl $0x140, %edi            # imm = 0x140
addq %rdi, %rsi
jmp 0x33b4
shrl $0x6, %esi
leaq 0x6016(%rip), %rdi      # 0x93c0
addq %rdi, %rsi
addq $0x100, %rsi            # imm = 0x100
movzbl (%rsi), %r8d
movslq 0xc4(%r14), %rsi
movl 0xcc(%r14), %edi
orl %esi, %edi
leal 0x25(%r8), %r9d
addl $0x4a, %r8d
testb %dil, %dil
cmovsl %r9d, %r8d
incw 0x104(%r14,%r8,4)
movzwl %dx, %r8d
movl %r8d, %r9d
shrl $0x7, %r9d
movl $0x100, %r10d           # imm = 0x100
addl %r10d, %r9d
cmpl %r10d, %r8d
movzwl %dx, %edx
cmovbq %rdx, %r9
leaq 0x5dbb(%rip), %rdx      # 0x91c0
movzbl (%rdx,%r9), %edx
incw 0x884(%r14,%rdx,4)
andl $0x1f, %edi
incw 0xd7c(%r14,%rdi,4)
movl 0x1a40(%r14), %edx
addl $-0x2, %edx
cmpl %edx, %ecx
sete %bl
cmpq $0x101, 0xd8(%r14) # imm = 0x101
jb 0x3454
cmpl $0x0, 0x1a88(%r14,%rsi,4)
je 0x347f
movl $0x0, 0x1a88(%r14,%rsi,4)
jmp 0x3495
movl $0x1, 0x1a88(%r14,%rsi,4)
movl 0xe4(%r14), %ecx
addl 0xac(%r14), %ecx
movslq 0xc4(%r14), %rdx
movq %rcx, 0x1a78(%r14,%rdx,8)
jmp 0x3495
movl 0xe4(%r14), %ecx
addl 0xac(%r14), %ecx
movq %rcx, 0x1a78(%r14,%rsi,8)
movl %eax, %edx
shrl $0x1f, %edx
addl %eax, %edx
sarl %edx
movslq %edx, %rax
movq 0x18(%rsp), %rcx
cmpq $0x0, 0x40(%rcx,%rax,8)
je 0x34c9
movl 0xac(%r14), %r8d
movl 0xe4(%r14), %ecx
movq %r14, %rdi
leaq 0x20(%rsp), %rsi
callq 0x3f1b
leal (%r12,%rbp), %edx
addl $-0x3, %edx
movl 0xe4(%r14), %esi
movl 0xb4(%r14), %eax
movl 0xbc(%r14), %ecx
subl %esi, %ecx
incl %ecx
movl %ecx, 0xbc(%r14)
leal -0x2(%rsi), %ecx
movl %ecx, 0xe4(%r14)
addl $-0x3, %esi
incl %eax
movl %eax, 0xb4(%r14)
cmpl %edx, %eax
ja 0x3554
movl 0x88(%r14), %edi
movb 0x9c(%r14), %cl
shll %cl, %edi
leal 0x2(%rax), %ecx
movq 0x48(%r14), %r8
movzbl (%r8,%rcx), %ecx
xorl %edi, %ecx
andl 0x98(%r14), %ecx
movq 0x68(%r14), %rdi
movl %ecx, 0x88(%r14)
movq 0x78(%r14), %r8
movzwl (%r8,%rcx,2), %r9d
movl 0x40(%r14), %r10d
andl %eax, %r10d
movw %r9w, (%rdi,%r10,2)
movw %ax, (%r8,%rcx,2)
movl %esi, 0xe4(%r14)
incl %eax
addl $-0x1, %esi
jb 0x34ff
xorl %ecx, %ecx
movl %ecx, 0xb0(%r14)
movl $0x2, 0xa8(%r14)
movq $0x8000, 0xd0(%r14) # imm = 0x8000
movl %ecx, 0xe0(%r14)
movl %eax, 0xb4(%r14)
testb %bl, %bl
je 0x2f97
movq 0xa0(%r14), %rcx
testq %rcx, %rcx
js 0x35ab
movl %ecx, %esi
addq 0x48(%r14), %rsi
jmp 0x35ad
xorl %esi, %esi
movl %eax, %edx
subq %rcx, %rdx
xorl %ebp, %ebp
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x4c16
movl 0xb4(%r14), %eax
movq %rax, 0xa0(%r14)
movq (%r14), %rdi
callq 0x267b
movq (%r14), %rax
cmpl $0x0, 0x20(%rax)
jne 0x2f97
jmp 0x36b9
xorl %ebp, %ebp
jmp 0x36b9
cmpl $0x0, 0xb0(%r14)
je 0x364a
movq 0x48(%r14), %rax
movl 0xb4(%r14), %ecx
decl %ecx
movzbl (%rax,%rcx), %eax
movq 0x1a50(%r14), %rcx
movl 0x1a44(%r14), %edx
movb $0x40, (%rcx,%rdx)
movq 0x1a48(%r14), %rcx
movl 0x1a44(%r14), %edx
leal 0x1(%rdx), %esi
movl %esi, 0x1a44(%r14)
movw %ax, (%rcx,%rdx,2)
incw 0x480(%r14,%rax,4)
movl $0x0, 0xb0(%r14)
movq 0xa0(%r14), %rax
testq %rax, %rax
movl 0xc(%rsp), %ebx
js 0x3662
movl %eax, %esi
addq 0x48(%r14), %rsi
jmp 0x3664
xorl %esi, %esi
movl 0xb4(%r14), %edx
subq %rax, %rdx
xorl %ecx, %ecx
cmpl $0x4, %ebx
sete %cl
movq %r14, %rdi
callq 0x4c16
movl 0xb4(%r14), %eax
movq %rax, 0xa0(%r14)
movq (%r14), %rdi
callq 0x267b
movq (%r14), %rax
cmpl $0x0, 0x20(%rax)
je 0x36ae
xorl %eax, %eax
cmpl $0x4, %ebx
sete %al
leal 0x1(,%rax,2), %ebp
jmp 0x36b9
xorl %ebp, %ebp
cmpl $0x4, %ebx
sete %bpl
addl %ebp, %ebp
movl %ebp, %eax
addq $0x3ec8, %rsp           # imm = 0x3EC8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq