// File: dgboy2000[P]compress/compress.cpp
// Function: test_rle()
void test_rle() {
    int n = 14;
    int s[] = {0,0,0,0,0,1,1,1,1,0,1,1,0,0};
    int rle_expected[] = {n,0,0,0,0,1,1,1,1,1,0,0,1,1,0,0};

    int *encoded, *decoded;

    vector<int> vec_s, vec_encoded, vec_decoded;

    DATCompression dat;
    dat.init();

    encoded = dat.run_length_encode(s, n);
    decoded = dat.run_length_decode(encoded);

    for (int i=0; i<n; ++i) {
        if (s[i] != decoded[i]) {
            printf("FAIL: s[%d] = %d != decoded[%d] = %d\n", i, s[i], i, decoded[i]);
            goto test_rle_cleanup;
        }
    }
    printf("PASS: rle is correct\n");
    
    copy(s, s+n, back_inserter(vec_s));
    vec_encoded = dat.run_length_encode(vec_s);
    vec_decoded = dat.run_length_decode(vec_encoded);
    for (int i=0; i<n; ++i) {
        if (vec_s[i] != vec_decoded[i]) {
            printf("FAIL: vec_s[%d] = %d != vec_decoded[%d] = %d\n", i, vec_s[i], i, vec_decoded[i]);
            goto test_rle_cleanup;
        }
    }
    printf("PASS: vector rle is correct\n");
    
test_rle_cleanup:
    free(encoded);
    free(decoded);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movl $0xe, -0x4(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x20(%rbp)
movaps %xmm0, -0x30(%rbp)
movaps %xmm0, -0x40(%rbp)
movq $0x0, -0x10(%rbp)
movl $0x1, -0x2c(%rbp)
movl $0x1, -0x28(%rbp)
movl $0x1, -0x24(%rbp)
movl $0x1, -0x20(%rbp)
movl $0x1, -0x18(%rbp)
movl $0x1, -0x14(%rbp)
movl -0x4(%rbp), %eax
movl %eax, -0x80(%rbp)
movl $0x0, -0x7c(%rbp)
movl $0x0, -0x78(%rbp)
movl $0x0, -0x74(%rbp)
movl $0x0, -0x70(%rbp)
movl $0x1, -0x6c(%rbp)
movl $0x1, -0x68(%rbp)
movl $0x1, -0x64(%rbp)
movl $0x1, -0x60(%rbp)
movl $0x1, -0x5c(%rbp)
movl $0x0, -0x58(%rbp)
movl $0x0, -0x54(%rbp)
movl $0x1, -0x50(%rbp)
movl $0x1, -0x4c(%rbp)
movl $0x0, -0x48(%rbp)
movl $0x0, -0x44(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x8d20
leaq -0xc0(%rbp), %rdi
callq 0x8d20
leaq -0xd8(%rbp), %rdi
callq 0x8d20
leaq -0xdc(%rbp), %rdi
callq 0x98c0
jmp 0x7ce4
movl -0x4(%rbp), %edx
leaq -0xdc(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x5d10
movq %rax, -0x170(%rbp)
jmp 0x7d00
movq -0x170(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rsi
leaq -0xdc(%rbp), %rdi
callq 0x5ed0
movq %rax, -0x90(%rbp)
movl $0x0, -0xf0(%rbp)
movl -0xf0(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x7db7
movslq -0xf0(%rbp), %rax
movl -0x40(%rbp,%rax,4), %eax
movq -0x90(%rbp), %rcx
movslq -0xf0(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
je 0x7da1
movslq -0xf0(%rbp), %rsi
movl %esi, %ecx
movl -0x40(%rbp,%rsi,4), %edx
movq -0x90(%rbp), %rax
movl (%rax,%rsi,4), %r8d
leaq 0x845e(%rip), %rdi      # 0x101d8
xorl %eax, %eax
movl %ecx, %esi
callq 0x2040
jmp 0x7d85
jmp 0x8024
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
jmp 0x8069
jmp 0x7da3
movl -0xf0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf0(%rbp)
jmp 0x7d32
leaq 0x8591(%rip), %rdi      # 0x1034f
xorl %eax, %eax
callq 0x2040
jmp 0x7dc7
leaq -0x40(%rbp), %rax
movq %rax, -0x188(%rbp)
movslq -0x4(%rbp), %rax
leaq -0x40(%rbp,%rax,4), %rax
movq %rax, -0x180(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x9930
movq %rax, -0x178(%rbp)
jmp 0x7df7
movq -0x180(%rbp), %rsi
movq -0x188(%rbp), %rdi
movq -0x178(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0xf8(%rbp), %rdx
callq 0x98e0
movq %rax, -0x190(%rbp)
jmp 0x7e28
movq -0x190(%rbp), %rax
movq %rax, -0x100(%rbp)
leaq -0x130(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x8f80
jmp 0x7e4b
leaq -0x118(%rbp), %rdi
leaq -0xdc(%rbp), %rsi
leaq -0x130(%rbp), %rdx
callq 0x2e70
jmp 0x7e67
leaq -0xc0(%rbp), %rdi
movq %rdi, -0x198(%rbp)
leaq -0x118(%rbp), %rsi
movq %rsi, -0x1a0(%rbp)
callq 0x9070
movq -0x1a0(%rbp), %rdi
callq 0x8f20
leaq -0x130(%rbp), %rdi
callq 0x8f20
movq -0x198(%rbp), %rsi
leaq -0x160(%rbp), %rdi
callq 0x8f80
jmp 0x7eb5
leaq -0x148(%rbp), %rdi
leaq -0xdc(%rbp), %rsi
leaq -0x160(%rbp), %rdx
callq 0x4ab0
jmp 0x7ed1
leaq -0xd8(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x9070
leaq -0x148(%rbp), %rdi
callq 0x8f20
leaq -0x160(%rbp), %rdi
callq 0x8f20
movl $0x0, -0x164(%rbp)
movl -0x164(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x8012
movslq -0x164(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
callq 0x8db0
movl (%rax), %eax
movl %eax, -0x1a4(%rbp)
movslq -0x164(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x8db0
movq %rax, %rcx
movl -0x1a4(%rbp), %eax
cmpl (%rcx), %eax
je 0x7ffc
movl -0x164(%rbp), %eax
movl %eax, -0x1b0(%rbp)
movslq %eax, %rsi
leaq -0xa8(%rbp), %rdi
callq 0x8db0
movl (%rax), %eax
movl %eax, -0x1ac(%rbp)
movl -0x164(%rbp), %eax
movl %eax, -0x1a8(%rbp)
movslq %eax, %rsi
leaq -0xd8(%rbp), %rdi
callq 0x8db0
movl -0x1b0(%rbp), %esi
movl -0x1ac(%rbp), %edx
movl -0x1a8(%rbp), %ecx
movl (%rax), %r8d
leaq 0x82de(%rip), %rdi      # 0x1028c
xorl %eax, %eax
callq 0x2040
jmp 0x7fb7
jmp 0x8024
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x8f20
jmp 0x8069
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x8f20
jmp 0x8069
jmp 0x7ffe
movl -0x164(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x164(%rbp)
jmp 0x7f06
leaq 0x834c(%rip), %rdi      # 0x10365
xorl %eax, %eax
callq 0x2040
jmp 0x8022
jmp 0x8024
movq -0x88(%rbp), %rdi
callq 0x22a0
movq -0x90(%rbp), %rdi
callq 0x22a0
leaq -0xd8(%rbp), %rdi
callq 0x8f20
leaq -0xc0(%rbp), %rdi
callq 0x8f20
leaq -0xa8(%rbp), %rdi
callq 0x8f20
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
leaq -0xd8(%rbp), %rdi
callq 0x8f20
leaq -0xc0(%rbp), %rdi
callq 0x8f20
leaq -0xa8(%rbp), %rdi
callq 0x8f20
movq -0xe8(%rbp), %rdi
callq 0x2380
nopl (%rax)