// File: dgboy2000[P]compress/compress.cpp
// Function: DATCompression::golomb_compress(std::vector<int, std::allocator<int>>)
vector<int> DATCompression::golomb_compress(vector<int> data)
{
  vector<int> compressed;
  int q, r, temp = 0, t = 0;

  for(int i = 0; i < data.size(); i++)
  {
    if(data[i] < 0)
    {
      cout << "Error: golomb_compress do not accept negative data" << endl;
      exit(0);
    }
    q = data[i] / golomb_n, r = data[i] % golomb_n;
    for(int j = 0; j < q; j++)
    {
      temp <<= 1;
      temp |= 0x1;
      t++;
      if(t >= 8)
      {
        compressed.push_back(temp);
        temp = 0, t = 0;
      }
    }
    temp <<= 1;
    t++;
    if(t >= 8)
    {
      compressed.push_back(temp);
      temp = 0, t = 0;
    }
    for(int j = 0; j < int(log(golomb_n) / log(2.0) + 1e-8); j++)
    {
      temp <<= 1;
      if(r % 2)
        temp |= 0x1;
      t++;
      if(t >= 8)
      {
        compressed.push_back(temp);
        temp = 0, t = 0;
      }
      r /= 2;
    }
  }
  
  if(t)
  {
    for(int i = 0; i < 8 - t; i++)
    {
      temp <<= 1;
      temp |= 0x1;
    }
    compressed.push_back(temp);
  }

  return compressed;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdx, -0x68(%rbp)
movq %rdi, -0x60(%rbp)
movq %rdi, %rax
movq %rax, -0x58(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movb $0x0, -0x19(%rbp)
callq 0x8d20
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movq -0x68(%rbp), %rdi
movslq -0x30(%rbp), %rax
movq %rax, -0x70(%rbp)
callq 0x90a0
movq %rax, %rcx
movq -0x70(%rbp), %rax
cmpq %rcx, %rax
jae 0x34e8
movq -0x68(%rbp), %rdi
movslq -0x30(%rbp), %rsi
callq 0x8db0
cmpl $0x0, (%rax)
jge 0x335b
movq 0x12cc2(%rip), %rdi     # 0x15fd8
leaq 0xcd54(%rip), %rsi      # 0x10071
callq 0x2200
movq %rax, -0x78(%rbp)
jmp 0x3328
movq -0x78(%rbp), %rdi
movq 0x12c95(%rip), %rsi     # 0x15fc8
callq 0x2240
jmp 0x333a
xorl %edi, %edi
callq 0x22b0
movq -0x60(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
callq 0x8f20
jmp 0x3551
movq -0x68(%rbp), %rdi
movslq -0x30(%rbp), %rsi
callq 0x8db0
movq -0x68(%rbp), %rdi
movq -0x50(%rbp), %rcx
movl (%rax), %eax
cltd
idivl (%rcx)
movl %eax, -0x20(%rbp)
movslq -0x30(%rbp), %rsi
callq 0x8db0
movq -0x50(%rbp), %rcx
movl (%rax), %eax
cltd
idivl (%rcx)
movl %edx, -0x24(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x33e6
movl -0x28(%rbp), %eax
shll %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x28(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x8, -0x2c(%rbp)
jl 0x33d9
movq -0x60(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x8d40
jmp 0x33cb
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
jmp 0x33db
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x3394
movl -0x28(%rbp), %eax
shll %eax
movl %eax, -0x28(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x8, -0x2c(%rbp)
jl 0x341a
movq -0x60(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x8d40
jmp 0x340c
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x50(%rbp), %rax
movl -0x44(%rbp), %ecx
movl %ecx, -0x84(%rbp)
movl (%rax), %edi
callq 0x90e0
movsd %xmm0, -0x80(%rbp)
jmp 0x343c
movsd 0xcbcc(%rip), %xmm0     # 0x10010
callq 0x21c0
movl -0x84(%rbp), %eax
movaps %xmm0, %xmm1
movsd -0x80(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd 0xcba5(%rip), %xmm1     # 0x10008
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
cmpl %ecx, %eax
jge 0x34d8
movl -0x28(%rbp), %eax
shll %eax
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x3490
movl -0x28(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x28(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x8, -0x2c(%rbp)
jl 0x34bc
movq -0x60(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x8d40
jmp 0x34ae
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x24(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x24(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x3421
jmp 0x34da
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x32dc
cmpl $0x0, -0x2c(%rbp)
je 0x3531
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
movl $0x8, %ecx
subl -0x2c(%rbp), %ecx
cmpl %ecx, %eax
jge 0x3520
movl -0x28(%rbp), %eax
shll %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x28(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x34f5
movq -0x60(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x8d40
jmp 0x352f
jmp 0x3531
movb $0x1, -0x19(%rbp)
testb $0x1, -0x19(%rbp)
jne 0x3544
movq -0x60(%rbp), %rdi
callq 0x8f20
movq -0x58(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x2380
nopw (%rax,%rax)