// File: /workspace/github_c_makefile_star2_O2/snej[P]zdelta/deflate.c
// Function: target_longest_match
local void target_longest_match(s, cur_match)
     deflate_state *s;
     IPos cur_match;
{
  register Bytef *scan = s->window + s->strstart;/* current string */
  register Bytef *match;                         /* matched string */
  register uInt len;                             /* length of current match */
  register uInt chain_length = s->max_chain_length;/* max hash chain length */
  uInt nice_match            = s->nice_match;    /*stop if match long enough */
  register int benefit;
  register int strategy = s->strategy; /* expected length for literal codes */
  uInt best_len      = s->match_length;
  uInt best_distance = s->match_distance;
  int best_benefit   = s->match_benefit;
  IPos best_match = 0;
  
  uInt cur_distance ;	       /* the shortest distance to the current match */

  IPos limit;
  Posf *prev = s->prev;
  uInt wmask = s->w_mask;
    
  register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  register Byte scan_end1  = scan[best_len-1];
    
  Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  Assert(cur_match < s->strstart, "no future");

  limit = s->strstart > (IPos)ZD_UNREACHABLE ? 
    s->strstart - ((IPos) ZD_UNREACHABLE) : NIL;
    
  /* Do not waste too much time if we already have a good match: */
  if (best_len >= s->good_match) {
    chain_length >>= 2;
  }
  /* Do not look for matches beyond the end of the input. This is necessary
   * to make deflate deterministic.
   */
  if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;

  do {
    match = s->window + cur_match;
    /* Skip to next match if the match length cannot increase
     * or if the match length is less than 2:
     */
    
    if (match[best_len-1] != scan_end1 ||	
	*match            != *scan     ||
	*++match          != scan[1])      continue;
      
    /* The check at best_len-1 can be removed because it will be made
     * again later. (This heuristic is not always a win.)
     * It is not necessary to compare scan[2] and match[2] since they
     * are always equal when the other bytes match, given that
     * the hash keys are equal and that HASH_BITS >= 8.
     */
    scan += 2, match++;
    Assert(*scan == *match, "match[2]?");


    /* We check for insufficient lookahead only every 8th comparison;
     * the 256th check will be made at strstart+258.
     */
    do {
    } while (*++scan == *++match && *++scan == *++match &&
	     *++scan == *++match && *++scan == *++match &&
	     *++scan == *++match && *++scan == *++match &&
	     *++scan == *++match && *++scan == *++match &&
	     scan < strend);
      
    Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
    
    len = MAX_MATCH - (int)(strend - scan);
    if (len > s->lookahead) { len = s->lookahead; }
    scan = strend - MAX_MATCH;
 
    cur_distance = s->strstart - cur_match;
    GetBenefit(len, cur_distance);

    if (benefit > best_benefit || \
	(benefit == best_benefit && cur_distance < best_distance)) {

      best_match    = cur_match;
      best_distance = cur_distance;
      best_benefit   = benefit;

      if ((uInt)len >= nice_match){
	best_len=nice_match;
	break;
      } 
      best_len = len;
      scan_end1  = scan[best_len-1];	
    }
  } while ((cur_match = prev[cur_match & wmask]) > limit &&
	   --chain_length);

  if(best_benefit != s->match_benefit || best_distance != s->match_distance){
    s->match_ptr      = ZD_TARP;
    s->match_length   = best_len;
    s->match_distance = best_distance;
    s->match_sign     = ZD_MINUS;
    s->match_start    = best_match;
    s->match_benefit  = best_benefit;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq 0x48(%rdi), %r8
movl 0xb4(%rdi), %r15d
leaq (%r8,%r15), %r11
movl 0xec(%rdi), %eax
movl 0x100(%rdi), %ebp
movl 0xf8(%rdi), %ecx
movl %ecx, -0x24(%rsp)
movl 0xa8(%rdi), %r9d
movq 0xd0(%rdi), %rdx
movl 0xe0(%rdi), %ebx
leal -0x1(%r9), %ecx
movb (%rcx,%r11), %r13b
xorl %r10d, %r10d
movl %r15d, %r14d
subl $0x8000, %r14d          # imm = 0x8000
movl $0x0, %ecx
movq %rcx, -0x30(%rsp)
cmovbl %r10d, %r14d
movl %eax, %r12d
shrl $0x2, %r12d
cmpl 0xfc(%rdi), %r9d
cmovbl %eax, %r12d
movl 0xbc(%rdi), %eax
cmpl %eax, %ebp
cmovael %eax, %ebp
movl %ebp, -0x34(%rsp)
movq 0x68(%rdi), %rbp
movl 0x40(%rdi), %r10d
movq %r15, -0x8(%rsp)
leaq 0x1002(%r8,%r15), %rcx
movq %rcx, -0x10(%rsp)
leaq 0xa(%r8), %rcx
movq %rcx, -0x18(%rsp)
movq %rdx, -0x20(%rsp)
movl %edx, -0x38(%rsp)
movl %ebx, -0x28(%rsp)
movl %ebx, -0x3c(%rsp)
movl %esi, %edx
leaq (%r8,%rdx), %rcx
leal -0x1(%r9), %ebx
cmpb %r13b, (%rbx,%rcx)
jne 0x3cad
movb (%rcx), %bl
cmpb (%r11), %bl
jne 0x3cad
movb 0x1(%rcx), %cl
cmpb 0x1(%r11), %cl
jne 0x3cad
addq -0x18(%rsp), %rdx
xorl %ebx, %ebx
movb 0x3(%r11,%rbx), %cl
cmpb -0x7(%rdx,%rbx), %cl
jne 0x3bfb
movb 0x4(%r11,%rbx), %cl
cmpb -0x6(%rdx,%rbx), %cl
jne 0x3c05
movb 0x5(%r11,%rbx), %cl
cmpb -0x5(%rdx,%rbx), %cl
jne 0x3c0f
movb 0x6(%r11,%rbx), %cl
cmpb -0x4(%rdx,%rbx), %cl
jne 0x3c19
movb 0x7(%r11,%rbx), %cl
cmpb -0x3(%rdx,%rbx), %cl
jne 0x3c23
movb 0x8(%r11,%rbx), %cl
cmpb -0x2(%rdx,%rbx), %cl
jne 0x3c2d
movb 0x9(%r11,%rbx), %cl
cmpb -0x1(%rdx,%rbx), %cl
jne 0x3c37
leaq 0x2(%rbx), %r15
leaq 0x8(%rbx), %rcx
cmpq $0xff9, %r15            # imm = 0xFF9
ja 0x3bf1
movb (%rdx,%rbx), %r15b
cmpb %r15b, 0xa(%r11,%rbx)
movq %rcx, %rbx
je 0x3b85
leaq (%r11,%rcx), %rdx
addq $0x2, %rdx
jmp 0x3c3f
leaq (%r11,%rbx), %rdx
addq $0x3, %rdx
jmp 0x3c3f
leaq (%r11,%rbx), %rdx
addq $0x4, %rdx
jmp 0x3c3f
leaq (%r11,%rbx), %rdx
addq $0x5, %rdx
jmp 0x3c3f
leaq (%r11,%rbx), %rdx
addq $0x6, %rdx
jmp 0x3c3f
leaq (%r11,%rbx), %rdx
addq $0x7, %rdx
jmp 0x3c3f
leaq (%r11,%rbx), %rdx
addq $0x8, %rdx
jmp 0x3c3f
leaq (%r11,%rbx), %rdx
addq $0x9, %rdx
subl -0x10(%rsp), %edx
addl $0x1002, %edx           # imm = 0x1002
movq -0x8(%rsp), %rcx
movl %ecx, %ebx
subl %esi, %ebx
cmpl %edx, %eax
movl %edx, %r15d
cmovbl %eax, %r15d
imull -0x24(%rsp), %r15d
addl $-0xb, %r15d
movl %ebx, %ecx
cmpl $0x2, %ecx
jb 0x3c73
shrl %ecx
decl %r15d
jmp 0x3c67
cmpl %eax, %edx
movl %eax, %ecx
cmovbl %edx, %ecx
cmpl -0x3c(%rsp), %r15d
jg 0x3c89
jne 0x3cad
cmpl -0x38(%rsp), %ebx
jae 0x3cad
cmpl -0x34(%rsp), %edx
jae 0x3d1a
leal -0x1(%rcx), %edx
movb (%r11,%rdx), %r13b
movl %ecx, %r9d
movl %ebx, -0x38(%rsp)
movl %r15d, -0x3c(%rsp)
movl %esi, %ecx
movq %rcx, -0x30(%rsp)
andl %r10d, %esi
movzwl (%rbp,%rsi,2), %esi
cmpl %esi, %r14d
jae 0x3cc3
decl %r12d
jne 0x3b52
movl -0x38(%rsp), %eax
movl -0x3c(%rsp), %ecx
cmpl -0x28(%rsp), %ecx
jne 0x3cd8
cmpq %rax, -0x20(%rsp)
je 0x3d0f
movl $0x2, 0xc0(%rdi)
movl %r9d, 0xa8(%rdi)
movq %rax, 0xd0(%rdi)
movl $0x80, 0xc8(%rdi)
movq -0x30(%rsp), %rax
movl %eax, 0xb8(%rdi)
movl -0x3c(%rsp), %eax
movl %eax, 0xe0(%rdi)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl -0x34(%rsp), %eax
movl %eax, %r9d
movl %ebx, -0x38(%rsp)
movl %r15d, -0x3c(%rsp)
movq %rsi, -0x30(%rsp)
jmp 0x3cc3