// File: /workspace/github_cpp_makefile_star2_O3/blackle[P]LZMA-Vizualizer/LzmaSpec.cpp
// Function: CLzmaDecoder::Decode(bool, unsigned long)
int CLzmaDecoder::Decode(bool unpackSizeDefined, UInt64 unpackSize)
{
  if (!RangeDec.Init())
    return LZMA_RES_ERROR;

  Init();

  UInt32 rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;
  unsigned state = 0;

  for (;;)
  {
    if (unpackSizeDefined && unpackSize == 0 && !markerIsMandatory)
      if (RangeDec.IsFinishedOK())
        return LZMA_RES_FINISHED_WITHOUT_MARKER;

    unsigned posState = OutWindow.TotalPos & ((1 << pb) - 1);

    if (RangeDec.DecodeBit(&IsMatch[(state << kNumPosBitsMax) + posState]) == 0)
    {
      if (unpackSizeDefined && unpackSize == 0)
        return LZMA_RES_ERROR;
      DecodeLiteral(state, rep0);
      PushPerplexities(1);
      Literals.push_back(true);
      state = UpdateState_Literal(state);
      unpackSize--;
      continue;
    }

    unsigned len;

    if (RangeDec.DecodeBit(&IsRep[state]) != 0)
    {
      if (unpackSizeDefined && unpackSize == 0)
        return LZMA_RES_ERROR;
      if (OutWindow.IsEmpty())
        return LZMA_RES_ERROR;
      if (RangeDec.DecodeBit(&IsRepG0[state]) == 0)
      {
        if (RangeDec.DecodeBit(&IsRep0Long[(state << kNumPosBitsMax) + posState]) == 0)
        {
          state = UpdateState_ShortRep(state);
          OutWindow.PutByte(OutWindow.GetByte(rep0 + 1));
          PushPerplexities(1);
          Literals.push_back(false);
          unpackSize--;
          continue;
        }
      }
      else
      {
        UInt32 dist;
        if (RangeDec.DecodeBit(&IsRepG1[state]) == 0)
          dist = rep1;
        else
        {
          if (RangeDec.DecodeBit(&IsRepG2[state]) == 0)
            dist = rep2;
          else
          {
            dist = rep3;
            rep3 = rep2;
          }
          rep2 = rep1;
        }
        rep1 = rep0;
        rep0 = dist;
      }
      len = RepLenDecoder.Decode(&RangeDec, posState);
      state = UpdateState_Rep(state);
    }
    else
    {
      rep3 = rep2;
      rep2 = rep1;
      rep1 = rep0;
      len = LenDecoder.Decode(&RangeDec, posState);
      state = UpdateState_Match(state);
      rep0 = DecodeDistance(len);
      if (rep0 == 0xFFFFFFFF)
        return RangeDec.IsFinishedOK() ?
            LZMA_RES_FINISHED_WITH_MARKER :
            LZMA_RES_ERROR;

      if (unpackSizeDefined && unpackSize == 0)
        return LZMA_RES_ERROR;
      if (rep0 >= dictSize || !OutWindow.CheckDistance(rep0))
        return LZMA_RES_ERROR;
    }
    len += kMatchMinLen;
    bool isError = false;
    if (unpackSizeDefined && unpackSize < len)
    {
      len = (unsigned)unpackSize;
      isError = true;
    }
    OutWindow.CopyMatch(rep0 + 1, len);
    Literals.insert(Literals.end(), len, false);
    PushPerplexities(len);
    unpackSize -= len;
    if (isError)
      return LZMA_RES_ERROR;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdx, %r14
movl %esi, -0x44(%rbp)
movq %rdi, %rbx
callq 0x245c
testb %al, %al
je 0x2b14
movq %r14, %r13
movq %rbx, %rdi
callq 0x3938
leaq 0x18(%rbx), %rax
movq %rax, -0x68(%rbp)
leaq 0x3ae(%rbx), %rax
movq %rax, -0xb8(%rbp)
leaq 0x52e(%rbx), %rax
movq %rax, -0xa8(%rbp)
leaq 0x546(%rbx), %rax
movq %rax, -0xa0(%rbp)
leaq 0x55e(%rbx), %rax
movq %rax, -0x80(%rbp)
leaq 0x576(%rbx), %rax
movq %rax, -0x78(%rbp)
leaq 0x58e(%rbx), %rax
movq %rax, -0x98(%rbp)
leaq 0xb12(%rbx), %rax
movq %rax, -0x90(%rbp)
leaq 0x60(%rbx), %rax
movq %rax, -0x50(%rbp)
leaq 0x70e(%rbx), %rax
movq %rax, -0x88(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq $0x0, -0x40(%rbp)
movq %rbx, -0x60(%rbp)
movq %rbx, %r14
movq -0x40(%rbp), %rax
leal 0x1(%rax), %ecx
movl %ecx, -0x58(%rbp)
notl %eax
movl %eax, -0x54(%rbp)
movq %r13, %rdx
movq %r13, %rcx
movl -0x2c(%rbp), %ebx
subq $0x1, %rcx
setb %r13b
andb -0x44(%rbp), %r13b
cmpb $0x1, %r13b
jne 0x2801
cmpb $0x0, 0x88(%r14)
jne 0x2801
cmpl $0x0, 0x4(%r14)
je 0x2b2a
movq %rdx, -0xb0(%rbp)
movq %rcx, -0x70(%rbp)
movb 0x90(%r14), %cl
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
shll %cl, %r12d
notl %r12d
andl 0x2c(%r14), %r12d
movl %ebx, %r15d
shll $0x4, %r15d
addl %r12d, %r15d
movq -0xb8(%rbp), %rax
leaq (%rax,%r15,2), %rsi
movq %r14, %rdi
callq 0x2570
testl %eax, %eax
je 0x291c
movl %ebx, -0x2c(%rbp)
movl %ebx, %ebx
movq -0xa8(%rbp), %rax
leaq (%rax,%rbx,2), %rsi
movq %r14, %rdi
callq 0x2570
testl %eax, %eax
je 0x2987
xorl %edx, %edx
testb %r13b, %r13b
jne 0x2b16
cmpl $0x0, 0x20(%r14)
jne 0x2885
testb $0x1, 0x28(%r14)
je 0x2b16
movq -0xa0(%rbp), %rax
leaq (%rax,%rbx,2), %rsi
movq %r14, %rdi
callq 0x2570
testl %eax, %eax
jne 0x29f8
movq -0x98(%rbp), %rax
leaq (%rax,%r15,2), %rsi
movq %r14, %rdi
callq 0x2570
testl %eax, %eax
jne 0x2a3b
xorl %ecx, %ecx
cmpl $0x7, -0x2c(%rbp)
setae %sil
movl 0x20(%r14), %eax
movl $0x0, %edx
cmpl -0x58(%rbp), %eax
jae 0x28d7
movl 0x24(%r14), %edx
movb %sil, %cl
movq %r14, %rbx
leal 0x9(,%rcx,2), %r14d
movq 0x18(%rbx), %rcx
addl -0x54(%rbp), %eax
addl %edx, %eax
movzbl (%rcx,%rax), %esi
movq -0x68(%rbp), %rdi
callq 0x3c64
movq %rbx, %r12
movq %rbx, %rdi
movl $0x1, %esi
callq 0x3b94
movq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x3c10
movq -0x70(%rbp), %rcx
jmp 0x2979
testb %r13b, %r13b
jne 0x2b14
movq -0x60(%rbp), %rdi
movl %ebx, %r15d
movq %rdi, %rbx
movl %r15d, %esi
movq -0x40(%rbp), %rdx
callq 0x3a6a
movq %rbx, %r12
movq %rbx, %rdi
movl $0x1, %esi
callq 0x3b94
movq -0x50(%rbp), %rdi
movl $0x1, %esi
callq 0x3c10
xorl %r14d, %r14d
cmpl $0x4, %r15d
movq -0x70(%rbp), %rcx
jb 0x2979
cmpl $0x9, %r15d
ja 0x2972
addl $-0x3, %r15d
jmp 0x2976
addl $-0x6, %r15d
movl %r15d, %r14d
movl %r14d, %ebx
movq %rcx, %rdx
movq %r12, %r14
jmp 0x27da
movq -0x88(%rbp), %rdi
movq %r14, %rsi
movl %r12d, %edx
callq 0x3c9c
movl %eax, %r12d
movq %r14, %rbx
xorl %r14d, %r14d
cmpl $0x7, -0x2c(%rbp)
setae %r15b
movq %rbx, %rdi
movl %eax, %esi
callq 0x3d7c
cmpl $-0x1, %eax
je 0x2b31
movl %eax, %ecx
cmpl 0x98(%rbx), %eax
setae %al
xorl %edx, %edx
orb %al, %r13b
jne 0x2b16
movb %r15b, %r14b
leal (%r14,%r14,2), %eax
addl $0x7, %eax
movl %eax, -0x2c(%rbp)
cmpl %ecx, 0x20(%rbx)
jae 0x2a96
testb $0x1, 0x28(%rbx)
jne 0x2a96
jmp 0x2b16
movq -0x80(%rbp), %rax
leaq (%rax,%rbx,2), %rsi
movq %r14, %rdi
callq 0x2570
testl %eax, %eax
je 0x2a45
movq -0x78(%rbp), %rax
leaq (%rax,%rbx,2), %rsi
movq %r14, %rdi
callq 0x2570
testl %eax, %eax
movl -0x38(%rbp), %edx
movl %edx, %eax
movl -0x30(%rbp), %ecx
cmovel %ecx, %eax
cmovel %edx, %ecx
movl %ecx, -0x38(%rbp)
movl -0x34(%rbp), %ecx
movq -0x40(%rbp), %rdx
movl %edx, %r14d
jmp 0x2a52
movl -0x34(%rbp), %r14d
movq -0x40(%rbp), %rax
jmp 0x2a4f
movq -0x40(%rbp), %rax
movl %eax, %r14d
movl -0x34(%rbp), %eax
movl -0x30(%rbp), %ecx
movl -0x2c(%rbp), %ebx
movl %eax, %r13d
movl %ecx, -0x34(%rbp)
movq -0x90(%rbp), %rdi
movq -0x60(%rbp), %r15
movq %r15, %rsi
movl %r12d, %edx
callq 0x3c9c
movq %r13, %rcx
movl %eax, %r12d
xorl %eax, %eax
cmpl $0x7, %ebx
movq %r15, %rbx
setae %al
leal 0x8(%rax,%rax,2), %eax
movl %eax, -0x2c(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x30(%rbp)
movl %r14d, %eax
movq %rax, -0x40(%rbp)
addl $0x2, %r12d
movq -0xb0(%rbp), %r13
cmpq %r12, %r13
setb %r14b
andb -0x44(%rbp), %r14b
movl %r13d, %r15d
cmovel %r12d, %r15d
leal 0x1(%rcx), %esi
movq -0x68(%rbp), %rdi
movl %r15d, %edx
movq %rcx, %r12
callq 0x3eba
movq 0x70(%rbx), %rsi
movl 0x78(%rbx), %edx
movq -0x50(%rbp), %rdi
movq %r15, %rcx
xorl %r8d, %r8d
callq 0x511e
movq %rbx, %rdi
movl %r15d, %esi
callq 0x3b94
xorl %edx, %edx
subq %r15, %r13
movl -0x30(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x40(%rbp), %rax
movl %eax, -0x34(%rbp)
movl %r12d, %eax
movq %rax, -0x40(%rbp)
cmpb $0x1, %r14b
movq %rbx, %r14
jne 0x27c2
jmp 0x2b16
xorl %edx, %edx
movl %edx, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x2, %edx
jmp 0x2b16
xorl %edx, %edx
cmpl $0x0, 0x4(%rbx)
sete %dl
jmp 0x2b16