// File: /workspace/github_cpp_makefile_star2_O2/dgboy2000[P]compress/compress.cpp
// Function: DATCompression::diff_compress(std::vector<int, std::allocator<int>>)
vector<int> DATCompression::diff_compress(vector<int> data) {
    vector<int> compressed;
    int x, y, L;
    
    x = data[0];
    y = data[1];
    L = data[2];
    
    compressed.push_back(x);
    compressed.push_back(y);
    compressed.push_back(L);
    
    for (int x_ind=0; x_ind < x; ++x_ind) {
        for (int y_ind=0; y_ind < y; ++y_ind) {
            int val = data[3 + L * (x_ind*y + y_ind)];

            compressed.push_back(val / 256);
            compressed.push_back(val % 256);
            
            for (int L_ind=1; L_ind < L; ++L_ind) {
                int diff = data[3 + L * (x_ind*y + y_ind) + L_ind] - val;
                val = diff + val;
                if (abs(diff) < 128) {
                    if (diff > 0) compressed.push_back(2*diff-1);
                    else compressed.push_back(-2*diff);
                    // compressed.push_back(diff + 127);
                    continue;
                }
                
                compressed.push_back(255);
                compressed.push_back(val / 256);
                compressed.push_back(val % 256);
            }
        }
    }
    
    return compressed;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movq %rdx, 0x20(%rsp)
movq (%rdx), %rax
movl (%rax), %ecx
leaq 0x1c(%rsp), %rsi
movl %ecx, (%rsi)
movl 0x4(%rax), %ecx
movl %ecx, 0x14(%rsp)
movl 0x8(%rax), %eax
movl %eax, 0x10(%rsp)
callq 0x51de
leaq 0x14(%rsp), %rsi
movq %rbx, %rdi
callq 0x51de
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x51de
xorl %r15d, %r15d
leaq 0x4(%rsp), %r14
movq %rbx, 0x8(%rsp)
cmpl 0x1c(%rsp), %r15d
jge 0x291d
xorl %edx, %edx
movl 0x14(%rsp), %eax
cmpl %eax, %edx
jge 0x2915
movslq 0x10(%rsp), %rcx
imull %r15d, %eax
movl %edx, 0x18(%rsp)
addl %edx, %eax
cltq
imulq %rcx, %rax
movq 0x20(%rsp), %rcx
movq (%rcx), %rcx
movl 0xc(%rcx,%rax,4), %r12d
movl %r12d, %eax
cltd
movl $0x100, %ecx            # imm = 0x100
idivl %ecx
movl %edx, %ebp
movl %eax, 0x4(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5602
movl %ebp, 0x4(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5602
pushq $0x4
popq %rax
movl %eax, %r13d
movl 0x18(%rsp), %ebx
leal -0x3(%r13), %ecx
movl 0x10(%rsp), %eax
cmpl %eax, %ecx
jge 0x2902
movl 0x14(%rsp), %ecx
imull %r15d, %ecx
addl %ebx, %ecx
imull %ecx, %eax
addl %r13d, %eax
cltq
movq 0x20(%rsp), %rcx
movq (%rcx), %rcx
movl (%rcx,%rax,4), %ebp
movl %ebp, %eax
subl %r12d, %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
cmpl $0x7f, %ecx
ja 0x2891
testl %eax, %eax
jle 0x28e0
leal -0x1(,%rax,2), %eax
movl %eax, 0x4(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x5602
jmp 0x28f7
movl $0xff, 0x4(%rsp)
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
leaq 0x4(%rsp), %r14
movq %r14, %rsi
callq 0x5602
movl %ebp, %eax
cltd
movl $0x100, %ecx            # imm = 0x100
idivl %ecx
movl %edx, %r12d
movl %eax, 0x4(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5602
movl %r12d, 0x4(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5602
movl 0x18(%rsp), %ebx
jmp 0x28f7
addl %eax, %eax
negl %eax
movl %eax, 0x4(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x5602
incl %r13d
movl %ebp, %r12d
jmp 0x2833
incl %ebx
leaq 0x4(%rsp), %r14
movl %ebx, %edx
movq 0x8(%rsp), %rbx
jmp 0x27d0
incl %r15d
jmp 0x27c3
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x293b
jmp 0x293b
jmp 0x293b
jmp 0x2940
jmp 0x2940
jmp 0x293b
movq %rax, %r14
jmp 0x2948
movq %rax, %r14
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x5466
movq %r14, %rdi
callq 0x22a0