// File: /workspace/github_c_makefile_star2_O1/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, 0x48(%rsp)
movsd %xmm1, 0x70(%rsp)
movsd %xmm0, 0x28(%rsp)
movl %r8d, %r15d
movl %ecx, 0x34(%rsp)
movq %rdx, %r12
movl %esi, 0x20(%rsp)
movq %rdi, %r13
movl %esi, %ebp
movl $0x4, %esi
movq %rbp, %rdi
callq 0x3240
movq %rax, %rbx
movl $0x8, %esi
movq %rbp, %rdi
callq 0x3240
movl %r15d, %r14d
cmpl $0x0, 0x20(%rsp)
je 0xf294
xorl %r11d, %r11d
movsd 0xa2cd(%rip), %xmm0     # 0x194d0
leaq (%r11,%r11,8), %rcx
leaq (,%rcx,8), %rcx
addq %r13, %rcx
movl 0x4(%rcx), %edx
testq %rdx, %rdx
je 0xf255
movq 0x8(%rcx), %rdi
movq (%rax,%r11,8), %rsi
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 0xf246
movl 0x10(%r9), %r9d
addl %r9d, (%rbx,%r11,4)
addq %r10, %rsi
incq %r8
cmpq %r8, %rdx
jne 0xf225
movq %rsi, (%rax,%r11,8)
movl (%rbx,%r11,4), %edx
xorps %xmm1, %xmm1
cvtsi2sd %rdx, %xmm1
movq (%rax,%r11,8), %rdx
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 0xf288
movl %ecx, (%rbx,%r11,4)
incq %r11
cmpq %rbp, %r11
jne 0xf203
leaq -0x21b0(%rip), %rcx     # 0xd0eb
movl $0x8, %edx
movq %rax, 0x58(%rsp)
movq %rax, %rdi
movq %rbp, %rsi
callq 0x30c0
movl $0x4, %esi
movq %rbp, 0x10(%rsp)
movq %rbp, %rdi
callq 0x3240
cmpl $0x0, 0x20(%rsp)
movq %rax, 0x60(%rsp)
movq %r13, 0x50(%rsp)
je 0xf4b1
xorl %ebp, %ebp
xorpd %xmm1, %xmm1
xorpd %xmm3, %xmm3
movl $0x0, 0xc(%rsp)
xorl %r13d, %r13d
movq 0x58(%rsp), %rdx
movsd 0x28(%rsp), %xmm0
movq 0xc0(%rsp), %rdi
movq (%rdx,%rbp,8), %rsi
movq %rsi, %rcx
shrq $0x20, %rcx
je 0xf4cd
movl %esi, %r8d
leaq (%r8,%r8,8), %rcx
movq 0x50(%rsp), %rsi
cmpl %r15d, 0x40(%rsi,%rcx,8)
jne 0xf34b
leaq (%rsi,%rcx,8), %rcx
movsd 0x18(%rcx), %xmm2
ucomisd %xmm2, %xmm0
jbe 0xf33a
ucomisd 0x70(%rsp), %xmm2
ja 0xf34b
movl (%rbx,%r8,4), %ecx
leal (%rcx,%r13), %esi
cmpl 0xb0(%rsp), %esi
jbe 0xf368
movl %r13d, %esi
movapd %xmm3, %xmm2
incq %rbp
movapd %xmm2, %xmm3
movl %esi, %r13d
cmpq %rbp, 0x10(%rsp)
jne 0xf2ff
jmp 0xf4d4
cmpl $0x0, 0xc(%rsp)
je 0xf38c
cmpl 0x48(%rsp), %ecx
jb 0xf381
ucomisd %xmm3, %xmm2
jb 0xf397
ucomisd %xmm2, %xmm1
jb 0xf397
xorl %ecx, %ecx
movapd %xmm3, %xmm2
jmp 0xf494
xorl %ecx, %ecx
movapd %xmm2, %xmm1
jmp 0xf494
movq %r8, 0x68(%rsp)
movl %esi, 0x8(%rsp)
movsd %xmm1, 0x38(%rsp)
movapd %xmm3, %xmm0
divsd %xmm2, %xmm0
movsd %xmm2, 0x40(%rsp)
movsd %xmm3, 0x18(%rsp)
callq 0x31f0
movsd 0xa191(%rip), %xmm2     # 0x19558
movapd 0xa1b1(%rip), %xmm1     # 0x19580
andpd %xmm1, %xmm0
movb $0x1, %cl
ucomisd %xmm0, %xmm2
jae 0xf3f7
movsd 0x18(%rsp), %xmm2
movq 0x58(%rsp), %rdx
movsd 0x28(%rsp), %xmm0
movsd 0x38(%rsp), %xmm1
jmp 0xf47e
movsd 0x38(%rsp), %xmm0
divsd 0x40(%rsp), %xmm0
callq 0x31f0
movsd 0xa148(%rip), %xmm2     # 0x19558
movapd 0xa168(%rip), %xmm1     # 0x19580
andpd %xmm1, %xmm0
ucomisd %xmm0, %xmm2
jae 0xf453
movsd 0x18(%rsp), %xmm2
movq 0x58(%rsp), %rdx
movsd 0x28(%rsp), %xmm0
movsd 0x38(%rsp), %xmm1
movq 0x60(%rsp), %rax
movq 0xc0(%rsp), %rdi
movl 0x8(%rsp), %esi
movq 0x68(%rsp), %r8
movb $0x1, %cl
jmp 0xf494
movsd 0x40(%rsp), %xmm1
movapd %xmm1, %xmm0
minsd 0x18(%rsp), %xmm1
maxsd 0x38(%rsp), %xmm0
xorl %ecx, %ecx
movapd %xmm1, %xmm2
movapd %xmm0, %xmm1
movq 0x58(%rsp), %rdx
movsd 0x28(%rsp), %xmm0
movq 0x60(%rsp), %rax
movq 0xc0(%rsp), %rdi
movl 0x8(%rsp), %esi
movq 0x68(%rsp), %r8
testb %cl, %cl
je 0xf4a0
movl %r13d, %esi
jmp 0xf352
movl $0x1, (%rax,%r8,4)
incl 0xc(%rsp)
jmp 0xf352
xorpd %xmm2, %xmm2
xorl %esi, %esi
movl $0x0, 0xc(%rsp)
xorpd %xmm1, %xmm1
movq 0xc0(%rsp), %rdi
jmp 0xf4d4
movl %r13d, %esi
movapd %xmm3, %xmm2
movl %esi, 0x8(%rsp)
movsd %xmm2, 0x40(%rsp)
movsd %xmm1, 0x38(%rsp)
movl 0x34(%rsp), %eax
movq %rax, 0x48(%rsp)
leaq (,%rax,4), %rdx
xorl %esi, %esi
callq 0x31b0
movq 0xc0(%rsp), %r10
movq 0x60(%rsp), %r9
cmpl $0x0, 0x20(%rsp)
movq 0x50(%rsp), %r11
movq 0x10(%rsp), %r13
je 0xf57a
xorl %eax, %eax
cmpl $0x0, (%r9,%rax,4)
je 0xf572
leaq (%rax,%rax,8), %rcx
cmpl $0x0, 0x4(%r11,%rcx,8)
je 0xf572
leaq (%r11,%rcx,8), %rcx
movl 0x10(%rcx), %edx
movl (%rbx,%rax,4), %esi
xorl %edi, %edi
cmpl %esi, %edx
je 0xf55a
movq 0x8(%rcx), %r8
movslq (%r8,%rdi,4), %r8
leaq (%r8,%r8,2), %r8
shlq $0x4, %r8
addq %r12, %r8
cmpl $0x0, 0x18(%r8,%r14,4)
jle 0xf566
movq 0x8(%rcx), %r8
movslq (%r8,%rdi,4), %r8
movl %r15d, (%r10,%r8,4)
incq %rdi
movl 0x4(%rcx), %r8d
cmpq %r8, %rdi
jb 0xf53b
incq %rax
cmpq %r13, %rax
jne 0xf51c
cmpl $0x1, %r15d
je 0xf595
cmpl $0x2, %r15d
jne 0xf5b1
movl $0x0, 0x10(%rsp)
movl $0x1, %eax
jmp 0xf5a2
movl $0x0, 0x10(%rsp)
movl $0x2, %eax
movq %rax, 0x20(%rsp)
movl $0x0, 0x50(%rsp)
jmp 0xf5c8
movl $0x0, 0x10(%rsp)
movb $0x1, %al
movl %eax, 0x50(%rsp)
movq $0x0, 0x20(%rsp)
movl $0x4, %esi
movq 0x48(%rsp), %rdi
callq 0x3240
movq 0x48(%rsp), %rsi
movq %rax, %rbp
movl $0x0, 0x18(%rsp)
cmpl $0x0, 0x34(%rsp)
movsd 0x28(%rsp), %xmm2
movq 0xc0(%rsp), %rdx
movl 0x8(%rsp), %eax
je 0xf6bb
addq $0x18, %r12
xorl %r13d, %r13d
movl $0x0, 0x18(%rsp)
movl $0x0, 0x10(%rsp)
cmpl $0x0, (%rdx,%r13,4)
jne 0xf6ab
movsd -0x10(%r12), %xmm1
cmpb $0x0, 0x50(%rsp)
jne 0xf647
movq 0x20(%rsp), %rcx
cmpl $0x0, (%r12,%rcx,4)
je 0xf647
cmpl $0x0, (%r12,%r14,4)
jle 0xf6ab
ucomisd %xmm2, %xmm1
jb 0xf6ab
movsd 0x70(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jb 0xf6ab
movsd 0x40(%rsp), %xmm0
divsd %xmm1, %xmm0
callq 0x31f0
andpd 0x9f10(%rip), %xmm0     # 0x19580
movsd 0x9ee0(%rip), %xmm1     # 0x19558
ucomisd %xmm0, %xmm1
jb 0xf694
movl 0x10(%rsp), %eax
addl -0x8(%r12), %eax
movl %eax, 0x10(%rsp)
incl 0x18(%rsp)
movl %r15d, (%rbp,%r13,4)
movsd 0x28(%rsp), %xmm2
movq 0xc0(%rsp), %rdx
movl 0x8(%rsp), %eax
movq 0x48(%rsp), %rsi
incq %r13
addq $0x30, %r12
cmpq %r13, %rsi
jne 0xf61b
movl 0xc8(%rsp), %r15d
movl 0x10(%rsp), %r13d
addl %eax, %r13d
cmpl 0xb0(%rsp), %r13d
jbe 0xf6da
movl %eax, %r13d
jmp 0xf6fe
cmpl $0x0, 0x34(%rsp)
je 0xf6f6
xorl %eax, %eax
movl (%rbp,%rax,4), %ecx
testl %ecx, %ecx
je 0xf6ee
movl %ecx, (%rdx,%rax,4)
incq %rax
cmpq %rax, %rsi
jne 0xf6e3
movl 0x18(%rsp), %eax
addl %eax, 0xc(%rsp)
movq 0xb8(%rsp), %r12
movq %rbx, %rdi
callq 0x3060
movq 0x58(%rsp), %rdi
callq 0x3060
movq 0x60(%rsp), %rdi
callq 0x3060
movq %rbp, %rdi
callq 0x3060
cmpl $0x3, %r15d
jge 0xf753
testq %r12, %r12
movsd 0x40(%rsp), %xmm0
je 0xf741
movsd %xmm0, (%r12)
movl %r13d, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xf89e(%rip), %rax      # 0x1eff8
movq (%rax), %rdi
leaq 0xf3dc(%rip), %rax      # 0x1eb40
movq (%rax,%r14,8), %rcx
leaq 0xae6a(%rip), %rsi      # 0x1a5d9
leaq 0xaeb3(%rip), %rdx      # 0x1a629
movl 0xc(%rsp), %r8d
movl %r13d, %r9d
movsd 0x40(%rsp), %xmm0
movsd 0x38(%rsp), %xmm1
movb $0x2, %al
callq 0x3290
jmp 0xf730