// File: dgboy2000[P]compress/compress.cpp
// Function: test_compression_on_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void test_compression_on_file(string filename) {
    DATCompression dat;
    dat.init();
    
    vector<int> data = read_data(filename);
    for (int i=0; i<data.size(); ++i) {
        if (data[i] < 0 || data[i] > PH_MAX) {
            printf("ERROR: initial data value is outside of [0, %d] range!\n", PH_MAX);
            exit(1);
        }
    }
        
    vector<int> compressed = dat.compress(data);
    for (int i=0; i<compressed.size(); ++i) {
        if (compressed[i] < 0 || compressed[i] > 255) {
            cout << "ERROR: compressed value is outside of [0, 255] range!" << endl;
            exit(1);
        }
    }
    //cout << "Verified that all " << compressed.size() << " compressed ints are in within [0, 255] legal range" << endl;
    
    vector<int> decompressed = dat.decompress(compressed);
    
    if (data.size() != decompressed.size()) {
        printf("ERROR: decompressed %ld elements but expected %ld\n", decompressed.size(), data.size());
        exit(1);
    }
    for (int i=0; i<data.size(); ++i) {
        if (data[i] != decompressed[i]) {
            cout << "ERROR: decompression doesn't equal compression!" << endl;
            exit(1);
        }
    }
    
    printf("Correctly recovered the original %ld elements of the data\n", data.size());
    printf("TopCoder Compression ratio is %f\n", 2 * data.size() / (float) compressed.size());
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0xd8(%rbp)
movq %rdi, -0x8(%rbp)
leaq -0xc(%rbp), %rdi
callq 0x98c0
movq -0xd8(%rbp), %rsi
leaq -0x48(%rbp), %rdi
movq %rdi, -0xd0(%rbp)
callq 0x20f0
movq -0xd0(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0x80a0
jmp 0x86d8
leaq -0x48(%rbp), %rdi
callq 0x2130
movl $0x0, -0x58(%rbp)
movslq -0x58(%rbp), %rax
movq %rax, -0xe0(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x90a0
movq %rax, %rcx
movq -0xe0(%rbp), %rax
cmpq %rcx, %rax
jae 0x8790
movslq -0x58(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0x8db0
cmpl $0x0, (%rax)
jl 0x8736
movslq -0x58(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0x8db0
cmpl $0x3fff, (%rax)         # imm = 0x3FFF
jle 0x8780
leaq 0x7cf4(%rip), %rdi      # 0x10431
xorl %eax, %eax
movl $0x3fff, %esi           # imm = 0x3FFF
callq 0x2040
jmp 0x874b
movl $0x1, %edi
callq 0x22b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x2130
jmp 0x8b66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x8b5d
jmp 0x8782
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x86e8
leaq -0x88(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x8f80
jmp 0x87a2
leaq -0x70(%rbp), %rdi
leaq -0xc(%rbp), %rsi
leaq -0x88(%rbp), %rdx
callq 0x9c00
jmp 0x87b8
leaq -0x88(%rbp), %rdi
callq 0x8f20
movl $0x0, -0x8c(%rbp)
movslq -0x8c(%rbp), %rax
movq %rax, -0xe8(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x90a0
movq %rax, %rcx
movq -0xe8(%rbp), %rax
cmpq %rcx, %rax
jae 0x88a4
movslq -0x8c(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x8db0
cmpl $0x0, (%rax)
jl 0x8825
movslq -0x8c(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x8db0
cmpl $0xff, (%rax)
jle 0x888e
movq 0xd7ac(%rip), %rdi      # 0x15fd8
leaq 0x7c36(%rip), %rsi      # 0x10469
callq 0x2200
movq %rax, -0xf0(%rbp)
jmp 0x8841
movq -0xf0(%rbp), %rdi
movq 0xd779(%rip), %rsi      # 0x15fc8
callq 0x2240
jmp 0x8856
movl $0x1, %edi
callq 0x22b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x8f20
jmp 0x8b5d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x8b54
jmp 0x8890
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x87ce
leaq -0xc0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x8f80
jmp 0x88b6
leaq -0xa8(%rbp), %rdi
leaq -0xc(%rbp), %rsi
leaq -0xc0(%rbp), %rdx
callq 0x9c90
jmp 0x88cf
leaq -0xc0(%rbp), %rdi
callq 0x8f20
leaq -0x28(%rbp), %rdi
callq 0x90a0
movq %rax, -0xf8(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x90a0
movq %rax, %rcx
movq -0xf8(%rbp), %rax
cmpq %rcx, %rax
je 0x8980
leaq -0xa8(%rbp), %rdi
callq 0x90a0
movq %rax, -0x100(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x90a0
movq -0x100(%rbp), %rsi
movq %rax, %rdx
leaq 0x7b6c(%rip), %rdi      # 0x1049f
xorl %eax, %eax
callq 0x2040
jmp 0x893c
movl $0x1, %edi
callq 0x22b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x8f20
jmp 0x8b54
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x8f20
jmp 0x8b54
movl $0x0, -0xc4(%rbp)
movslq -0xc4(%rbp), %rax
movq %rax, -0x108(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x90a0
movq %rax, %rcx
movq -0x108(%rbp), %rax
cmpq %rcx, %rax
jae 0x8a3d
movslq -0xc4(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0x8db0
movl (%rax), %eax
movl %eax, -0x10c(%rbp)
movslq -0xc4(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
callq 0x8db0
movq %rax, %rcx
movl -0x10c(%rbp), %eax
cmpl (%rcx), %eax
je 0x8a27
movq 0xd5e5(%rip), %rdi      # 0x15fd8
leaq 0x7ad8(%rip), %rsi      # 0x104d2
callq 0x2200
movq %rax, -0x118(%rbp)
jmp 0x8a08
movq -0x118(%rbp), %rdi
movq 0xd5b2(%rip), %rsi      # 0x15fc8
callq 0x2240
jmp 0x8a1d
movl $0x1, %edi
callq 0x22b0
jmp 0x8a29
movl -0xc4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc4(%rbp)
jmp 0x898a
leaq -0x28(%rbp), %rdi
callq 0x90a0
movq %rax, %rsi
leaq 0x7ab2(%rip), %rdi      # 0x10502
xorl %eax, %eax
callq 0x2040
jmp 0x8a59
leaq -0x28(%rbp), %rdi
callq 0x90a0
movq %rax, %rcx
movq %rcx, %rax
addq %rax, %rax
movabsq $0x7fffffffffffffff, %rdx # imm = 0x7FFFFFFFFFFFFFFF
andq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, -0x120(%rbp)
testq %rax, %rax
movss %xmm0, -0x11c(%rbp)
js 0x8aab
movss -0x120(%rbp), %xmm0
movss %xmm0, -0x11c(%rbp)
movss -0x11c(%rbp), %xmm0
movss %xmm0, -0x12c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x90a0
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, -0x128(%rbp)
testq %rax, %rax
movss %xmm0, -0x124(%rbp)
js 0x8b05
movss -0x128(%rbp), %xmm0
movss %xmm0, -0x124(%rbp)
movss -0x12c(%rbp), %xmm0
movss -0x124(%rbp), %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x7a19(%rip), %rdi      # 0x1053d
movb $0x1, %al
callq 0x2040
jmp 0x8b2d
leaq -0xa8(%rbp), %rdi
callq 0x8f20
leaq -0x70(%rbp), %rdi
callq 0x8f20
leaq -0x28(%rbp), %rdi
callq 0x8f20
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
leaq -0x70(%rbp), %rdi
callq 0x8f20
leaq -0x28(%rbp), %rdi
callq 0x8f20
movq -0x50(%rbp), %rdi
callq 0x2380
nop