// File: ctSkennerton[P]fxtract/util/rsort.c
// Function: analyze
static int
analyze(int maxleng, int const *lengv,
        int nsrcs, RANGE const *srcv,
        PARTNO ** mapv, PARTNO mdata[][256], int *posp, int *skipp, int *lenp)
{
    int i, j, k, step, width[maxleng + 1];
    int pos = *posp, skip = 0, len = 0, nparts = 1;
//fprintf(stderr,"calculate nparts: "); char const *sep = "";
    while (1) {
        int p = pos + skip, more;

        if (p >= maxleng)
            break;

        if (!mapv[p])           // get (SCANWID) more maps 
            keyscan(p, srcv, nsrcs, mdata, mapv);

        for (i = more = 0; i < 256; ++i)
            more += mapv[p][i];
        if (!more)
            break;
        width[p] = more += lengv[p] && p > *posp;
        if (more == 1) {
            *mapv[p] = UNUSED;
            mapv[p] = mdata[0];
        }

        // TODO: nparts at any stage is not this value! It needs to be
        // the sum of child indices, not just the product of dimensions.
        if (nparts * more == 1)
            ++pos;              // skip leading const bytes at start of range in first iteration only 
        else if (nparts * more > MAXPARTS)  //WRONG
            break;
        else
            ++skip, nparts *= more; //WRONG
//fprintf(stderr, "%s(%d%s)", sep, more, lengv[p] && p > *posp ? "" : "-1"); sep = " * ";
    }
    for (len = skip; width[pos + len - 1] == 1; --len);

//fprintf(stderr, " = %d; recalc = 1", nparts);
    for (i = len, nparts = step = 1; --i >= 0;) {

        if (width[pos + i] > 1) {

            j = lengv[pos + i] ? step : 0;
            for (k = 0; k < 256; ++k) {
                if (mapv[pos + i][k]) {
                    mapv[pos + i][k] = j;
                    j += step;
                }
            }
//fprintf(stderr, " + %d", j - step);
            nparts += j - step;
            step = j;
        }
    }
//fprintf(stderr, "= %d\n", nparts);
    *posp = pos;
    *skipp = skip;
    *lenp = len;
    return nparts;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movl -0x4(%rbp), %eax
incl %eax
movq %rsp, %rcx
movq %rcx, -0x48(%rbp)
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x70(%rbp)
movq %rcx, %rsp
movq %rax, -0x50(%rbp)
movq 0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x54(%rbp)
movl $0x0, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movl $0x1, -0x60(%rbp)
jmp 0x6336
movl -0x54(%rbp), %eax
addl -0x58(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x4(%rbp), %eax
jl 0x634c
jmp 0x645d
movq -0x28(%rbp), %rax
movslq -0x64(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x6372
movl -0x64(%rbp), %edi
movq -0x20(%rbp), %rsi
movl -0x14(%rbp), %edx
movq -0x30(%rbp), %rcx
movq -0x28(%rbp), %r8
callq 0x6950
movl $0x0, -0x68(%rbp)
movl $0x0, -0x34(%rbp)
cmpl $0x100, -0x34(%rbp)     # imm = 0x100
jge 0x63ad
movq -0x28(%rbp), %rax
movslq -0x64(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %eax
addl -0x68(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x6380
cmpl $0x0, -0x68(%rbp)
jne 0x63b8
jmp 0x645d
movq -0x10(%rbp), %rcx
movslq -0x64(%rbp), %rdx
xorl %eax, %eax
cmpl $0x0, (%rcx,%rdx,4)
movb %al, -0x71(%rbp)
je 0x63da
movl -0x64(%rbp), %eax
movq 0x10(%rbp), %rcx
cmpl (%rcx), %eax
setg %al
movb %al, -0x71(%rbp)
movq -0x70(%rbp), %rax
movb -0x71(%rbp), %cl
andb $0x1, %cl
movzbl %cl, %edx
addl -0x68(%rbp), %edx
movl %edx, -0x68(%rbp)
movslq -0x64(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
cmpl $0x1, -0x68(%rbp)
jne 0x641c
movq -0x28(%rbp), %rax
movslq -0x64(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl $0x109d1, (%rax)        # imm = 0x109D1
movq -0x30(%rbp), %rdx
movq -0x28(%rbp), %rax
movslq -0x64(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x60(%rbp), %eax
imull -0x68(%rbp), %eax
cmpl $0x1, %eax
jne 0x6433
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x6458
movl -0x60(%rbp), %eax
imull -0x68(%rbp), %eax
cmpl $0x109d1, %eax          # imm = 0x109D1
jle 0x6443
jmp 0x645d
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
movl -0x68(%rbp), %eax
imull -0x60(%rbp), %eax
movl %eax, -0x60(%rbp)
jmp 0x6458
jmp 0x6334
movl -0x58(%rbp), %eax
movl %eax, -0x5c(%rbp)
movq -0x70(%rbp), %rax
movl -0x54(%rbp), %ecx
addl -0x5c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
cmpl $0x1, (%rax,%rcx,4)
jne 0x6486
jmp 0x647b
movl -0x5c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x6463
movl -0x5c(%rbp), %eax
movl %eax, -0x34(%rbp)
movl $0x1, -0x40(%rbp)
movl $0x1, -0x60(%rbp)
movl -0x34(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, %eax
jl 0x655e
movq -0x70(%rbp), %rax
movl -0x54(%rbp), %ecx
addl -0x34(%rbp), %ecx
movslq %ecx, %rcx
cmpl $0x1, (%rax,%rcx,4)
jle 0x6559
movq -0x10(%rbp), %rax
movl -0x54(%rbp), %ecx
addl -0x34(%rbp), %ecx
movslq %ecx, %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x64de
movl -0x40(%rbp), %eax
movl %eax, -0x78(%rbp)
jmp 0x64e5
xorl %eax, %eax
movl %eax, -0x78(%rbp)
jmp 0x64e5
movl -0x78(%rbp), %eax
movl %eax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
cmpl $0x100, -0x3c(%rbp)     # imm = 0x100
jge 0x6547
movq -0x28(%rbp), %rax
movl -0x54(%rbp), %ecx
addl -0x34(%rbp), %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x653a
movl -0x38(%rbp), %edx
movq -0x28(%rbp), %rax
movl -0x54(%rbp), %ecx
addl -0x34(%rbp), %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x40(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x653c
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x64f2
movl -0x38(%rbp), %eax
subl -0x40(%rbp), %eax
addl -0x60(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x649a
movl -0x54(%rbp), %ecx
movq 0x10(%rbp), %rax
movl %ecx, (%rax)
movl -0x58(%rbp), %ecx
movq 0x18(%rbp), %rax
movl %ecx, (%rax)
movl -0x5c(%rbp), %ecx
movq 0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x60(%rbp), %eax
movq -0x48(%rbp), %rcx
movq %rcx, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax,%rax)