// File: sisong[P]ApkDiffPatch/lzma/C/LzFind.c
// Function: MatchFinder_ReadBlock
Z7_NO_INLINE
static void MatchFinder_ReadBlock(CMatchFinder *p)
{
  if (p->streamEndWasReached || p->result != SZ_OK)
    return;

  /* We use (p->streamPos - p->pos) value.
     (p->streamPos < p->pos) is allowed. */

  if (p->directInput)
  {
    UInt32 curSize = 0xFFFFFFFF - GET_AVAIL_BYTES(p);
    if (curSize > p->directInputRem)
      curSize = (UInt32)p->directInputRem;
    p->streamPos += curSize;
    p->directInputRem -= curSize;
    if (p->directInputRem == 0)
      p->streamEndWasReached = 1;
    return;
  }
  
  for (;;)
  {
    const Byte *dest = p->buffer + GET_AVAIL_BYTES(p);
    size_t size = (size_t)(p->bufBase + p->blockSize - dest);
    if (size == 0)
    {
      /* we call ReadBlock() after NeedMove() and MoveBlock().
         NeedMove() and MoveBlock() povide more than (keepSizeAfter)
         to the end of (blockSize).
         So we don't execute this branch in normal code flow.
         We can go here, if we will call ReadBlock() before NeedMove(), MoveBlock().
      */
      // p->result = SZ_ERROR_FAIL; // we can show error here
      return;
    }

    // #define kRead 3
    // if (size > kRead) size = kRead; // for debug

    /*
    // we need cast (Byte *)dest.
    #ifdef __clang__
      #pragma GCC diagnostic ignored "-Wcast-qual"
    #endif
    */
    p->result = ISeqInStream_Read(p->stream,
        p->bufBase + (dest - p->bufBase), &size);
    if (p->result != SZ_OK)
      return;
    if (size == 0)
    {
      p->streamEndWasReached = 1;
      return;
    }
    p->streamPos += (UInt32)size;
    if (GET_AVAIL_BYTES(p) > p->keepSizeAfter)
      return;
    /* here and in another (p->keepSizeAfter) checks we keep on 1 byte more than was requested by Create() function
         (GET_AVAIL_BYTES(p) >= p->keepSizeAfter) - minimal required size */
  }

  // on exit: (p->result != SZ_OK || p->streamEndWasReached || GET_AVAIL_BYTES(p) > p->keepSizeAfter)
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x20(%rax), %eax
cmpl $0x0, %eax
jne 0x6f193
movq -0x8(%rbp), %rax
cmpl $0x0, 0x74(%rax)
je 0x6f198
jmp 0x6f2db
movq -0x8(%rbp), %rax
cmpb $0x0, 0x23(%rax)
je 0x6f20b
movq -0x8(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x8(%rbp), %rax
subl 0x8(%rax), %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
subl %ecx, %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpq 0x60(%rcx), %rax
jbe 0x6f1d2
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
addl 0x10(%rax), %ecx
movl %ecx, 0x10(%rax)
movl -0xc(%rbp), %eax
movl %eax, %edx
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x60(%rax)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x60(%rax)
jne 0x6f206
movq -0x8(%rbp), %rax
movb $0x1, 0x20(%rax)
jmp 0x6f2db
jmp 0x6f20d
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x10(%rcx), %ecx
movq -0x8(%rbp), %rdx
subl 0x8(%rdx), %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x50(%rcx), %ecx
addq %rcx, %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x6f254
jmp 0x6f2db
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x48(%rcx), %rdi
movq -0x8(%rbp), %rcx
movq 0x40(%rcx), %rsi
movq -0x18(%rbp), %rcx
movq -0x8(%rbp), %rdx
movq 0x40(%rdx), %rdx
subq %rdx, %rcx
addq %rcx, %rsi
leaq -0x20(%rbp), %rdx
callq *%rax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x74(%rax)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x74(%rax)
je 0x6f29c
jmp 0x6f2db
cmpq $0x0, -0x20(%rbp)
jne 0x6f2ad
movq -0x8(%rbp), %rax
movb $0x1, 0x20(%rax)
jmp 0x6f2db
movq -0x20(%rbp), %rax
movl %eax, %ecx
movq -0x8(%rbp), %rax
addl 0x10(%rax), %ecx
movl %ecx, 0x10(%rax)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x8(%rbp), %rcx
subl 0x8(%rcx), %eax
movq -0x8(%rbp), %rcx
cmpl 0x58(%rcx), %eax
jbe 0x6f2d6
jmp 0x6f2db
jmp 0x6f20d
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)