// File: dgboy2000[P]compress/compress.cpp
// Function: DATCompression::golomb_decompress(std::vector<int, std::allocator<int>>)
vector<int> DATCompression::golomb_decompress(vector<int> compressed)
{
  vector<int> decompressed;
  int temp, q = 0, r = 0, power = 1, nr = 0;
  char status = 'q';

  for(int i = 0; i < compressed.size(); i++)
  {
    temp = compressed[i];
    for(int j = 0; j < 8; j++)
    {
      if(status == 'q')
      {
        if((temp & 0x80) == 0x80)
          q++;
        else
          status = 'r', r = 0, power = 1, nr = 0;
      }
      else
      {
        if((temp & 0x80) == 0x80)
          r += power;
        nr++, power *= 2;
        if(nr == int(log(golomb_n) / log(2.0) + 1e-8))
        {
          status = 'q';
          decompressed.push_back(q * golomb_n + r);
          q = 0;
        }
      }
      temp <<= 1;
    }
  }

  return decompressed;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdx, -0x70(%rbp)
movq %rdi, -0x68(%rbp)
movq %rdi, %rax
movq %rax, -0x60(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
movb $0x0, -0x19(%rbp)
callq 0x8d20
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x1, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movb $0x71, -0x31(%rbp)
movl $0x0, -0x38(%rbp)
movq -0x70(%rbp), %rdi
movslq -0x38(%rbp), %rax
movq %rax, -0x78(%rbp)
callq 0x90a0
movq %rax, %rcx
movq -0x78(%rbp), %rax
cmpq %rcx, %rax
jae 0x4a78
movq -0x70(%rbp), %rdi
movslq -0x38(%rbp), %rsi
callq 0x8db0
movl (%rax), %eax
movl %eax, -0x20(%rbp)
movl $0x0, -0x3c(%rbp)
cmpl $0x8, -0x3c(%rbp)
jge 0x4a68
movsbl -0x31(%rbp), %eax
cmpl $0x71, %eax
jne 0x4993
movl -0x20(%rbp), %eax
andl $0x80, %eax
cmpl $0x80, %eax
jne 0x4975
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x498e
movb $0x72, -0x31(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x1, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
jmp 0x4a52
movl -0x20(%rbp), %eax
andl $0x80, %eax
cmpl $0x80, %eax
jne 0x49ab
movl -0x2c(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x58(%rbp), %rax
movl -0x30(%rbp), %ecx
incl %ecx
movl %ecx, -0x30(%rbp)
movl -0x2c(%rbp), %ecx
addl %ecx, %ecx
movl %ecx, -0x2c(%rbp)
movl -0x30(%rbp), %ecx
movl %ecx, -0x84(%rbp)
movl (%rax), %edi
callq 0x90e0
movsd %xmm0, -0x80(%rbp)
jmp 0x49d6
movsd 0xb632(%rip), %xmm0     # 0x10010
callq 0x21c0
movl -0x84(%rbp), %eax
movaps %xmm0, %xmm1
movsd -0x80(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd 0xb60b(%rip), %xmm1     # 0x10008
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
cmpl %ecx, %eax
jne 0x4a50
movq -0x68(%rbp), %rdi
movq -0x58(%rbp), %rcx
movb $0x71, -0x31(%rbp)
movl -0x24(%rbp), %eax
movl (%rcx), %ecx
imull %ecx, %eax
movl -0x28(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x50(%rbp)
leaq -0x50(%rbp), %rsi
callq 0x8ed0
jmp 0x4a30
movl $0x0, -0x24(%rbp)
jmp 0x4a50
movq -0x68(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x8f20
jmp 0x4a98
jmp 0x4a52
movl -0x20(%rbp), %eax
shll %eax
movl %eax, -0x20(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x4948
jmp 0x4a6a
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x490e
movb $0x1, -0x19(%rbp)
testb $0x1, -0x19(%rbp)
jne 0x4a8b
movq -0x68(%rbp), %rdi
callq 0x8f20
movq -0x60(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x2380
nopw %cs:(%rax,%rax)