// File: 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
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdx, -0xb0(%rbp)
movq %rdi, -0xa8(%rbp)
movq %rdi, %rax
movq %rax, -0xb8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movb $0x0, -0x19(%rbp)
callq 0x8d20
movq -0xb0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x8db0
movq -0xb0(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x20(%rbp)
movl $0x1, %esi
callq 0x8db0
movq -0xb0(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x24(%rbp)
movl $0x2, %esi
callq 0x8db0
movq -0xa8(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x28(%rbp)
leaq -0x20(%rbp), %rsi
callq 0x8d40
jmp 0x4f8b
movq -0xa8(%rbp), %rdi
leaq -0x24(%rbp), %rsi
callq 0x8d40
jmp 0x4f9d
movq -0xa8(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x8d40
jmp 0x4faf
movq -0xb0(%rbp), %rdi
callq 0x8dd0
movq %rax, -0x40(%rbp)
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
callq 0x8e00
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
callq 0x8e00
movq %rax, -0x50(%rbp)
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
callq 0x8e00
movq %rax, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x520a
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x51fa
leaq -0x40(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
xorl %esi, %esi
movl %esi, -0xc0(%rbp)
callq 0x8e00
movq %rax, -0x70(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x8eb0
movq -0xc8(%rbp), %rdi
movl -0xc0(%rbp), %esi
movl (%rax), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
shll $0x8, %eax
movl %eax, -0xbc(%rbp)
callq 0x8e00
movq %rax, -0x78(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x8eb0
movq -0xa8(%rbp), %rdi
movq %rax, %rcx
movl -0xbc(%rbp), %eax
movl (%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x64(%rbp)
leaq -0x64(%rbp), %rsi
callq 0x8d40
jmp 0x5089
movl $0x1, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x51ea
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
callq 0x8e00
movq %rax, -0x88(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x8eb0
movl (%rax), %eax
movl %eax, -0x80(%rbp)
cmpl $0xff, -0x80(%rbp)
jge 0x5157
movl -0x80(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x511c
movl -0x64(%rbp), %eax
movl %eax, -0xcc(%rbp)
movl -0x80(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0xcc(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x64(%rbp)
jmp 0x5140
movq -0xa8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
callq 0x8f20
jmp 0x5273
movl -0x64(%rbp), %eax
movl %eax, -0xd0(%rbp)
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0xd0(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x64(%rbp)
movq -0xa8(%rbp), %rdi
leaq -0x64(%rbp), %rsi
callq 0x8d40
jmp 0x5152
jmp 0x51dc
leaq -0x40(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
xorl %esi, %esi
movl %esi, -0xd8(%rbp)
callq 0x8e00
movq %rax, -0x90(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x8eb0
movq -0xe0(%rbp), %rdi
movl -0xd8(%rbp), %esi
movl (%rax), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
shll $0x8, %eax
movl %eax, -0xd4(%rbp)
callq 0x8e00
movq %rax, -0x98(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x8eb0
movq -0xa8(%rbp), %rdi
movq %rax, %rcx
movl -0xd4(%rbp), %eax
movl (%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x64(%rbp)
leaq -0x64(%rbp), %rsi
callq 0x8d40
jmp 0x51da
jmp 0x51dc
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x5090
jmp 0x51ec
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x5006
jmp 0x51fc
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x4ff3
movq -0xb0(%rbp), %rdi
callq 0x8e80
movq %rax, -0xa0(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x8e40
testb $0x1, %al
jne 0x5233
jmp 0x524d
leaq 0xae6c(%rip), %rdi      # 0x100a6
xorl %eax, %eax
callq 0x2040
jmp 0x5243
movl $0x1, %edi
callq 0x22b0
movb $0x1, -0x19(%rbp)
testb $0x1, -0x19(%rbp)
jne 0x5263
movq -0xa8(%rbp), %rdi
callq 0x8f20
movq -0xb8(%rbp), %rax
addq $0xe0, %rsp
popq %rbp
retq
movq -0x30(%rbp), %rdi
callq 0x2380
nopl (%rax)