// File: /workspace/github_cpp_makefile_star2_O1/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 0x3116
movq %rsi, %r15
xorl %edx, %edx
xorl %r12d, %r12d
movq %rdx, 0x10(%rsp)
movl (%rax,%rdx,4), %eax
testl %eax, %eax
js 0x3183
cltd
idivl (%r15)
movl %edx, %r14d
movl %eax, %r13d
testl %eax, %eax
jle 0x2ffc
movl 0x4(%rsp), %eax
leal 0x1(,%rax,2), %eax
movl %eax, 0x4(%rsp)
cmpl $0x7, %r12d
jl 0x2fda
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x2fdf
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x2fec
incl %r12d
jmp 0x2ff7
movq %rbx, %rdi
leaq 0x4(%rsp), %rdx
callq 0x62c2
movl $0x0, 0x4(%rsp)
xorl %r12d, %r12d
decl %r13d
jne 0x2faf
movl 0x4(%rsp), %eax
addl %eax, %eax
movl %eax, 0x4(%rsp)
cmpl $0x6, %r12d
jle 0x3022
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x3027
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x3034
incl %r12d
jmp 0x303f
movq %rbx, %rdi
leaq 0x4(%rsp), %rdx
callq 0x62c2
movl $0x0, 0x4(%rsp)
xorl %r12d, %r12d
xorps %xmm0, %xmm0
cvtsi2sdl (%r15), %xmm0
callq 0x2160
divsd 0x4fb4(%rip), %xmm0     # 0x8008
addsd 0x4fb4(%rip), %xmm0     # 0x8010
cvttsd2si %xmm0, %eax
testl %eax, %eax
jle 0x30f0
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 0x3098
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x309d
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x30aa
incl %r12d
jmp 0x30b5
movq %rbx, %rdi
leaq 0x4(%rsp), %rdx
callq 0x62c2
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 0x4f30(%rip), %xmm0     # 0x8008
addsd 0x4f30(%rip), %xmm0     # 0x8010
cvttsd2si %xmm0, %eax
movl %ebp, %r14d
cmpl %eax, %r13d
jl 0x306b
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 0x2f91
jmp 0x3119
xorl %r12d, %r12d
testl %r12d, %r12d
je 0x3171
cmpl $0x7, %r12d
jg 0x314a
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 0x313b
movl %eax, 0x4(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x3164
movl 0x4(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x3171
leaq 0x4(%rsp), %rdx
movq %rbx, %rdi
callq 0x62c2
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x7e4e(%rip), %rdi      # 0xafd8
leaq 0x4ee0(%rip), %rsi      # 0x8071
movl $0x32, %edx
callq 0x21e0
movq 0x7e36(%rip), %rdi      # 0xafd8
callq 0x20d0
xorl %edi, %edi
callq 0x2200
jmp 0x31b6
jmp 0x31b6
jmp 0x31b6
jmp 0x31b6
movq %rax, %r14
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x31cd
movq 0x10(%rbx), %rsi
subq %rdi, %rsi
callq 0x21b0
movq %r14, %rdi
callq 0x22c0
nop