// File: sisong[P]ApkDiffPatch/lzma/C/Lzma2Dec.c
// Function: Lzma2Dec_UpdateState
static unsigned Lzma2Dec_UpdateState(CLzma2Dec *p, Byte b)
{
  switch (p->state)
  {
    case LZMA2_STATE_CONTROL:
      p->isExtraMode = False;
      p->control = b;
      PRF(printf("\n %8X", (unsigned)p->decoder.dicPos));
      PRF(printf(" %02X", (unsigned)b));
      if (b == 0)
        return LZMA2_STATE_FINISHED;
      if (LZMA2_IS_UNCOMPRESSED_STATE(p))
      {
        if (b == LZMA2_CONTROL_COPY_RESET_DIC)
          p->needInitLevel = 0xC0;
        else if (b > 2 || p->needInitLevel == 0xE0)
          return LZMA2_STATE_ERROR;
      }
      else
      {
        if (b < p->needInitLevel)
          return LZMA2_STATE_ERROR;
        p->needInitLevel = 0;
        p->unpackSize = (UInt32)(b & 0x1F) << 16;
      }
      return LZMA2_STATE_UNPACK0;
    
    case LZMA2_STATE_UNPACK0:
      p->unpackSize |= (UInt32)b << 8;
      return LZMA2_STATE_UNPACK1;
    
    case LZMA2_STATE_UNPACK1:
      p->unpackSize |= (UInt32)b;
      p->unpackSize++;
      PRF(printf(" %7u", (unsigned)p->unpackSize));
      return LZMA2_IS_UNCOMPRESSED_STATE(p) ? LZMA2_STATE_DATA : LZMA2_STATE_PACK0;
    
    case LZMA2_STATE_PACK0:
      p->packSize = (UInt32)b << 8;
      return LZMA2_STATE_PACK1;

    case LZMA2_STATE_PACK1:
      p->packSize |= (UInt32)b;
      p->packSize++;
      // if (p->packSize < 5) return LZMA2_STATE_ERROR;
      PRF(printf(" %5u", (unsigned)p->packSize));
      return (p->control & 0x40) ? LZMA2_STATE_PROP : LZMA2_STATE_DATA;

    case LZMA2_STATE_PROP:
    {
      unsigned lc, lp;
      if (b >= (9 * 5 * 5))
        return LZMA2_STATE_ERROR;
      lc = b % 9;
      b /= 9;
      p->decoder.prop.pb = (Byte)(b / 5);
      lp = b % 5;
      if (lc + lp > LZMA2_LCLP_MAX)
        return LZMA2_STATE_ERROR;
      p->decoder.prop.lc = (Byte)lc;
      p->decoder.prop.lp = (Byte)lp;
      return LZMA2_STATE_DATA;
    }
    
    default:
      return LZMA2_STATE_ERROR;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movb %sil, %al
movq %rdi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movq %rax, -0x28(%rbp)
subq $0x5, %rax
ja 0xab7bc
movq -0x28(%rbp), %rax
leaq 0x14f13(%rip), %rcx     # 0xc04d0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
movb $0x0, 0x6(%rax)
movb -0x11(%rbp), %cl
movq -0x10(%rbp), %rax
movb %cl, 0x4(%rax)
movzbl -0x11(%rbp), %eax
cmpl $0x0, %eax
jne 0xab5ed
movl $0x8, -0x4(%rbp)
jmp 0xab7c3
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
jne 0xab63a
movzbl -0x11(%rbp), %eax
cmpl $0x1, %eax
jne 0xab612
movq -0x10(%rbp), %rax
movb $-0x40, 0x5(%rax)
jmp 0xab638
movzbl -0x11(%rbp), %eax
cmpl $0x2, %eax
jg 0xab62a
movq -0x10(%rbp), %rax
movzbl 0x5(%rax), %eax
cmpl $0xe0, %eax
jne 0xab636
movl $0x9, -0x4(%rbp)
jmp 0xab7c3
jmp 0xab638
jmp 0xab66f
movzbl -0x11(%rbp), %eax
movq -0x10(%rbp), %rcx
movzbl 0x5(%rcx), %ecx
cmpl %ecx, %eax
jge 0xab656
movl $0x9, -0x4(%rbp)
jmp 0xab7c3
movq -0x10(%rbp), %rax
movb $0x0, 0x5(%rax)
movzbl -0x11(%rbp), %ecx
andl $0x1f, %ecx
shll $0x10, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movl $0x1, -0x4(%rbp)
jmp 0xab7c3
movzbl -0x11(%rbp), %ecx
shll $0x8, %ecx
movq -0x10(%rbp), %rax
orl 0xc(%rax), %ecx
movl %ecx, 0xc(%rax)
movl $0x2, -0x4(%rbp)
jmp 0xab7c3
movzbl -0x11(%rbp), %ecx
movq -0x10(%rbp), %rax
orl 0xc(%rax), %ecx
movl %ecx, 0xc(%rax)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xc(%rax)
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %edx
andl $0x80, %edx
movl $0x3, %eax
movl $0x6, %ecx
cmpl $0x0, %edx
cmovel %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0xab7c3
movzbl -0x11(%rbp), %ecx
shll $0x8, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x8(%rax)
movl $0x4, -0x4(%rbp)
jmp 0xab7c3
movzbl -0x11(%rbp), %ecx
movq -0x10(%rbp), %rax
orl 0x8(%rax), %ecx
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %edx
andl $0x40, %edx
movl $0x6, %eax
movl $0x5, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0xab7c3
movzbl -0x11(%rbp), %eax
cmpl $0xe1, %eax
jl 0xab745
movl $0x9, -0x4(%rbp)
jmp 0xab7c3
movzbl -0x11(%rbp), %eax
movl $0x9, %ecx
cltd
idivl %ecx
movl %edx, -0x18(%rbp)
movzbl -0x11(%rbp), %eax
movl $0x9, %ecx
cltd
idivl %ecx
movb %al, -0x11(%rbp)
movzbl -0x11(%rbp), %eax
movl $0x5, %ecx
cltd
idivl %ecx
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x12(%rax)
movzbl -0x11(%rbp), %eax
movl $0x5, %ecx
cltd
idivl %ecx
movl %edx, -0x1c(%rbp)
movl -0x18(%rbp), %eax
addl -0x1c(%rbp), %eax
cmpl $0x4, %eax
jbe 0xab79b
movl $0x9, -0x4(%rbp)
jmp 0xab7c3
movl -0x18(%rbp), %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x10(%rax)
movl -0x1c(%rbp), %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x11(%rax)
movl $0x6, -0x4(%rbp)
jmp 0xab7c3
movl $0x9, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopl (%rax,%rax)