// File: /workspace/github_cpp_makefile_star2_O3/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), %rbp
movq 0x50(%rsp), %r13
movq 0x48(%rsp), %r8
movq 0x40(%rsp), %r11
movq 0x38(%rsp), %r10
movq %rcx, -0x48(%rsp)
leaq 0x8(%rcx), %rax
movq %rax, -0x10(%rsp)
movl %r14d, -0x74(%rsp)
cmpq %r13, %r11
je 0x3b3da
movl (%r11), %r15d
testl %r15d, %r15d
je 0x3b3ca
movl %edx, %ecx
cmpl %edx, %esi
jae 0x3b010
movl %esi, %ecx
cmpl %esi, %r15d
ja 0x3b3ca
leaq 0x4(%r11), %rbx
leaq 0x1(%rdi), %rax
movq %rax, -0x58(%rsp)
cmpl %ecx, %r15d
jae 0x3b1de
movq %r11, -0x8(%rsp)
movq %rbx, -0x20(%rsp)
movq %r9, -0x28(%rsp)
leaq 0x4(%r9), %r12
movq -0x48(%rsp), %rax
leaq (%rax,%rbp,8), %r8
leaq 0x4(%rax,%rbp,8), %r9
movq -0x68(%rsp), %rbx
leaq (%rbx,%r10), %rax
movq %rax, -0x50(%rsp)
movl %ecx, -0x38(%rsp)
movl %ecx, %r11d
movq %rbx, %rdx
movq %r12, -0x30(%rsp)
movq %r12, -0x60(%rsp)
movq %rbp, -0x70(%rsp)
movq %rsi, -0x40(%rsp)
movq %r11, -0x18(%rsp)
movl %r15d, %r12d
movq %r12, %r15
negq %r15
movq %rbp, %rax
subq %r12, %rax
movl $0x0, %ecx
cmovbq %r11, %rcx
addq %rcx, %rax
movq -0x48(%rsp), %rcx
leaq (%rcx,%rax,8), %r10
cmpq %rbx, %rdx
movq %rbx, %rcx
cmovbq %rdx, %rcx
movq %rcx, %r13
subq %r12, %r13
movb (%r13), %r13b
cmpb (%rcx), %r13b
jne 0x3b147
leaq 0x1(%rcx), %r13
cmpq %rdi, %rcx
je 0x3b0eb
movb (%r13,%r15), %bpl
cmpb (%r13), %bpl
jne 0x3b0eb
addq $0x2, %rcx
movq %rcx, %r13
decq %rcx
cmpq %rdi, %rcx
je 0x3b0eb
movb (%r13,%r15), %bpl
leaq 0x1(%r13), %rcx
cmpb (%r13), %bpl
je 0x3b0d1
cmpq %r13, -0x50(%rsp)
jae 0x3b13f
movq -0x48(%rsp), %rcx
movl (%rcx,%rax,8), %ecx
movl %r13d, %eax
subl -0x68(%rsp), %eax
movq -0x60(%rsp), %r11
movl %eax, (%r11)
leal -0x1(%r12), %ebp
leaq 0x8(%r11), %rax
movl %ebp, 0x4(%r11)
cmpq -0x58(%rsp), %r13
je 0x3b21d
movq %r13, -0x50(%rsp)
movq %r13, %rcx
movq %rax, -0x60(%rsp)
movq -0x70(%rsp), %rbp
movq -0x40(%rsp), %rsi
movq -0x18(%rsp), %r11
jmp 0x3b147
movq %r13, %rcx
movq -0x70(%rsp), %rbp
movl %esi, %r13d
subl %r12d, %r13d
movb (%rcx,%r15), %al
cmpb (%rcx), %al
jae 0x3b174
movl 0x4(%r10), %eax
movl %r13d, (%r8)
cmpl %r13d, %eax
jae 0x3b3ca
movq %r10, %r8
addq $0x4, %r8
movq %r9, %r10
movq %rcx, %rbx
jmp 0x3b186
movl (%r10), %eax
movl %r13d, (%r9)
movq %rcx, %rdx
cmpl %r13d, %eax
jae 0x3b3ca
decl %r14d
je 0x3b19f
movl %esi, %r15d
subl %eax, %r15d
movq %r10, %r9
cmpl -0x38(%rsp), %r15d
jb 0x3b078
xorl %eax, %eax
movl %eax, (%r8)
movl %eax, (%r10)
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), %r13
movq 0x48(%rsp), %r8
movq 0x38(%rsp), %r10
movq -0x20(%rsp), %rbx
jmp 0x3b1f9
movl $0x0, (%r9)
addq $0x4, %r9
movq -0x48(%rsp), %rax
movq $0x0, (%rax,%rbp,8)
movq %r9, %rcx
incq %rsi
incq %rbp
incq -0x68(%rsp)
movq %rbx, %r11
movq %rcx, %r9
movq -0x58(%rsp), %rdi
cmpq %r8, %rcx
jb 0x3afea
jmp 0x3b3dd
movl 0x4(%r10), %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), %r13
movq -0x20(%rsp), %rbx
cmpq %r13, %rbx
movq -0x40(%rsp), %rsi
je 0x3b3aa
cmpl %r12d, (%rbx)
movl 0x60(%rsp), %edx
movq 0x48(%rsp), %r8
movq 0x38(%rsp), %r10
jne 0x3b398
movq -0x58(%rsp), %r11
movb (%r11,%r15), %cl
cmpb (%r11), %cl
jne 0x3b398
cmpq %r8, %rax
jae 0x3b398
movl %edi, %edx
subl -0x68(%rsp), %edx
incl %edx
movq -0x70(%rsp), %rax
leaq 0x1(%rax), %rcx
movq %rcx, -0x38(%rsp)
movq -0x10(%rsp), %r8
leaq (%r8,%rax,8), %r8
leaq (,%r12,8), %rax
movq %r8, -0x50(%rsp)
subq %rax, %r8
movq -0x8(%rsp), %r14
addq $0x8, %r14
movq -0x60(%rsp), %rbx
addq $0x14, %rbx
leaq 0x2(%rdi), %r10
movq %r10, -0x60(%rsp)
subq %r12, %r10
movq %r14, %rax
xorl %r15d, %r15d
movq %r15, %r11
movl $0x2, -0xc(%rbx)
movl %edx, -0x8(%rbx)
movq %rbx, %rcx
movl %ebp, -0x4(%rbx)
movq -0x38(%rsp), %rsi
leaq (%rsi,%r15), %rbx
cmpq %r12, %rbx
movl $0x0, %ebx
cmovbq -0x18(%rsp), %rbx
leaq (%r8,%rbx,8), %rbx
movq (%rbx,%r15,8), %rbx
movq -0x50(%rsp), %rsi
movq %rbx, (%rsi,%r15,8)
movq %r14, %r9
cmpq %r13, %r14
je 0x3b34f
cmpl %r12d, (%rax,%r11,4)
jne 0x3b34f
movb (%r10,%r11), %bl
movq -0x60(%rsp), %rsi
cmpb (%rsi,%r11), %bl
jne 0x3b34f
leaq -0xc(%rcx), %r13
addq $0xc, %r13
leaq 0x1(%r11), %r15
leaq 0x4(%r9), %r14
leaq 0xc(%rcx), %rbx
cmpq 0x48(%rsp), %r13
movq 0x50(%rsp), %r13
jb 0x3b2d7
movq -0x70(%rsp), %rbp
addq %r11, %rbp
incq %rbp
movq -0x68(%rsp), %rax
leaq 0x1(%rax,%r11), %rax
movq %rax, -0x68(%rsp)
movq -0x40(%rsp), %rsi
leaq 0x1(%rsi,%r11), %rsi
leaq 0x2(%rdi,%r11), %rax
movq %rax, -0x58(%rsp)
movl -0x74(%rsp), %r14d
movl 0x60(%rsp), %edx
movq 0x48(%rsp), %r8
movq 0x38(%rsp), %r10
movq %r9, %rbx
jmp 0x3b1f9
movq %rax, %rcx
movl -0x74(%rsp), %r14d
movq -0x70(%rsp), %rbp
jmp 0x3b1f9
movq %rax, %rcx
movl -0x74(%rsp), %r14d
movl 0x60(%rsp), %edx
movq -0x70(%rsp), %rbp
movq 0x48(%rsp), %r8
movq 0x38(%rsp), %r10
jmp 0x3b1f9
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 0x3b3cc
nop