// File: /workspace/github_c_makefile_star2_O2/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, 0x68(%rsp)
movsd %xmm0, 0x30(%rsp)
movl %r8d, %ebp
movl %ecx, 0x60(%rsp)
movq %rdx, %r12
movq %rdi, 0x8(%rsp)
movl %esi, %r14d
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x3240
movq %rax, %rbx
pushq $0x8
popq %rsi
movq %r14, %rdi
callq 0x3240
movq %rax, %r15
movl %ebp, %r13d
xorl %eax, %eax
movsd 0x8c5e(%rip), %xmm0     # 0x164f0
cmpq %r14, %rax
je 0xd908
imulq $0x48, %rax, %rdx
movq 0x8(%rsp), %rdi
leaq (%rdi,%rdx), %rcx
movl 0x4(%rdi,%rdx), %edx
xorl %r9d, %r9d
cmpq %r9, %rdx
je 0xd8d8
movq 0x8(%rcx), %rdi
movl (%rdi,%r9,4), %edi
imulq $0x30, %rdi, %rdi
addq %r12, %rdi
movslq 0x18(%rdi,%r13,4), %r8
addq %r8, (%r15,%rax,8)
testq %r8, %r8
jle 0xd8d3
movl 0x10(%rdi), %edi
addl %edi, (%rbx,%rax,4)
incq %r9
jmp 0xd8ab
movl (%rbx,%rax,4), %edx
cvtsi2sd %rdx, %xmm1
movq (%r15,%rax,8), %rdx
shlq $0x20, %rdx
orq %rax, %rdx
movq %rdx, (%r15,%rax,8)
movl 0x10(%rcx), %ecx
cvtsi2sd %ecx, %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
jbe 0xd903
movl %ecx, (%rbx,%rax,4)
incq %rax
jmp 0xd892
leaq -0x20ab(%rip), %rcx     # 0xb864
pushq $0x8
popq %rdx
movq %r15, %rdi
movq %r14, %rsi
movq %r14, 0x10(%rsp)
callq 0x30c0
pushq $0x4
popq %rsi
movq 0x10(%rsp), %rdi
callq 0x3240
movq 0x10(%rsp), %r9
xorpd %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
xorl %r11d, %r11d
xorl %r10d, %r10d
movl $0x0, 0x24(%rsp)
xorpd %xmm1, %xmm1
movq 0xc0(%rsp), %rdi
movsd 0x30(%rsp), %xmm0
movl 0xb0(%rsp), %edx
movq %rax, 0x50(%rsp)
movq 0x8(%rsp), %r8
cmpq %r11, %r9
je 0xdaf0
movq (%r15,%r11,8), %rsi
movq %rsi, %rcx
shrq $0x20, %rcx
je 0xdaf0
movl %esi, %r14d
imulq $0x48, %r14, %rcx
cmpl %ebp, 0x40(%r8,%rcx)
jne 0xd9b9
addq %r8, %rcx
movsd 0x18(%rcx), %xmm2
ucomisd %xmm2, %xmm0
jbe 0xd9ad
ucomisd 0x68(%rsp), %xmm2
ja 0xd9b9
movl (%rbx,%r14,4), %ecx
leal (%rcx,%r10), %esi
cmpl %edx, %esi
jbe 0xd9c4
movl %r10d, %esi
incq %r11
movl %esi, %r10d
jmp 0xd96f
cmpl $0x0, 0x24(%rsp)
je 0xd9e7
cmpl 0x48(%rsp), %ecx
jb 0xd9df
ucomisd 0x18(%rsp), %xmm2
jb 0xd9ff
ucomisd %xmm2, %xmm1
jb 0xd9ff
movsd 0x18(%rsp), %xmm2
jmp 0xd9eb
movapd %xmm2, %xmm1
movl $0x1, (%rax,%r14,4)
incl 0x24(%rsp)
movsd %xmm2, 0x18(%rsp)
jmp 0xd9bc
movl %esi, 0x74(%rsp)
movq %r11, 0x28(%rsp)
movq %r10, 0x40(%rsp)
movsd %xmm1, 0x38(%rsp)
movsd 0x18(%rsp), %xmm0
divsd %xmm2, %xmm0
movsd %xmm2, 0x58(%rsp)
callq 0x31f0
andpd 0x8b50(%rip), %xmm0     # 0x16580
movsd 0x8b28(%rip), %xmm1     # 0x16560
ucomisd %xmm0, %xmm1
jb 0xda65
movsd 0x38(%rsp), %xmm0
divsd 0x58(%rsp), %xmm0
callq 0x31f0
andpd 0x8b29(%rip), %xmm0     # 0x16580
movsd 0x8b01(%rip), %xmm1     # 0x16560
ucomisd %xmm0, %xmm1
jae 0xdaa0
movq 0x40(%rsp), %rax
movl %eax, %esi
movq 0xc0(%rsp), %rdi
movsd 0x30(%rsp), %xmm0
movl 0xb0(%rsp), %edx
movsd 0x38(%rsp), %xmm1
movq 0x50(%rsp), %rax
movq 0x8(%rsp), %r8
movq 0x10(%rsp), %r9
movq 0x28(%rsp), %r11
jmp 0xd9bc
movsd 0x58(%rsp), %xmm1
movapd %xmm1, %xmm0
minsd 0x18(%rsp), %xmm1
maxsd 0x38(%rsp), %xmm0
movapd %xmm1, %xmm2
movapd %xmm0, %xmm1
movq 0xc0(%rsp), %rdi
movsd 0x30(%rsp), %xmm0
movl 0xb0(%rsp), %edx
movq 0x50(%rsp), %rax
movq 0x8(%rsp), %r8
movq 0x10(%rsp), %r9
movq 0x28(%rsp), %r11
movl 0x74(%rsp), %esi
jmp 0xd9eb
movq %r10, 0x40(%rsp)
movsd %xmm1, 0x38(%rsp)
movl 0x60(%rsp), %eax
movq %rax, 0x48(%rsp)
leaq (,%rax,4), %rdx
xorl %r14d, %r14d
xorl %esi, %esi
callq 0x31b0
movq 0x8(%rsp), %r11
movq 0x50(%rsp), %r10
movq 0xc0(%rsp), %r9
cmpq 0x10(%rsp), %r14
je 0xdb7a
cmpl $0x0, (%r10,%r14,4)
je 0xdb75
imulq $0x48, %r14, %rcx
leaq (%r11,%rcx), %rax
movl 0x10(%r11,%rcx), %ecx
movl (%rbx,%r14,4), %edx
xorl %esi, %esi
movl 0x4(%rax), %edi
cmpq %rdi, %rsi
jae 0xdb75
movq 0x8(%rax), %rdi
movslq (%rdi,%rsi,4), %rdi
cmpl %edx, %ecx
je 0xdb6c
imulq $0x30, %rdi, %r8
addq %r12, %r8
cmpl $0x0, 0x18(%r8,%r13,4)
jle 0xdb70
movl %ebp, (%r9,%rdi,4)
incq %rsi
jmp 0xdb49
incq %r14
jmp 0xdb28
cmpl $0x1, %ebp
je 0xdb91
cmpl $0x2, %ebp
jne 0xdbad
movq $0x0, 0x8(%rsp)
pushq $0x1
jmp 0xdb9c
movq $0x0, 0x8(%rsp)
pushq $0x2
popq %rax
movq %rax, 0x60(%rsp)
movq $0x0, 0x10(%rsp)
jmp 0xdbc6
movq $0x0, 0x8(%rsp)
movb $0x1, %al
movq %rax, 0x10(%rsp)
movq $0x0, 0x60(%rsp)
pushq $0x4
popq %rsi
movq 0x48(%rsp), %rdi
callq 0x3240
movq 0x48(%rsp), %rsi
movq %rax, 0x28(%rsp)
addq $0x18, %r12
xorl %r14d, %r14d
movl $0x0, 0x58(%rsp)
movq 0xc0(%rsp), %rdx
movsd 0x30(%rsp), %xmm2
movq 0x40(%rsp), %rax
cmpq %r14, %rsi
je 0xdcab
cmpl $0x0, (%rdx,%r14,4)
jne 0xdc9f
movsd -0x10(%r12), %xmm1
cmpb $0x0, 0x10(%rsp)
jne 0xdc34
movq 0x60(%rsp), %rcx
cmpl $0x0, (%r12,%rcx,4)
je 0xdc34
cmpl $0x0, (%r12,%r13,4)
jle 0xdc9f
ucomisd %xmm2, %xmm1
jb 0xdc9f
movsd 0x68(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jb 0xdc9f
movsd 0x18(%rsp), %xmm0
divsd %xmm1, %xmm0
callq 0x31f0
andpd 0x8923(%rip), %xmm0     # 0x16580
movsd 0x88fb(%rip), %xmm1     # 0x16560
ucomisd %xmm0, %xmm1
jb 0xdc87
movq 0x8(%rsp), %rax
addl -0x8(%r12), %eax
movq %rax, 0x8(%rsp)
incl 0x58(%rsp)
movq 0x28(%rsp), %rax
movl %ebp, (%rax,%r14,4)
movq 0xc0(%rsp), %rdx
movsd 0x30(%rsp), %xmm2
movq 0x40(%rsp), %rax
movq 0x48(%rsp), %rsi
incq %r14
addq $0x30, %r12
jmp 0xdbff
movq 0x8(%rsp), %r14
addl %eax, %r14d
cmpl 0xb0(%rsp), %r14d
jbe 0xdcc7
movl %eax, %r14d
movq 0x28(%rsp), %r12
jmp 0xdceb
xorl %eax, %eax
movq 0x28(%rsp), %r12
cmpq %rax, %rsi
je 0xdce3
movl (%r12,%rax,4), %ecx
testl %ecx, %ecx
je 0xdcde
movl %ecx, (%rdx,%rax,4)
incq %rax
jmp 0xdcce
movl 0x58(%rsp), %eax
addl %eax, 0x24(%rsp)
movq %rbx, %rdi
callq 0x3060
movq %r15, %rdi
callq 0x3060
movq 0x50(%rsp), %rdi
callq 0x3060
movq %r12, %rdi
callq 0x3060
cmpl $0x3, 0xc8(%rsp)
jge 0xdd40
movq 0xb8(%rsp), %rax
testq %rax, %rax
je 0xdd2e
movsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rax)
movl %r14d, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xf2b1(%rip), %rax      # 0x1cff8
movq (%rax), %rdi
leaq 0xedef(%rip), %rax      # 0x1cb40
movq (%rax,%r13,8), %rcx
leaq 0x989d(%rip), %rsi      # 0x175f9
leaq 0x98e6(%rip), %rdx      # 0x17649
movl 0x24(%rsp), %r8d
movl %r14d, %r9d
movsd 0x18(%rsp), %xmm0
movsd 0x38(%rsp), %xmm1
movb $0x2, %al
callq 0x3290
jmp 0xdd17