// File: /workspace/github_cpp_makefile_star2_O1/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, %rbp
movq %rdi, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq (%rdx), %rcx
movl (%rcx), %eax
movl %eax, 0x14(%rsp)
movl 0x4(%rcx), %edx
movl %edx, 0xc(%rsp)
movl 0x8(%rcx), %ecx
movl %ecx, 0x8(%rsp)
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x29e5
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x29f2
leaq 0x14(%rsp), %rdx
movq %rbx, %rdi
callq 0x62c2
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x2a0c
movl 0xc(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x2a19
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
callq 0x62c2
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x2a33
movl 0x8(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x2a40
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
callq 0x62c2
cmpl $0x0, 0x14(%rsp)
jle 0x2c63
movl $0x0, 0x10(%rsp)
movl 0xc(%rsp), %eax
testl %eax, %eax
jle 0x2c4f
xorl %r12d, %r12d
movslq 0x8(%rsp), %rcx
imull 0x10(%rsp), %eax
addl %r12d, %eax
cltq
imulq %rcx, %rax
movq (%rbp), %rcx
movl 0xc(%rcx,%rax,4), %r13d
leal 0xff(%r13), %r15d
testl %r13d, %r13d
cmovnsl %r13d, %r15d
movl %r15d, %eax
sarl $0x8, %eax
movl %eax, 0x4(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x2aac
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x2ab9
movq %rbx, %rdi
leaq 0x4(%rsp), %rdx
callq 0x63e2
andl $0xffffff00, %r15d      # imm = 0xFFFFFF00
movl %r13d, %eax
subl %r15d, %eax
movl %eax, 0x4(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x2ae0
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x2aed
movq %rbx, %rdi
leaq 0x4(%rsp), %rdx
callq 0x63e2
movl 0x8(%rsp), %eax
cmpl $0x2, %eax
jl 0x2c3f
movl $0x4, %r15d
movl %r13d, %ecx
movl 0xc(%rsp), %edx
imull 0x10(%rsp), %edx
addl %r12d, %edx
imull %eax, %edx
addl %r15d, %edx
movslq %edx, %rax
movq (%rbp), %rdx
movl (%rdx,%rax,4), %r13d
movl %r13d, %eax
subl %ecx, %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
cmpl $0x7f, %ecx
ja 0x2b60
testl %eax, %eax
jle 0x2b82
leal -0x1(,%rax,2), %eax
movl %eax, 0x4(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
jne 0x2bff
movq %rbx, %rdi
leaq 0x4(%rsp), %rdx
callq 0x63e2
jmp 0x2c27
movl $0xff, 0x4(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x2b9c
movl $0xff, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x2ba9
addl %eax, %eax
negl %eax
movl %eax, 0x4(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x2c1a
movl %eax, (%rsi)
jmp 0x2c01
movq %rbx, %rdi
leaq 0x4(%rsp), %rdx
callq 0x63e2
leal 0xff(%r13), %r14d
testl %r13d, %r13d
cmovnsl %r13d, %r14d
movl %r14d, %eax
sarl $0x8, %eax
movl %eax, 0x4(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x2bd7
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x2be4
movq %rbx, %rdi
leaq 0x4(%rsp), %rdx
callq 0x63e2
andl $0xffffff00, %r14d      # imm = 0xFFFFFF00
movl %r13d, %eax
subl %r14d, %eax
movl %eax, 0x4(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x2c0b
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x2c27
movq %rbx, %rdi
leaq 0x4(%rsp), %rdx
callq 0x63e2
jmp 0x2c27
movq %rbx, %rdi
leaq 0x4(%rsp), %rdx
callq 0x63e2
movl 0x8(%rsp), %eax
leal 0x1(%r15), %ecx
addl $-0x2, %r15d
cmpl %eax, %r15d
movl %ecx, %r15d
jl 0x2b00
incl %r12d
movl 0xc(%rsp), %eax
cmpl %eax, %r12d
jl 0x2a62
movl 0x10(%rsp), %eax
incl %eax
movl %eax, 0x10(%rsp)
cmpl 0x14(%rsp), %eax
jl 0x2a53
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2c83
jmp 0x2c83
jmp 0x2c83
jmp 0x2c83
jmp 0x2c83
jmp 0x2c83
jmp 0x2c83
movq %rax, %r14
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x2c9a
movq 0x10(%rbx), %rsi
subq %rdi, %rsi
callq 0x21b0
movq %r14, %rdi
callq 0x22c0