// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x8(%rbp), %rcx
movl 0xb4(%rcx), %ecx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movl 0xec(%rax), %eax
movl %eax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movl 0x100(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movl 0xf8(%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rax
movl 0xa8(%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0xd0(%rax), %rax
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rax
movl 0xe0(%rax), %eax
movl %eax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rax
movl 0x40(%rax), %eax
movl %eax, -0x5c(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x8(%rbp), %rcx
movl 0xb4(%rcx), %ecx
addq %rcx, %rax
addq $0x1002, %rax           # imm = 0x1002
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rax
movl -0x38(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %al
movb %al, -0x69(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x8000, 0xb4(%rax)     # imm = 0x8000
jbe 0x5d15
movq -0x8(%rbp), %rax
movl 0xb4(%rax), %eax
subl $0x8000, %eax           # imm = 0x8000
movl %eax, -0x78(%rbp)
jmp 0x5d1c
xorl %eax, %eax
movl %eax, -0x78(%rbp)
jmp 0x5d1c
movl -0x78(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x38(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0xfc(%rcx), %eax
jb 0x5d3a
movl -0x28(%rbp), %eax
shrl $0x2, %eax
movl %eax, -0x28(%rbp)
movl -0x2c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0xbc(%rcx), %eax
jbe 0x5d56
movq -0x8(%rbp), %rax
movl 0xbc(%rax), %eax
movl %eax, -0x2c(%rbp)
jmp 0x5d58
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movl -0xc(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movl -0x38(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
movzbl -0x69(%rbp), %ecx
cmpl %ecx, %eax
jne 0x5db3
movq -0x20(%rbp), %rax
movzbl (%rax), %eax
movq -0x18(%rbp), %rcx
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jne 0x5db3
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rbp)
movzbl 0x1(%rax), %eax
movq -0x18(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
cmpl %ecx, %eax
je 0x5db8
jmp 0x6051
movq -0x18(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x18(%rbp)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x5dd2
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movzbl 0x1(%rax), %ecx
movq -0x20(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x20(%rbp)
movzbl 0x1(%rax), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x79(%rbp)
jne 0x5f6c
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movzbl 0x1(%rax), %ecx
movq -0x20(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x20(%rbp)
movzbl 0x1(%rax), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x79(%rbp)
jne 0x5f6c
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movzbl 0x1(%rax), %ecx
movq -0x20(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x20(%rbp)
movzbl 0x1(%rax), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x79(%rbp)
jne 0x5f6c
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movzbl 0x1(%rax), %ecx
movq -0x20(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x20(%rbp)
movzbl 0x1(%rax), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x79(%rbp)
jne 0x5f6c
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movzbl 0x1(%rax), %ecx
movq -0x20(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x20(%rbp)
movzbl 0x1(%rax), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x79(%rbp)
jne 0x5f6c
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movzbl 0x1(%rax), %ecx
movq -0x20(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x20(%rbp)
movzbl 0x1(%rax), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x79(%rbp)
jne 0x5f6c
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movzbl 0x1(%rax), %ecx
movq -0x20(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x20(%rbp)
movzbl 0x1(%rax), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x79(%rbp)
jne 0x5f6c
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movzbl 0x1(%rax), %ecx
movq -0x20(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x20(%rbp)
movzbl 0x1(%rax), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x79(%rbp)
jne 0x5f6c
movq -0x18(%rbp), %rax
cmpq -0x68(%rbp), %rax
setb %al
movb %al, -0x79(%rbp)
movb -0x79(%rbp), %al
testb $0x1, %al
jne 0x5dd0
movq -0x68(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
movl %eax, %ecx
movl $0x1002, %eax           # imm = 0x1002
subl %ecx, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0xbc(%rcx), %eax
jbe 0x5faa
movq -0x8(%rbp), %rax
movl 0xbc(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x68(%rbp), %rax
addq $-0x1002, %rax          # imm = 0xEFFE
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movl 0xb4(%rax), %eax
subl -0xc(%rbp), %eax
movl %eax, -0x48(%rbp)
movl $0x0, -0x70(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
shrl %eax
movl %eax, -0x74(%rbp)
cmpl $0x0, %eax
je 0x5fed
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x5fd5
movl -0x34(%rbp), %eax
imull -0x24(%rbp), %eax
subl $0xb, %eax
subl -0x70(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x40(%rbp), %eax
jg 0x6015
movl -0x30(%rbp), %eax
cmpl -0x40(%rbp), %eax
jne 0x604f
movl -0x48(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jae 0x604f
movl -0xc(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jb 0x6037
movl -0x2c(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x608b
movl -0x24(%rbp), %eax
movl %eax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movl -0x38(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %al
movb %al, -0x69(%rbp)
jmp 0x6051
movq -0x58(%rbp), %rax
movl -0xc(%rbp), %ecx
andl -0x5c(%rbp), %ecx
movl %ecx, %ecx
movzwl (%rax,%rcx,2), %ecx
movl %ecx, -0xc(%rbp)
xorl %eax, %eax
cmpl -0x4c(%rbp), %ecx
movb %al, -0x7a(%rbp)
jbe 0x6080
movl -0x28(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, %eax
setne %al
movb %al, -0x7a(%rbp)
movb -0x7a(%rbp), %al
testb $0x1, %al
jne 0x5d58
movl -0x40(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0xe0(%rcx), %eax
jne 0x60aa
movl -0x3c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpq 0xd0(%rcx), %rax
je 0x60fd
movq -0x8(%rbp), %rax
movl $0x2, 0xc0(%rax)
movl -0x38(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0xa8(%rax)
movl -0x3c(%rbp), %eax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movq %rcx, 0xd0(%rax)
movq -0x8(%rbp), %rax
movl $0x80, 0xc8(%rax)
movl -0x44(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0xb8(%rax)
movl -0x40(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0xe0(%rax)
popq %rbp
retq
nop