// File: /workspace/github_cpp_makefile_star2_O1/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 0x3b08
movq 0x8(%rsi), %rdi
callq 0x48cb
movq %rax, %rdi
movq %rdx, %rsi
callq 0x4269
leaq 0x4(%rsp), %rbx
movq %rax, %rdi
movl $0xa, %esi
movq %rbx, %rdx
callq 0x47c0
movq %rax, 0x20(%rsp)
movslq (%rbx), %rbx
shlq $0x4, %rbx
movq %rbx, %rdi
callq 0x3270
movq %rax, %r14
movq %rbx, %rdi
callq 0x3270
movq %rax, %r15
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, 0x38(%rsp)
movq %rbx, 0x30(%rsp)
addq $-0x10, %rbx
movq %rbx, 0x78(%rsp)
movl $0x2, %r12d
leaq 0x11ab(%rip), %r13      # 0x4797
movq %r15, 0x40(%rsp)
movq %r14, 0x68(%rsp)
movslq 0x4(%rsp), %rdx
shlq $0x4, %rdx
movq %r14, %rdi
movq 0x20(%rsp), %rsi
callq 0x3150
callq 0x4b66
movsd %xmm0, 0x70(%rsp)
movslq 0x4(%rsp), %rax
cmpq %rax, %r12
movq %r12, 0x48(%rsp)
jge 0x3853
movl %r12d, %ecx
cmpl $0x3, %r12d
movl %ecx, 0x28(%rsp)
je 0x3681
cmpl $0x2, %r12d
jne 0x3706
movq (%r14), %rdi
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rdx
movq 0x18(%r14), %rcx
callq 0x4713
testl %eax, %eax
jle 0x382f
movups (%r14), %xmm0
movaps %xmm0, 0x50(%rsp)
movq 0x38(%rsp), %rax
movups (%rax), %xmm0
movups %xmm0, (%r14)
movapd 0x50(%rsp), %xmm0
movupd %xmm0, (%rax)
jmp 0x382f
movq (%r14), %rbp
movq 0x8(%r14), %r13
movq 0x10(%r14), %r15
movq 0x18(%r14), %rbx
movq 0x20(%r14), %r12
movq 0x28(%r14), %rax
movq %rax, 0x8(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x4713
testl %eax, %eax
jle 0x3792
movq %rbp, 0x10(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq 0x8(%rsp), %rbp
movq %rbp, %rcx
callq 0x4713
testl %eax, %eax
jle 0x37e0
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %rbp, %rcx
callq 0x4713
testl %eax, %eax
jle 0x37f2
movq %r12, (%r14)
movq %rbp, 0x8(%r14)
movq %r15, 0x10(%r14)
movq %rbx, 0x18(%r14)
jmp 0x3801
cltq
shlq $0x4, %rax
addq %r14, %rax
movq %rax, 0x8(%rsp)
movq 0x38(%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 0x4713
movq %rbp, %r13
cmpq %r14, %r12
jbe 0x377a
movq %rbp, %r13
testl %eax, %eax
jle 0x377a
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 0x4713
cmpq %r14, %r12
jbe 0x377a
testl %eax, %eax
jg 0x374a
movq %rbx, (%r13)
movq %r15, 0x8(%r13)
addq $0x10, %rbp
cmpq 0x8(%rsp), %rbp
jne 0x3719
jmp 0x382f
movq %r15, 0x18(%rsp)
movq %r15, %rdi
movq %rbx, 0x10(%rsp)
movq %rbx, %rsi
movq %r12, %rdx
movq 0x8(%rsp), %rcx
callq 0x4713
testl %eax, %eax
jle 0x382f
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq 0x8(%rsp), %rcx
callq 0x4713
testl %eax, %eax
jle 0x3810
movq %r12, (%r14)
movq 0x8(%rsp), %rax
movq %rax, 0x8(%r14)
movq %rbp, 0x10(%r14)
movq %r13, 0x18(%r14)
jmp 0x381d
movq %r12, 0x10(%r14)
movq %rbp, 0x18(%r14)
movq %r15, 0x20(%r14)
movq %rbx, 0x28(%r14)
jmp 0x382f
movq %r15, (%r14)
movq %rbx, 0x8(%r14)
movq %r12, 0x10(%r14)
movq %rbp, 0x18(%r14)
movq 0x10(%rsp), %rax
movq %rax, 0x20(%r14)
movq %r13, 0x28(%r14)
jmp 0x382f
movq %r12, 0x10(%r14)
movq 0x8(%rsp), %rax
movq %rax, 0x18(%r14)
movq 0x18(%rsp), %rax
movq %rax, 0x20(%r14)
movq 0x10(%rsp), %rax
movq %rax, 0x28(%r14)
movq 0x48(%rsp), %r12
movl 0x28(%rsp), %ecx
addl %r12d, %ecx
movl 0x4(%rsp), %eax
cmpl %eax, %ecx
movq 0x40(%rsp), %r15
leaq 0xf4a(%rip), %r13       # 0x4797
jl 0x362d
callq 0x4b66
subsd 0x70(%rsp), %xmm0
addsd 0x480(%rsp,%r12,8), %xmm0
movsd %xmm0, 0x480(%rsp,%r12,8)
movslq 0x4(%rsp), %rdx
shlq $0x4, %rdx
movq %r15, %rdi
movq 0x20(%rsp), %rsi
callq 0x3150
callq 0x4b66
movsd %xmm0, 0x8(%rsp)
movslq 0x4(%rsp), %rax
cmpq %rax, %r12
jge 0x38be
movl %r12d, %ebx
movslq %eax, %rsi
movl $0x10, %edx
movq %r15, %rdi
movq %r13, %rcx
callq 0x3350
addl %r12d, %ebx
movl 0x4(%rsp), %eax
cmpl %eax, %ebx
jl 0x38a0
callq 0x4b66
subsd 0x8(%rsp), %xmm0
addsd 0x280(%rsp,%r12,8), %xmm0
movsd %xmm0, 0x280(%rsp,%r12,8)
movslq 0x4(%rsp), %rbx
shlq $0x4, %rbx
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x31c0
testl %eax, %eax
jne 0x3aca
movq 0x30(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq %rbx, %rdx
callq 0x3150
callq 0x4b66
movsd %xmm0, 0x18(%rsp)
movslq 0x4(%rsp), %rcx
cmpq %rcx, %r12
jge 0x39e0
movl %r12d, %eax
movl %eax, 0x10(%rsp)
leal (%rcx,%rcx,4), %eax
leal (%rax,%rax,4), %r13d
cmpl $0x20, %r13d
jb 0x39c8
movslq %ecx, %rax
leaq 0x1(%rax), %rdx
movq %rdx, 0x28(%rsp)
shlq $0x4, %rax
addq 0x78(%rsp), %rax
movq %rax, 0x8(%rsp)
sarl $0x5, %r13d
movq %rcx, %r14
cmpl %ecx, %r13d
jge 0x39b6
movslq %r13d, %rbp
movq 0x28(%rsp), %r12
subq %rbp, %r12
shlq $0x4, %rbp
negq %rbp
movq 0x8(%rsp), %rbx
leaq (%rbx,%rbp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x4797
testl %eax, %eax
jle 0x39a9
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 0x397c
leal (%r13,%r13,4), %eax
leal (%rax,%rax,4), %r13d
cmpl $0x20, %r13d
movq %r14, %rcx
jae 0x3959
movq 0x48(%rsp), %r12
movl 0x10(%rsp), %eax
addl %r12d, %eax
movl 0x4(%rsp), %ecx
cmpl %ecx, %eax
jl 0x392a
callq 0x4b66
subsd 0x18(%rsp), %xmm0
addsd 0x80(%rsp,%r12,8), %xmm0
movsd %xmm0, 0x80(%rsp,%r12,8)
movslq 0x4(%rsp), %rdx
shlq $0x4, %rdx
movq 0x68(%rsp), %r14
movq %r14, %rdi
movq 0x30(%rsp), %rsi
callq 0x31c0
testl %eax, %eax
jne 0x3ae9
incq %r12
cmpq $0x40, %r12
movq 0x40(%rsp), %r15
leaq 0xd62(%rip), %r13       # 0x4797
jne 0x35f6
xorl %r14d, %r14d
leaq 0x2653(%rip), %rbx      # 0x6098
movsd 0x490(%rsp,%r14,8), %xmm0
movsd 0x25b1(%rip), %xmm5     # 0x6008
mulsd %xmm5, %xmm0
leal 0x2(%r14), %esi
xorps %xmm3, %xmm3
cvtsi2sd %esi, %xmm3
mulsd %xmm3, %xmm0
xorps %xmm4, %xmm4
cvtsi2sdl 0x4(%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 0x3a45
xorl %eax, %eax
addq $0x688, %rsp            # imm = 0x688
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2557(%rip), %rdi      # 0x6028
leaq 0x2578(%rip), %rsi      # 0x6050
leaq 0x257a(%rip), %rcx      # 0x6059
movl $0x47, %edx
callq 0x3120
leaq 0x2580(%rip), %rdi      # 0x6070
leaq 0x2559(%rip), %rsi      # 0x6050
leaq 0x255b(%rip), %rcx      # 0x6059
movl $0x4d, %edx
callq 0x3120
leaq 0x2501(%rip), %rdi      # 0x6010
xorl %eax, %eax
callq 0x42b7
nop