// File: /workspace/github_cpp_makefile_star2_O1/dgboy2000[P]compress/compress.cpp
// Function: DATCompression::huffman_decompress(std::vector<int, std::allocator<int>>)
vector<int> DATCompression::huffman_decompress(vector<int> compressed)
{
  vector<int> decompressed;
  vector<int> code[HUFFMAN_MAX];
  int code_space[65536], position;
  int number, d = 0, power = 1, code_ind = 0, c, temp = 0, q, r, g = 0;
  int useless_bits = compressed[compressed.size() - 1];
  char status = 'd';

  memset(code_space, -1, sizeof(code_space));
  for(int i = 0; i < compressed.size() - 1; i++)
  {
    number = compressed[i];
    for(int j = 0; j < 8; j++)
    {
      if(status == 'd')
      {
        if((number & 0x80) == 0x80)
          temp += power;
        number <<= 1;
        power *= 2, d++;
        if(d == 4)
          status = 'c', c = temp;
      }
      else if(status == 'c')
      {
        if((number & 0x80) == 0x80)
          code[code_ind].push_back(1);
        else
          code[code_ind].push_back(0);
        number <<= 1;
        c--;
        if(!c)
          status = 'd', code_ind++, d = 0, power = 1, temp = 0;
        if(code_ind == HUFFMAN_MAX)
        {
          status = 't';
          // generate code space
          for(int k = 0; k < HUFFMAN_MAX; k++)
          {
            position = 0;
            for(int l = 0; l < code[k].size(); l++)
            {
              if(!code[k][l])
                position = position * 2 + 1;
              else
                position = position * 2 + 2;
            }
            code_space[position] = k;
          }
          position = 0;
        }
      }
      else if(status == 't')
      {
        if(i == compressed.size() - 2 && 8 - j == useless_bits)
          break;

        if((number & 0x80) == 0x80)
          position = position * 2 + 2;
        else
          position = position * 2 + 1;
        if(code_space[position] >= 0)
        {
          if(!g)
            q = code_space[position], g = 1;
          else
          {
            r = code_space[position], g = 0;
            decompressed.push_back(q * HUFFMAN_MAX + r);
          }
          position = 0;
        }
        number <<= 1;
      }
    }
  }

  return decompressed;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x401c8, %rsp          # imm = 0x401C8
movq %rdx, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq %rdi, 0x10(%rsp)
movq $0x0, 0x10(%rdi)
leaq 0x40(%rsp), %rdi
movq $0x0, 0x18(%rsp)
movl $0x180, %edx            # imm = 0x180
xorl %esi, %esi
callq 0x20f0
movq 0x8(%rbx), %rax
movl -0x4(%rax), %eax
movl %eax, 0x24(%rsp)
leaq 0x1c0(%rsp), %rdi
movl $0x40000, %edx          # imm = 0x40000
movl $0xff, %esi
callq 0x20f0
movq (%rbx), %rax
movq %rbx, 0x30(%rsp)
movq 0x8(%rbx), %rcx
subq %rax, %rcx
cmpq $0x4, %rcx
je 0x3d66
movl $0x1, 0xc(%rsp)
movb $0x64, %r14b
xorl %edx, %edx
movl $0x0, 0x8(%rsp)
xorl %r15d, %r15d
xorl %r12d, %r12d
movq %rdx, 0x38(%rsp)
movl (%rax,%rdx,4), %ebp
xorl %ebx, %ebx
cmpb $0x63, %r14b
je 0x3c16
movzbl %r14b, %eax
cmpl $0x74, %eax
je 0x3b91
cmpl $0x64, %eax
jne 0x3d34
movsbl %bpl, %eax
sarl $0x7, %eax
movl 0xc(%rsp), %ecx
andl %ecx, %eax
addl %eax, 0x8(%rsp)
addl %ebp, %ebp
addl %ecx, %ecx
movl %ecx, 0xc(%rsp)
incl %r12d
cmpl $0x4, %r12d
jne 0x3d34
movb $0x63, %r14b
movl $0x4, %r12d
movl 0x8(%rsp), %eax
movl %eax, 0x2c(%rsp)
jmp 0x3d34
movq 0x30(%rsp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
sarq $0x2, %rax
addq $-0x2, %rax
cmpq 0x38(%rsp), %rax
jne 0x3bbd
movl $0x8, %eax
subl %ebx, %eax
cmpl 0x24(%rsp), %eax
je 0x3d3f
testb %bpl, %bpl
leal 0x2(%r13,%r13), %eax
leal 0x1(%r13,%r13), %r13d
cmovsl %eax, %r13d
movslq %r13d, %rax
movl 0x1c0(%rsp,%rax,4), %eax
testl %eax, %eax
js 0x3d32
cmpl $0x0, 0x18(%rsp)
je 0x3c66
movl 0x28(%rsp), %ecx
shll $0x4, %ecx
addl %ecx, %eax
movl %eax, 0x4(%rsp)
movq 0x10(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x3d1c
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x3d26
movslq %r15d, %rax
leaq (%rax,%rax,2), %rax
leaq (%rsp,%rax,8), %rdi
addq $0x40, %rdi
testb %bpl, %bpl
js 0x3c44
movl $0x0, 0x4(%rsp)
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x3c7c
movl $0x0, (%rsi)
jmp 0x3c5c
movl $0x1, 0x4(%rsp)
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x3c88
movl $0x1, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x3c92
movl $0x1, %ecx
movq %rcx, 0x18(%rsp)
xorl %r13d, %r13d
movl %eax, 0x28(%rsp)
jmp 0x3d32
leaq 0x4(%rsp), %rdx
callq 0x63e2
jmp 0x3c92
leaq 0x4(%rsp), %rdx
callq 0x63e2
decl 0x2c(%rsp)
jne 0x3cb1
incl %r15d
movb $0x64, %r14b
movl $0x1, 0xc(%rsp)
xorl %r12d, %r12d
movl $0x0, 0x8(%rsp)
addl %ebp, %ebp
cmpl $0x10, %r15d
jne 0x3d34
xorl %eax, %eax
leaq (%rax,%rax,2), %rdx
movq 0x40(%rsp,%rdx,8), %rcx
movq 0x48(%rsp,%rdx,8), %rdx
subq %rcx, %rdx
je 0x3cfc
sarq $0x2, %rdx
cmpq $0x1, %rdx
adcq $0x0, %rdx
xorl %esi, %esi
xorl %edi, %edi
cmpl $0x0, (%rcx,%rsi,4)
leal 0x2(%rdi,%rdi), %r8d
leal 0x1(%rdi,%rdi), %edi
cmovnel %r8d, %edi
incq %rsi
cmpq %rsi, %rdx
jne 0x3cde
movslq %edi, %rcx
jmp 0x3cfe
xorl %ecx, %ecx
movl %eax, 0x1c0(%rsp,%rcx,4)
incq %rax
cmpq $0x10, %rax
jne 0x3cbb
movb $0x74, %r14b
xorl %r13d, %r13d
movl $0x10, %r15d
jmp 0x3d34
leaq 0x4(%rsp), %rdx
callq 0x63e2
xorl %r13d, %r13d
movq $0x0, 0x18(%rsp)
addl %ebp, %ebp
incl %ebx
cmpl $0x8, %ebx
jne 0x3b39
movq 0x38(%rsp), %rdx
incq %rdx
movq 0x30(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
decq %rcx
cmpq %rdx, %rcx
ja 0x3b2f
movq 0x10(%rsp), %rbx
movl $0x180, %r14d           # imm = 0x180
movq 0x28(%rsp,%r14), %rdi
testq %rdi, %rdi
je 0x3d88
movq 0x38(%rsp,%r14), %rsi
subq %rdi, %rsi
callq 0x21b0
addq $-0x18, %r14
jne 0x3d71
movq %rbx, %rax
addq $0x401c8, %rsp          # imm = 0x401C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3da7
jmp 0x3da7
movq %rax, %r14
movl $0x180, %ebx            # imm = 0x180
movq 0x28(%rsp,%rbx), %rdi
testq %rdi, %rdi
je 0x3dc6
movq 0x38(%rsp,%rbx), %rsi
subq %rdi, %rsi
callq 0x21b0
addq $-0x18, %rbx
jne 0x3daf
movq 0x10(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x3dea
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rsi
subq %rdi, %rsi
callq 0x21b0
movq %r14, %rdi
callq 0x22c0