// File: /workspace/github_cpp_makefile_star2_O3/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 0x3ad9
movq 0x8(%rsi), %rdi
callq 0x48b1
movq %rax, %rdi
movq %rdx, %rsi
callq 0x423c
leaq 0xc(%rsp), %rbx
movq %rax, %rdi
movl $0xa, %esi
movq %rbx, %rdx
callq 0x477d
movq %rax, 0x18(%rsp)
movslq (%rbx), %r15
movq %r15, %rbx
shlq $0x4, %rbx
movq %rbx, %rdi
callq 0x3270
movq %rax, %r14
movq %rbx, %rdi
callq 0x3270
movq %rax, 0x60(%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
leaq 0x10(%r14), %rax
movq %rax, 0x40(%rsp)
movq %rbx, 0x38(%rsp)
addq $-0x10, %rbx
movq %rbx, 0x78(%rsp)
movl $0x2, %r12d
leaq 0x1163(%rip), %r13      # 0x4754
movq %r14, 0x70(%rsp)
movslq %r15d, %rdx
shlq $0x4, %rdx
movq %r14, %rdi
movq 0x18(%rsp), %rsi
callq 0x3150
callq 0x4b39
movsd %xmm0, 0x68(%rsp)
movslq 0xc(%rsp), %rax
cmpq %rax, %r12
movq %r12, 0x48(%rsp)
jge 0x3821
movl %r12d, %ecx
cmpl $0x3, %r12d
movl %ecx, 0x30(%rsp)
je 0x367f
cmpl $0x2, %r12d
jne 0x370e
movq (%r14), %rdi
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rdx
movq 0x18(%r14), %rcx
callq 0x46d0
testl %eax, %eax
jle 0x3802
movups (%r14), %xmm0
movaps %xmm0, 0x50(%rsp)
movq 0x40(%rsp), %rax
movups (%rax), %xmm0
movups %xmm0, (%r14)
movapd 0x50(%rsp), %xmm0
movupd %xmm0, (%rax)
jmp 0x3802
movq (%r14), %r15
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rbx
movq 0x18(%r14), %rbp
movq 0x20(%r14), %r13
movq 0x28(%r14), %r12
movq %r15, %rdi
movq %rsi, 0x10(%rsp)
movq %rbx, %rdx
movq %rbp, %rcx
callq 0x46d0
testl %eax, %eax
jle 0x3797
movq %r15, %rdi
movq 0x10(%rsp), %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0x46d0
testl %eax, %eax
jle 0x37ec
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0x46d0
testl %eax, %eax
movq %r13, %rax
cmovleq %rbx, %rax
movq %r12, %rcx
cmovleq %rbp, %rcx
cmovleq %r13, %rbx
cmovleq %r12, %rbp
movq %rax, %r13
movq %rcx, %rdx
movq %rbx, %rcx
movq %rdx, %rbx
movq %rbp, %r12
movq 0x10(%rsp), %rbp
jmp 0x37e0
cltq
shlq $0x4, %rax
addq %r14, %rax
movq %rax, 0x10(%rsp)
movq 0x40(%rsp), %rbp
movq (%rbp), %rbx
movq 0x8(%rbp), %r15
leaq -0x10(%rbp), %r12
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq %rbx, %rdx
movq %r15, %rcx
callq 0x46d0
movq %rbp, %r13
cmpq %r14, %r12
jbe 0x3782
movq %rbp, %r13
testl %eax, %eax
jle 0x3782
movq %rbp, %r13
movupd -0x10(%r13), %xmm0
movupd %xmm0, (%r13)
leaq -0x20(%r13), %r12
movq -0x20(%r13), %rdi
movq -0x18(%r13), %rsi
addq $-0x10, %r13
movq %rbx, %rdx
movq %r15, %rcx
callq 0x46d0
cmpq %r14, %r12
jbe 0x3782
testl %eax, %eax
jg 0x3752
movq %rbx, (%r13)
movq %r15, 0x8(%r13)
addq $0x10, %rbp
cmpq 0x10(%rsp), %rbp
jne 0x3721
jmp 0x3802
movq %rbx, 0x20(%rsp)
movq %rbx, %rdi
movq %rbp, 0x28(%rsp)
movq %rbp, %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0x46d0
testl %eax, %eax
jle 0x3802
movq %r12, %rbx
movq %r15, %rdi
movq 0x10(%rsp), %r12
movq %r12, %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x46d0
movq %r15, %rcx
testl %eax, %eax
movq 0x28(%rsp), %rbp
movq 0x20(%rsp), %r15
jle 0x37f2
movq %r13, (%r14)
movq %rbx, 0x8(%r14)
movq %rcx, %r13
jmp 0x37ef
movq %rbx, %r15
movq %r12, %rbx
movq %r13, 0x10(%r14)
movq %rbx, 0x18(%r14)
movq %r15, 0x20(%r14)
movq %rbp, 0x28(%r14)
movq 0x48(%rsp), %r12
movl 0x30(%rsp), %ecx
addl %r12d, %ecx
movl 0xc(%rsp), %eax
cmpl %eax, %ecx
leaq 0xf39(%rip), %r13       # 0x4754
jl 0x362b
callq 0x4b39
subsd 0x68(%rsp), %xmm0
addsd 0x480(%rsp,%r12,8), %xmm0
movsd %xmm0, 0x480(%rsp,%r12,8)
movslq 0xc(%rsp), %rdx
shlq $0x4, %rdx
movq 0x60(%rsp), %r15
movq %r15, %rdi
movq 0x18(%rsp), %rsi
callq 0x3150
callq 0x4b39
movsd %xmm0, 0x10(%rsp)
movslq 0xc(%rsp), %rax
cmpq %rax, %r12
jge 0x3891
movl %r12d, %ebx
movslq %eax, %rsi
movl $0x10, %edx
movq %r15, %rdi
movq %r13, %rcx
callq 0x3350
addl %r12d, %ebx
movl 0xc(%rsp), %eax
cmpl %eax, %ebx
jl 0x3873
callq 0x4b39
subsd 0x10(%rsp), %xmm0
addsd 0x280(%rsp,%r12,8), %xmm0
movsd %xmm0, 0x280(%rsp,%r12,8)
movslq 0xc(%rsp), %rbx
shlq $0x4, %rbx
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x31c0
testl %eax, %eax
jne 0x3a9b
movq 0x38(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %rbx, %rdx
callq 0x3150
callq 0x4b39
movsd %xmm0, 0x20(%rsp)
movslq 0xc(%rsp), %rcx
cmpq %rcx, %r12
jge 0x39b8
movl %r12d, %edx
leal (%rcx,%rcx,4), %eax
leal (%rax,%rax,4), %r13d
cmpl $0x20, %r13d
jb 0x39ad
movl %edx, 0x28(%rsp)
movslq %ecx, %rax
leaq 0x1(%rax), %rdx
movq %rdx, 0x30(%rsp)
shlq $0x4, %rax
addq 0x78(%rsp), %rax
movq %rax, 0x10(%rsp)
sarl $0x5, %r13d
movq %rcx, %r14
cmpl %ecx, %r13d
jge 0x3989
movslq %r13d, %rbp
movq 0x30(%rsp), %r12
subq %rbp, %r12
shlq $0x4, %rbp
negq %rbp
movq 0x10(%rsp), %rbx
leaq (%rbx,%rbp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x4754
testl %eax, %eax
jle 0x397c
movups (%r15), %xmm0
movaps %xmm0, 0x50(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%r15)
movapd 0x50(%rsp), %xmm0
movupd %xmm0, (%rbx)
decq %r12
addq $-0x10, %rbx
cmpq $0x1, %r12
jg 0x394f
leal (%r13,%r13,4), %eax
leal (%rax,%rax,4), %r13d
cmpl $0x20, %r13d
movq %r14, %rcx
jae 0x392c
movl 0xc(%rsp), %ecx
movq 0x48(%rsp), %r12
movq 0x70(%rsp), %r14
movl 0x28(%rsp), %edx
addl %r12d, %edx
cmpl %ecx, %edx
jl 0x38fd
callq 0x4b39
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 %r14, %rdi
movq 0x38(%rsp), %rsi
callq 0x31c0
testl %eax, %eax
jne 0x3aba
incq %r12
cmpq $0x40, %r12
leaq 0xd4e(%rip), %r13       # 0x4754
jne 0x35f6
xorl %r14d, %r14d
leaq 0x2682(%rip), %rbx      # 0x6098
movsd 0x490(%rsp,%r14,8), %xmm0
movsd 0x25e0(%rip), %xmm5     # 0x6008
mulsd %xmm5, %xmm0
leal 0x2(%r14), %esi
xorps %xmm3, %xmm3
cvtsi2sd %esi, %xmm3
mulsd %xmm3, %xmm0
xorps %xmm4, %xmm4
cvtsi2sdl 0xc(%rsp), %xmm4
divsd %xmm4, %xmm0
movsd 0x290(%rsp,%r14,8), %xmm1
mulsd %xmm5, %xmm1
mulsd %xmm3, %xmm1
divsd %xmm4, %xmm1
movsd 0x90(%rsp,%r14,8), %xmm2
mulsd %xmm5, %xmm2
mulsd %xmm3, %xmm2
divsd %xmm4, %xmm2
movq %rbx, %rdi
movb $0x3, %al
callq 0x3040
incq %r14
cmpq $0x3e, %r14
jne 0x3a16
xorl %eax, %eax
addq $0x688, %rsp            # imm = 0x688
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2586(%rip), %rdi      # 0x6028
leaq 0x25a7(%rip), %rsi      # 0x6050
leaq 0x25a9(%rip), %rcx      # 0x6059
movl $0x47, %edx
callq 0x3120
leaq 0x25af(%rip), %rdi      # 0x6070
leaq 0x2588(%rip), %rsi      # 0x6050
leaq 0x258a(%rip), %rcx      # 0x6059
movl $0x4d, %edx
callq 0x3120
leaq 0x2530(%rip), %rdi      # 0x6010
xorl %eax, %eax
callq 0x428a
nop