// File: /workspace/github_c_makefile_star2_O2/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, 0x1c(%rsp)
movl %esi, 0x2c(%rsp)
movsd %xmm0, 0x20(%rsp)
movq %rdi, %rbx
movq 0x8(%rdi), %r12
movq 0x20(%rdi), %r13
movl %r12d, %ebp
pushq $0x1
popq %rsi
movq %rbp, %rdi
callq 0x3240
movq %rax, %r14
xorl %eax, %eax
movq $0x0, 0x10(%rsp)
xorl %esi, %esi
xorl %r15d, %r15d
movq %rbx, 0x50(%rsp)
movq %r13, 0x40(%rsp)
movq %r12, 0x38(%rsp)
movl %eax, 0xc(%rsp)
cmpl %r12d, %eax
jae 0x9aee
movl %eax, %ecx
cmpb $0x0, (%r14,%rcx)
jne 0x9aad
movq 0x10(%r13), %rdx
imulq $0x28, %rcx, %rcx
testb $0x40, 0x23(%rdx,%rcx)
jne 0x9aad
movq %rsi, 0x48(%rsp)
movq %r13, %rdi
xorl %esi, %esi
callq 0x9778
movq %rax, 0x20(%rbx)
movl $0x1, (%rsp)
movq %rax, %rdi
leaq 0xc(%rsp), %rsi
pushq $0x1
popq %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x12281
movq %rbx, %rdi
movsd 0x20(%rsp), %xmm0
xorl %esi, %esi
movl 0x2c(%rsp), %edx
xorl %ecx, %ecx
callq 0x447d
cmpl $0x2, 0x1c(%rsp)
movsd %xmm0, 0x30(%rsp)
jge 0x9ab4
pushq $0x20
popq %r12
xorl %r13d, %r13d
movsd 0x20(%rsp), %xmm1
xorpd %xmm2, %xmm2
movq 0x48(%rsp), %rdx
movq 0x20(%rbx), %rdi
cmpq %r13, %rbp
je 0x9a94
movq 0x10(%rdi), %rax
movl (%rax,%r12), %eax
btl $0x1e, %eax
jb 0x9a88
ucomisd %xmm2, %xmm0
jne 0x9a14
jnp 0x9a83
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
cvtsi2sd %eax, %xmm3
divsd %xmm0, %xmm3
ucomisd %xmm3, %xmm1
jbe 0x9a83
cmpq %rdx, %r15
jne 0x9a72
movq %r15, %rbx
movq %r14, %r15
leaq (%rdx,%rdx), %r14
testq %rdx, %rdx
pushq $0x2
popq %rax
cmoveq %rax, %r14
leaq (,%r14,4), %rsi
movq 0x10(%rsp), %rdi
callq 0x3330
movsd 0x30(%rsp), %xmm0
xorpd %xmm2, %xmm2
movsd 0x20(%rsp), %xmm1
movq %r14, %rdx
movq %r15, %r14
movq %rbx, %r15
movq 0x50(%rsp), %rbx
jmp 0x9a77
movq 0x10(%rsp), %rax
movq %rax, 0x10(%rsp)
movl %r13d, (%rax,%r15,4)
incq %r15
movb $0x1, (%r14,%r13)
incq %r13
addq $0x28, %r12
jmp 0x99f1
movq %rdx, %r12
callq 0xf9e0
movq %r12, %rsi
movl 0xc(%rsp), %eax
movq 0x40(%rsp), %r13
movq 0x38(%rsp), %r12
incl %eax
jmp 0x9955
movq 0x1353d(%rip), %rax     # 0x1cff8
movq (%rax), %rdi
movq 0x10(%rbx), %rax
movl 0xc(%rsp), %ecx
imulq $0x18, %rcx, %rcx
movq (%rax,%rcx), %rcx
leaq 0xcfbc(%rip), %rsi      # 0x16a91
leaq 0xcff7(%rip), %rdx      # 0x16ad3
movb $0x1, %al
callq 0x3290
movsd 0x30(%rsp), %xmm0
jmp 0x99db
movq %r13, 0x20(%rbx)
xorl %eax, %eax
movq 0x10(%rsp), %r12
movl %eax, 0xc(%rsp)
cmpl %r15d, %eax
jae 0x9b18
movl %eax, %eax
movl (%r12,%rax,4), %esi
movq %r13, %rdi
callq 0x5fc7
movl 0xc(%rsp), %eax
incl %eax
jmp 0x9af9
movq %r13, %rdi
xorl %esi, %esi
callq 0xfcc3
cmpl $0x2, 0x1c(%rsp)
jge 0x9b4b
movq %r12, %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 0x9b7c
movq 0x134a4(%rip), %r12     # 0x1cff8
movq (%r12), %rdi
leaq 0xcf95(%rip), %rsi      # 0x16af4
leaq 0xcf6d(%rip), %rdx      # 0x16ad3
xorl %eax, %eax
callq 0x3290
movq (%r12), %rsi
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x9c19
movq 0x13475(%rip), %rax     # 0x1cff8
movq (%rax), %rdi
leaq 0xcf85(%rip), %rsi      # 0x16b12
leaq 0xcf3f(%rip), %r13      # 0x16ad3
movq %r13, %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x3290
leaq 0xcf8f(%rip), %rbp      # 0x16b37
xorl %eax, %eax
movl %eax, 0xc(%rsp)
movq 0x13443(%rip), %rcx     # 0x1cff8
movq (%rcx), %rdi
cmpl %r15d, %eax
jae 0x9be8
movq 0x10(%rbx), %rcx
movl %eax, %eax
movq 0x10(%rsp), %rdx
movl (%rdx,%rax,4), %eax
imulq $0x18, %rax, %rax
movq (%rcx,%rax), %rcx
movq %rbp, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x3290
movl 0xc(%rsp), %eax
incl %eax
jmp 0x9baa
leaq 0xcf5c(%rip), %rsi      # 0x16b4b
leaq 0xcedd(%rip), %rdx      # 0x16ad3
xorl %eax, %eax
callq 0x3290
movq 0x133f4(%rip), %rax     # 0x1cff8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x9d83
movq 0x10(%rsp), %r12
jmp 0x9b29