// File: sisong[P]ApkDiffPatch/lzma/C/Lzma2Dec.c
// Function: Lzma2Dec_Parse
ELzma2ParseStatus Lzma2Dec_Parse(CLzma2Dec *p,
    SizeT outSize,
    const Byte *src, SizeT *srcLen,
    int checkFinishBlock)
{
  SizeT inSize = *srcLen;
  *srcLen = 0;

  while (p->state != LZMA2_STATE_ERROR)
  {
    if (p->state == LZMA2_STATE_FINISHED)
      return (ELzma2ParseStatus)LZMA_STATUS_FINISHED_WITH_MARK;

    if (outSize == 0 && !checkFinishBlock)
      return (ELzma2ParseStatus)LZMA_STATUS_NOT_FINISHED;
    
    if (p->state != LZMA2_STATE_DATA && p->state != LZMA2_STATE_DATA_CONT)
    {
      if (*srcLen == inSize)
        return (ELzma2ParseStatus)LZMA_STATUS_NEEDS_MORE_INPUT;
      (*srcLen)++;

      p->state = Lzma2Dec_UpdateState(p, *src++);

      if (p->state == LZMA2_STATE_UNPACK0)
      {
        // if (p->decoder.dicPos != 0)
        if (p->control == LZMA2_CONTROL_COPY_RESET_DIC || p->control >= 0xE0)
          return LZMA2_PARSE_STATUS_NEW_BLOCK;
        // if (outSize == 0) return LZMA_STATUS_NOT_FINISHED;
      }

      // The following code can be commented.
      // It's not big problem, if we read additional input bytes.
      // It will be stopped later in LZMA2_STATE_DATA / LZMA2_STATE_DATA_CONT state.

      if (outSize == 0 && p->state != LZMA2_STATE_FINISHED)
      {
        // checkFinishBlock is true. So we expect that block must be finished,
        // We can return LZMA_STATUS_NOT_SPECIFIED or LZMA_STATUS_NOT_FINISHED here
        // break;
        return (ELzma2ParseStatus)LZMA_STATUS_NOT_FINISHED;
      }

      if (p->state == LZMA2_STATE_DATA)
        return LZMA2_PARSE_STATUS_NEW_CHUNK;

      continue;
    }

    if (outSize == 0)
      return (ELzma2ParseStatus)LZMA_STATUS_NOT_FINISHED;

    {
      SizeT inCur = inSize - *srcLen;

      if (LZMA2_IS_UNCOMPRESSED_STATE(p))
      {
        if (inCur == 0)
          return (ELzma2ParseStatus)LZMA_STATUS_NEEDS_MORE_INPUT;
        if (inCur > p->unpackSize)
          inCur = p->unpackSize;
        if (inCur > outSize)
          inCur = outSize;
        p->decoder.dicPos += inCur;
        src += inCur;
        *srcLen += inCur;
        outSize -= inCur;
        p->unpackSize -= (UInt32)inCur;
        p->state = (p->unpackSize == 0) ? LZMA2_STATE_CONTROL : LZMA2_STATE_DATA_CONT;
      }
      else
      {
        p->isExtraMode = True;

        if (inCur == 0)
        {
          if (p->packSize != 0)
            return (ELzma2ParseStatus)LZMA_STATUS_NEEDS_MORE_INPUT;
        }
        else if (p->state == LZMA2_STATE_DATA)
        {
          p->state = LZMA2_STATE_DATA_CONT;
          if (*src != 0)
          {
            // first byte of lzma chunk must be Zero
            *srcLen += 1;
            p->packSize--;
            break;
          }
        }
  
        if (inCur > p->packSize)
          inCur = (SizeT)p->packSize;

        src += inCur;
        *srcLen += inCur;
        p->packSize -= (UInt32)inCur;

        if (p->packSize == 0)
        {
          SizeT rem = outSize;
          if (rem > p->unpackSize)
            rem = p->unpackSize;
          p->decoder.dicPos += rem;
          p->unpackSize -= (UInt32)rem;
          outSize -= rem;
          if (p->unpackSize == 0)
            p->state = LZMA2_STATE_CONTROL;
        }
      }
    }
  }
  
  p->state = LZMA2_STATE_ERROR;
  return (ELzma2ParseStatus)LZMA_STATUS_NOT_SPECIFIED;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movq -0x10(%rbp), %rax
cmpl $0x9, (%rax)
je 0xabba8
movq -0x10(%rbp), %rax
cmpl $0x8, (%rax)
jne 0xab8b4
movl $0x1, -0x4(%rbp)
jmp 0xabbb9
cmpq $0x0, -0x18(%rbp)
jne 0xab8cd
cmpl $0x0, -0x2c(%rbp)
jne 0xab8cd
movl $0x2, -0x4(%rbp)
jmp 0xabbb9
movq -0x10(%rbp), %rax
cmpl $0x6, (%rax)
je 0xab99a
movq -0x10(%rbp), %rax
cmpl $0x7, (%rax)
je 0xab99a
movq -0x28(%rbp), %rax
movq (%rax), %rax
cmpq -0x38(%rbp), %rax
jne 0xab900
movl $0x3, -0x4(%rbp)
jmp 0xabbb9
movq -0x28(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rbp)
movzbl (%rax), %esi
callq 0xab590
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
cmpl $0x1, (%rax)
jne 0xab964
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x1, %eax
je 0xab956
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0xe0, %eax
jl 0xab962
movl $0x5, -0x4(%rbp)
jmp 0xabbb9
jmp 0xab964
cmpq $0x0, -0x18(%rbp)
jne 0xab980
movq -0x10(%rbp), %rax
cmpl $0x8, (%rax)
je 0xab980
movl $0x2, -0x4(%rbp)
jmp 0xabbb9
movq -0x10(%rbp), %rax
cmpl $0x6, (%rax)
jne 0xab995
movl $0x6, -0x4(%rbp)
jmp 0xabbb9
jmp 0xab892
cmpq $0x0, -0x18(%rbp)
jne 0xab9ad
movl $0x2, -0x4(%rbp)
jmp 0xabbb9
movq -0x38(%rbp), %rax
movq -0x28(%rbp), %rcx
subq (%rcx), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
jne 0xaba7c
cmpq $0x0, -0x40(%rbp)
jne 0xab9e5
movl $0x3, -0x4(%rbp)
jmp 0xabbb9
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0xc(%rcx), %ecx
cmpq %rcx, %rax
jbe 0xaba00
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x18(%rbp), %rax
jbe 0xaba12
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
addq 0x38(%rax), %rcx
movq %rcx, 0x38(%rax)
movq -0x40(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x40(%rbp), %rcx
movq -0x28(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x40(%rbp), %rcx
movq -0x18(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x18(%rbp)
movq -0x40(%rbp), %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movl 0xc(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0xc(%rax)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %edx
movl $0x7, %ecx
xorl %eax, %eax
cmpl $0x0, %edx
cmovel %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
jmp 0xabba3
movq -0x10(%rbp), %rax
movb $0x1, 0x6(%rax)
cmpq $0x0, -0x40(%rbp)
jne 0xabaa3
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
je 0xabaa1
movl $0x3, -0x4(%rbp)
jmp 0xabbb9
jmp 0xabae6
movq -0x10(%rbp), %rax
cmpl $0x6, (%rax)
jne 0xabae4
movq -0x10(%rbp), %rax
movl $0x7, (%rax)
movq -0x20(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
je 0xabae2
movq -0x28(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x8(%rax)
jmp 0xabba8
jmp 0xabae4
jmp 0xabae6
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x8(%rcx), %ecx
cmpq %rcx, %rax
jbe 0xabb01
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x40(%rbp), %rcx
movq -0x28(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x40(%rbp), %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0xabba1
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0xc(%rcx), %ecx
cmpq %rcx, %rax
jbe 0xabb5a
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rcx
movq -0x10(%rbp), %rax
addq 0x38(%rax), %rcx
movq %rcx, 0x38(%rax)
movq -0x48(%rbp), %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movl 0xc(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0xc(%rax)
movq -0x48(%rbp), %rcx
movq -0x18(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0xabb9f
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
jmp 0xabba1
jmp 0xabba3
jmp 0xab892
movq -0x10(%rbp), %rax
movl $0x9, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)