// File: /workspace/github_c_makefile_star2_O2/snej[P]zdelta/deflate.c
// Function: delta_deflate_fast
local block_state delta_deflate_fast(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->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->match_benefit>0){ 
      /* update best_ptr, but only if it is a base copy */
      if(s->match_ptr != ZD_TARP){
	rw = s->match_ptr/2;
	/* output reference window match */
	_tr_tally_dist_ref(s, s->match_distance, s->match_length-3,
			   ZCODE(s->match_sign,s->match_ptr), bflush);
	/* update reference pointers */
	UPDATE_REF_POINTERS(s->match_ptr, s->match_start, 
			    s->match_length, s->match_distance);
 
	/* slide reference data here */
	if(strm->base_avail[rw] > 0) 
	  slide_ref_window(s, &ph, rw, s->match_length, s->match_start);
      }
      else{
	/* output target match */
	_tr_tally_dist_tar(s, s->match_distance, s->match_length-3, bflush);
      }

      s->lookahead -= s->match_length;

      /* Insert new strings in the hash table only if the match length
       * is not too large. This saves time but degrades compression.
       */
      if (s->match_length <= s->max_insert_length &&
	  s->lookahead >= MIN_MATCH) {
	s->match_length--;
	do {
	  s->strstart++;
	  INSERT_STRING(s, s->strstart, hash_head);
	} while (--s->match_length != 0);
	s->strstart++;   
	s->match_distance = ZD_UNREACHABLE;
	s->match_benefit  = 0;
      }
      else{
	s->strstart+=s->match_length;
	s->match_length   = MIN_MATCH-1;
	s->match_distance = ZD_UNREACHABLE;
	s->match_benefit  = 0;
	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 lookahead < MIN_MATCH, ins_h is garbage, but it does not
	* matter since it will be recomputed at next deflate call.
	*/
      }
    }
    else{
      _tr_tally_lit(s, s->window[s->strstart], bflush);
      s->strstart++;
      s->lookahead--;
    }
    if (bflush) FLUSH_BLOCK(s, 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 $0x3eb8, %rsp           # imm = 0x3EB8
movl %esi, %ebx
movq %rdi, %r14
movq (%rdi), %rax
movq %rax, 0x8(%rsp)
movl 0x48(%rax), %r15d
xorl %eax, %eax
testl %r15d, %r15d
cmovlel %eax, %r15d
xorps %xmm0, %xmm0
cmpq %rax, %r15
je 0x271e
movups %xmm0, 0x3e90(%rsp,%rax,8)
andl $0x0, 0x3eb0(%rsp,%rax,4)
andq $0x0, 0x3ea8(%rsp,%rax,4)
incq %rax
jmp 0x26fb
movl $0x100, %r13d           # imm = 0x100
movl $0x140, %eax            # imm = 0x140
leaq 0x6c90(%rip), %rcx      # 0x93c0
addq %rax, %rcx
movq %rcx, (%rsp)
cmpl $0x1005, 0xbc(%r14) # imm = 0x1005
ja 0x277b
testl %ebx, %ebx
sete %bpl
movq %r14, %rdi
callq 0x34e5
movl 0xbc(%r14), %eax
cmpl $0x1006, %eax           # imm = 0x1006
setb %cl
testb %cl, %bpl
jne 0x2cde
testl %eax, %eax
je 0x2ce2
cmpl $0x3, %eax
jb 0x2842
cmpl $0x0, 0xf8(%r14)
je 0x2842
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 %edx, 0x88(%r14)
movq 0x78(%r14), %rax
movzwl (%rax,%rdx,2), %ebp
movl 0x40(%r14), %esi
andl %ecx, %esi
movw %bp, (%rdi,%rsi,2)
movw %cx, (%rax,%rdx,2)
xorl %r12d, %r12d
cmpq %r12, %r15
je 0x2814
movq 0x80(%r14,%r12,8), %rax
movl 0x88(%r14), %ecx
movzwl (%rax,%rcx,2), %esi
testl %esi, %esi
je 0x280f
movl 0xa8(%r14), %eax
cmpl 0xf0(%r14), %eax
jae 0x280f
movq %r14, %rdi
movl %r12d, %edx
callq 0x36b3
incq %r12
jmp 0x27d8
testl %ebp, %ebp
je 0x2842
movl 0xa8(%r14), %eax
cmpl 0xf0(%r14), %eax
jae 0x2842
movl 0xb4(%r14), %eax
subl %ebp, %eax
cmpl $0x8000, %eax           # imm = 0x8000
ja 0x2842
movq %r14, %rdi
movl %ebp, %esi
callq 0x3a97
cmpl $0x0, 0xe0(%r14)
jle 0x28c3
movl 0xc0(%r14), %ecx
cmpl $0x2, %ecx
jne 0x2937
movl 0xa8(%r14), %edx
addl $-0x3, %edx
movq 0xd0(%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, %esi
cmpw $0xff, %dx
ja 0x29a8
addq 0xb6fd(%rip), %rsi      # 0xdfb8
movq %rsi, %rdi
jmp 0x29c8
movq 0x48(%r14), %rax
movl 0xb4(%r14), %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), %ecx
movl 0xb4(%r14), %eax
decl 0xbc(%r14)
addl $-0x2, %ecx
incl %eax
movl %eax, 0xb4(%r14)
cmpl %ecx, %edx
jne 0x2737
jmp 0x2c92
movl %ecx, %eax
cltd
pushq $0x2
popq %rsi
idivl %esi
movl 0xa8(%r14), %esi
addl $-0x3, %esi
movq 0xd0(%r14), %rdx
movq 0x1a48(%r14), %rdi
movl 0x1a44(%r14), %r8d
movw %dx, (%rdi,%r8,2)
orl 0xc8(%r14), %ecx
movq 0x1a50(%r14), %rdi
movb %cl, (%rdi,%r8)
movq 0x1a38(%r14), %rdi
movl 0x1a44(%r14), %ecx
leal 0x1(%rcx), %r8d
movl %r8d, 0x1a44(%r14)
movw %si, (%rdi,%rcx,2)
movzwl %si, %edi
cmpw $0xff, %si
ja 0x2a12
addq 0xb615(%rip), %rdi      # 0xdfb8
jmp 0x2a3e
movq (%rsp), %rdi
cmpw $0xfff, %dx             # imm = 0xFFF
je 0x29c8
shrl $0x6, %esi
leaq 0x6a03(%rip), %rdx      # 0x93c0
leaq (%rsi,%rdx), %rdi
addq $0x100, %rdi            # imm = 0x100
movzbl (%rdi), %edx
incw 0x104(%r14,%rdx,4)
movzwl %cx, %edx
movl %edx, %esi
shrl $0x7, %esi
addl %r13d, %esi
cmpl %r13d, %edx
movzwl %cx, %ecx
cmovbq %rcx, %rsi
leaq 0x67d0(%rip), %rcx      # 0x91c0
movzbl (%rcx,%rsi), %ecx
incw 0x884(%r14,%rcx,4)
movl 0x1a40(%r14), %ecx
addl $-0x2, %ecx
cmpl %ecx, %eax
sete %bpl
jmp 0x2b44
cmpw $0xfff, %si             # imm = 0xFFF
jne 0x2a2a
leaq 0x69a0(%rip), %rsi      # 0x93c0
movl $0x140, %edi            # imm = 0x140
addq %rsi, %rdi
jmp 0x2a3e
shrl $0x6, %edi
leaq 0x698c(%rip), %rsi      # 0x93c0
addq %rsi, %rdi
addq $0x100, %rdi            # imm = 0x100
movzbl (%rdi), %r8d
movslq 0xc0(%r14), %rsi
movl 0xc8(%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
addl %r13d, %r9d
cmpl %r13d, %r8d
movzwl %dx, %edx
cmovbq %rdx, %r9
leaq 0x6737(%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 %bpl
cmpq $0x101, 0xd0(%r14) # imm = 0x101
jb 0x2ad6
cmpl $0x0, 0x1a88(%r14,%rsi,4)
je 0x2b01
andl $0x0, 0x1a88(%r14,%rsi,4)
jmp 0x2b17
movl $0x1, 0x1a88(%r14,%rsi,4)
movl 0xa8(%r14), %ecx
addl 0xb8(%r14), %ecx
movslq 0xc0(%r14), %rdx
movq %rcx, 0x1a78(%r14,%rdx,8)
jmp 0x2b17
movl 0xa8(%r14), %ecx
addl 0xb8(%r14), %ecx
movq %rcx, 0x1a78(%r14,%rsi,8)
movslq %eax, %rcx
movq 0x8(%rsp), %rdx
cmpq $0x0, 0x40(%rdx,%rcx,8)
je 0x2b44
movl 0xa8(%r14), %ecx
movl 0xb8(%r14), %r8d
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
movl %eax, %edx
callq 0x3d31
movl 0xa8(%r14), %edx
movl 0xbc(%r14), %eax
subl %edx, %eax
movl %eax, 0xbc(%r14)
cmpl 0xf0(%r14), %edx
setbe %cl
cmpl $0x3, %eax
setae %al
andb %cl, %al
cmpb $0x1, %al
jne 0x2c26
movl %ebx, %r13d
leal -0x1(%rdx), %eax
movl %eax, 0xa8(%r14)
movl 0x9c(%r14), %ecx
movq 0x48(%r14), %rsi
movl 0x98(%r14), %edi
movq 0x78(%r14), %r8
movq 0x68(%r14), %r9
movl 0x40(%r14), %r10d
movl 0xb4(%r14), %eax
movl 0x88(%r14), %r11d
addl $-0x2, %edx
incl %eax
shll %cl, %r11d
movl %eax, 0xb4(%r14)
leal 0x2(%rax), %r12d
movzbl (%rsi,%r12), %r12d
xorl %r11d, %r12d
andl %edi, %r12d
movl %r12d, 0x88(%r14)
movzwl (%r8,%r12,2), %r11d
movl %r10d, %ebx
andl %eax, %ebx
movw %r11w, (%r9,%rbx,2)
movw %ax, (%r8,%r12,2)
movl %edx, 0xa8(%r14)
incl %eax
movl %r12d, %r11d
addl $-0x1, %edx
jb 0x2bb3
movl %eax, 0xb4(%r14)
movq $0x8000, 0xd0(%r14) # imm = 0x8000
andl $0x0, 0xe0(%r14)
testb %bpl, %bpl
movl %r13d, %ebx
movl $0x100, %r13d           # imm = 0x100
je 0x2737
jmp 0x2c92
movl 0xb4(%r14), %esi
leal (%rsi,%rdx), %eax
movl %eax, 0xb4(%r14)
movl $0x2, 0xa8(%r14)
movq $0x8000, 0xd0(%r14) # imm = 0x8000
andl $0x0, 0xe0(%r14)
movq 0x48(%r14), %rdi
movzbl (%rdi,%rax), %r8d
movl %r8d, 0x88(%r14)
movb 0x9c(%r14), %cl
shll %cl, %r8d
leal (%rsi,%rdx), %ecx
incl %ecx
movzbl (%rdi,%rcx), %ecx
xorl %r8d, %ecx
andl 0x98(%r14), %ecx
movl %ecx, 0x88(%r14)
testb %bpl, %bpl
je 0x2737
movq 0xa0(%r14), %rcx
testq %rcx, %rcx
js 0x2ca6
movl %ecx, %esi
addq 0x48(%r14), %rsi
jmp 0x2ca8
xorl %esi, %esi
movl %eax, %edx
subq %rcx, %rdx
xorl %ebp, %ebp
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x49d2
movl 0xb4(%r14), %eax
movq %rax, 0xa0(%r14)
movq (%r14), %rdi
callq 0x24c9
movq (%r14), %rax
cmpl $0x0, 0x20(%rax)
jne 0x2737
jmp 0x2d4d
xorl %ebp, %ebp
jmp 0x2d4d
movq 0xa0(%r14), %rax
testq %rax, %rax
js 0x2cf6
movl %eax, %esi
addq 0x48(%r14), %rsi
jmp 0x2cf8
xorl %esi, %esi
movl 0xb4(%r14), %edx
subq %rax, %rdx
xorl %ecx, %ecx
cmpl $0x4, %ebx
sete %cl
movq %r14, %rdi
callq 0x49d2
movl 0xb4(%r14), %eax
movq %rax, 0xa0(%r14)
movq (%r14), %rdi
callq 0x24c9
movq (%r14), %rax
cmpl $0x0, 0x20(%rax)
je 0x2d42
xorl %eax, %eax
cmpl $0x4, %ebx
sete %al
leal 0x1(,%rax,2), %ebp
jmp 0x2d4d
xorl %ebp, %ebp
cmpl $0x4, %ebx
sete %bpl
addl %ebp, %ebp
movl %ebp, %eax
addq $0x3eb8, %rsp           # imm = 0x3EB8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq