// File: /workspace/github_cpp_makefile_star2_O2/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 %rdx, 0x8(%rsp)
movq %rsi, %r15
movq %rdi, %rbx
andq $0x0, 0x10(%rdi)
leaq 0x4(%rsp), %rax
andl $0x0, (%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rdi)
pushq $0x2
popq %r14
xorl %edx, %edx
xorl %r12d, %r12d
movq 0x8(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rdx, %rcx
jbe 0x2c90
movq %rdx, 0x10(%rsp)
movl (%rax,%rdx,4), %eax
testl %eax, %eax
js 0x2cd1
cltd
idivl (%r15)
movl %edx, %ebp
movl %eax, %r13d
testl %eax, %eax
movl $0x0, %eax
cmovlel %eax, %r13d
movl 0x4(%rsp), %eax
addl %eax, %eax
subl $0x1, %r13d
jb 0x2bfe
orl $0x1, %eax
movl %eax, 0x4(%rsp)
cmpl $0x7, %r12d
jl 0x2bf9
movq %rbx, %rdi
leaq 0x4(%rsp), %rsi
callq 0x51de
andl $0x0, 0x4(%rsp)
xorl %r12d, %r12d
jmp 0x2bc9
incl %r12d
jmp 0x2bc9
movl %eax, 0x4(%rsp)
cmpl $0x6, %r12d
jle 0x2c1f
movq %rbx, %rdi
leaq 0x4(%rsp), %rsi
callq 0x51de
andl $0x0, 0x4(%rsp)
xorl %r12d, %r12d
jmp 0x2c22
incl %r12d
xorl %r13d, %r13d
movl (%r15), %edi
callq 0x5249
divsd 0x43d3(%rip), %xmm0     # 0x7008
addsd 0x43d3(%rip), %xmm0     # 0x7010
cvttsd2si %xmm0, %eax
cmpl %eax, %r13d
jge 0x2c83
movl 0x4(%rsp), %eax
movl %ebp, %ecx
andl $0x1, %ecx
leal (%rcx,%rax,2), %eax
movl %eax, 0x4(%rsp)
cmpl $0x7, %r12d
jl 0x2c73
movq %rbx, %rdi
leaq 0x4(%rsp), %rsi
callq 0x51de
andl $0x0, 0x4(%rsp)
xorl %r12d, %r12d
jmp 0x2c76
incl %r12d
movl %ebp, %eax
cltd
idivl %r14d
incl %r13d
movl %eax, %ebp
jmp 0x2c25
movq 0x10(%rsp), %rdx
incq %rdx
jmp 0x2b89
testl %r12d, %r12d
je 0x2cbf
movl 0x4(%rsp), %eax
addl $-0x8, %r12d
testl %r12d, %r12d
je 0x2cb2
leal 0x1(,%rax,2), %eax
movl %eax, 0x4(%rsp)
incl %r12d
jmp 0x2c9d
leaq 0x4(%rsp), %rsi
movq %rbx, %rdi
callq 0x51de
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8300(%rip), %rdi      # 0xafd8
leaq 0x4392(%rip), %rsi      # 0x7071
callq 0x2180
movq %rax, %rdi
callq 0x20d0
xorl %edi, %edi
callq 0x21e0
jmp 0x2cfb
jmp 0x2cfb
jmp 0x2cfb
jmp 0x2cfb
movq %rax, %r14
movq %rbx, %rdi
callq 0x5466
movq %r14, %rdi
callq 0x22a0