// File: /workspace/github_cpp_makefile_star2_O1/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 %r9, %r13
movq %rcx, %rax
movl %edi, %r9d
movq 0x48(%rsp), %rbp
movl 0x38(%rsp), %ecx
leaq (%r8,%r13,8), %rdi
movq %rdi, -0x30(%rsp)
movq %r8, -0x20(%rsp)
leaq (%r8,%r13,8), %r8
addq $0x4, %r8
xorl %edi, %edi
movl %edx, -0x24(%rsp)
subl %ecx, %edx
cmovbl %edi, %edx
movl %edx, -0x28(%rsp)
cmpl %esi, %edx
jae 0x3819a
movl 0x50(%rsp), %edx
movl %edx, -0x38(%rsp)
movl 0x40(%rsp), %r15d
movl %ecx, %ecx
movq %rcx, -0x8(%rsp)
movl $0x0, -0x34(%rsp)
xorl %ebx, %ebx
movl %r9d, %edx
movq %r13, -0x10(%rsp)
movl -0x24(%rsp), %ecx
movl %ecx, %r14d
subl %esi, %r14d
movq %r13, %rcx
subq %r14, %rcx
movl $0x0, %edi
cmovbq -0x8(%rsp), %rdi
leaq (%rcx,%rdi), %r10
movq %rax, %rcx
subq %r14, %rcx
movl -0x34(%rsp), %edi
cmpl %ebx, %edi
movl %ebx, %r12d
cmovbl %edi, %r12d
movq -0x20(%rsp), %rdi
leaq (%rdi,%r10,8), %r11
movb (%rcx,%r12), %dil
cmpb (%rax,%r12), %dil
jne 0x38154
leal 0x1(%r12), %edi
cmpl %edx, %edi
je 0x38110
movq %r8, %r13
movq %rbp, %r8
movl %edi, %ebp
movb (%rcx,%rbp), %r9b
cmpb (%rax,%rbp), %r9b
movq %r8, %rbp
movq %r13, %r8
movq -0x10(%rsp), %r13
jne 0x38110
addl $0x2, %r12d
cmpl %r12d, %edx
je 0x3810e
movl %r12d, %edi
movb (%rcx,%rdi), %r9b
incl %r12d
cmpb (%rax,%rdi), %r9b
je 0x380f1
decl %r12d
movl %r12d, %edi
jmp 0x38110
movl %edx, %edi
cmpl %edi, -0x38(%rsp)
jae 0x38151
movq -0x20(%rsp), %r9
movl (%r9,%r10,8), %r10d
movl %edi, (%rbp)
decl %r14d
movl %r14d, 0x4(%rbp)
addq $0x8, %rbp
cmpl %edx, %edi
jne 0x3814d
movq -0x30(%rsp), %rcx
movl %r10d, (%rcx)
movl 0x4(%r11), %ecx
movl %ecx, (%r8)
xorl %ecx, %ecx
movl %edi, -0x38(%rsp)
movq %rbp, -0x18(%rsp)
jmp 0x38187
movl %edi, -0x38(%rsp)
movl %edi, %r12d
movl %r12d, %edi
movb (%rcx,%rdi), %cl
cmpb (%rax,%rdi), %cl
jae 0x38171
movq -0x30(%rsp), %rcx
movl %esi, (%rcx)
addq $0x4, %r11
movq %r11, -0x30(%rsp)
jmp 0x3817f
movl %esi, (%r8)
movq %r11, %r8
movl %r12d, -0x34(%rsp)
movl %ebx, %r12d
movl (%r11), %esi
movb $0x1, %cl
movl %r12d, %ebx
testb %cl, %cl
je 0x381ab
decl %r15d
je 0x3819a
cmpl %esi, -0x28(%rsp)
jb 0x3807e
xorl %eax, %eax
movq -0x30(%rsp), %rcx
movl %eax, (%rcx)
movl %eax, (%r8)
movq %rbp, %rax
jmp 0x381b0
movq -0x18(%rsp), %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq