// File: /workspace/github_cpp_makefile_star2_O3/dgboy2000[P]compress/compress.cpp
// Function: DATCompression::diff_decompress(std::vector<int, std::allocator<int>>)
vector<int> DATCompression::diff_decompress(vector<int> compressed) {
    vector<int> decompressed;
    int x, y, L;
    
    x = compressed[0];
    y = compressed[1];
    L = compressed[2];
    
    decompressed.push_back(x);
    decompressed.push_back(y);
    decompressed.push_back(L);
    
    vector<int>::iterator viter = compressed.begin();
    viter++;
    viter++;
    viter++;
    
    for (int x_ind=0; x_ind < x; ++x_ind) {
        for (int y_ind=0; y_ind < y; ++y_ind) {
            int val = *(viter++);
            val = 256 * val + *(viter++);

            decompressed.push_back(val);
            
            for (int L_ind=1; L_ind < L; ++L_ind) {
                int diff = *(viter++);
                if (diff < 255) {
                    if (diff % 2 == 0) val = val - diff/2;
                    else val = val + (diff+1)/2;
                    decompressed.push_back(val);
                    continue;
                }
                
                val = *(viter++);
                val = 256 * val + *(viter++);
                decompressed.push_back(val);
            }
        }
    }
    
    if (viter != compressed.end()) {
        printf("ERROR: finished decompressing before the end of the compressed string!\n");
        exit(1);
    }
    
    return decompressed;
}

// 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 0x4412
movl 0x8(%rsp), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x4427
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
callq 0x652a
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rax
cmpq %rax, %rsi
je 0x443c
movl 0x4(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x4449
leaq 0x4(%rsp), %rdx
movq %rbx, %rdi
callq 0x652a
movq %r14, 0x10(%rsp)
movq (%r14), %r12
addq $0xc, %r12
movl 0xc(%rsp), %ecx
testl %ecx, %ecx
jle 0x4555
xorl %ebp, %ebp
movl 0x8(%rsp), %eax
movq %rsp, %r15
testl %eax, %eax
jle 0x454b
xorl %r13d, %r13d
movl (%r12), %eax
shll $0x8, %eax
addl 0x4(%r12), %eax
movl %eax, (%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x449a
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x44a5
movq %rbx, %rdi
movq %r15, %rdx
callq 0x652a
addq $0x8, %r12
cmpl $0x2, 0x4(%rsp)
jl 0x4537
movl $0x1, %r14d
movl (%r12), %ecx
cmpl $0xfe, %ecx
jg 0x44d4
movl (%rsp), %eax
testb $0x1, %cl
jne 0x44ff
sarl %ecx
subl %ecx, %eax
jmp 0x4505
movl 0x4(%r12), %eax
shll $0x8, %eax
addl 0x8(%r12), %eax
addq $0xc, %r12
movl %eax, (%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
jne 0x4516
movq %rbx, %rdi
movq %r15, %rdx
callq 0x652a
jmp 0x452d
incl %ecx
sarl %ecx
addl %ecx, %eax
addq $0x4, %r12
movl %eax, (%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x4522
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x452d
movq %rbx, %rdi
movq %r15, %rdx
callq 0x652a
incl %r14d
cmpl 0x4(%rsp), %r14d
jl 0x44ba
incl %r13d
movl 0x8(%rsp), %eax
cmpl %eax, %r13d
jl 0x4475
movl 0xc(%rsp), %ecx
incl %ebp
cmpl %ecx, %ebp
jl 0x446a
movq 0x10(%rsp), %rax
cmpq 0x8(%rax), %r12
jne 0x4572
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3cb5(%rip), %rdi      # 0x822e
callq 0x2240
movl $0x1, %edi
callq 0x2200
jmp 0x458c
jmp 0x458c
movq %rax, %r14
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x45a3
movq 0x10(%rbx), %rsi
subq %rdi, %rsi
callq 0x21b0
movq %r14, %rdi
callq 0x22c0
nop