// File: /workspace/github_cpp_makefile_star2_O2/sisong[P]ApkDiffPatch/lzma/C/LzFindOpt.c
// Function: GetMatchesSpecN_2
Z7_NO_INLINE
UInt32 * Z7_FASTCALL GetMatchesSpecN_2(const Byte *lenLimit, size_t pos, const Byte *cur, CLzRef *son,
    UInt32 _cutValue, UInt32 *d, size_t _maxLen, const UInt32 *hash, const UInt32 *limit, const UInt32 *size,
    size_t _cyclicBufferPos, UInt32 _cyclicBufferSize,
    UInt32 *posRes)
{
  do // while (hash != size)
  {
    UInt32 delta;
    
  #ifndef cbs
    UInt32 cbs;
  #endif

    if (hash == size)
      break;

    delta = *hash++;

    if (delta == 0)
      return NULL;

    lenLimit++;

  #ifndef cbs
    cbs = _cyclicBufferSize;
    if ((UInt32)pos < cbs)
    {
      if (delta > (UInt32)pos)
        return NULL;
      cbs = (UInt32)pos;
    }
  #endif

    if (delta >= cbs)
    {
      CLzRef *ptr1 = son + ((size_t)_cyclicBufferPos << 1);
      *d++ = 0;
      ptr1[0] = kEmptyHashValue;
      ptr1[1] = kEmptyHashValue;
    }
else
{
  UInt32 *_distances = ++d;

  CLzRef *ptr0 = son + ((size_t)_cyclicBufferPos << 1) + 1;
  CLzRef *ptr1 = son + ((size_t)_cyclicBufferPos << 1);

  UInt32 cutValue = _cutValue;
  const Byte *len0 = cur, *len1 = cur;
  const Byte *maxLen = cur + _maxLen;

  // if (cutValue == 0) { *ptr0 = *ptr1 = kEmptyHashValue; } else
  for (LOG_ITER(g_NumIters_Tree++);;)
  {
    LOG_ITER(g_NumIters_Loop++);
    {
      // SPEC code
      CLzRef *pair = son + ((size_t)((ptrdiff_t)_cyclicBufferPos - (ptrdiff_t)delta
          + (ptrdiff_t)(UInt32)(_cyclicBufferPos < delta ? cbs : 0)
          ) << 1);

      const ptrdiff_t diff = (ptrdiff_t)0 - (ptrdiff_t)delta;
      const Byte *len = (len0 < len1 ? len0 : len1);

    #ifdef USE_SON_PREFETCH
      const UInt32 pair0 = *pair;
    #endif

      if (len[diff] == len[0])
      {
        if (++len != lenLimit && len[diff] == len[0])
          while (++len != lenLimit)
          {
            LOG_ITER(g_NumIters_Bytes++);
            if (len[diff] != len[0])
              break;
          }
        if (maxLen < len)
        {
          maxLen = len;
          *d++ = (UInt32)(len - cur);
          *d++ = delta - 1;
          
          if (len == lenLimit)
          {
            const UInt32 pair1 = pair[1];
            *ptr1 =
              #ifdef USE_SON_PREFETCH
                pair0;
              #else
                pair[0];
              #endif
            *ptr0 = pair1;

            _distances[-1] = (UInt32)(d - _distances);

            #ifdef USE_LONG_MATCH_OPT

                if (hash == size || *hash != delta || lenLimit[diff] != lenLimit[0] || d >= limit)
                  break;

            {
              for (;;)
              {
                *d++ = 2;
                *d++ = (UInt32)(lenLimit - cur);
                *d++ = delta - 1;
                cur++;
                lenLimit++;
                // SPEC
                _cyclicBufferPos++;
                {
                  // SPEC code
                  CLzRef *dest = son + ((size_t)(_cyclicBufferPos) << 1);
                  const CLzRef *src = dest + ((diff
                      + (ptrdiff_t)(UInt32)((_cyclicBufferPos < delta) ? cbs : 0)) << 1);
                  // CLzRef *ptr = son + ((size_t)(pos) << 1) - CYC_TO_POS_OFFSET * 2;
                  #if 0
                  *(UInt64 *)(void *)dest = *((const UInt64 *)(const void *)src);
                  #else
                  const UInt32 p0 = src[0];
                  const UInt32 p1 = src[1];
                  dest[0] = p0;
                  dest[1] = p1;
                  #endif
                }
                pos++;
                hash++;
                if (hash == size || *hash != delta || lenLimit[diff] != lenLimit[0] || d >= limit)
                  break;
              } // for() end for long matches
            }
            #endif

            break; // break from TREE iterations
          }
        }
      }
      {
        const UInt32 curMatch = (UInt32)pos - delta; // (UInt32)(pos + diff);
        if (len[diff] < len[0])
        {
          delta = pair[1];
          *ptr1 = curMatch;
          ptr1 = pair + 1;
          len1 = len;
          if (delta >= curMatch)
            return NULL;
        }
        else
        {
          delta = *pair;
          *ptr0 = curMatch;
          ptr0 = pair;
          len0 = len;
          if (delta >= curMatch)
            return NULL;
        }
        delta = (UInt32)pos - delta;
 
        if (--cutValue == 0 || delta >= cbs)
        {
          *ptr0 = *ptr1 = kEmptyHashValue;
          _distances[-1] = (UInt32)(d - _distances);
          break;
        }
      }
    }
  } // for (tree iterations)
}
    pos++;
    _cyclicBufferPos++;
    cur++;
  }
  while (d < limit);
  *posRes = (UInt32)pos;
  return d;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl %r8d, %r14d
movq %rdx, -0x68(%rsp)
movl 0x60(%rsp), %edx
movq 0x58(%rsp), %r13
movq 0x50(%rsp), %rbp
movq 0x48(%rsp), %r8
movq 0x40(%rsp), %r11
movq %rcx, -0x48(%rsp)
leaq 0x8(%rcx), %rax
movq %rax, -0x10(%rsp)
movl %r14d, -0x74(%rsp)
cmpq %rbp, %r11
je 0x32fef
movl (%r11), %r10d
testl %r10d, %r10d
je 0x32fdf
movl %edx, %ecx
cmpl %edx, %esi
jae 0x32c2b
movl %esi, %ecx
cmpl %esi, %r10d
ja 0x32fdf
leaq 0x4(%r11), %rbx
leaq 0x1(%rdi), %rax
movq %rax, -0x58(%rsp)
cmpl %ecx, %r10d
jae 0x32df2
movq %r11, -0x8(%rsp)
movq %rbx, -0x20(%rsp)
movq %r9, -0x28(%rsp)
leaq 0x4(%r9), %r15
movq -0x48(%rsp), %rax
leaq (%rax,%r13,8), %r8
leaq 0x4(%rax,%r13,8), %r9
movq -0x68(%rsp), %rbx
movq 0x38(%rsp), %rax
addq %rbx, %rax
movq %rax, -0x50(%rsp)
movl %ecx, -0x38(%rsp)
movl %ecx, %r11d
movq %rbx, %rdx
movq %r15, -0x30(%rsp)
movq %r15, -0x60(%rsp)
movq %r13, -0x70(%rsp)
movq %rsi, -0x40(%rsp)
movq %r11, -0x18(%rsp)
movl %r10d, %r12d
movq %r12, %r15
negq %r15
movq %r13, %rax
subq %r12, %rax
movl $0x0, %ecx
cmovbq %r11, %rcx
addq %rcx, %rax
movq -0x48(%rsp), %rcx
leaq (%rcx,%rax,8), %rbp
cmpq %rbx, %rdx
movq %rbx, %rcx
cmovbq %rdx, %rcx
movq %rcx, %r10
subq %r12, %r10
movb (%r10), %r10b
cmpb (%rcx), %r10b
jne 0x32d61
leaq 0x1(%rcx), %r10
cmpq %rdi, %rcx
je 0x32d05
movb (%r10,%r15), %r13b
cmpb (%r10), %r13b
jne 0x32d05
addq $0x2, %rcx
movq %rcx, %r10
decq %rcx
cmpq %rdi, %rcx
je 0x32d05
movb (%r10,%r15), %r13b
leaq 0x1(%r10), %rcx
cmpb (%r10), %r13b
je 0x32ced
cmpq %r10, -0x50(%rsp)
jae 0x32d59
movq -0x48(%rsp), %rcx
movl (%rcx,%rax,8), %ecx
movl %r10d, %eax
subl -0x68(%rsp), %eax
movq -0x60(%rsp), %r11
movl %eax, (%r11)
leal -0x1(%r12), %r13d
leaq 0x8(%r11), %rax
movl %r13d, 0x4(%r11)
cmpq -0x58(%rsp), %r10
je 0x32e2b
movq %r10, -0x50(%rsp)
movq %r10, %rcx
movq %rax, -0x60(%rsp)
movq -0x70(%rsp), %r13
movq -0x40(%rsp), %rsi
movq -0x18(%rsp), %r11
jmp 0x32d61
movq %r10, %rcx
movq -0x70(%rsp), %r13
movl %esi, %r10d
subl %r12d, %r10d
movb (%rcx,%r15), %al
cmpb (%rcx), %al
jae 0x32d8d
movl 0x4(%rbp), %eax
movl %r10d, (%r8)
cmpl %r10d, %eax
jae 0x32fdf
movq %rbp, %r8
addq $0x4, %r8
movq %r9, %rbp
movq %rcx, %rbx
jmp 0x32d9f
movl (%rbp), %eax
movl %r10d, (%r9)
movq %rcx, %rdx
cmpl %r10d, %eax
jae 0x32fdf
decl %r14d
je 0x32db8
movl %esi, %r10d
subl %eax, %r10d
movq %rbp, %r9
cmpl -0x38(%rsp), %r10d
jb 0x32c97
andl $0x0, (%r8)
andl $0x0, (%rbp)
movq -0x60(%rsp), %rcx
movq %rcx, %rax
subq -0x30(%rsp), %rax
shrq $0x2, %rax
movq -0x28(%rsp), %rdx
movl %eax, (%rdx)
movl -0x74(%rsp), %r14d
movl 0x60(%rsp), %edx
movq 0x50(%rsp), %rbp
movq 0x48(%rsp), %r8
movq -0x20(%rsp), %rbx
jmp 0x32e07
andl $0x0, (%r9)
addq $0x4, %r9
movq -0x48(%rsp), %rax
andq $0x0, (%rax,%r13,8)
movq %r9, %rcx
incq %rsi
incq %r13
incq -0x68(%rsp)
movq %rbx, %r11
movq %rcx, %r9
movq -0x58(%rsp), %rdi
cmpq %r8, %rcx
jb 0x32c05
jmp 0x32ff2
movl 0x4(%rbp), %edx
movl %ecx, (%r8)
movl %edx, (%r9)
movq %rax, %rcx
subq -0x30(%rsp), %rcx
shrq $0x2, %rcx
movq -0x28(%rsp), %rdx
movl %ecx, (%rdx)
movq 0x50(%rsp), %rbp
movq -0x20(%rsp), %rbx
cmpq %rbp, %rbx
movq -0x40(%rsp), %rsi
je 0x32fc4
cmpl %r12d, (%rbx)
movl 0x60(%rsp), %edx
movq 0x48(%rsp), %r8
jne 0x32fb2
movq -0x58(%rsp), %r10
movb (%r10,%r15), %cl
cmpb (%r10), %cl
jne 0x32fb2
cmpq %r8, %rax
jae 0x32fb2
movq -0x70(%rsp), %rax
leaq 0x1(%rax), %rcx
movq %rcx, -0x38(%rsp)
movq -0x10(%rsp), %rcx
leaq (%rcx,%rax,8), %r8
leaq (,%r12,8), %rax
movq %r8, -0x50(%rsp)
subq %rax, %r8
movq -0x8(%rsp), %rbx
addq $0x8, %rbx
movq -0x60(%rsp), %rax
addq $0x14, %rax
leaq 0x2(%rdi), %rdx
movq %rdx, %r10
subq %r12, %r10
leaq 0x1(%rdi), %rcx
movq %rcx, -0x60(%rsp)
movq %rbx, %r11
xorl %r15d, %r15d
movq %r15, %r14
movq %rbx, %rsi
movq %rax, %r15
movl $0x2, -0xc(%rax)
movq -0x60(%rsp), %rax
addl %r14d, %eax
movq -0x68(%rsp), %rbx
addl %r14d, %ebx
subl %ebx, %eax
movl %eax, -0x8(%r15)
movq %r15, %rcx
movl %r13d, -0x4(%r15)
movq -0x38(%rsp), %rax
addq %r14, %rax
cmpq %r12, %rax
movl $0x0, %eax
cmovbq -0x18(%rsp), %rax
leaq (%r8,%rax,8), %rax
movq (%rax,%r14,8), %rax
movq -0x50(%rsp), %r9
movq %rax, (%r9,%r14,8)
movq %rsi, %r9
cmpq %rbp, %rsi
je 0x32f6e
cmpl %r12d, (%r11,%r14,4)
jne 0x32f6e
movb (%r10,%r14), %al
cmpb (%rdx,%r14), %al
jne 0x32f6e
leaq -0xc(%rcx), %rbp
addq $0xc, %rbp
leaq 0x1(%r14), %r15
leaq 0x4(%r9), %rbx
leaq 0xc(%rcx), %rax
cmpq 0x48(%rsp), %rbp
movq 0x50(%rsp), %rbp
jb 0x32ede
movq -0x70(%rsp), %r13
addq %r14, %r13
incq %r13
movq -0x68(%rsp), %rax
leaq 0x1(%rax,%r14), %rax
movq %rax, -0x68(%rsp)
movq -0x40(%rsp), %rsi
leaq 0x1(%rsi,%r14), %rsi
leaq 0x2(%rdi,%r14), %rax
movq %rax, -0x58(%rsp)
movl -0x74(%rsp), %r14d
movl 0x60(%rsp), %edx
movq 0x48(%rsp), %r8
movq %r9, %rbx
jmp 0x32e07
movq %rax, %rcx
movl -0x74(%rsp), %r14d
movq -0x70(%rsp), %r13
jmp 0x32e07
movq %rax, %rcx
movl -0x74(%rsp), %r14d
movl 0x60(%rsp), %edx
movq -0x70(%rsp), %r13
movq 0x48(%rsp), %r8
jmp 0x32e07
xorl %ecx, %ecx
movq %rcx, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r9, %rcx
movq 0x68(%rsp), %rax
movl %esi, (%rax)
jmp 0x32fe1
nop