// File: /workspace/github_cpp_makefile_star2_O2/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, -0x54(%rbp)
movq %rdi, %rbx
callq 0x240c
testb %al, %al
je 0x2ac5
movq %r14, %r13
movq %rbx, %rdi
callq 0x3444
leaq 0x18(%rbx), %rax
movq %rax, -0x78(%rbp)
leaq 0x3ae(%rbx), %rax
movq %rax, -0xc0(%rbp)
leaq 0x52e(%rbx), %rax
movq %rax, -0xb0(%rbp)
leaq 0x546(%rbx), %rax
movq %rax, -0xa8(%rbp)
leaq 0x55e(%rbx), %rax
movq %rax, -0x88(%rbp)
leaq 0x576(%rbx), %rax
movq %rax, -0x80(%rbp)
leaq 0x58e(%rbx), %rax
movq %rax, -0xa0(%rbp)
leaq 0xb12(%rbx), %rax
movq %rax, -0x98(%rbp)
leaq 0x60(%rbx), %rax
movq %rax, -0x60(%rbp)
leaq 0x70e(%rbx), %rax
movq %rax, -0x90(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movq $0x0, -0x48(%rbp)
movq %rbx, -0x70(%rbp)
movq %rbx, %r14
movq -0x48(%rbp), %rax
leal 0x1(%rax), %ecx
movl %ecx, -0x68(%rbp)
notl %eax
movl %eax, -0x64(%rbp)
movq %r13, %rcx
movl -0x2c(%rbp), %ebx
subq $0x1, %rcx
setb %r12b
andb -0x54(%rbp), %r12b
cmpb $0x1, %r12b
jne 0x27a7
cmpb $0x0, 0x88(%r14)
jne 0x27a7
cmpl $0x0, 0x4(%r14)
je 0x2ad9
movq %r13, -0xb8(%rbp)
movq %rcx, -0x50(%rbp)
movb 0x90(%r14), %cl
pushq $-0x1
popq %r15
shll %cl, %r15d
notl %r15d
andl 0x2c(%r14), %r15d
movl %ebx, %r13d
shll $0x4, %r13d
addl %r15d, %r13d
movq -0xc0(%rbp), %rax
leaq (%rax,%r13,2), %rsi
movq %r14, %rdi
callq 0x2520
testl %eax, %eax
je 0x28be
movl %ebx, -0x2c(%rbp)
movl %ebx, %ebx
movq -0xb0(%rbp), %rax
leaq (%rax,%rbx,2), %rsi
movq %r14, %rdi
callq 0x2520
testl %eax, %eax
je 0x2929
xorl %eax, %eax
testb %r12b, %r12b
jne 0x2ac7
cmpl $0x0, 0x20(%r14)
jne 0x2829
testb $0x1, 0x28(%r14)
je 0x2ac7
movq -0xa8(%rbp), %rax
leaq (%rax,%rbx,2), %rsi
movq %r14, %rdi
callq 0x2520
testl %eax, %eax
jne 0x299a
movq -0xa0(%rbp), %rax
leaq (%rax,%r13,2), %rsi
movq %r14, %rdi
callq 0x2520
testl %eax, %eax
jne 0x29e3
xorl %ecx, %ecx
cmpl $0x7, -0x2c(%rbp)
setae %sil
movl 0x20(%r14), %eax
movl $0x0, %edx
cmpl -0x68(%rbp), %eax
jae 0x287b
movl 0x24(%r14), %edx
movb %sil, %cl
movq %r14, %rbx
leal 0x9(,%rcx,2), %r14d
movq 0x18(%rbx), %rcx
addl -0x64(%rbp), %eax
addl %edx, %eax
movzbl (%rcx,%rax), %esi
movq -0x78(%rbp), %rdi
callq 0x36d4
movq %rbx, %r12
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0x362c
movq -0x60(%rbp), %rdi
xorl %esi, %esi
callq 0x3688
movq -0x50(%rbp), %rcx
jmp 0x291b
testb %r12b, %r12b
jne 0x2ac5
movq -0x70(%rbp), %rdi
movl %ebx, %r15d
movq %rdi, %rbx
movl %r15d, %esi
movq -0x48(%rbp), %rdx
callq 0x350a
movq %rbx, %r12
movq %rbx, %rdi
pushq $0x1
popq %r14
movl %r14d, %esi
callq 0x362c
movq -0x60(%rbp), %rdi
movl %r14d, %esi
callq 0x3688
xorl %r14d, %r14d
cmpl $0x4, %r15d
movq -0x50(%rbp), %rcx
jb 0x291b
cmpl $0x9, %r15d
ja 0x2914
addl $-0x3, %r15d
jmp 0x2918
addl $-0x6, %r15d
movl %r15d, %r14d
movl %r14d, %ebx
movq %rcx, %r13
movq %r12, %r14
jmp 0x2780
movq -0x90(%rbp), %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x370a
movl %eax, %r15d
movq %r14, %rbx
xorl %r14d, %r14d
cmpl $0x7, -0x2c(%rbp)
setae %r13b
movq %rbx, %rdi
movl %eax, %esi
callq 0x379c
cmpl $-0x1, %eax
je 0x2ade
movl %eax, %edx
cmpl 0x98(%rbx), %eax
setae %cl
xorl %eax, %eax
orb %cl, %r12b
jne 0x2ac7
movb %r13b, %r14b
leal (%r14,%r14,2), %ecx
addl $0x7, %ecx
movl %ecx, -0x2c(%rbp)
cmpl %edx, 0x20(%rbx)
jae 0x2a42
testb $0x1, 0x28(%rbx)
jne 0x2a42
jmp 0x2ac7
movq -0x88(%rbp), %rax
leaq (%rax,%rbx,2), %rsi
movq %r14, %rdi
callq 0x2520
testl %eax, %eax
je 0x29ef
movq -0x80(%rbp), %rax
leaq (%rax,%rbx,2), %rsi
movq %r14, %rdi
callq 0x2520
testl %eax, %eax
movl -0x3c(%rbp), %edx
movl %edx, %eax
movl -0x34(%rbp), %ecx
cmovel %ecx, %eax
cmovel %edx, %ecx
movl %ecx, %r13d
movl -0x38(%rbp), %ecx
movq -0x48(%rbp), %rdx
movl %edx, -0x50(%rbp)
movl -0x2c(%rbp), %ebx
jmp 0x2a03
movl -0x38(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x48(%rbp), %rax
jmp 0x29f9
movq -0x48(%rbp), %rax
movl %eax, -0x50(%rbp)
movl -0x38(%rbp), %eax
movl -0x34(%rbp), %ecx
movl -0x2c(%rbp), %ebx
movl -0x3c(%rbp), %r13d
movl %eax, %r14d
movl %ecx, -0x38(%rbp)
movq -0x98(%rbp), %rdi
movq -0x70(%rbp), %r12
movq %r12, %rsi
movl %r15d, %edx
callq 0x370a
movq %r14, %rdx
movl %eax, %r15d
xorl %eax, %eax
cmpl $0x7, %ebx
movq %r12, %rbx
setae %al
leal 0x8(%rax,%rax,2), %eax
movl %eax, -0x2c(%rbp)
movl %r13d, -0x34(%rbp)
movl -0x50(%rbp), %eax
movq %rax, -0x48(%rbp)
addl $0x2, %r15d
movq -0xb8(%rbp), %r13
cmpq %r15, %r13
setb %r14b
andb -0x54(%rbp), %r14b
movl %r13d, %r12d
cmovel %r15d, %r12d
leal 0x1(%rdx), %esi
movq -0x78(%rbp), %rdi
movq %rdx, %r15
movl %r12d, %edx
callq 0x383a
movq 0x70(%rbx), %rsi
movl 0x78(%rbx), %edx
movb $0x0, -0x2d(%rbp)
movq -0x60(%rbp), %rdi
movq %r12, %rcx
leaq -0x2d(%rbp), %r8
callq 0x387e
movq %rbx, %rdi
movl %r12d, %esi
callq 0x362c
subq %r12, %r13
xorl %eax, %eax
movl -0x34(%rbp), %ecx
movl %ecx, -0x3c(%rbp)
movl -0x38(%rbp), %ecx
movl %ecx, -0x34(%rbp)
movq -0x48(%rbp), %rcx
movl %ecx, -0x38(%rbp)
movl %r15d, %ecx
movq %rcx, -0x48(%rbp)
cmpb $0x1, %r14b
movq %rbx, %r14
jne 0x276b
jmp 0x2ac7
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x2
popq %rax
jmp 0x2ac7
xorl %eax, %eax
cmpl $0x0, 0x4(%rbx)
sete %al
jmp 0x2ac7
nop