// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/hic.cpp
// Function: clean_hap(hc_links*, bubble_type*, ma_ug_t const*)
min_cut_t* clean_hap(hc_links* link, bubble_type* bub, const ma_ug_t *ug)
{
    double index_time = yak_realtime();
    min_cut_t* x; CALLOC(x, 1);
    kvec_t_u64_warp buff;
    kv_init(buff.a);
    init_min_cut_t(x, link, (const bubble_type*)bub, ug);

    // get_Connected_Components(&x);
    // check_connective(&x, link);
    // print_rGraph(&x);

    long long i;
    uint64_t k, uID;
    
    ///for (i = 0; (uint64_t)i < x.n; i++)
    for (i = x->n - 1; i >= 0; i--)
    {
        uID = x->order.a[i] & x->uID_mode;
        ///fprintf(stderr, "uID: %lu, f.n: %lu\n", uID, (uint64_t)link->a.a[uID].f.n);
        if(link->a.a[uID].f.n == 0) continue;
        for (k = 0; k < link->a.a[uID].f.n; k++)
        {
            if(link->a.a[uID].f.a[k].del) continue;
            if(x->utgVis.a[link->a.a[uID].f.a[k].uID] == 0) break;
        }
        ///fprintf(stderr, "k: %lu\n", k);
        if(k == link->a.a[uID].f.n) continue;
        reset_min_cut_t(x, link);
        ///fprintf(stderr, "reset\n");
        get_s_t(x, link, uID, &(x->src), &(x->dest), &buff);
        ///fprintf(stderr, "x.src: %lu, x.dest: %lu\n", x.src, x.dest);
        ///Note: should only consider edges betweem bubbles, ignore edges to homo untigs

        /*******************************for debug************************************/
        ///if(!select_large_node(ug, &x, x.src, x.dest, 10, 0)) continue; 
        ///if(uID != 26818) continue;
        //if(uID != 45179) continue;
        ///memset(x.bmerVis.a, 1, x.bmerVis.n);
        get_bmer_unitgs(x, bub, x->b_mer, x->src);
        x->bmerVis.a[x->src] = x->bmerVis.a[x->dest] = 1;
        /*******************************for debug************************************/

        graph_cut(x->src, x->dest, x);
        ///fprintf(stderr, "graph_cut\n");
        x->utgVis.a[uID] = 1;
        ///exit(0);
    }

    reset_min_cut_t(x, link);

    fprintf(stderr, "[M::%s::%.3f] # edges: %lu, # cutted edges: %lu\n", 
                                    __func__, yak_realtime()-index_time, x->n_e, x->c_e);
    update_link_by_min_cut_t(x, link);
    ///destory_min_cut_t(x);
    kv_destroy(buff.a);
    return x;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r15
movq %rdi, %rbx
callq 0xefea7
movsd %xmm0, 0x8(%rsp)
pushq $0x1
popq %rdi
movl $0x180, %esi            # imm = 0x180
callq 0x2120
movq %rax, %r14
xorpd %xmm0, %xmm0
leaq 0x20(%rsp), %rax
movapd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, 0x18(%rsp)
movq %r15, %rdx
callq 0xff9dd
movq 0x148(%r14), %rcx
leaq 0x150(%r14), %rax
movq %rax, 0x10(%rsp)
movq %r14, %rbp
addq $0x158, %rbp            # imm = 0x158
movb $0x1, %r15b
movq %rcx, %r13
decq %r13
js 0x101858
movq 0x28(%r14), %rax
movq 0x138(%r14), %r12
andq -0x8(%rax,%rcx,8), %r12
movq 0x10(%rbx), %rdx
imulq $0x30, %r12, %rsi
movq 0x18(%rdx,%rsi), %rax
movq %r13, %rcx
testq %rax, %rax
je 0x10176b
leaq (%rdx,%rsi), %rcx
addq $0x18, %rcx
movq 0x10(%rcx), %rcx
addq $0x18, %rcx
movq %rax, %rdx
subq $0x1, %rdx
jb 0x101850
cmpb $0x0, (%rcx)
js 0x1017ce
movq 0xd8(%r14), %rsi
movl -0x10(%rcx), %edi
cmpb $0x0, (%rsi,%rdi)
je 0x1017d7
addq $0x28, %rcx
movq %rdx, %rax
jmp 0x1017af
movq %r13, %rcx
testq %rax, %rax
je 0x10176b
movq %r14, %rdi
movq %rbx, %rsi
callq 0xffe66
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq 0x10(%rsp), %rcx
movq %rbp, %r8
leaq 0x20(%rsp), %r9
callq 0x100328
movslq 0x178(%r14), %rdx
movq 0x150(%r14), %rcx
movq %r14, %rdi
movq 0x18(%rsp), %rsi
callq 0x101647
movq 0xf0(%r14), %rax
movq 0x158(%r14), %rsi
movb %r15b, (%rax,%rsi)
movq 0x150(%r14), %rdi
movb %r15b, (%rax,%rdi)
movq %r14, %rdx
callq 0x100b91
movq 0xd8(%r14), %rax
movb %r15b, (%rax,%r12)
movq %r13, %rcx
jmp 0x10176b
movq %r14, %rdi
movq %rbx, %rsi
callq 0xffe66
movq 0x151776(%rip), %rax    # 0x252fe0
movq (%rax), %r15
callq 0xefea7
subsd 0x8(%rsp), %xmm0
movq 0x160(%r14), %rcx
movq 0x168(%r14), %r8
leaq 0xec1c1(%rip), %rsi     # 0x1eda4e
leaq 0xec1eb(%rip), %rdx     # 0x1eda7f
movq %r15, %rdi
movb $0x1, %al
callq 0x22b0
movq %r14, %rdi
movq %rbx, %rsi
callq 0xfff26
movq 0x30(%rsp), %rdi
callq 0x2220
movq %r14, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq