// File: /workspace/github_cpp_makefile_star2_O2/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, %r13d
movq 0x48(%rsp), %rax
movl 0x38(%rsp), %ecx
leaq (%r8,%r9,8), %r11
movq %r8, -0x20(%rsp)
leaq (%r8,%r9,8), %rdi
addq $0x4, %rdi
movq %rdi, -0x38(%rsp)
xorl %edi, %edi
movl %edx, -0x2c(%rsp)
movl %edx, %r8d
subl %ecx, %r8d
movl $0x0, %edx
movq %rdx, -0x18(%rsp)
cmovbl %edi, %r8d
movl %r8d, -0x30(%rsp)
cmpl %esi, %r8d
jae 0x2fb40
movl 0x50(%rsp), %edi
movl %edi, -0x3c(%rsp)
movl 0x40(%rsp), %ebp
movl %ecx, %ecx
movq %rcx, -0x8(%rsp)
xorl %r8d, %r8d
movq %r9, -0x28(%rsp)
movl -0x2c(%rsp), %ecx
movl %ecx, %r15d
subl %esi, %r15d
movq %r9, %rcx
subq %r15, %rcx
movl $0x0, %edi
cmovbq -0x8(%rsp), %rdi
leaq (%rcx,%rdi), %rbx
movq %r12, %rcx
subq %r15, %rcx
movq -0x18(%rsp), %rdi
cmpl %r8d, %edi
movl %r8d, %edx
movl %r8d, %r14d
cmovbl %edi, %r14d
movq -0x20(%rsp), %rdi
leaq (%rdi,%rbx,8), %r10
movb (%rcx,%r14), %dil
cmpb (%r12,%r14), %dil
jne 0x2fb00
leal 0x1(%r14), %r9d
movl %r13d, %edi
cmpl %r13d, %r9d
je 0x2fad3
movl %r9d, %r8d
movq %rax, -0x10(%rsp)
movq %r11, %rax
movb (%rcx,%r8), %r11b
movl %r9d, %edi
cmpb (%r12,%r8), %r11b
movq %rax, %r11
movq -0x10(%rsp), %rax
jne 0x2fad3
addl $0x2, %r14d
cmpl %r14d, %r13d
je 0x2fad0
movl %r14d, %edi
movb (%rcx,%rdi), %r8b
incl %r14d
cmpb (%r12,%rdi), %r8b
je 0x2fab3
decl %r14d
movl %r14d, %edi
jmp 0x2fad3
movl %r13d, %edi
cmpl %edi, -0x3c(%rsp)
jae 0x2faf8
movq -0x20(%rsp), %r8
movl (%r8,%rbx,8), %r9d
movl %edi, (%rax)
decl %r15d
movl %r15d, 0x4(%rax)
addq $0x8, %rax
cmpl %r13d, %edi
je 0x2fb57
movl %edi, -0x3c(%rsp)
movl %edi, %r14d
movq -0x28(%rsp), %r9
movl %r14d, %edi
movb (%rcx,%rdi), %cl
cmpb (%r12,%rdi), %cl
jae 0x2fb1b
movl %esi, (%r11)
addq $0x4, %r10
movq %r10, %r11
movl %r14d, %r8d
jmp 0x2fb2f
movq -0x38(%rsp), %rcx
movl %esi, (%rcx)
movq %r10, -0x38(%rsp)
movq %r14, -0x18(%rsp)
movl %edx, %r8d
decl %ebp
je 0x2fb40
movl (%r10), %esi
cmpl %esi, -0x30(%rsp)
jb 0x2fa39
andl $0x0, (%r11)
movq -0x38(%rsp), %rcx
andl $0x0, (%rcx)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r9d, (%r11)
movl 0x4(%r10), %ecx
movq -0x38(%rsp), %rdx
movl %ecx, (%rdx)
jmp 0x2fb4c