// File: /workspace/github_cpp_makefile_star2_O2/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 $0x98, %rsp
movq %r9, -0x68(%rbp)
movq %rcx, -0xb8(%rbp)
movq 0x10(%rbp), %r10
movl %edi, -0x44(%rbp)
movl %edi, %eax
movq %rsp, %r11
leaq 0x13(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %r11
movq %r11, %rsp
movslq (%r10), %r14
xorl %r13d, %r13d
testl %edx, %edx
cmovlel %r13d, %edx
movq %rdx, -0xc0(%rbp)
movq %rsi, -0xb0(%rbp)
leaq (%rsi,%r14,4), %rax
movq %rax, -0x58(%rbp)
leaq (%r8,%r14,8), %rax
movq %rax, -0x50(%rbp)
leaq -0x1(%r14), %rax
movq %rax, -0x60(%rbp)
leaq -0x4(%r11,%r14,4), %rdx
leaq 0x1(%r14), %rsi
movq %r8, -0x38(%rbp)
leaq -0x8(%r8), %rdi
pushq $0x1
popq %rax
movl %eax, -0x2c(%rbp)
movq %r11, -0x98(%rbp)
movq %rdi, -0x80(%rbp)
movslq %r13d, %rax
leaq 0x1(%rax), %rcx
movq %rcx, -0x78(%rbp)
movq %rdx, -0x90(%rbp)
leaq (%rdx,%rax,4), %rcx
movq %rcx, -0x70(%rbp)
movq %rsi, -0x88(%rbp)
leaq (%rsi,%rax), %rbx
addq %r14, %rax
leaq (%rdi,%rax,8), %r12
movq %r14, -0xa0(%rbp)
leal (%r14,%r13), %r15d
cmpl -0x44(%rbp), %r15d
jge 0x51c9
movslq %r15d, %rcx
movq -0x38(%rbp), %rax
movq %rcx, -0x40(%rbp)
movq (%rax,%rcx,8), %rax
testq %rax, %rax
jne 0x5113
movq %r13, -0xa8(%rbp)
xorl %r14d, %r14d
movq -0x68(%rbp), %r13
cmpl $0x10, %r14d
jge 0x5087
cmpl $0x109d1, (%r13)        # imm = 0x109D1
jne 0x507e
movl $0x400, %edx            # imm = 0x400
movq %r13, %rdi
xorl %esi, %esi
callq 0x30f0
leal 0x1(%r14), %eax
addl %r15d, %r14d
movslq %r14d, %rcx
movq -0x38(%rbp), %rdx
movq %r13, (%rdx,%rcx,8)
movl %eax, %r14d
addq $0x400, %r13            # imm = 0x400
jmp 0x504a
xorl %eax, %eax
movq 0x10(%rbp), %r10
movq -0x98(%rbp), %r11
movq -0xa0(%rbp), %r14
movq -0xa8(%rbp), %r13
cmpq -0xc0(%rbp), %rax
je 0x5107
movq %rax, %rdx
shlq $0x4, %rdx
movq -0xb8(%rbp), %rsi
movq (%rsi,%rdx), %rcx
movq 0x8(%rsi,%rdx), %rdx
cmpq %rdx, %rcx
je 0x5102
movq (%rcx), %rsi
movzwl (%rsi), %edi
subl %r15d, %edi
cmpl $0x10, %edi
pushq $0x10
popq %r8
cmovgel %r8d, %edi
movslq %edi, %rdi
addq %rbx, %rsi
testq %rdi, %rdi
jle 0x50fc
movq (%r12,%rdi,8), %r8
movzbl (%rsi,%rdi), %r9d
decq %rdi
movl $0x1, (%r8,%r9,4)
jmp 0x50e1
addq $0x8, %rcx
jmp 0x50c2
incq %rax
jmp 0x50a2
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
xorl %ecx, %ecx
xorl %edx, %edx
cmpq $0x100, %rcx            # imm = 0x100
je 0x5128
addl (%rax,%rcx,4), %edx
incq %rcx
jmp 0x5117
testl %edx, %edx
je 0x51c9
movq -0xb0(%rbp), %rcx
movq -0x40(%rbp), %rsi
cmpl $0x0, (%rcx,%rsi,4)
je 0x514b
xorl %ecx, %ecx
cmpl (%r10), %r15d
setg %cl
jmp 0x514d
xorl %ecx, %ecx
addl %edx, %ecx
movq -0x40(%rbp), %rsi
movl %ecx, (%r11,%rsi,4)
cmpl $0x1, %ecx
jne 0x516e
movl $0x109d1, (%rax)        # imm = 0x109D1
movq -0x68(%rbp), %rax
movq -0x38(%rbp), %rdx
movq %rax, (%rdx,%rsi,8)
imull -0x2c(%rbp), %ecx
cmpl $0x1, %ecx
je 0x519a
cmpl $0x109d1, %ecx          # imm = 0x109D1
jg 0x51c9
incl %r13d
incq -0x78(%rbp)
addq $0x4, -0x70(%rbp)
incq %rbx
addq $0x8, %r12
movl %ecx, -0x2c(%rbp)
jmp 0x5016
incq %r14
addq $0x4, -0x58(%rbp)
addq $0x8, -0x50(%rbp)
incq -0x60(%rbp)
movq -0x90(%rbp), %rdx
addq $0x4, %rdx
movq -0x88(%rbp), %rsi
incq %rsi
movq -0x80(%rbp), %rdi
jmp 0x4fe3
movq -0x78(%rbp), %rbx
movq -0x70(%rbp), %rax
decq %rbx
cmpl $0x1, (%rax)
leaq -0x4(%rax), %rax
je 0x51d1
pushq $0x1
popq %rdx
movq %rbx, %rcx
movl %edx, %eax
movq -0x60(%rbp), %r9
leaq (%r9,%rcx), %rsi
leaq (%r11,%rsi,4), %rsi
xorl %edi, %edi
leaq (%rcx,%rdi), %r8
testq %r8, %r8
jle 0x524f
leaq -0x1(%rdi), %r8
cmpl $0x2, (%rsi,%rdi,4)
movq %r8, %rdi
jl 0x51f3
movq -0x58(%rbp), %rsi
leaq (%rsi,%rcx,4), %rsi
movl (%rsi,%r8,4), %esi
testl %esi, %esi
cmovnel %edx, %esi
movq -0x50(%rbp), %rdi
leaq (%rdi,%rcx,8), %rdi
movq (%rdi,%r8,8), %rdi
addq %r8, %rcx
xorl %r8d, %r8d
cmpq $0x100, %r8             # imm = 0x100
je 0x5247
cmpl $0x0, (%rdi,%r8,4)
je 0x5242
movl %esi, (%rdi,%r8,4)
addl %edx, %esi
incq %r8
jmp 0x522c
subl %edx, %eax
addl %esi, %eax
movl %esi, %edx
jmp 0x51e9
movl %r14d, (%r10)
movq 0x18(%rbp), %rcx
movl %r13d, (%rcx)
movq 0x20(%rbp), %rcx
movl %ebx, (%rcx)
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop