// File: ctSkennerton[P]fxtract/util/rsort.c
// Function: gather
static int
gather(int nextpos, int nparts, PARTNO const *partv,
       PART const *pdata, RANGE * dstv)
{
    int ndsts = 0, i, curr;

    for (i = nparts; --i >= 0;) {

        for (curr = partv[i]; curr;) {
            RANGE *rngp = pdata[curr].rng;
            RSREC **rpp = rngp->omega, **omega;

            do {
                *--rpp = pdata[curr].rec;
                curr = pdata[curr].next;
            } while (pdata[curr].rng == rngp);

            omega = rpp;
            while (KEYLENG(*rpp) <= nextpos && ++rpp < rngp->omega);

            int count = rngp->omega - rpp;

            if (count >= MINRANGE) {

                dstv[ndsts++] = (RANGE) {
                rpp, rngp->omega};
                DIAG_NRECS(_nrecs + count);

            }
            else if (count > 1 && KEYLENG(*rpp) > nextpos) {

                insort(rpp, rngp->omega, nextpos);
            }

            rngp->omega = omega;
        }
    }

    return ndsts;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x8(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, %eax
jl 0x6938
movq -0x10(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x6933
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rcx
movq -0x40(%rbp), %rax
movq %rax, %rdx
addq $-0x8, %rdx
movq %rdx, -0x40(%rbp)
movq %rcx, -0x8(%rax)
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
cmpq -0x38(%rbp), %rax
je 0x67f4
movq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
movq (%rax), %rdi
callq 0x6260
movl %eax, %ecx
xorl %eax, %eax
cmpl -0x4(%rbp), %ecx
movb %al, -0x61(%rbp)
jg 0x6881
movq -0x40(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rcx
cmpq 0x8(%rcx), %rax
setb %al
movb %al, -0x61(%rbp)
movb -0x61(%rbp), %al
testb $0x1, %al
jne 0x688a
jmp 0x688c
jmp 0x684f
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x40(%rbp), %rcx
subq %rcx, %rax
sarq $0x3, %rax
movl %eax, -0x4c(%rbp)
cmpl $0x10, -0x4c(%rbp)
jl 0x68f5
movq -0x20(%rbp), %rax
movl -0x24(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x24(%rbp)
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x40(%rbp), %rcx
movq %rcx, -0x60(%rbp)
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, -0x58(%rbp)
movq -0x60(%rbp), %rcx
movq %rcx, (%rax)
movq -0x58(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl 0x4eb6(%rip), %eax      # 0xb7a0
addl -0x4c(%rbp), %eax
movl %eax, 0x4ead(%rip)      # 0xb7a0
jmp 0x6922
cmpl $0x1, -0x4c(%rbp)
jle 0x6920
movq -0x40(%rbp), %rax
movq (%rax), %rdi
callq 0x6260
cmpl -0x4(%rbp), %eax
jle 0x6920
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rsi
movl -0x4(%rbp), %edx
callq 0x6b20
jmp 0x6922
movq -0x48(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x67c7
jmp 0x67a7
movl -0x24(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)