// File: /workspace/github_cpp_makefile_star2_O2/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 (%rcx), %r8
andq $0x0, (%rcx)
movq %rdi, %r14
movq %r9, (%rsp)
andl $0x0, (%r9)
leaq 0x10(%rdi), %rax
movq %rax, 0x18(%rsp)
movq %r8, 0x10(%rsp)
movl %ebx, 0x24(%rsp)
movq %rcx, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movl (%r14), %eax
cmpl $0x9, %eax
je 0x4d406
cmpl $0x8, %eax
je 0x4d3dc
testl %ebx, %ebx
setne %dl
movq 0x38(%r14), %r15
movq %rbp, %rcx
subq %r15, %rcx
setne %sil
orb %dl, %sil
je 0x4d3e8
movl %eax, %edx
andl $-0x2, %edx
cmpl $0x6, %edx
jne 0x4d271
movq (%r13), %rdx
movq %r8, %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 0x4d2b4
cmpq %rdx, %r8
je 0x4d3f4
cmpl $0x6, %eax
jne 0x4d221
xorl %esi, %esi
cmpb $0x1, %cl
sete %sil
movq 0x18(%rsp), %rdi
xorl %edx, %edx
callq 0x4aaac
movq 0x8(%rsp), %rbx
cmpq %rbp, %rbx
movq 0x30(%rsp), %r13
jbe 0x4d233
movq %rbp, 0x8(%rsp)
movq %rbp, %rbx
testq %rbx, %rbx
movq 0x28(%rsp), %rbp
je 0x4d406
movq 0x28(%r14), %rdi
addq 0x38(%r14), %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x42c0
addq %rbx, 0x38(%r14)
cmpl $0x0, 0x54(%r14)
je 0x4d395
movl 0x50(%r14), %eax
movq 0x10(%rsp), %r8
jmp 0x4d3af
movq (%r13), %rax
cmpq %r8, %rax
je 0x4d3f4
incq %rax
movq %rax, (%r13)
movzbl (%r12), %esi
incq %r12
movq %r14, %rdi
callq 0x4d426
movq 0x10(%rsp), %r8
movl %eax, (%r14)
cmpq %r15, %rbp
jne 0x4d18d
cmpl $0x8, %eax
je 0x4d18d
jmp 0x4d406
cmpl $0x6, %eax
jne 0x4d2e4
movl %esi, %ebx
xorl %esi, %esi
cmpb $-0x20, %cl
setae %sil
xorl %edx, %edx
cmpb $-0x60, %cl
setae %dl
movq 0x18(%rsp), %rdi
callq 0x4aaac
movl %ebx, %esi
movl $0x7, (%r14)
movq 0x8(%rsp), %rbx
movl 0x8(%r14), %eax
cmpq %rax, %rbx
jbe 0x4d2f2
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 0x4aae9
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 0x4d406
movq (%rsp), %rax
movl (%rax), %eax
cmpl $0x3, %eax
je 0x4d402
xorq %r15, %r8
orq %rcx, %r8
jne 0x4d387
cmpl $0x4, %eax
jne 0x4d406
cmpl %edi, %esi
jne 0x4d406
cmpl %ecx, %edx
jne 0x4d406
andl $0x0, (%r14)
movq (%rsp), %rax
andl $0x0, (%rax)
movq 0x10(%rsp), %r8
jmp 0x4d3d0
movl 0x14(%r14), %ecx
movl 0x50(%r14), %eax
movl %ecx, %edx
subl %eax, %edx
cmpq %rdx, %rbx
movq 0x10(%rsp), %r8
jb 0x4d3af
movl %ecx, 0x54(%r14)
addl %eax, %ebx
movl %ebx, 0x50(%r14)
movq 0x8(%rsp), %rcx
addq %rcx, (%r13)
subl %ecx, 0xc(%r14)
pushq $0x7
popq %rax
movl $0x0, %edx
cmovel %edx, %eax
movl %eax, (%r14)
addq %rcx, %r12
movl 0x24(%rsp), %ebx
jmp 0x4d18d
movq (%rsp), %rax
movl $0x1, (%rax)
jmp 0x4d3fe
movq (%rsp), %rax
movl $0x2, (%rax)
jmp 0x4d3fe
movq (%rsp), %rax
movl $0x3, (%rax)
xorl %eax, %eax
jmp 0x4d417
cmpl %ecx, %edx
jne 0x4d3fe
movq (%rsp), %rax
andl $0x0, (%rax)
movl $0x9, (%r14)
pushq $0x1
popq %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq