// File: /workspace/github_c_makefile_star2_O3/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), %r10
movl 0xec(%rdi), %edx
movl 0x100(%rdi), %ebx
movl 0xf8(%rdi), %eax
movl %eax, -0x24(%rsp)
movl 0xa8(%rdi), %eax
movq 0xd0(%rdi), %r9
movl 0xe0(%rdi), %r11d
leal -0x1(%rax), %ecx
xorl %r14d, %r14d
movl %r15d, %ebp
subl $0x8000, %ebp           # imm = 0x8000
cmovbl %r14d, %ebp
movl %edx, %r12d
shrl $0x2, %r12d
cmpl 0xfc(%rdi), %eax
cmovbl %edx, %r12d
movl 0xbc(%rdi), %edx
cmpl %edx, %ebx
movl %edx, -0x28(%rsp)
cmovael %edx, %ebx
movl %ebx, -0x30(%rsp)
movb (%rcx,%r10), %bl
movq 0x68(%rdi), %r14
movl 0x40(%rdi), %r13d
movq %r15, -0x8(%rsp)
leaq 0x1002(%r8,%r15), %rcx
movq %rcx, -0x10(%rsp)
leaq 0xa(%r8), %rcx
movq %rcx, -0x18(%rsp)
movq %r9, -0x20(%rsp)
movl %r9d, -0x38(%rsp)
movl %r11d, -0x2c(%rsp)
movl %r11d, -0x3c(%rsp)
movl $0x0, -0x34(%rsp)
movl %esi, %r11d
leaq (%r8,%r11), %rcx
leal -0x1(%rax), %edx
cmpb %bl, (%rdx,%rcx)
jne 0x3dfe
movb (%rcx), %dl
cmpb (%r10), %dl
jne 0x3dfe
movb 0x1(%rcx), %cl
cmpb 0x1(%r10), %cl
jne 0x3dfe
addq -0x18(%rsp), %r11
xorl %edx, %edx
movb 0x3(%r10,%rdx), %cl
cmpb -0x7(%r11,%rdx), %cl
jne 0x3d3e
movb 0x4(%r10,%rdx), %cl
cmpb -0x6(%r11,%rdx), %cl
jne 0x3d48
movb 0x5(%r10,%rdx), %cl
cmpb -0x5(%r11,%rdx), %cl
jne 0x3d52
movb 0x6(%r10,%rdx), %cl
cmpb -0x4(%r11,%rdx), %cl
jne 0x3d5c
movb 0x7(%r10,%rdx), %cl
cmpb -0x3(%r11,%rdx), %cl
jne 0x3d66
movb 0x8(%r10,%rdx), %cl
cmpb -0x2(%r11,%rdx), %cl
jne 0x3d70
movb 0x9(%r10,%rdx), %cl
cmpb -0x1(%r11,%rdx), %cl
jne 0x3d7a
leaq 0x2(%rdx), %r15
leaq 0x8(%rdx), %rcx
cmpq $0xff9, %r15            # imm = 0xFF9
ja 0x3d34
movb (%r11,%rdx), %r15b
cmpb %r15b, 0xa(%r10,%rdx)
movq %rcx, %rdx
je 0x3cc1
leaq (%r10,%rcx), %r11
addq $0x2, %r11
jmp 0x3d82
leaq (%r10,%rdx), %r11
addq $0x3, %r11
jmp 0x3d82
leaq (%r10,%rdx), %r11
addq $0x4, %r11
jmp 0x3d82
leaq (%r10,%rdx), %r11
addq $0x5, %r11
jmp 0x3d82
leaq (%r10,%rdx), %r11
addq $0x6, %r11
jmp 0x3d82
leaq (%r10,%rdx), %r11
addq $0x7, %r11
jmp 0x3d82
leaq (%r10,%rdx), %r11
addq $0x8, %r11
jmp 0x3d82
leaq (%r10,%rdx), %r11
addq $0x9, %r11
subl -0x10(%rsp), %r11d
addl $0x1002, %r11d          # imm = 0x1002
movl -0x28(%rsp), %ecx
cmpl %ecx, %r11d
movl %ecx, %r9d
cmovbl %r11d, %r9d
movq -0x8(%rsp), %rcx
movl %ecx, %edx
subl %esi, %edx
bsrl %edx, %r15d
xorl $0x1f, %r15d
addl $-0x1f, %r15d
cmpl $0x2, %edx
movl $0x0, %ecx
cmovbl %ecx, %r15d
movl %r9d, %ecx
imull -0x24(%rsp), %ecx
addl %ecx, %r15d
addl $-0xb, %r15d
cmpl -0x3c(%rsp), %r15d
jg 0x3ddb
jne 0x3dfe
cmpl -0x38(%rsp), %edx
jae 0x3dfe
cmpl -0x30(%rsp), %r11d
jae 0x3e68
leal -0x1(%r9), %eax
movb (%r10,%rax), %bl
movl %r9d, %eax
movl %edx, -0x38(%rsp)
movl %r15d, -0x3c(%rsp)
movl %esi, -0x34(%rsp)
andl %r13d, %esi
movzwl (%r14,%rsi,2), %esi
cmpl %esi, %ebp
jae 0x3e13
decl %r12d
jne 0x3c8f
movl -0x38(%rsp), %ecx
movl -0x3c(%rsp), %edx
cmpl -0x2c(%rsp), %edx
jne 0x3e28
cmpq %rcx, -0x20(%rsp)
je 0x3e5d
movl $0x2, 0xc0(%rdi)
movl %eax, 0xa8(%rdi)
movq %rcx, 0xd0(%rdi)
movl $0x80, 0xc8(%rdi)
movl -0x34(%rsp), %eax
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 -0x30(%rsp), %eax
movl %edx, -0x38(%rsp)
movl %r15d, -0x3c(%rsp)
movl %esi, -0x34(%rsp)
jmp 0x3e13