// File: /workspace/github_cpp_makefile_star2_O3/sisong[P]ApkDiffPatch/lzma/C/LzFind.c
// Function: GetMatchesSpec1
Z7_FORCE_INLINE
UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
    size_t _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
    UInt32 *d, UInt32 maxLen)
{
  CLzRef *ptr0 = son + ((size_t)_cyclicBufferPos << 1) + 1;
  CLzRef *ptr1 = son + ((size_t)_cyclicBufferPos << 1);
  unsigned len0 = 0, len1 = 0;

  UInt32 cmCheck;

  // if (curMatch >= pos) { *ptr0 = *ptr1 = kEmptyHashValue; return NULL; }

  cmCheck = (UInt32)(pos - _cyclicBufferSize);
  if ((UInt32)pos <= _cyclicBufferSize)
    cmCheck = 0;

  if (cmCheck < curMatch)
  do
  {
    const UInt32 delta = pos - curMatch;
    {
      CLzRef *pair = son + ((size_t)(_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
      const Byte *pb = cur - delta;
      unsigned len = (len0 < len1 ? len0 : len1);
      const UInt32 pair0 = pair[0];
      if (pb[len] == cur[len])
      {
        if (++len != lenLimit && pb[len] == cur[len])
          while (++len != lenLimit)
            if (pb[len] != cur[len])
              break;
        if (maxLen < len)
        {
          maxLen = (UInt32)len;
          *d++ = (UInt32)len;
          *d++ = delta - 1;
          if (len == lenLimit)
          {
            *ptr1 = pair0;
            *ptr0 = pair[1];
            return d;
          }
        }
      }
      if (pb[len] < cur[len])
      {
        *ptr1 = curMatch;
        // const UInt32 curMatch2 = pair[1];
        // if (curMatch2 >= curMatch) { *ptr0 = *ptr1 = kEmptyHashValue;  return NULL; }
        // curMatch = curMatch2;
        curMatch = pair[1];
        ptr1 = pair + 1;
        len1 = len;
      }
      else
      {
        *ptr0 = curMatch;
        curMatch = pair[0];
        ptr0 = pair;
        len0 = len;
      }
    }
  }
  while(--cutValue && cmCheck < curMatch);

  *ptr0 = *ptr1 = kEmptyHashValue;
  return d;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rcx, %r12
movl %edi, %r11d
movq 0x48(%rsp), %rax
movl 0x38(%rsp), %ecx
leaq (%r8,%r9,8), %r13
movq %r8, -0x18(%rsp)
leaq (%r8,%r9,8), %rdi
addq $0x4, %rdi
movq %rdi, -0x30(%rsp)
xorl %edi, %edi
movl %edx, -0x24(%rsp)
subl %ecx, %edx
cmovbl %edi, %edx
movl %edx, -0x28(%rsp)
cmpl %esi, %edx
jae 0x37e25
movl 0x50(%rsp), %edi
movl %edi, -0x38(%rsp)
movl 0x40(%rsp), %r14d
movl %ecx, %ecx
movq %rcx, -0x8(%rsp)
movl $0x0, -0x34(%rsp)
xorl %r8d, %r8d
movq %r9, -0x20(%rsp)
movl -0x24(%rsp), %ecx
movl %ecx, %r15d
subl %esi, %r15d
movq %r9, %rcx
subq %r15, %rcx
movl $0x0, %edi
cmovbq -0x8(%rsp), %rdi
leaq (%rcx,%rdi), %rbp
movq %r12, %rcx
subq %r15, %rcx
movl -0x34(%rsp), %edi
cmpl %r8d, %edi
movl %r8d, %edx
movl %r8d, %ebx
cmovbl %edi, %ebx
movq -0x18(%rsp), %rdi
leaq (%rdi,%rbp,8), %r10
movb (%rcx,%rbx), %dil
cmpb (%r12,%rbx), %dil
jne 0x37de5
leal 0x1(%rbx), %r9d
movl %r11d, %edi
cmpl %r11d, %r9d
je 0x37db9
movl %r9d, %r8d
movq %rax, -0x10(%rsp)
movq %r13, %rax
movb (%rcx,%r8), %r13b
movl %r9d, %edi
cmpb (%r12,%r8), %r13b
movq %rax, %r13
movq -0x10(%rsp), %rax
jne 0x37db9
addl $0x2, %ebx
cmpl %ebx, %r11d
je 0x37db6
movl %ebx, %edi
movb (%rcx,%rdi), %r8b
incl %ebx
cmpb (%r12,%rdi), %r8b
je 0x37d9d
decl %ebx
movl %ebx, %edi
jmp 0x37db9
movl %r11d, %edi
cmpl %edi, -0x38(%rsp)
jae 0x37dde
movq -0x18(%rsp), %r8
movl (%r8,%rbp,8), %r9d
movl %edi, (%rax)
decl %r15d
movl %r15d, 0x4(%rax)
addq $0x8, %rax
cmpl %r11d, %edi
je 0x37e3d
movl %edi, -0x38(%rsp)
movl %edi, %ebx
movq -0x20(%rsp), %r9
movl %ebx, %edi
movb (%rcx,%rdi), %cl
cmpb (%r12,%rdi), %cl
jae 0x37e00
movl %esi, (%r13)
addq $0x4, %r10
movq %r10, %r13
movl %ebx, %r8d
jmp 0x37e13
movq -0x30(%rsp), %rcx
movl %esi, (%rcx)
movq %r10, -0x30(%rsp)
movl %ebx, -0x34(%rsp)
movl %edx, %r8d
decl %r14d
je 0x37e25
movl (%r10), %esi
cmpl %esi, -0x28(%rsp)
jb 0x37d26
xorl %ecx, %ecx
movl %ecx, (%r13)
movq -0x30(%rsp), %rdx
movl %ecx, (%rdx)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r9d, (%r13)
movl 0x4(%r10), %ecx
movq -0x30(%rsp), %rdx
movl %ecx, (%rdx)
jmp 0x37e32