// File: /workspace/github_cpp_makefile_star2_O3/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 %rsi, %r13
movq %rdi, %rbx
movq (%rcx), %r15
movq $0x0, (%rcx)
movl (%rdi), %eax
movl %r8d, 0x4(%rsp)
movl $0x2, %r12d
testl %r8d, %r8d
setne %cl
testq %r13, %r13
setne %dil
orb %cl, %dil
movb %dil, 0x3(%rsp)
movq %rdx, %rbp
cmpl $0x8, %eax
je 0x57def
cmpl $0x9, %eax
je 0x57e21
cmpb $0x0, 0x3(%rsp)
je 0x57e2a
movl %eax, %ecx
andl $-0x2, %ecx
cmpl $0x6, %ecx
je 0x57cee
movq (%r14), %rax
cmpq %r15, %rax
je 0x57df7
incq %rax
movq %rax, (%r14)
movzbl (%rbp), %esi
movq %rbx, %rdi
callq 0x57af5
movl %eax, (%rbx)
cmpl $0x1, %eax
jne 0x57ccf
movb 0x4(%rbx), %cl
cmpb $0x1, %cl
sete %dl
cmpb $-0x20, %cl
setae %cl
orb %dl, %cl
jne 0x57e07
testq %r13, %r13
jne 0x57cdd
jmp 0x57e07
testq %r13, %r13
jne 0x57cdd
cmpl $0x8, %eax
jne 0x57e2a
incq %rbp
cmpl $0x6, %eax
jne 0x57c62
jmp 0x57dff
testq %r13, %r13
je 0x57e2a
movq (%r14), %rdi
movq %r15, %r11
subq %rdi, %r11
cmpb $0x0, 0x4(%rbx)
jns 0x57da6
movb $0x1, 0x6(%rbx)
movq %r15, %rcx
subq %rdi, %rcx
jne 0x57d24
xorl %r8d, %r8d
cmpl $0x0, 0x8(%rbx)
je 0x57d4d
jmp 0x57df7
cmpl $0x6, %eax
je 0x57d34
movl 0x8(%rbx), %r8d
movl $0x7, %eax
jmp 0x57d4d
movl $0x7, (%rbx)
cmpb $0x0, (%rbp)
movl 0x8(%rbx), %r8d
movl $0x7, %eax
jne 0x57e14
movl %r8d, %r9d
cmpq %r9, %r11
cmovaeq %r9, %r11
leaq (%r11,%rbp), %rdx
addq %r11, %rdi
movq %rdi, (%r14)
subl %r11d, %r8d
movl %r8d, 0x8(%rbx)
jne 0x57c5f
movl 0xc(%rbx), %r8d
cmpq %r8, %r13
movq %r8, %rdi
cmovbq %r13, %rdi
addq %rdi, 0x38(%rbx)
subq %rdi, %r13
cmpq %r9, %rcx
cmovbq %rcx, %r9
addq %r9, %rbp
xorl %ecx, %ecx
movq %rbp, %rdx
subl %edi, %r8d
movl %r8d, 0xc(%rbx)
movl 0x4(%rsp), %r8d
jne 0x57c4a
jmp 0x57de3
cmpq %rdi, %r15
je 0x57df7
movl 0xc(%rbx), %eax
cmpq %rax, %r11
movq %rax, %rcx
cmovbq %r11, %rcx
cmpq %r13, %rcx
cmovaeq %r13, %rcx
addq %rcx, 0x38(%rbx)
addq %rcx, (%r14)
addq %rcx, %rbp
subq %rcx, %r13
subl %ecx, %eax
movl %eax, 0xc(%rbx)
movl $0x7, %ecx
movl $0x0, %eax
cmovel %eax, %ecx
movl 0x4(%rsp), %r8d
movl %ecx, (%rbx)
movl %ecx, %eax
movq %rbp, %rdx
jmp 0x57c4a
movl $0x1, %r12d
jmp 0x57e2a
movl $0x3, %r12d
jmp 0x57e2a
movl $0x6, %r12d
jmp 0x57e2a
movzbl %cl, %eax
leal (%rax,%rax,2), %r12d
addl $0x2, %r12d
jmp 0x57e2a
incq %rdi
movq %rdi, (%r14)
decl %r8d
movl %r8d, 0x8(%rbx)
movl $0x9, (%rbx)
xorl %r12d, %r12d
movl %r12d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq