// File: sisong[P]ApkDiffPatch/lzma/C/LzFind.c
// Function: MatchFinder_CheckLimits
Z7_NO_INLINE
static void MatchFinder_CheckLimits(CMatchFinder *p)
{
  if (// !p->streamEndWasReached && p->result == SZ_OK &&
      p->keepSizeAfter == GET_AVAIL_BYTES(p))
  {
    // we try to read only in exact state (p->keepSizeAfter == GET_AVAIL_BYTES(p))
    if (MatchFinder_NeedMove(p))
      MatchFinder_MoveBlock(p);
    MatchFinder_ReadBlock(p);
  }

  if (p->pos == kMaxValForNormalize)
  if (GET_AVAIL_BYTES(p) >= p->numHashBytes) // optional optimization for last bytes of data.
    /*
       if we disable normalization for last bytes of data, and
       if (data_size == 4 GiB), we don't call wastfull normalization,
       but (pos) will be wrapped over Zero (0) in that case.
       And we cannot resume later to normal operation
    */
  {
    // MatchFinder_Normalize(p);
    /* after normalization we need (p->pos >= p->historySize + 1); */
    /* we can reduce subValue to aligned value, if want to keep alignment
       of (p->pos) and (p->buffer) for speculated accesses. */
    const UInt32 subValue = (p->pos - p->historySize - 1) /* & ~(UInt32)(kNormalizeAlign - 1) */;
    // const UInt32 subValue = (1 << 15); // for debug
    // printf("\nMatchFinder_Normalize() subValue == 0x%x\n", subValue);
    MatchFinder_REDUCE_OFFSETS(p, subValue)
    MatchFinder_Normalize3(subValue, p->hash, (size_t)p->hashMask + 1 + p->fixedHashSize);
    {
      size_t numSonRefs = p->cyclicBufferSize;
      if (p->btMode)
        numSonRefs <<= 1;
      MatchFinder_Normalize3(subValue, p->son, numSonRefs);
    }
  }

  if (p->cyclicBufferPos == p->cyclicBufferSize)
    p->cyclicBufferPos = 0;
  
  MatchFinder_SetLimits(p);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movl 0x58(%rax), %eax
movq -0x8(%rbp), %rcx
movl 0x10(%rcx), %ecx
movq -0x8(%rbp), %rdx
subl 0x8(%rdx), %ecx
cmpl %ecx, %eax
jne 0x70875
movq -0x8(%rbp), %rdi
callq 0x6f0b0
cmpl $0x0, %eax
je 0x7086c
movq -0x8(%rbp), %rdi
callq 0x6f010
movq -0x8(%rbp), %rdi
callq 0x6f170
movq -0x8(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0x7092d
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x8(%rbp), %rcx
subl 0x8(%rcx), %eax
movq -0x8(%rbp), %rcx
cmpl 0x5c(%rcx), %eax
jb 0x7092b
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x8(%rbp), %rcx
subl 0x68(%rcx), %eax
subl $0x1, %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %edx
movq -0x8(%rbp), %rax
movl 0x8(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x8(%rax)
movl -0xc(%rbp), %edx
movq -0x8(%rbp), %rax
movl 0x10(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x10(%rax)
movl -0xc(%rbp), %edi
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rsi
movq -0x8(%rbp), %rax
movl 0x38(%rax), %eax
movl %eax, %edx
addq $0x1, %rdx
movq -0x8(%rbp), %rax
movl 0x6c(%rax), %eax
addq %rax, %rdx
callq 0x6fdf0
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %eax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
cmpb $0x0, 0x21(%rax)
je 0x70917
movq -0x18(%rbp), %rax
shlq %rax
movq %rax, -0x18(%rbp)
movl -0xc(%rbp), %edi
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rsi
movq -0x18(%rbp), %rdx
callq 0x6fdf0
jmp 0x7092d
movq -0x8(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x8(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jne 0x70948
movq -0x8(%rbp), %rax
movl $0x0, 0x18(%rax)
movq -0x8(%rbp), %rdi
callq 0x6fd10
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)