// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
movl %edx, 0xc(%rsp)
movl %esi, 0x24(%rsp)
movsd %xmm0, 0x18(%rsp)
movq %rdi, %rbx
movq 0x8(%rdi), %r12
movq 0x20(%rdi), %r14
movl %r12d, %ebp
movl $0x1, %esi
movq %rbp, %rdi
callq 0x3240
movl $0x0, 0x8(%rsp)
testl %r12d, %r12d
movq %rax, 0x10(%rsp)
je 0xb5cf
xorl %r15d, %r15d
xorl %r13d, %r13d
xorl %edi, %edi
xorl %esi, %esi
movq %r14, 0x38(%rsp)
movq %r12, 0x30(%rsp)
movl %esi, %ecx
cmpb $0x0, (%rax,%rcx)
jne 0xb549
movq 0x10(%r14), %rdx
leaq (%rcx,%rcx,4), %rcx
testb $0x40, 0x23(%rdx,%rcx,8)
jne 0xb549
movq %rdi, 0x40(%rsp)
movq %r14, %rdi
xorl %esi, %esi
callq 0xb1fb
movq %rax, 0x20(%rbx)
movl $0x1, (%rsp)
movq %rax, %rdi
leaq 0x8(%rsp), %rsi
movl $0x1, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x14ff2
movq %rbx, %rdi
movsd 0x18(%rsp), %xmm0
xorl %esi, %esi
movl 0x24(%rsp), %edx
xorl %ecx, %ecx
callq 0x4d39
cmpl $0x2, 0xc(%rsp)
movsd %xmm0, 0x28(%rsp)
jge 0xb55a
movl $0x20, %r12d
xorl %r14d, %r14d
movq 0x10(%rsp), %rcx
movq 0x40(%rsp), %rdi
movsd 0x18(%rsp), %xmm1
xorpd %xmm2, %xmm2
movq 0x20(%rbx), %rax
movq 0x10(%rax), %rax
movl (%rax,%r12), %eax
btl $0x1e, %eax
jb 0xb517
ucomisd %xmm2, %xmm0
jne 0xb4bb
jnp 0xb512
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
xorps %xmm3, %xmm3
cvtsi2sd %eax, %xmm3
divsd %xmm0, %xmm3
ucomisd %xmm3, %xmm1
jbe 0xb512
cmpq %r13, %r15
jne 0xb50b
leaq (%r15,%r15), %r13
testq %r15, %r15
movl $0x2, %eax
cmoveq %rax, %r13
leaq (,%r13,4), %rsi
callq 0x3330
movsd 0x28(%rsp), %xmm0
xorpd %xmm2, %xmm2
movsd 0x18(%rsp), %xmm1
movq 0x10(%rsp), %rcx
movq %rax, %rdi
movl %r14d, (%rdi,%r15,4)
incq %r15
movb $0x1, (%rcx,%r14)
incq %r14
addq $0x28, %r12
cmpq %r14, %rbp
jne 0xb4a1
movq %rdi, %r14
movq 0x20(%rbx), %rdi
callq 0x11ef0
movq %r14, %rdi
movq 0x10(%rsp), %rax
movl 0x8(%rsp), %esi
movq 0x38(%rsp), %r14
movq 0x30(%rsp), %r12
incl %esi
movl %esi, 0x8(%rsp)
cmpl %r12d, %esi
jb 0xb40a
jmp 0xb594
movq 0x14a97(%rip), %rax     # 0x1fff8
movq (%rax), %rdi
movq 0x10(%rbx), %rax
movl 0x8(%rsp), %ecx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rcx
leaq 0xf506(%rip), %rsi      # 0x1aa81
leaq 0xf541(%rip), %rdx      # 0x1aac3
movb $0x1, %al
callq 0x3290
movsd 0x28(%rsp), %xmm0
jmp 0xb484
movq %r14, 0x20(%rbx)
movl $0x0, 0x8(%rsp)
testl %r15d, %r15d
sete %bpl
movq %rdi, %r12
je 0xb5de
xorl %eax, %eax
movl %eax, %eax
movl (%rdi,%rax,4), %esi
movq %r14, %rdi
callq 0x6f45
movq %r12, %rdi
movl 0x8(%rsp), %eax
incl %eax
movl %eax, 0x8(%rsp)
cmpl %r15d, %eax
jb 0xb5ae
jmp 0xb5e4
movq %r14, 0x20(%rbx)
xorl %r15d, %r15d
movb $0x1, %bpl
xorl %r12d, %r12d
jmp 0xb5e4
xorl %r15d, %r15d
movb $0x1, %bpl
movq %r14, %rdi
xorl %esi, %esi
callq 0x121d6
cmpl $0x2, 0xc(%rsp)
jge 0xb619
movq %r12, %rdi
callq 0x3060
movq 0x10(%rsp), %rdi
callq 0x3060
movl %r15d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
je 0xb623
movq %rbx, %rdi
callq 0x3834
movq 0x149ce(%rip), %r14     # 0x1fff8
movq (%r14), %rdi
leaq 0xf4ce(%rip), %rsi      # 0x1ab02
leaq 0xf488(%rip), %rdx      # 0x1aac3
movl %r15d, %ecx
xorl %eax, %eax
callq 0x3290
movl $0x0, 0x8(%rsp)
testb %bpl, %bpl
jne 0xb665
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
movq %r12, %rsi
movl %r15d, %ecx
callq 0x3870
movq (%r14), %rdi
leaq 0xf4cc(%rip), %rsi      # 0x1ab3b
leaq 0xf44d(%rip), %rdx      # 0x1aac3
xorl %eax, %eax
callq 0x3290
movq (%r14), %rsi
movq %rbx, %rdi
callq 0xb826
jmp 0xb5f5