// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
movq (%rcx), %r13
movq $0x0, (%rcx)
movl %r8d, 0x4(%rsp)
testl %r8d, %r8d
setne %al
testq %r12, %r12
setne %bpl
orb %al, %bpl
movl (%rbx), %ecx
cmpl $0x8, %ecx
je 0x5811a
cmpl $0x9, %ecx
je 0x58110
movl $0x2, %eax
testb %bpl, %bpl
je 0x5812d
movl %ecx, %edx
andl $-0x2, %edx
cmpl $0x6, %edx
je 0x58028
movq (%r14), %rax
cmpq %r13, %rax
je 0x58121
incq %rax
movq %rax, (%r14)
movzbl (%r15), %esi
movq %rbx, %rdi
callq 0x57e37
movl %eax, %ecx
movl %eax, (%rbx)
cmpl $0x1, %eax
jne 0x58004
movb 0x4(%rbx), %dl
movl $0x5, %eax
cmpb $0x1, %dl
je 0x5812d
cmpb $-0x21, %dl
ja 0x5812d
testq %r12, %r12
jne 0x58017
movl $0x2, %eax
cmpl $0x8, %ecx
jne 0x5812d
incq %r15
cmpl $0x6, %ecx
jne 0x57f97
jmp 0x58128
testq %r12, %r12
je 0x5812d
movq (%r14), %rax
movq %r13, %rdx
subq %rax, %rdx
cmpb $0x0, 0x4(%rbx)
js 0x58082
movl $0x1, %ecx
cmpq %rax, %r13
je 0x580f9
movl 0xc(%rbx), %eax
cmpq %rax, %rdx
movq %rax, %rsi
cmovbq %rdx, %rsi
cmpq %r12, %rsi
cmovaeq %r12, %rsi
addq %rsi, 0x38(%rbx)
addq %rsi, %r15
addq %rsi, (%r14)
subq %rsi, %r12
xorl %ecx, %ecx
subl %esi, %eax
movl %eax, 0xc(%rbx)
movl $0x7, %eax
cmovel %ecx, %eax
movl %eax, (%rbx)
jmp 0x580f9
movb $0x1, 0x6(%rbx)
cmpq %rax, %r13
jne 0x58098
movl $0x1, %ecx
cmpl $0x0, 0x8(%rbx)
jne 0x580f9
jmp 0x580b9
cmpl $0x6, %ecx
jne 0x580b9
movl $0x7, (%rbx)
cmpb $0x0, (%r15)
je 0x580b9
incq %rax
movq %rax, (%r14)
decl 0x8(%rbx)
movl $0x3, %ecx
jmp 0x580f9
movl 0x8(%rbx), %esi
cmpq %rsi, %rdx
movq %rsi, %rdi
cmovbq %rdx, %rdi
addq %rdi, %r15
addq %rdi, %rax
movq %rax, (%r14)
xorl %ecx, %ecx
subl %edi, %esi
movl %esi, 0x8(%rbx)
jne 0x580f9
movl 0xc(%rbx), %eax
cmpq %rax, %r12
movq %rax, %rdx
cmovbq %r12, %rdx
addq %rdx, 0x38(%rbx)
subq %rdx, %r12
subl %edx, %eax
movl %eax, 0xc(%rbx)
jne 0x580f9
movl $0x0, (%rbx)
movl 0x4(%rsp), %r8d
testl %ecx, %ecx
je 0x57f87
movl $0x3, %eax
cmpl $0x3, %ecx
jne 0x5812d
movl $0x9, (%rbx)
xorl %eax, %eax
jmp 0x5812d
movl $0x1, %eax
jmp 0x5812d
movl $0x3, %eax
jmp 0x5812d
movl $0x6, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq