// File: /workspace/github_cpp_makefile_star2_O3/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, -0x60(%rbp)
movq %r8, -0x48(%rbp)
movq %rcx, -0x80(%rbp)
movq %rsi, %r13
movq 0x10(%rbp), %r15
movl %edi, %eax
movq %rsp, %r12
leaq 0x13(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %r12
movq %r12, %rsp
movl (%r15), %ebx
xorl %r14d, %r14d
movl %edi, -0x54(%rbp)
cmpl %edi, %ebx
jge 0x53ec
movl %edx, %r11d
movl %edx, %eax
movq %rax, -0x78(%rbp)
xorl %r14d, %r14d
movl $0x1, -0x2c(%rbp)
movl %ebx, %eax
movq %r13, -0x70(%rbp)
movq %r12, -0x68(%rbp)
movq %rax, -0x38(%rbp)
movq %r14, -0x40(%rbp)
movslq %ebx, %rcx
movq -0x48(%rbp), %rax
movq %rcx, -0x50(%rbp)
leaq (%rax,%rcx,8), %r14
cmpq $0x0, (%r14)
movl $0x10, %r12d
jne 0x533f
xorl %r13d, %r13d
movq -0x60(%rbp), %r15
cmpl $0x109d1, (%r15)        # imm = 0x109D1
jne 0x52bc
movl $0x400, %edx            # imm = 0x400
movq %r15, %rdi
xorl %esi, %esi
movl %r11d, %r12d
callq 0x30f0
movl %r12d, %r11d
movl $0x10, %r12d
leal 0x1(%r13), %eax
addl %ebx, %r13d
movslq %r13d, %rcx
movq -0x48(%rbp), %rdx
movq %r15, (%rdx,%rcx,8)
movl %eax, %r13d
addq $0x400, %r15            # imm = 0x400
cmpl $0x10, %r13d
jl 0x5283
testl %r11d, %r11d
movq 0x10(%rbp), %r15
movq -0x70(%rbp), %r13
jle 0x533f
movl %ebx, %eax
negl %eax
cltq
xorl %ecx, %ecx
movq %rcx, %rsi
shlq $0x4, %rsi
movq -0x80(%rbp), %rdi
movq (%rdi,%rsi), %rdx
movq 0x8(%rdi,%rsi), %rsi
cmpq %rsi, %rdx
je 0x5336
movq (%rdx), %rdi
movzwl (%rdi), %r8d
cmpl %r8d, %ebx
jge 0x5330
addq %rax, %r8
cmpq $0x10, %r8
cmovgeq %r12, %r8
incq %r8
addq -0x50(%rbp), %rdi
movq -0x10(%r14,%r8,8), %r9
movzbl (%rdi,%r8), %r10d
movl $0x1, (%r9,%r10,4)
decq %r8
cmpq $0x1, %r8
jg 0x5315
addq $0x8, %rdx
jmp 0x52f2
incq %rcx
cmpq -0x78(%rbp), %rcx
jne 0x52de
movq (%r14), %rax
pxor %xmm0, %xmm0
xorl %ecx, %ecx
movdqu (%rax,%rcx,4), %xmm1
paddd %xmm1, %xmm0
addq $0x4, %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0x5348
pshufd $0xee, %xmm0, %xmm1     # xmm1 = xmm0[2,3,2,3]
paddd %xmm0, %xmm1
pshufd $0x55, %xmm1, %xmm0     # xmm0 = xmm1[1,1,1,1]
paddd %xmm1, %xmm0
movd %xmm0, %edx
testl %edx, %edx
je 0x53f0
movq -0x50(%rbp), %rcx
cmpl $0x0, (%r13,%rcx,4)
je 0x538e
xorl %ecx, %ecx
cmpl (%r15), %ebx
setg %cl
jmp 0x5390
xorl %ecx, %ecx
addl %edx, %ecx
movq -0x68(%rbp), %rdx
movq -0x50(%rbp), %rsi
movl %ecx, (%rdx,%rsi,4)
movq %rdx, %r12
cmpl $0x1, %ecx
jne 0x53b2
movl $0x109d1, (%rax)        # imm = 0x109D1
movq -0x60(%rbp), %rax
movq %rax, (%r14)
imull -0x2c(%rbp), %ecx
cmpl $0x1, %ecx
jne 0x53c7
movq -0x38(%rbp), %rax
incl %eax
movq -0x40(%rbp), %r14
jmp 0x53dd
cmpl $0x109d1, %ecx          # imm = 0x109D1
movq -0x40(%rbp), %r14
movq -0x38(%rbp), %rax
jg 0x53fc
incl %r14d
movl %ecx, -0x2c(%rbp)
leal (%r14,%rax), %ebx
cmpl -0x54(%rbp), %ebx
jl 0x5255
jmp 0x53fc
movl %ebx, %eax
jmp 0x53fc
movq -0x68(%rbp), %r12
movq -0x40(%rbp), %r14
movq -0x38(%rbp), %rax
movq 0x18(%rbp), %rdx
movslq %r14d, %rsi
movq %rax, %rcx
movslq %eax, %rdi
incq %rsi
leaq (%r12,%rdi,4), %rax
cmpl $0x1, -0x8(%rax,%rsi,4)
leaq -0x1(%rsi), %rsi
je 0x5410
movl $0x1, %eax
testq %rsi, %rsi
jle 0x5482
movq %rsi, %r8
movl $0x1, %r9d
leaq (%r8,%rdi), %r11
decq %r11
cmpl $0x2, (%r12,%r11,4)
jl 0x5475
movl (%r13,%r11,4), %r10d
testl %r10d, %r10d
cmovnel %r9d, %r10d
movq -0x48(%rbp), %rbx
movq (%rbx,%r11,8), %r11
xorl %ebx, %ebx
cmpl $0x0, (%r11,%rbx,4)
je 0x5460
movl %r10d, (%r11,%rbx,4)
addl %r9d, %r10d
incq %rbx
cmpq $0x100, %rbx            # imm = 0x100
jne 0x5452
subl %r9d, %eax
addl %r10d, %eax
movl %r10d, %r9d
leaq -0x1(%r8), %r10
cmpq $0x1, %r8
movq %r10, %r8
jg 0x542e
movl %ecx, (%r15)
movl %r14d, (%rdx)
movq 0x20(%rbp), %rcx
movl %esi, (%rcx)
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)