// File: /workspace/github_cpp_makefile_star2_O2/ctSkennerton[P]fxtract/util/sort_x.c
// Function: main
int
main(int argc, char **argv)
{
    if (argc != 2) die("usage: sort_x <inpfile>");

    MEMBUF  inp = chomp(slurp(argv[1]));
    int	    nrecs;
    MEMREF  *inpv = refsplit(inp.ptr, '\n', &nrecs);
    MEMREF  *v1 = malloc(nrecs * sizeof(MEMREF));
    MEMREF  *v2 = malloc(nrecs * sizeof(MEMREF));
    MEMREF  *v3 = malloc(nrecs * sizeof(MEMREF));
    int     wid, i;

    double  t1[MAXWID] = {}, t2[MAXWID] = {}, t3[MAXWID] = {};
    
    for (wid = 2; wid < MAXWID; wid++) {
        memcpy(v1, inpv, nrecs * sizeof(MEMREF));
        double  start = tick();
        for (i = 0; i + wid < nrecs; i+= wid) {
            switch (wid) {
            case 2:
                if (refcmp(v1[0], v1[1]) > 0)
                    SWAP(v1[0], v1[1]);
                break;
            case 3:
                simpl3(v1);
                break;
            default:
                simple(v1, nrecs);
            }
        }
        t1[wid] += tick() - start;

        memcpy(v2, inpv, nrecs * sizeof(MEMREF));
        start = tick();
        for (i = 0; i + wid < nrecs; i+= wid) quick(v2, nrecs);
        t2[wid] += tick() - start;
        assert(!memcmp(v1, v2, nrecs * sizeof(MEMREF)));

        memcpy(v3, inpv, nrecs * sizeof(MEMREF));
        start = tick();
        for (i = 0; i + wid < nrecs; i+= wid) owsort(v3, nrecs);
        t3[wid] += tick() - start;
        assert(!memcmp(v1, v3, nrecs * sizeof(MEMREF)));
    }

    for (wid = 2; wid < MAXWID; wid++)
        printf("%4d %.6f %.6f %.6f ms\n", wid, 
                1000 * t1[wid] * wid / nrecs,
                1000 * t2[wid] * wid / nrecs,
                1000 * t3[wid] * wid / nrecs);

    return  0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x688, %rsp            # imm = 0x688
cmpl $0x2, %edi
jne 0x3a02
movq 0x8(%rsi), %rdi
callq 0x473c
movq %rax, %rdi
movq %rdx, %rsi
callq 0x40e7
pushq $0xa
popq %rsi
leaq 0xc(%rsp), %rbx
movq %rax, %rdi
movq %rbx, %rdx
callq 0x4640
movq %rax, 0x28(%rsp)
movslq (%rbx), %r15
movq %r15, %rbx
shlq $0x4, %rbx
movq %rbx, %rdi
callq 0x3270
movq %rax, %r12
movq %rbx, %rdi
callq 0x3270
movq %rax, 0x30(%rsp)
movq %rbx, %rdi
callq 0x3270
movq %rax, %rbx
leaq 0x480(%rsp), %rdi
movl $0x200, %edx            # imm = 0x200
xorl %esi, %esi
callq 0x30f0
leaq 0x280(%rsp), %rdi
movl $0x200, %edx            # imm = 0x200
xorl %esi, %esi
callq 0x30f0
leaq 0x80(%rsp), %rdi
movl $0x200, %edx            # imm = 0x200
xorl %esi, %esi
callq 0x30f0
movq %r12, 0x18(%rsp)
leaq 0x10(%r12), %rax
movq %rax, 0x40(%rsp)
movq %rbx, 0x38(%rsp)
addq $-0x10, %rbx
movq %rbx, 0x78(%rsp)
pushq $0x2
popq %r12
cmpq $0x40, %r12
je 0x395a
movslq %r15d, %rdx
shlq $0x4, %rdx
movq 0x18(%rsp), %r14
movq %r14, %rdi
movq 0x28(%rsp), %rsi
callq 0x3150
callq 0x49a5
movq %r14, %r8
movsd %xmm0, 0x60(%rsp)
xorl %r13d, %r13d
movq %r12, 0x48(%rsp)
addl %r12d, %r13d
movslq 0xc(%rsp), %rcx
cmpl %ecx, %r13d
jge 0x379b
cmpl $0x3, %r12d
je 0x35f5
cmpl $0x2, %r12d
jne 0x368f
movq (%r8), %rdi
movq 0x8(%r8), %rsi
movq 0x10(%r8), %rdx
movq 0x18(%r8), %rcx
movq %r8, %rbx
callq 0x4593
movq %rbx, %r8
testl %eax, %eax
jle 0x3595
movups (%r8), %xmm0
movaps %xmm0, 0x50(%rsp)
movq 0x40(%rsp), %rax
movups (%rax), %xmm0
movups %xmm0, (%r8)
movapd 0x50(%rsp), %xmm0
movupd %xmm0, (%rax)
jmp 0x3595
movq (%r8), %rdi
movq 0x8(%r8), %rsi
movq 0x10(%r8), %rbx
movq 0x18(%r8), %r15
movq 0x20(%r8), %r14
movq 0x28(%r8), %rbp
movq %rdi, 0x20(%rsp)
movq %rsi, 0x10(%rsp)
movq %rbx, %rdx
movq %r15, %rcx
callq 0x4593
testl %eax, %eax
jle 0x3716
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq %r14, %rdx
movq %rbp, %rcx
callq 0x4593
testl %eax, %eax
jle 0x3781
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %rbp, %rcx
callq 0x4593
testl %eax, %eax
movq %r14, %rax
cmovleq %rbx, %rax
movq %rbp, %rcx
cmovleq %r15, %rcx
cmovleq %r14, %rbx
cmovleq %rbp, %r15
movq %rax, %r14
movq %rcx, %rbp
movq %rbx, %rcx
movq %r15, %rdx
movq 0x20(%rsp), %rbx
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %r8
jmp 0x3772
movq %rcx, %rax
movl %r13d, 0x20(%rsp)
shlq $0x4, %rax
addq %r8, %rax
movq %rax, 0x10(%rsp)
movq %r8, %rbp
movq %r8, %r14
movq 0x40(%rsp), %r13
movq (%r13), %rbx
movq 0x8(%r13), %r15
movq %r14, %r12
movq (%r12), %rdi
movq 0x8(%r12), %rsi
movq %rbx, %rdx
movq %r15, %rcx
callq 0x4593
cmpq %rbp, %r12
jbe 0x36eb
testl %eax, %eax
jle 0x36eb
leaq 0x10(%r12), %rax
movupd (%r12), %xmm0
movupd %xmm0, (%rax)
addq $-0x10, %r12
jmp 0x36b9
movq %rbx, 0x10(%r12)
movq %r15, 0x18(%r12)
addq $0x10, %r13
addq $0x10, %r14
cmpq 0x10(%rsp), %r13
jne 0x36ae
movq %rbp, %r8
movq 0x48(%rsp), %r12
movl 0x20(%rsp), %r13d
jmp 0x3595
movq %rbx, 0x68(%rsp)
movq %rbx, %rdi
movq %r15, 0x70(%rsp)
movq %r15, %rsi
movq %r14, %rdx
movq %rbp, %rcx
callq 0x4593
testl %eax, %eax
movq 0x18(%rsp), %r8
jle 0x3595
movq 0x20(%rsp), %r15
movq %r15, %rdi
movq 0x10(%rsp), %rbx
movq %rbx, %rsi
movq %r14, %rdx
movq %rbp, %rcx
callq 0x4593
movq 0x18(%rsp), %r8
movq %r15, %rcx
movq %rbx, %rdx
testl %eax, %eax
movq 0x70(%rsp), %r15
movq 0x68(%rsp), %rbx
jle 0x3786
movq %r14, (%r8)
movq %rbp, 0x8(%r8)
movq %rcx, %r14
movq %rdx, %rbp
jmp 0x3786
movq 0x18(%rsp), %r8
movq %r14, 0x10(%r8)
movq %rbp, 0x18(%r8)
movq %rbx, 0x20(%r8)
movq %r15, 0x28(%r8)
jmp 0x3595
callq 0x49a5
subsd 0x60(%rsp), %xmm0
addsd 0x480(%rsp,%r12,8), %xmm0
movsd %xmm0, 0x480(%rsp,%r12,8)
movslq 0xc(%rsp), %rdx
shlq $0x4, %rdx
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x3150
callq 0x49a5
movsd %xmm0, 0x10(%rsp)
movl %r12d, %ebx
movslq 0xc(%rsp), %rsi
cmpl %esi, %ebx
jge 0x3802
movq 0x30(%rsp), %rdi
pushq $0x10
popq %rdx
leaq 0xe1f(%rip), %rcx       # 0x4617
callq 0x3350
addl %r12d, %ebx
jmp 0x37e0
callq 0x49a5
subsd 0x10(%rsp), %xmm0
addsd 0x280(%rsp,%r12,8), %xmm0
movsd %xmm0, 0x280(%rsp,%r12,8)
movslq 0xc(%rsp), %rbx
shlq $0x4, %rbx
movq 0x18(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq %rbx, %rdx
callq 0x31c0
testl %eax, %eax
jne 0x39e5
movq 0x38(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq %rbx, %rdx
callq 0x3150
xorl %r14d, %r14d
callq 0x49a5
movsd %xmm0, 0x20(%rsp)
addl %r12d, %r14d
movl 0xc(%rsp), %ecx
cmpl %ecx, %r14d
jge 0x38f9
movl %r14d, 0x10(%rsp)
movl %ecx, %r13d
imull $0x19, %r13d, %eax
movl %eax, %r13d
sarl $0x5, %r13d
cmpl $0x20, %eax
jb 0x38ea
movl %ecx, %r14d
movl %ecx, %eax
subl %r13d, %eax
movslq %eax, %rbp
movslq %r13d, %r12
shlq $0x4, %r12
movq %rbp, %rbx
shlq $0x4, %rbx
addq 0x78(%rsp), %rbx
testq %rbp, %rbp
jle 0x38e5
leaq (%rbx,%r12), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4617
testl %eax, %eax
jle 0x38dc
movups (%rbx), %xmm0
movaps %xmm0, 0x50(%rsp)
movups (%r15), %xmm0
movups %xmm0, (%rbx)
movapd 0x50(%rsp), %xmm0
movupd %xmm0, (%r15)
addq $-0x10, %rbx
decq %rbp
jmp 0x38aa
movl %r14d, %ecx
jmp 0x387c
movq 0x48(%rsp), %r12
movl 0x10(%rsp), %r14d
jmp 0x3864
callq 0x49a5
subsd 0x20(%rsp), %xmm0
addsd 0x80(%rsp,%r12,8), %xmm0
movsd %xmm0, 0x80(%rsp,%r12,8)
movslq 0xc(%rsp), %r15
movq %r15, %rdx
shlq $0x4, %rdx
movq 0x18(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x31c0
incq %r12
testl %eax, %eax
je 0x355c
leaq 0x272b(%rip), %rdi      # 0x6070
leaq 0x2704(%rip), %rsi      # 0x6050
leaq 0x2706(%rip), %rcx      # 0x6059
pushq $0x4d
jmp 0x39fc
pushq $-0x3e
popq %r14
leaq 0x2733(%rip), %rbx      # 0x6098
testq %r14, %r14
je 0x39d1
movsd 0x680(%rsp,%r14,8), %xmm0
movsd 0x268c(%rip), %xmm5     # 0x6008
mulsd %xmm5, %xmm0
leal 0x40(%r14), %esi
cvtsi2sd %esi, %xmm3
mulsd %xmm3, %xmm0
cvtsi2sdl 0xc(%rsp), %xmm4
divsd %xmm4, %xmm0
movsd 0x480(%rsp,%r14,8), %xmm1
mulsd %xmm5, %xmm1
mulsd %xmm3, %xmm1
divsd %xmm4, %xmm1
movsd 0x280(%rsp,%r14,8), %xmm2
mulsd %xmm5, %xmm2
mulsd %xmm3, %xmm2
divsd %xmm4, %xmm2
movq %rbx, %rdi
movb $0x3, %al
callq 0x3040
incq %r14
jmp 0x3965
xorl %eax, %eax
addq $0x688, %rsp            # imm = 0x688
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x263c(%rip), %rdi      # 0x6028
leaq 0x265d(%rip), %rsi      # 0x6050
leaq 0x265f(%rip), %rcx      # 0x6059
pushq $0x47
popq %rdx
callq 0x3120
leaq 0x2607(%rip), %rdi      # 0x6010
xorl %eax, %eax
callq 0x4135