// File: /workspace/github_cpp_makefile_star2_O3/sisong[P]ApkDiffPatch/lzma/C/Lzma2Dec.c
// Function: Lzma2Dec_DecodeToDic
SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit,
    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
{
  SizeT inSize = *srcLen;
  *srcLen = 0;
  *status = LZMA_STATUS_NOT_SPECIFIED;

  while (p->state != LZMA2_STATE_ERROR)
  {
    SizeT dicPos;

    if (p->state == LZMA2_STATE_FINISHED)
    {
      *status = LZMA_STATUS_FINISHED_WITH_MARK;
      return SZ_OK;
    }
    
    dicPos = p->decoder.dicPos;
    
    if (dicPos == dicLimit && finishMode == LZMA_FINISH_ANY)
    {
      *status = LZMA_STATUS_NOT_FINISHED;
      return SZ_OK;
    }

    if (p->state != LZMA2_STATE_DATA && p->state != LZMA2_STATE_DATA_CONT)
    {
      if (*srcLen == inSize)
      {
        *status = LZMA_STATUS_NEEDS_MORE_INPUT;
        return SZ_OK;
      }
      (*srcLen)++;
      p->state = Lzma2Dec_UpdateState(p, *src++);
      if (dicPos == dicLimit && p->state != LZMA2_STATE_FINISHED)
        break;
      continue;
    }
    
    {
      SizeT inCur = inSize - *srcLen;
      SizeT outCur = dicLimit - dicPos;
      ELzmaFinishMode curFinishMode = LZMA_FINISH_ANY;
      
      if (outCur >= p->unpackSize)
      {
        outCur = (SizeT)p->unpackSize;
        curFinishMode = LZMA_FINISH_END;
      }

      if (LZMA2_IS_UNCOMPRESSED_STATE(p))
      {
        if (inCur == 0)
        {
          *status = LZMA_STATUS_NEEDS_MORE_INPUT;
          return SZ_OK;
        }

        if (p->state == LZMA2_STATE_DATA)
        {
          BoolInt initDic = (p->control == LZMA2_CONTROL_COPY_RESET_DIC);
          LzmaDec_InitDicAndState(&p->decoder, initDic, False);
        }

        if (inCur > outCur)
          inCur = outCur;
        if (inCur == 0)
          break;

        LzmaDec_UpdateWithUncompressed(&p->decoder, src, inCur);

        src += inCur;
        *srcLen += inCur;
        p->unpackSize -= (UInt32)inCur;
        p->state = (p->unpackSize == 0) ? LZMA2_STATE_CONTROL : LZMA2_STATE_DATA_CONT;
      }
      else
      {
        SRes res;

        if (p->state == LZMA2_STATE_DATA)
        {
          BoolInt initDic = (p->control >= 0xE0);
          BoolInt initState = (p->control >= 0xA0);
          LzmaDec_InitDicAndState(&p->decoder, initDic, initState);
          p->state = LZMA2_STATE_DATA_CONT;
        }
  
        if (inCur > p->packSize)
          inCur = (SizeT)p->packSize;
        
        res = LzmaDec_DecodeToDic(&p->decoder, dicPos + outCur, src, &inCur, curFinishMode, status);

        src += inCur;
        *srcLen += inCur;
        p->packSize -= (UInt32)inCur;
        outCur = p->decoder.dicPos - dicPos;
        p->unpackSize -= (UInt32)outCur;

        if (res != 0)
          break;
        
        if (*status == LZMA_STATUS_NEEDS_MORE_INPUT)
        {
          if (p->packSize == 0)
            break;
          return SZ_OK;
        }

        if (inCur == 0 && outCur == 0)
        {
          if (*status != LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
              || p->unpackSize != 0
              || p->packSize != 0)
            break;
          p->state = LZMA2_STATE_CONTROL;
        }
        
        *status = LZMA_STATUS_NOT_SPECIFIED;
      }
    }
  }
  
  *status = LZMA_STATUS_NOT_SPECIFIED;
  p->state = LZMA2_STATE_ERROR;
  return SZ_ERROR_DATA;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r8d, %ebx
movq %rcx, %r13
movq %rdx, %r12
movq %rsi, %rbp
movq %rdi, %r14
movq (%rcx), %rdi
movq $0x0, (%rcx)
movq %r9, (%rsp)
movl $0x0, (%r9)
leaq 0x10(%r14), %rax
movq %rax, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
movl %r8d, 0x24(%rsp)
movq %rcx, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movl (%r14), %eax
cmpl $0x9, %eax
je 0x57ad0
cmpl $0x8, %eax
je 0x57aa6
testl %ebx, %ebx
setne %dl
movq 0x38(%r14), %r15
movq %rbp, %rcx
subq %r15, %rcx
setne %sil
orb %dl, %sil
je 0x57ab2
movl %eax, %edx
andl $-0x2, %edx
cmpl $0x6, %edx
jne 0x57933
movq (%r13), %rdx
movq %rdi, %rbx
subq %rdx, %rbx
movq %rbx, 0x8(%rsp)
movl 0xc(%r14), %ebp
xorl %r13d, %r13d
cmpq %rbp, %rcx
setae %sil
cmovbq %rcx, %rbp
movb 0x4(%r14), %cl
testb %cl, %cl
js 0x57976
cmpq %rdx, %rdi
je 0x57abe
cmpl $0x6, %eax
jne 0x578e3
xorl %esi, %esi
cmpb $0x1, %cl
sete %sil
movq 0x18(%rsp), %rdi
xorl %edx, %edx
callq 0x54fb4
movq 0x8(%rsp), %rbx
cmpq %rbp, %rbx
movq 0x30(%rsp), %r13
jbe 0x578f5
movq %rbp, 0x8(%rsp)
movq %rbp, %rbx
testq %rbx, %rbx
movq 0x28(%rsp), %rbp
je 0x57ad0
movq 0x28(%r14), %rdi
addq 0x38(%r14), %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x4290
addq %rbx, 0x38(%r14)
cmpl $0x0, 0x54(%r14)
je 0x57a5d
movl 0x50(%r14), %eax
movq 0x10(%rsp), %rdi
jmp 0x57a77
movq (%r13), %rax
cmpq %rdi, %rax
je 0x57abe
incq %rax
movq %rax, (%r13)
movzbl (%r12), %esi
incq %r12
movq %r14, %rdi
callq 0x57af5
movq 0x10(%rsp), %rdi
movl %eax, (%r14)
cmpq %r15, %rbp
jne 0x5784f
cmpl $0x8, %eax
je 0x5784f
jmp 0x57ad0
cmpl $0x6, %eax
jne 0x579a6
movl %esi, %ebx
xorl %esi, %esi
cmpb $-0x20, %cl
setae %sil
xorl %edx, %edx
cmpb $-0x60, %cl
setae %dl
movq 0x18(%rsp), %rdi
callq 0x54fb4
movl %ebx, %esi
movl $0x7, (%r14)
movq 0x8(%rsp), %rbx
movl 0x8(%r14), %eax
cmpq %rax, %rbx
jbe 0x579b4
movq %rax, 0x8(%rsp)
movb %sil, %r13b
addq %r15, %rbp
movq 0x18(%rsp), %rdi
movq %rbp, %rsi
movq %r12, %rdx
leaq 0x8(%rsp), %rcx
movl %r13d, %r8d
movq (%rsp), %r9
callq 0x54ffa
movq 0x8(%rsp), %rcx
movq 0x30(%rsp), %r13
addq %rcx, (%r13)
movl 0x8(%r14), %edx
movl 0xc(%r14), %esi
movl %edx, %edi
subl %ecx, %edi
movl %edi, 0x8(%r14)
movq 0x38(%r14), %r8
movl %r8d, %edi
subl %r15d, %edi
movl %esi, %r9d
subl %edi, %r9d
movl %r9d, 0xc(%r14)
testl %eax, %eax
movq 0x28(%rsp), %rbp
jne 0x57ad0
movq (%rsp), %rax
movl (%rax), %eax
cmpl $0x3, %eax
je 0x57acc
xorq %r15, %r8
orq %rcx, %r8
jne 0x57a4c
cmpl $0x4, %eax
jne 0x57ad0
cmpl %edi, %esi
jne 0x57ad0
cmpl %ecx, %edx
jne 0x57ad0
movl $0x0, (%r14)
movq (%rsp), %rax
movl $0x0, (%rax)
movq 0x10(%rsp), %rdi
jmp 0x57a9a
movl 0x14(%r14), %ecx
movl 0x50(%r14), %eax
movl %ecx, %edx
subl %eax, %edx
cmpq %rdx, %rbx
movq 0x10(%rsp), %rdi
jb 0x57a77
movl %ecx, 0x54(%r14)
addl %eax, %ebx
movl %ebx, 0x50(%r14)
movq 0x8(%rsp), %rcx
addq %rcx, (%r13)
subl %ecx, 0xc(%r14)
movl $0x7, %eax
movl $0x0, %edx
cmovel %edx, %eax
movl %eax, (%r14)
addq %rcx, %r12
movl 0x24(%rsp), %ebx
jmp 0x5784f
movq (%rsp), %rax
movl $0x1, (%rax)
jmp 0x57ac8
movq (%rsp), %rax
movl $0x2, (%rax)
jmp 0x57ac8
movq (%rsp), %rax
movl $0x3, (%rax)
xorl %eax, %eax
jmp 0x57ae6
cmpl %ecx, %edx
jne 0x57ac8
movq (%rsp), %rax
movl $0x0, (%rax)
movl $0x9, (%r14)
movl $0x1, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq