// File: /workspace/github_c_makefile_star2_O3/c-zhou[P]oatk/path.c
// Function: find_seeds_in_pure_graph
static uint32_t find_seeds_in_pure_graph(clust_t *clusts, uint32_t n_clust, clust_dp_t *comp_dps, uint32_t nv, OG_TYPE_t og_t, double min_mean, 
        double max_mean, double fold_thresh, uint32_t min_size, uint32_t max_size, double *_c_mean, OG_TYPE_t *og_seeds, int verbose)
{
    uint32_t i, j, c, v, seed, n_seeds, l_seeds, *seed_clust, *gseq_clust;
    uint64_t *gene_clust;
    double c_mean, min_mean1, max_mean1;

    // count number of best genes in each coverage cluster
    MYCALLOC(gseq_clust, n_clust);
    MYCALLOC(gene_clust, n_clust);
    for (i = 0; i < n_clust; ++i) {
        for (j = 0; j < clusts[i].n_dps; ++j) {
            v = clusts[i].dps[j];
            gene_clust[i] += comp_dps[v].gene_num[og_t];
            if (comp_dps[v].gene_num[og_t] > 0)
                gseq_clust[i] += comp_dps[v].size;
        }
        gene_clust[i] <<= 32;
        gene_clust[i] |= i;
        // a simple rule to decide if
        // all sequences in a cluster should be added together
        if (gseq_clust[i] > 0.5 * clusts[i].size)
            gseq_clust[i] = clusts[i].size;
    }
    // sort clusters by number of best genes in descending order
    qsort(gene_clust, n_clust, sizeof(uint64_t), u64_cmpfunc_r);
    
    // collect seeds in each cluster
    MYCALLOC(seed_clust, n_clust);
    min_mean1 = max_mean1 = 0;
    n_seeds = l_seeds = 0;
    for (i = 0; i < n_clust; ++i) {
        if ((gene_clust[i] >> 32) == 0)
            // no gene
            break;
        c = (uint32_t) gene_clust[i]; // cluster index
        if (clusts[c].og_type != og_t)
            // not the right organelle type
            continue;
        c_mean = clusts[c].mean;
        if (c_mean < min_mean && c_mean > max_mean)
            // coverage not in range
            continue;
        if (l_seeds + gseq_clust[c] > max_size)
            // too much sequence
            continue;
        seed = 0;
        if (n_seeds == 0) {
            // major cluster
            // mean coverage not set yet
            min_mean1 = c_mean;
            max_mean1 = c_mean;
            seed = 1;
        } else {
            // secondary clusters
            if (gseq_clust[c] >= min_size) {
                // this is a large cluster
                // make it a seed only when
                // the fold difference is within the range
                if (c_mean >= min_mean1 && c_mean <= max_mean1) {
                    // mean coverage is within the old range
                    seed = 1;
                } else if (fabs(log(min_mean1/c_mean)) <= fold_thresh &&
                        fabs(log(max_mean1/c_mean)) <= fold_thresh) {
                    // mean coverage is within the new range
                    // update coverage
                    if (c_mean < min_mean1)
                        min_mean1 = c_mean;
                    if (c_mean > max_mean1)
                        max_mean1 = c_mean;
                    seed = 1;
                }
            } else {
                // this is a small cluster
                // make it a seed
                // but do not change the coverage
                seed = 1;
            }
        }
        if (seed) {
            seed_clust[c] = 1;
            n_seeds += 1;
            l_seeds += gseq_clust[c];
        }
    }
    
    MYBZERO(og_seeds, nv);
    // process clusters
    int all_seq;
    for (i = 0; i < n_clust; ++i) {
        if (!seed_clust[i])
            continue;
        // not always to add all sequences
        all_seq = clusts[i].size == gseq_clust[i];
        for (j = 0; j < clusts[i].n_dps; ++j)
            if (all_seq || 
                    comp_dps[clusts[i].dps[j]].gene_num[og_t] > 0)
                og_seeds[clusts[i].dps[j]] = og_t;
    }

    // process each unclassified individual sequence
    uint32_t ext_l, ext_n;
    OG_TYPE_t og_t1, *og_seeds1;
    og_t1 = OG_UNCLASSIFIED;
    if (og_t == OG_MITO)
        og_t1 = OG_PLTD;
    else if (og_t == OG_PLTD)
        og_t1 = OG_MITO;
    MYCALLOC(og_seeds1, nv);
    ext_l = ext_n = 0;
    for (i = 0; i < nv; ++i) {
        c_mean = comp_dps[i].val;
        if (!og_seeds[i] && 
                (og_t1 == OG_UNCLASSIFIED || 
                 comp_dps[i].gene_num[og_t1] == 0 ||
                 comp_dps[i].gene_num[og_t] > 0) &&
                c_mean >= min_mean &&
                c_mean <= max_mean &&
                fabs(log(min_mean1/c_mean)) <= fold_thresh) {
            ext_l += comp_dps[i].size;
            ext_n += 1;
            og_seeds1[i] = og_t;
        }
    }
    // only add extra sequences if total size within threshold
    if (l_seeds + ext_l <= max_size) {
        for (i = 0; i < nv; ++i)
            if (og_seeds1[i])
                og_seeds[i] = og_seeds1[i];
        n_seeds += ext_n;
        l_seeds += ext_l;
    }

    free(gseq_clust);
    free(gene_clust);
    free(seed_clust);
    free(og_seeds1);
    
    if (verbose > 2)
        fprintf(stderr, "[M::%s] [%s] - seeds number: %u; seeds length: %u; seeds coverage: %.3f - %.3f\n", 
                __func__, OG_TYPES[og_t], n_seeds, l_seeds, min_mean1, max_mean1);

    if (_c_mean)
        *_c_mean = min_mean1;
    
    return l_seeds;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %r9d, 0xc(%rsp)
movsd %xmm1, 0x60(%rsp)
movsd %xmm0, 0x28(%rsp)
movl %r8d, %r15d
movl %ecx, 0x44(%rsp)
movq %rdx, %r12
movl %esi, %ebp
movq %rdi, %r13
movl %esi, %r14d
movl $0x4, %esi
movq %r14, %rdi
callq 0x3240
movq %rax, %rbx
movl $0x8, %esi
movq %r14, 0x20(%rsp)
movq %r14, %rdi
callq 0x3240
movl %r15d, %r14d
movl %ebp, 0x48(%rsp)
testl %ebp, %ebp
je 0xf805
xorl %r11d, %r11d
movsd 0xad84(%rip), %xmm0     # 0x1a4f8
leaq (%r11,%r11,8), %rcx
leaq (,%rcx,8), %rcx
addq %r13, %rcx
movl 0x4(%rcx), %esi
testq %rsi, %rsi
je 0xf7c4
movq 0x8(%rcx), %rdi
movq (%rax,%r11,8), %rdx
xorl %r8d, %r8d
movl (%rdi,%r8,4), %r9d
leaq (%r9,%r9,2), %r9
shlq $0x4, %r9
addq %r12, %r9
movslq 0x18(%r9,%r14,4), %r10
testq %r10, %r10
jle 0xf7b7
movl 0x10(%r9), %r9d
addl %r9d, (%rbx,%r11,4)
addq %r10, %rdx
incq %r8
cmpq %r8, %rsi
jne 0xf796
jmp 0xf7c8
movq (%rax,%r11,8), %rdx
movl (%rbx,%r11,4), %esi
xorps %xmm1, %xmm1
cvtsi2sd %rsi, %xmm1
shlq $0x20, %rdx
orq %r11, %rdx
movq %rdx, (%rax,%r11,8)
movl 0x10(%rcx), %ecx
xorps %xmm2, %xmm2
cvtsi2sd %ecx, %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
jbe 0xf7f7
movl %ecx, (%rbx,%r11,4)
incq %r11
cmpq 0x20(%rsp), %r11
jne 0xf774
leaq -0x2317(%rip), %rcx     # 0xd4f5
movl $0x8, %edx
movq %rax, 0x50(%rsp)
movq %rax, %rdi
movq 0x20(%rsp), %rbp
movq %rbp, %rsi
callq 0x30c0
movl $0x4, %esi
movq %rbp, %rdi
callq 0x3240
movq %rax, %rbp
movl 0x44(%rsp), %eax
movl %eax, %r8d
cmpl $0x0, 0x48(%rsp)
movq %rbp, 0x58(%rsp)
movq %r8, 0x30(%rsp)
je 0xf9fa
movq %r13, 0x38(%rsp)
xorl %ebp, %ebp
xorpd %xmm1, %xmm1
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
xorl %esi, %esi
xorl %r13d, %r13d
movq 0x50(%rsp), %rdx
movsd 0x28(%rsp), %xmm0
movq 0xc0(%rsp), %rdi
movq (%rdx,%rbp,8), %rax
movq %rax, %rcx
shrq $0x20, %rcx
je 0xfa2f
movl %eax, %r9d
leaq (%r9,%r9,8), %rax
movq 0x38(%rsp), %rcx
cmpl %r15d, 0x40(%rcx,%rax,8)
jne 0xf8cb
leaq (%rcx,%rax,8), %rax
movsd 0x18(%rax), %xmm2
ucomisd %xmm2, %xmm0
jbe 0xf8ba
ucomisd 0x60(%rsp), %xmm2
ja 0xf8cb
movl (%rbx,%r9,4), %eax
leal (%rax,%r13), %ecx
cmpl 0xb0(%rsp), %ecx
jbe 0xf8e0
movl %r13d, %ecx
incq %rbp
movl %ecx, %r13d
cmpq %rbp, 0x20(%rsp)
jne 0xf87f
jmp 0xfa32
testl %esi, %esi
je 0xf900
cmpl 0xc(%rsp), %eax
jb 0xf8f8
ucomisd 0x10(%rsp), %xmm2
jb 0xf91b
ucomisd %xmm2, %xmm1
jb 0xf91b
movsd 0x10(%rsp), %xmm2
jmp 0xf904
movapd %xmm2, %xmm1
movq 0x58(%rsp), %rax
movl $0x1, (%rax,%r9,4)
incl %esi
movsd %xmm2, 0x10(%rsp)
jmp 0xf8ce
movq %r9, 0x70(%rsp)
movl %ecx, 0x8(%rsp)
movsd %xmm1, 0x18(%rsp)
movl %esi, 0x4(%rsp)
movsd 0x10(%rsp), %xmm0
divsd %xmm2, %xmm0
movsd %xmm2, 0x68(%rsp)
callq 0x31f0
movsd 0xac0d(%rip), %xmm2     # 0x1a558
movapd 0xac2d(%rip), %xmm1     # 0x1a580
andpd %xmm1, %xmm0
ucomisd %xmm0, %xmm2
jb 0xf988
movsd 0x18(%rsp), %xmm0
divsd 0x68(%rsp), %xmm0
callq 0x31f0
movsd 0xabe2(%rip), %xmm2     # 0x1a558
movapd 0xac02(%rip), %xmm1     # 0x1a580
andpd %xmm1, %xmm0
ucomisd %xmm0, %xmm2
jae 0xf9b2
movl %r13d, %ecx
movq 0x50(%rsp), %rdx
movsd 0x28(%rsp), %xmm0
movl 0x4(%rsp), %esi
movsd 0x18(%rsp), %xmm1
movq 0xc0(%rsp), %rdi
movq 0x30(%rsp), %r8
jmp 0xf8ce
movsd 0x68(%rsp), %xmm1
movapd %xmm1, %xmm0
minsd 0x10(%rsp), %xmm1
maxsd 0x18(%rsp), %xmm0
movapd %xmm1, %xmm2
movapd %xmm0, %xmm1
movq 0x50(%rsp), %rdx
movsd 0x28(%rsp), %xmm0
movl 0x4(%rsp), %esi
movq 0xc0(%rsp), %rdi
movq 0x30(%rsp), %r8
movl 0x8(%rsp), %ecx
movq 0x70(%rsp), %r9
jmp 0xf904
leaq (,%r8,4), %rdx
movl $0x0, 0x4(%rsp)
movq 0xc0(%rsp), %rdi
xorl %esi, %esi
callq 0x31b0
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
movsd %xmm1, 0x10(%rsp)
xorl %r13d, %r13d
jmp 0xfae8
movl %r13d, %ecx
movl %ecx, %r13d
movsd %xmm1, 0x18(%rsp)
movl %esi, 0x4(%rsp)
leaq (,%r8,4), %rdx
xorl %esi, %esi
callq 0x31b0
cmpl $0x0, 0x48(%rsp)
je 0xfadd
xorl %eax, %eax
movsd 0x18(%rsp), %xmm0
movq 0x58(%rsp), %rbp
movq 0xc0(%rsp), %r11
cmpl $0x0, (%rbp,%rax,4)
je 0xfad1
leaq (%rax,%rax,8), %rdx
movq 0x38(%rsp), %rcx
movl 0x4(%rcx,%rdx,8), %ecx
testl %ecx, %ecx
je 0xfad1
movq 0x38(%rsp), %rsi
leaq (%rsi,%rdx,8), %rdx
movl 0x10(%rdx), %esi
movl (%rbx,%rax,4), %edi
movq 0x8(%rdx), %r8
xorl %r9d, %r9d
movslq (%r8,%r9,4), %r10
cmpl %edi, %esi
je 0xfabf
leaq (%r10,%r10,2), %r11
shlq $0x4, %r11
addq %r12, %r11
cmpl $0x0, 0x18(%r11,%r14,4)
movq 0xc0(%rsp), %r11
jle 0xfac6
movl %r15d, (%r11,%r10,4)
movl 0x4(%rdx), %ecx
incq %r9
movl %ecx, %r10d
cmpq %r10, %r9
jb 0xfa9c
incq %rax
cmpq 0x20(%rsp), %rax
jne 0xfa6e
jmp 0xfae8
movsd 0x18(%rsp), %xmm0
movq 0x58(%rsp), %rbp
movl %r13d, 0x8(%rsp)
cmpl $0x1, %r15d
movq 0x30(%rsp), %rdi
movsd %xmm0, 0x18(%rsp)
je 0xfb0b
cmpl $0x2, %r15d
jne 0xfb1f
movl $0x1, %eax
jmp 0xfb10
movl $0x2, %eax
movq %rax, 0x38(%rsp)
movl $0x0, 0x20(%rsp)
jmp 0xfb2e
movb $0x1, %al
movl %eax, 0x20(%rsp)
movq $0x0, 0x38(%rsp)
movl $0x4, %esi
callq 0x3240
movq %rax, 0x48(%rsp)
cmpl $0x0, 0x44(%rsp)
je 0xfc2b
addq $0x18, %r12
xorl %ebp, %ebp
movl $0x0, 0xc(%rsp)
xorl %r13d, %r13d
movsd 0x28(%rsp), %xmm2
movq 0xc0(%rsp), %rsi
movq 0x30(%rsp), %rdi
movl 0x8(%rsp), %eax
cmpl $0x0, (%rsi,%rbp,4)
jne 0xfbfb
movsd -0x10(%r12), %xmm1
cmpb $0x0, 0x20(%rsp)
jne 0xfb9b
movq 0x38(%rsp), %rcx
cmpl $0x0, (%r12,%rcx,4)
je 0xfb9b
cmpl $0x0, (%r12,%r14,4)
jle 0xfbfb
ucomisd %xmm2, %xmm1
jb 0xfbfb
movsd 0x60(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jb 0xfbfb
movsd 0x10(%rsp), %xmm0
divsd %xmm1, %xmm0
callq 0x31f0
andpd 0xa9bc(%rip), %xmm0     # 0x1a580
movsd 0xa98c(%rip), %xmm1     # 0x1a558
ucomisd %xmm0, %xmm1
jb 0xfbe4
addl -0x8(%r12), %r13d
incl 0xc(%rsp)
movq 0x48(%rsp), %rax
movl %r15d, (%rax,%rbp,4)
movsd 0x28(%rsp), %xmm2
movq 0xc0(%rsp), %rsi
movq 0x30(%rsp), %rdi
movl 0x8(%rsp), %eax
incq %rbp
addq $0x30, %r12
cmpq %rbp, %rdi
jne 0xfb70
addl %eax, %r13d
cmpl 0xb0(%rsp), %r13d
movl 0x4(%rsp), %edx
jbe 0xfc49
movq 0x58(%rsp), %rbp
movl 0xc8(%rsp), %r12d
jmp 0xfc8a
xorl %r13d, %r13d
movl 0x8(%rsp), %eax
cmpl 0xb0(%rsp), %eax
movl 0x4(%rsp), %edx
movl 0xc8(%rsp), %r12d
jbe 0xfc7f
jmp 0xfc8a
cmpl $0x0, 0x44(%rsp)
movq 0x58(%rsp), %rbp
movl 0xc8(%rsp), %r12d
je 0xfc77
xorl %eax, %eax
movq 0x48(%rsp), %r8
movl (%r8,%rax,4), %ecx
testl %ecx, %ecx
je 0xfc6f
movl %ecx, (%rsi,%rax,4)
incq %rax
cmpq %rax, %rdi
jne 0xfc64
movl %r13d, %eax
movl 0xc(%rsp), %r13d
movl %eax, 0x8(%rsp)
addl %r13d, %edx
movl %edx, 0x4(%rsp)
movq 0xb8(%rsp), %r15
movq %rbx, %rdi
callq 0x3060
movq 0x50(%rsp), %rdi
callq 0x3060
movq %rbp, %rdi
callq 0x3060
movq 0x48(%rsp), %rdi
callq 0x3060
cmpl $0x3, %r12d
jge 0xfcdf
testq %r15, %r15
movl 0x8(%rsp), %eax
je 0xfcd0
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%r15)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10312(%rip), %rax     # 0x1fff8
movq (%rax), %rdi
leaq 0xfe50(%rip), %rax      # 0x1fb40
movq (%rax,%r14,8), %rcx
leaq 0xb8e2(%rip), %rsi      # 0x1b5dd
leaq 0xb92b(%rip), %rdx      # 0x1b62d
movl 0x4(%rsp), %r8d
movl 0x8(%rsp), %r9d
movsd 0x10(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
movb $0x2, %al
callq 0x3290
jmp 0xfcbc