// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
xorpd %xmm0, %xmm0
movupd %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movl $0x0, 0x4(%rsp)
movq (%rdx), %rax
movq %rdx, 0x8(%rsp)
cmpq %rax, 0x8(%rdx)
je 0x31e7
movq %rsi, %r15
xorl %edx, %edx
xorl %r12d, %r12d
movq %rdx, 0x10(%rsp)
movl (%rax,%rdx,4), %eax
testl %eax, %eax
js 0x31f9
cltd
idivl (%r15)
movl %eax, %r13d
movl %edx, %r14d
movl 0x4(%rsp), %eax
testl %r13d, %r13d
jle 0x3085
leal 0x1(,%rax,2), %eax
movl %eax, 0x4(%rsp)
cmpl $0x7, %r12d
jl 0x3061
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x3066
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x3073
incl %r12d
jmp 0x3080
movq %rbx, %rdi
leaq 0x4(%rsp), %rdx
callq 0x652a
movl $0x0, 0x4(%rsp)
xorl %eax, %eax
xorl %r12d, %r12d
decl %r13d
jne 0x303a
addl %eax, %eax
movl %eax, 0x4(%rsp)
cmpl $0x6, %r12d
jle 0x30a7
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x30ac
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x30b9
incl %r12d
jmp 0x30c4
movq %rbx, %rdi
leaq 0x4(%rsp), %rdx
callq 0x652a
movl $0x0, 0x4(%rsp)
xorl %r12d, %r12d
xorps %xmm0, %xmm0
cvtsi2sdl (%r15), %xmm0
callq 0x2160
divsd 0x4f2f(%rip), %xmm0     # 0x8008
addsd 0x4f2f(%rip), %xmm0     # 0x8010
cvttsd2si %xmm0, %eax
testl %eax, %eax
jle 0x3175
xorl %r13d, %r13d
movl 0x4(%rsp), %eax
movl %r14d, %ecx
andl $0x1, %ecx
leal (%rcx,%rax,2), %eax
movl %eax, 0x4(%rsp)
cmpl $0x7, %r12d
jl 0x311d
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x3122
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x312f
incl %r12d
jmp 0x313a
movq %rbx, %rdi
leaq 0x4(%rsp), %rdx
callq 0x652a
movl $0x0, 0x4(%rsp)
xorl %r12d, %r12d
movl %r14d, %ebp
shrl $0x1f, %ebp
addl %r14d, %ebp
sarl %ebp
incl %r13d
xorps %xmm0, %xmm0
cvtsi2sdl (%r15), %xmm0
callq 0x2160
divsd 0x4eab(%rip), %xmm0     # 0x8008
addsd 0x4eab(%rip), %xmm0     # 0x8010
cvttsd2si %xmm0, %eax
movl %ebp, %r14d
cmpl %eax, %r13d
jl 0x30f0
movq 0x10(%rsp), %rdx
incq %rdx
movq 0x8(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rdx, %rcx
ja 0x3017
testl %r12d, %r12d
je 0x31e7
movl 0x4(%rsp), %eax
movl $0x8, %edx
subl %r12d, %edx
cmpl $0x2, %edx
movl $0x1, %ecx
cmovgel %edx, %ecx
leal 0x1(,%rax,2), %eax
decl %ecx
jne 0x31b5
movl %eax, 0x4(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x31da
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x31e7
leaq 0x4(%rsp), %rdx
movq %rbx, %rdi
callq 0x652a
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x7dd8(%rip), %rdi      # 0xafd8
leaq 0x4e8a(%rip), %rsi      # 0x8091
movl $0x32, %edx
callq 0x21e0
movq 0x7dc0(%rip), %rdi      # 0xafd8
callq 0x20d0
xorl %edi, %edi
callq 0x2200
jmp 0x322c
jmp 0x322c
jmp 0x322c
jmp 0x322c
movq %rax, %r14
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x3243
movq 0x10(%rbx), %rsi
subq %rdi, %rsi
callq 0x21b0
movq %r14, %rdi
callq 0x22c0
nop