// File: /workspace/github_c_makefile_star2_O1/c-zhou[P]oatk/path.c
// Function: clean_graph_by_sequence_coverage
int clean_graph_by_sequence_coverage(asg_t *asg, double min_cf, int max_copy, int verbose)
{
    uint32_t i, j, n_seg, nv;
    uint8_t *visited;
    double avg_cov;
    kvec_t(uint32_t) rm_v;
    asmg_t *g;

    g = asg->asmg;
    n_seg = asg->n_seg;
    kv_init(rm_v);

    MYCALLOC(visited, n_seg);
    for (i = 0; i < n_seg; ++i) {
        if (visited[i] || g->vtx[i].del) continue;
        asg->asmg = asg_make_asmg_copy(g, 0);
        asmg_subgraph(asg->asmg, &i, 1, 0, 0, 0, 1);
        avg_cov = graph_sequence_coverage_precise(asg, min_cf, 0, max_copy, 0);
        if (verbose > 1)
            fprintf(stderr, "[M::%s] subgraph seeding from %s per copy average coverage: %.3f\n", 
                    __func__, asg->seg[i].name, avg_cov);
        for (j = 0; j < n_seg; ++j) {
            if (asg->asmg->vtx[j].del) continue;
            if (avg_cov && asg->asmg->vtx[j].cov / avg_cov < min_cf)
                kv_push(uint32_t, rm_v, j);
            visited[j] = 1;
        }
        asmg_destroy(asg->asmg);
    }
    asg->asmg = g; // roll back

    nv = rm_v.n;
    for (i = 0; i < nv; ++i)
        asmg_vtx_del(g, rm_v.a[i], 1);
    asmg_finalize(g, 0);

    if (verbose > 1) {
        if (verbose > 2) {
            fprintf(stderr, "[M::%s] graph after cleaning\n", __func__);
            asg_print(asg, stderr, 1);
        }
        fprintf(stderr, "[M::%s] number sequence cleaned: %u\n", __func__, nv);
        for (i = 0; i < nv; ++i)
            fprintf(stderr, "[M::%s] %s removed\n", __func__, asg->seg[rm_v.a[i]].name);
        fprintf(stderr, "[M::%s] graph stats after cleaning\n", __func__);
        asg_stat(asg, stderr);
    }
    
    kv_destroy(rm_v);
    free(visited);

    return nv;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %edx, 0x14(%rsp)
movl %esi, 0x24(%rsp)
movsd %xmm0, 0x18(%rsp)
movq %rdi, %rbx
movq 0x8(%rdi), %r13
movq 0x20(%rdi), %r12
movl %r13d, %ebp
movl $0x1, %esi
movq %rbp, %rdi
callq 0x3240
movq %rax, %r14
movl $0x0, 0x10(%rsp)
testl %r13d, %r13d
je 0xb0e0
xorl %r15d, %r15d
movq $0x0, 0x28(%rsp)
xorl %edx, %edx
xorl %eax, %eax
movq %rbx, 0x50(%rsp)
movq %r12, 0x40(%rsp)
movq %r13, 0x38(%rsp)
movl %eax, %eax
cmpb $0x0, (%r14,%rax)
jne 0xb091
movq 0x10(%r12), %rcx
leaq (%rax,%rax,4), %rax
testb $0x40, 0x23(%rcx,%rax,8)
jne 0xb091
movq %rdx, 0x48(%rsp)
movq %r12, %rdi
xorl %esi, %esi
callq 0xad23
movq %rax, 0x20(%rbx)
movl $0x1, (%rsp)
movq %rax, %rdi
leaq 0x10(%rsp), %rsi
movl $0x1, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x1495a
movq %rbx, %rdi
movsd 0x18(%rsp), %xmm0
xorl %esi, %esi
movl 0x24(%rsp), %edx
xorl %ecx, %ecx
callq 0x4c49
cmpl $0x2, 0x14(%rsp)
movsd %xmm0, 0x30(%rsp)
jge 0xb0a6
movl $0x20, %r12d
xorl %r13d, %r13d
movq 0x48(%rsp), %rdi
movsd 0x18(%rsp), %xmm1
xorpd %xmm2, %xmm2
movq 0x28(%rsp), %rcx
movq 0x20(%rbx), %rax
movq 0x10(%rax), %rax
movl (%rax,%r12), %eax
btl $0x1e, %eax
jb 0xb063
ucomisd %xmm2, %xmm0
jne 0xaff8
jnp 0xb05e
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
xorps %xmm3, %xmm3
cvtsi2sd %eax, %xmm3
divsd %xmm0, %xmm3
ucomisd %xmm3, %xmm1
jbe 0xb05e
cmpq %rcx, %r15
jne 0xb057
movq %r15, %rbx
movq %r14, %r15
leaq (%rcx,%rcx), %r14
testq %rcx, %rcx
movl $0x2, %eax
cmoveq %rax, %r14
leaq (,%r14,4), %rsi
callq 0x3330
movsd 0x30(%rsp), %xmm0
xorpd %xmm2, %xmm2
movsd 0x18(%rsp), %xmm1
movq %rax, %rdi
movq %r14, %rcx
movq %r15, %r14
movq %rbx, %r15
movq 0x50(%rsp), %rbx
movl %r13d, (%rdi,%r15,4)
incq %r15
movb $0x1, (%r14,%r13)
incq %r13
addq $0x28, %r12
cmpq %r13, %rbp
jne 0xafde
movq %rcx, 0x28(%rsp)
movq %rdi, %r12
movq 0x20(%rbx), %rdi
callq 0x118c4
movq %r12, %rdx
movq 0x40(%rsp), %r12
movq 0x38(%rsp), %r13
movl 0x10(%rsp), %eax
incl %eax
movl %eax, 0x10(%rsp)
cmpl %r13d, %eax
jb 0xaf45
jmp 0xb0e5
movq 0x13f4b(%rip), %rax     # 0x1eff8
movq (%rax), %rdi
movq 0x10(%rbx), %rax
movl 0x10(%rsp), %ecx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rcx
leaq 0xe9aa(%rip), %rsi      # 0x19a71
leaq 0xe9e5(%rip), %rdx      # 0x19ab3
movb $0x1, %al
callq 0x3290
movsd 0x30(%rsp), %xmm0
jmp 0xafc1
xorl %edx, %edx
xorl %r15d, %r15d
movq %r12, 0x20(%rbx)
movl $0x0, 0x10(%rsp)
testl %r15d, %r15d
movq %rdx, %r13
je 0xb119
xorl %eax, %eax
movl %eax, %eax
movl (%r13,%rax,4), %esi
movq %r12, %rdi
callq 0x6dc8
movl 0x10(%rsp), %eax
incl %eax
movl %eax, 0x10(%rsp)
cmpl %r15d, %eax
jb 0xb0fb
movq %r12, %rdi
xorl %esi, %esi
callq 0x11baf
cmpl $0x2, 0x14(%rsp)
jge 0xb14c
movq %r13, %rdi
callq 0x3060
movq %r14, %rdi
callq 0x3060
movl %r15d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
je 0xb156
movq %rbx, %rdi
callq 0x3877
movq 0x13e9b(%rip), %r12     # 0x1eff8
movq (%r12), %rdi
leaq 0xe98a(%rip), %rsi      # 0x19af2
leaq 0xe944(%rip), %rdx      # 0x19ab3
movl %r15d, %ecx
xorl %eax, %eax
callq 0x3290
movl $0x0, 0x10(%rsp)
testl %r15d, %r15d
je 0xb199
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
movq %r13, %rsi
movl %r15d, %ecx
callq 0x38b3
movq (%r12), %rdi
leaq 0xe987(%rip), %rsi      # 0x19b2b
leaq 0xe908(%rip), %rdx      # 0x19ab3
xorl %eax, %eax
callq 0x3290
movq (%r12), %rsi
movq %rbx, %rdi
callq 0xb352
jmp 0xb12a