// File: /workspace/github_cpp_makefile_star2_O1/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
movq %r9, %rbx
movl %r8d, %r15d
movq %rcx, %r12
movq %rdx, %r13
movq %rdi, %r14
movq (%rcx), %r8
movq $0x0, (%rcx)
movl $0x0, (%r9)
leaq 0x10(%rdi), %rax
movq %rax, 0x30(%rsp)
movq %rsi, 0x20(%rsp)
movq %r8, 0x18(%rsp)
movl %r15d, 0xc(%rsp)
movq %rcx, 0x28(%rsp)
movl (%r14), %eax
cmpl $0x8, %eax
je 0x57b9f
cmpl $0x9, %eax
je 0x57e12
testl %r15d, %r15d
setne %dl
movq 0x38(%r14), %rbp
movq %rsi, %rcx
subq %rbp, %rcx
setne %dil
orb %dl, %dil
jne 0x57bb8
movl $0x2, (%rbx)
jmp 0x57ba5
movl $0x1, (%rbx)
movl $0x1, %ecx
testl %ecx, %ecx
je 0x57b6d
cmpl $0x2, %ecx
je 0x57b6d
jmp 0x57e0d
movl %eax, %edx
andl $-0x2, %edx
cmpl $0x6, %edx
jne 0x57c0b
movq (%r12), %rdx
movq %r8, %rdi
subq %rdx, %rdi
movq %rdi, 0x10(%rsp)
movl 0xc(%r14), %r12d
xorl %r15d, %r15d
cmpq %r12, %rcx
setae %dil
cmovbq %rcx, %r12
movb 0x4(%r14), %cl
testb %cl, %cl
js 0x57c5b
cmpq %rdx, %r8
jne 0x57d23
movl $0x3, (%rbx)
movl $0x1, %ecx
movl 0xc(%rsp), %r15d
movq 0x28(%rsp), %r12
jmp 0x57baa
movq (%r12), %rax
cmpq %r8, %rax
jne 0x57c1c
movl $0x3, (%rbx)
jmp 0x57ba5
cmpq %rbp, %rsi
sete %bpl
incq %rax
movq %rax, (%r12)
movzbl (%r13), %esi
incq %r13
movq %r14, %rdi
callq 0x57e37
movq 0x18(%rsp), %r8
movq 0x20(%rsp), %rsi
movl %eax, (%r14)
cmpl $0x8, %eax
setne %al
andb %bpl, %al
movzbl %al, %ecx
orl $0x2, %ecx
jmp 0x57baa
cmpl $0x6, %eax
jne 0x57c8c
xorl %esi, %esi
cmpb $-0x20, %cl
setae %sil
xorl %edx, %edx
cmpb $-0x60, %cl
setae %dl
movb %dil, 0xb(%rsp)
movq 0x30(%rsp), %rdi
callq 0x551e0
movb 0xb(%rsp), %dil
movl $0x7, (%r14)
movl 0x8(%r14), %eax
cmpq %rax, 0x10(%rsp)
jbe 0x57c9c
movq %rax, 0x10(%rsp)
movb %dil, %r15b
addq %rbp, %r12
movq 0x30(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
leaq 0x10(%rsp), %rcx
movl %r15d, %r8d
movq %rbx, %r9
callq 0x55226
movq 0x10(%rsp), %rdx
addq %rdx, %r13
movq 0x28(%rsp), %r12
addq %rdx, (%r12)
movl 0x8(%r14), %r11d
movl 0xc(%r14), %edi
movl %r11d, %ecx
subl %edx, %ecx
movl %ecx, 0x8(%r14)
movq 0x38(%r14), %r9
movl %r9d, %r8d
subl %ebp, %r8d
movl %edi, %ecx
subl %r8d, %ecx
movl %ecx, 0xc(%r14)
movl $0x3, %ecx
testl %eax, %eax
jne 0x57daf
movl (%rbx), %eax
cmpl $0x3, %eax
movl 0xc(%rsp), %r15d
jne 0x57ddc
xorl %eax, %eax
cmpl %edx, %r11d
sete %al
leal 0x1(,%rax,2), %ecx
jmp 0x57db4
cmpl $0x6, %eax
jne 0x57d42
xorl %esi, %esi
cmpb $0x1, %cl
sete %sil
movq 0x30(%rsp), %rdi
xorl %edx, %edx
callq 0x551e0
movq 0x18(%rsp), %r8
cmpq %r12, 0x10(%rsp)
jbe 0x57d4e
movq %r12, 0x10(%rsp)
movq 0x10(%rsp), %r15
testq %r15, %r15
je 0x57dc3
movq 0x28(%r14), %rdi
addq 0x38(%r14), %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x4290
addq %r15, 0x38(%r14)
cmpl $0x0, 0x54(%r14)
movq 0x28(%rsp), %r12
jne 0x57d8e
movl 0x14(%r14), %eax
movl %eax, %ecx
subl 0x50(%r14), %ecx
cmpq %rcx, %r15
jb 0x57d8e
movl %eax, 0x54(%r14)
addl %r15d, 0x50(%r14)
movq 0x10(%rsp), %rax
addq %rax, %r13
addq %rax, (%r12)
xorl %ecx, %ecx
subl %eax, 0xc(%r14)
movl $0x7, %eax
cmovel %ecx, %eax
movl %eax, (%r14)
movl 0xc(%rsp), %r15d
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %r8
jmp 0x57baa
movl $0x3, %ecx
movl 0xc(%rsp), %r15d
movq 0x28(%rsp), %r12
movq 0x20(%rsp), %rsi
jmp 0x57baa
xorq %rbp, %r9
movq %rdx, %r10
orq %r9, %r10
movq 0x20(%rsp), %rsi
jne 0x57e03
xorl $0x4, %eax
xorl %r8d, %edi
orl %eax, %edi
xorl %edx, %r11d
orl %edi, %r11d
jne 0x57db9
movl $0x0, (%r14)
movl $0x0, (%rbx)
xorl %ecx, %ecx
jmp 0x57db9
cmpl $0x3, %ecx
jne 0x57e26
movl $0x0, (%rbx)
movl $0x9, (%r14)
movl $0x1, %eax
jmp 0x57e28
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq