// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, -0x48(%rbp)
movq %r8, -0x30(%rbp)
movq %rcx, %r12
movq 0x10(%rbp), %rcx
movl %edi, %eax
movq %rsp, %r8
leaq 0x13(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %r8
movq %r8, -0x50(%rbp)
movq %r8, %rsp
movl (%rcx), %r15d
movl %edx, -0x3c(%rbp)
movl %edx, %eax
movq %rax, -0x78(%rbp)
movl $0x1, -0x34(%rbp)
xorl %r13d, %r13d
movl $0x10, %r14d
movq %rsi, -0x70(%rbp)
movl %edi, -0x38(%rbp)
leal (%r15,%r13), %ebx
cmpl %edi, %ebx
jge 0x53f3
movq %r13, -0x60(%rbp)
movq %r15, -0x68(%rbp)
movslq %ebx, %rcx
movq -0x30(%rbp), %rax
movq %rcx, -0x58(%rbp)
cmpq $0x0, (%rax,%rcx,8)
jne 0x5372
xorl %r13d, %r13d
movq -0x48(%rbp), %r15
cmpl $0x109d1, (%r15)        # imm = 0x109D1
jne 0x52df
movl $0x400, %edx            # imm = 0x400
movq %r15, %rdi
xorl %esi, %esi
callq 0x30f0
leal 0x1(%r13), %eax
addl %ebx, %r13d
movslq %r13d, %rcx
movq -0x30(%rbp), %rdx
movq %r15, (%rdx,%rcx,8)
movl %eax, %r13d
addq $0x400, %r15            # imm = 0x400
cmpl $0x10, %r13d
jl 0x52b2
cmpl $0x0, -0x3c(%rbp)
movq -0x70(%rbp), %rsi
jle 0x5372
movl %ebx, %eax
negl %eax
cltq
movq -0x30(%rbp), %rcx
movq -0x58(%rbp), %rdx
leaq (%rcx,%rdx,8), %rcx
movslq -0x60(%rbp), %rdi
movslq -0x68(%rbp), %rdx
addq %rdi, %rdx
xorl %r13d, %r13d
movq %r13, %r8
shlq $0x4, %r8
movq (%r12,%r8), %rdi
movq 0x8(%r12,%r8), %r8
cmpq %r8, %rdi
je 0x5369
movq (%rdi), %r9
movzwl (%r9), %r10d
cmpl %r10d, %ebx
jge 0x5363
addq %rax, %r10
cmpq $0x10, %r10
cmovgeq %r14, %r10
incq %r10
addq %rdx, %r9
movq -0x10(%rcx,%r10,8), %r11
movzbl (%r9,%r10), %r15d
movl $0x1, (%r11,%r15,4)
decq %r10
cmpq $0x1, %r10
jg 0x5348
addq $0x8, %rdi
jmp 0x5326
incq %r13
cmpq -0x78(%rbp), %r13
jne 0x5316
movq -0x30(%rbp), %rax
movq -0x58(%rbp), %r8
movq (%rax,%r8,8), %rax
xorl %edx, %edx
xorl %ecx, %ecx
addl (%rax,%rdx,4), %ecx
incq %rdx
cmpq $0x100, %rdx            # imm = 0x100
jne 0x5382
xorl %eax, %eax
testl %ecx, %ecx
movq -0x68(%rbp), %r15
movq -0x60(%rbp), %r13
je 0x53e7
cmpl $0x0, (%rsi,%r8,4)
movl -0x38(%rbp), %edi
je 0x53b4
xorl %eax, %eax
movq 0x10(%rbp), %rdx
cmpl (%rdx), %ebx
setg %al
addl %ecx, %eax
movq -0x50(%rbp), %rcx
movl %eax, (%rcx,%r8,4)
cmpl $0x1, %eax
jne 0x53d9
movq -0x30(%rbp), %rdx
movq (%rdx,%r8,8), %rcx
movl $0x109d1, (%rcx)        # imm = 0x109D1
movq -0x48(%rbp), %rcx
movq %rcx, (%rdx,%r8,8)
imull -0x34(%rbp), %eax
cmpl $0x1, %eax
jne 0x53ec
incl %r15d
jmp 0x53fd
movl -0x38(%rbp), %edi
jmp 0x53ff
cmpl $0x109d1, %eax          # imm = 0x109D1
jle 0x53f7
xorl %eax, %eax
jmp 0x53ff
incl %r13d
movl %eax, -0x34(%rbp)
movb $0x1, %al
testb %al, %al
jne 0x5281
movslq %r13d, %rcx
movslq %r15d, %rdx
incq %rcx
movq -0x50(%rbp), %rbx
leaq (%rbx,%rdx,4), %rax
cmpl $0x1, -0x8(%rax,%rcx,4)
leaq -0x1(%rcx), %rcx
je 0x5418
movl $0x1, %eax
testq %rcx, %rcx
jle 0x5488
movq %rcx, %r11
movl $0x1, %edi
leaq (%r11,%rdx), %r9
decq %r9
cmpl $0x2, (%rbx,%r9,4)
jl 0x547b
movl (%rsi,%r9,4), %r8d
testl %r8d, %r8d
cmovnel %edi, %r8d
movq -0x30(%rbp), %r10
movq (%r10,%r9,8), %r9
xorl %r10d, %r10d
cmpl $0x0, (%r9,%r10,4)
je 0x5467
movl %r8d, (%r9,%r10,4)
addl %edi, %r8d
incq %r10
cmpq $0x100, %r10            # imm = 0x100
jne 0x5459
subl %edi, %eax
addl %r8d, %eax
movl %r8d, %edi
leaq -0x1(%r11), %r8
cmpq $0x1, %r11
movq %r8, %r11
jg 0x5435
movq 0x10(%rbp), %rdx
movl %r15d, (%rdx)
movq 0x18(%rbp), %rdx
movl %r13d, (%rdx)
movq 0x20(%rbp), %rdx
movl %ecx, (%rdx)
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop