// File: ostafen[P]Fast-Insertion-Sort/src/test.cpp
// Function: main
int main()
{
    IntArrayGenerator gen;

    SortAlgorithm<int> *algo[] = {
        new BlockInsertionSort<int>,
        new FastInsertionSort<int>,
        new MergeSort<int>,
        new QuickSort<int>,
        new QuickInsertionSort<int>,
        new ChainedBlockInsertionSort<int>(0.666, new ChainedBlockInsertionSort<int>),
        new ChainedBlockInsertionSort<int>(0.8,
            new ChainedBlockInsertionSort<int>(0.666, new ChainedBlockInsertionSort<int>))
        };

    QuickSort<int> qs;
    MergeSort<int> ms;

    int num_algos = sizeof(algo) / sizeof(SortAlgorithm<int> *);
    for (int i = 0; i < num_algos; i++)
    {
        bool passed = true;
        int size = 512;
        for (int n = 0; n < TEST_NUM; n++)
        {
            SortAlgorithm<int> *oracle = typeid(algo[i]) != typeid(QuickSort<int>) ? (SortAlgorithm<int> *)&qs : (SortAlgorithm<int> *)&ms;

            int *A = gen.random(size);
            int *B = arrayCopy(A, size);
            cout << "e[A\r\e[0K" << algo[i]->name() << ": test "
                 << "[" << n + 1 << "/" << TEST_NUM << "]." << flush;

            oracle->sort(B, size);

            algo[i]->sort(A, size);

            if (!compare(A, B, size))
            {
                passed = false;
                break;
            }
            delete[] A;
            delete[] B;
            size = size * 2;
        }
        cout << "e[A\r\e[0K" << algo[i]->name() << ": " << (passed ? "[OK]." : "[FAILED].") << flush << endl;
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x200, %rsp            # imm = 0x200
movl $0x0, -0x4(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x2ba0
movl $0x18, %edi
callq 0x2160
movq %rax, %rdi
movq %rdi, -0x100(%rbp)
callq 0x2be0
movq -0x100(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq -0x48(%rbp), %rax
movq %rax, -0xf8(%rbp)
movl $0x20, %edi
callq 0x2160
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xf0(%rbp)
movss 0x2aab(%rip), %xmm0     # 0x5004
callq 0x2c20
jmp 0x2560
movq -0xf8(%rbp), %rax
movq -0xf0(%rbp), %rcx
movq %rcx, (%rax)
movl $0x8, %edi
callq 0x2160
movq %rax, %rdi
movq %rdi, -0x140(%rbp)
callq 0x2c70
movq -0x140(%rbp), %rax
movq %rax, -0x40(%rbp)
movl $0x10, %edi
movq %rdi, -0x130(%rbp)
callq 0x2160
movq %rax, %rdi
movq %rdi, -0x138(%rbp)
callq 0x2cb0
movq -0x138(%rbp), %rax
movq -0x130(%rbp), %rdi
movq %rax, -0x38(%rbp)
callq 0x2160
movq %rax, %rdi
movq %rdi, -0x128(%rbp)
callq 0x2cf0
movq -0x128(%rbp), %rax
movq %rax, -0x30(%rbp)
leaq -0x28(%rbp), %rax
movq %rax, -0x120(%rbp)
movl $0x20, %edi
movq %rdi, -0x118(%rbp)
callq 0x2160
movq -0x118(%rbp), %rdi
movq %rax, -0x110(%rbp)
callq 0x2160
movq %rax, -0x108(%rbp)
jmp 0x261e
movq -0x108(%rbp), %rdi
callq 0x2d30
jmp 0x262c
movq -0x108(%rbp), %rsi
movq -0x110(%rbp), %rdi
movss 0x29c6(%rip), %xmm0     # 0x5008
callq 0x2da0
jmp 0x2649
movq -0x120(%rbp), %rax
movq -0x110(%rbp), %rcx
movq %rcx, (%rax)
leaq -0x20(%rbp), %rax
movq %rax, -0x160(%rbp)
movl $0x20, %edi
movq %rdi, -0x158(%rbp)
callq 0x2160
movq -0x158(%rbp), %rdi
movq %rax, -0x150(%rbp)
callq 0x2160
movq %rax, -0x148(%rbp)
jmp 0x2692
movl $0x20, %edi
callq 0x2160
movq %rax, -0x168(%rbp)
jmp 0x26a5
movq -0x168(%rbp), %rdi
callq 0x2d30
jmp 0x26b3
movq -0x168(%rbp), %rsi
movq -0x148(%rbp), %rdi
movss 0x293f(%rip), %xmm0     # 0x5008
callq 0x2da0
jmp 0x26d0
movq -0x148(%rbp), %rsi
movq -0x150(%rbp), %rdi
movss 0x2926(%rip), %xmm0     # 0x500c
callq 0x2da0
jmp 0x26ed
movq -0x160(%rbp), %rax
movq -0x150(%rbp), %rcx
movq %rcx, (%rax)
leaq -0x70(%rbp), %rdi
callq 0x2cb0
leaq -0x78(%rbp), %rdi
callq 0x2c70
movl $0x7, -0x7c(%rbp)
movl $0x0, -0x80(%rbp)
movl -0x80(%rbp), %eax
cmpl -0x7c(%rbp), %eax
jge 0x2b8a
movb $0x1, -0x81(%rbp)
movl $0x200, -0x88(%rbp)     # imm = 0x200
movl $0x0, -0x8c(%rbp)
cmpl $0xa, -0x8c(%rbp)
jge 0x2a83
leaq 0x542f(%rip), %rdi      # 0x7b88
leaq 0x5448(%rip), %rsi      # 0x7ba8
callq 0x2df0
testb $0x1, %al
jne 0x276b
jmp 0x2778
leaq -0x70(%rbp), %rax
movq %rax, -0x170(%rbp)
jmp 0x2785
leaq -0x78(%rbp), %rax
movq %rax, -0x170(%rbp)
jmp 0x2785
movq -0x170(%rbp), %rax
movq %rax, -0x98(%rbp)
movl -0x88(%rbp), %esi
leaq -0x18(%rbp), %rdi
callq 0x2e20
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rdi
movl -0x88(%rbp), %esi
callq 0x2ea0
movq %rax, -0xa8(%rbp)
movq 0x5807(%rip), %rdi      # 0x7fd0
leaq 0x2879(%rip), %rsi      # 0x5049
callq 0x2150
movq %rax, -0x188(%rbp)
movslq -0x80(%rbp), %rax
movq -0x50(%rbp,%rax,8), %rsi
movq (%rsi), %rax
movq 0x8(%rax), %rax
leaq -0xc8(%rbp), %rdi
movq %rdi, -0x180(%rbp)
callq *%rax
movq -0x188(%rbp), %rdi
movq -0x180(%rbp), %rsi
callq 0x2120
movq %rax, -0x178(%rbp)
jmp 0x2818
movq -0x178(%rbp), %rdi
leaq 0x282c(%rip), %rsi      # 0x5052
callq 0x2150
movq %rax, -0x190(%rbp)
jmp 0x2834
movq -0x190(%rbp), %rdi
leaq 0x2818(%rip), %rsi      # 0x505a
callq 0x2150
movq %rax, -0x198(%rbp)
jmp 0x2850
movq -0x198(%rbp), %rdi
movl -0x8c(%rbp), %esi
incl %esi
callq 0x2250
movq %rax, -0x1a0(%rbp)
jmp 0x286d
movq -0x1a0(%rbp), %rdi
leaq 0x27e1(%rip), %rsi      # 0x505c
callq 0x2150
movq %rax, -0x1a8(%rbp)
jmp 0x2889
movq -0x1a8(%rbp), %rdi
movl $0xa, %esi
callq 0x2250
movq %rax, -0x1b0(%rbp)
jmp 0x28a3
movq -0x1b0(%rbp), %rdi
leaq 0x27bd(%rip), %rsi      # 0x506e
callq 0x2150
movq %rax, -0x1b8(%rbp)
jmp 0x28bf
movq -0x1b8(%rbp), %rdi
movq 0x570b(%rip), %rsi      # 0x7fd8
callq 0x2180
jmp 0x28d4
leaq -0xc8(%rbp), %rdi
callq 0x20b0
movq -0x98(%rbp), %rdi
movq -0xa8(%rbp), %rsi
movl -0x88(%rbp), %edx
movq (%rdi), %rax
callq *(%rax)
movslq -0x80(%rbp), %rax
movq -0x50(%rbp,%rax,8), %rdi
movq -0xa0(%rbp), %rsi
movl -0x88(%rbp), %edx
movq (%rdi), %rax
callq *(%rax)
movq -0xa0(%rbp), %rdi
movq -0xa8(%rbp), %rsi
movl -0x88(%rbp), %edx
callq 0x2490
testb $0x1, %al
jne 0x2a21
movb $0x0, -0x81(%rbp)
jmp 0x2a83
movq -0xf0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
movl $0x20, %esi
callq 0x2170
jmp 0x2b95
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x298e
movq -0x108(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
movl $0x20, %esi
callq 0x2170
movq -0x110(%rbp), %rdi
movl $0x20, %esi
callq 0x2170
jmp 0x2b95
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x29ee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x29dd
movq -0x168(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
movl $0x20, %esi
callq 0x2170
movq -0x148(%rbp), %rdi
movl $0x20, %esi
callq 0x2170
movq -0x150(%rbp), %rdi
movl $0x20, %esi
callq 0x2170
jmp 0x2b95
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x20b0
jmp 0x2b95
movq -0xa0(%rbp), %rax
movq %rax, -0x1c0(%rbp)
cmpq $0x0, %rax
je 0x2a41
movq -0x1c0(%rbp), %rdi
callq 0x21f0
movq -0xa8(%rbp), %rax
movq %rax, -0x1c8(%rbp)
cmpq $0x0, %rax
je 0x2a61
movq -0x1c8(%rbp), %rdi
callq 0x21f0
movl -0x88(%rbp), %eax
shll %eax
movl %eax, -0x88(%rbp)
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x2745
movq 0x5546(%rip), %rdi      # 0x7fd0
leaq 0x25b8(%rip), %rsi      # 0x5049
callq 0x2150
movq %rax, -0x1e0(%rbp)
movslq -0x80(%rbp), %rax
movq -0x50(%rbp,%rax,8), %rsi
movq (%rsi), %rax
movq 0x8(%rax), %rax
leaq -0xe8(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq *%rax
movq -0x1e0(%rbp), %rdi
movq -0x1d8(%rbp), %rsi
callq 0x2120
movq %rax, -0x1d0(%rbp)
jmp 0x2ad9
movq -0x1d0(%rbp), %rdi
leaq 0x2577(%rip), %rsi      # 0x505e
callq 0x2150
movq %rax, -0x1e8(%rbp)
jmp 0x2af5
movq -0x1e8(%rbp), %rdi
movb -0x81(%rbp), %cl
leaq 0x2558(%rip), %rax      # 0x5061
leaq 0x2557(%rip), %rsi      # 0x5067
testb $0x1, %cl
cmovneq %rax, %rsi
callq 0x2150
movq %rax, -0x1f0(%rbp)
jmp 0x2b25
movq -0x1f0(%rbp), %rdi
movq 0x54a5(%rip), %rsi      # 0x7fd8
callq 0x2180
movq %rax, -0x1f8(%rbp)
jmp 0x2b41
movq -0x1f8(%rbp), %rdi
movq 0x5471(%rip), %rsi      # 0x7fc0
callq 0x2180
jmp 0x2b56
leaq -0xe8(%rbp), %rdi
callq 0x20b0
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x271e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x20b0
jmp 0x2b95
xorl %eax, %eax
addq $0x200, %rsp            # imm = 0x200
popq %rbp
retq
movq -0x58(%rbp), %rdi
callq 0x2270
nop