// File: /workspace/github_cpp_makefile_star2_O3/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 $0x18, %rsp
movq %rdx, %r14
movq %rdi, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq (%rdx), %rax
movl (%rax), %ecx
leaq 0xc(%rsp), %rdx
movl %ecx, (%rdx)
movl 0x4(%rax), %ecx
movl %ecx, 0x8(%rsp)
movl 0x8(%rax), %eax
movl %eax, 0x4(%rsp)
xorl %esi, %esi
callq 0x652a
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rax
cmpq %rax, %rsi
je 0x2a9a
movl 0x8(%rsp), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x2aaf
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
callq 0x652a
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rax
cmpq %rax, %rsi
je 0x2ac4
movl 0x4(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x2ad1
leaq 0x4(%rsp), %rdx
movq %rbx, %rdi
callq 0x652a
movl 0xc(%rsp), %eax
testl %eax, %eax
jle 0x2cf7
xorl %ebp, %ebp
movl 0x8(%rsp), %ecx
movq %r14, 0x10(%rsp)
testl %ecx, %ecx
jle 0x2ced
xorl %r12d, %r12d
movl 0x4(%rsp), %eax
imull %ebp, %ecx
addl %r12d, %ecx
imull %eax, %ecx
movq (%r14), %rax
movslq %ecx, %rcx
movl 0xc(%rax,%rcx,4), %r13d
leal 0xff(%r13), %r15d
testl %r13d, %r13d
cmovnsl %r13d, %r15d
movl %r15d, %ecx
sarl $0x8, %ecx
movl %ecx, (%rsp)
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rax
cmpq %rax, %rsi
je 0x2b3b
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x2b4e
movq %rbx, %rdi
movq %rsp, %rdx
callq 0x664a
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rax
andl $0xffffff00, %r15d      # imm = 0xFFFFFF00
movl %r13d, %ecx
subl %r15d, %ecx
movl %ecx, (%rsp)
cmpq %rax, %rsi
je 0x2b6f
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x2b7a
movq %rbx, %rdi
movq %rsp, %rdx
callq 0x664a
movl 0x4(%rsp), %eax
cmpl $0x2, %eax
jl 0x2cd9
movl $0x4, %r15d
movl %r13d, %ecx
movl 0x8(%rsp), %edx
imull %ebp, %edx
addl %r12d, %edx
imull %eax, %edx
addl %r15d, %edx
movslq %edx, %rax
movq (%r14), %rdx
movl (%rdx,%rax,4), %r13d
movl %r13d, %eax
subl %ecx, %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
cmpl $0x7f, %ecx
ja 0x2bdb
testl %eax, %eax
jle 0x2bff
leal -0x1(,%rax,2), %eax
movl %eax, (%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x2ca9
movl %eax, (%rsi)
jmp 0x2c16
movl $0xff, (%rsp)
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rax
cmpq %rax, %rsi
je 0x2c23
movl $0xff, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x2c36
addl %eax, %eax
negl %eax
movl %eax, (%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x2cb6
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x2cc1
movq %rbx, %rdi
movq %rsp, %rdx
callq 0x664a
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rax
leal 0xff(%r13), %r14d
testl %r13d, %r13d
cmovnsl %r13d, %r14d
movl %r14d, %ecx
sarl $0x8, %ecx
movl %ecx, (%rsp)
cmpq %rax, %rsi
je 0x2c5e
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x2c71
movq %rbx, %rdi
movq %rsp, %rdx
callq 0x664a
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rax
andl $0xffffff00, %r14d      # imm = 0xFFFFFF00
movl %r13d, %ecx
subl %r14d, %ecx
movl %ecx, (%rsp)
cmpq %rax, %rsi
je 0x2c97
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rsp), %r14
jmp 0x2cc1
movq %rbx, %rdi
movq %rsp, %rdx
callq 0x664a
movq 0x10(%rsp), %r14
jmp 0x2cc1
movq %rbx, %rdi
movq %rsp, %rdx
callq 0x664a
jmp 0x2cc1
movq %rbx, %rdi
movq %rsp, %rdx
callq 0x664a
movl 0x4(%rsp), %eax
leal 0x1(%r15), %ecx
addl $-0x2, %r15d
cmpl %eax, %r15d
movl %ecx, %r15d
jl 0x2b8d
incl %r12d
movl 0x8(%rsp), %ecx
cmpl %ecx, %r12d
jl 0x2af7
movl 0xc(%rsp), %eax
incl %ebp
cmpl %eax, %ebp
jl 0x2ae8
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2d17
jmp 0x2d17
jmp 0x2d17
jmp 0x2d17
jmp 0x2d17
jmp 0x2d17
jmp 0x2d17
movq %rax, %r14
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x2d2e
movq 0x10(%rbx), %rsi
subq %rdi, %rsi
callq 0x21b0
movq %r14, %rdi
callq 0x22c0