// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/hic.cpp
// Function: init_min_cut_t(min_cut_t*, hc_links*, bubble_type const*, ma_ug_t const*)
void init_min_cut_t(min_cut_t* x, hc_links* link, const bubble_type* bub, const ma_ug_t *ug)
{
    uint64_t utg_num = link->a.n, i, k, u, v;
    x->n = utg_num;
    x->n_e = x->c_e = 0;

    kv_malloc(x->rGraphSet, utg_num); x->rGraphSet.n = utg_num;
    ///must utg_num<<1)
    kv_malloc(x->rGraphVis, utg_num); x->rGraphVis.n = utg_num;
    kv_malloc(x->utgVis, utg_num); x->utgVis.n = utg_num;
    kv_malloc(x->bmerVis, utg_num); x->bmerVis.n = utg_num;
    kv_malloc(x->order, utg_num); x->order.n = utg_num;
    kv_malloc(x->parent, utg_num); x->parent.n = utg_num;
    kv_malloc(x->p_weight, utg_num); x->p_weight.n = utg_num;
    ///uresolved BUGs, if use kv_resize segfault; if use kv_malloc, work?????
    kv_malloc(x->rGraph, utg_num); x->rGraph.n = utg_num;
    // kv_init(x->rGraph); kv_resize(hc_edge_warp, x->rGraph, utg_num); x->rGraph.n = utg_num;
    x->enzymes = link->enzymes.a;
    init_pdq(&(x->pq), utg_num<<1);

    //must be utg_num + 2 since we may need to add fake nodes
    for (i = 1; (uint64_t)(1<<i) < (utg_num + 2); i++);
    x->uID_mode = ((uint64_t)-1) >> (64-i); 
    x->uID_shift = i;
    for (i = 0; i < utg_num; i++)
    {
        ///x->order.a[i] = link->a.a[i].f.n;
        ///x->order.a[i] = ug->u.a[i].len;
        x->order.a[i] = x->enzymes[i];
        x->order.a[i] <<= x->uID_shift; 
        x->order.a[i] |= (uint64_t)(i & x->uID_mode);

        x->rGraphSet.a[i] = 0;
        x->rGraphVis.a[i] = 0;
        x->utgVis.a[i] = 0;
        x->bmerVis.a[i] = 0;
        x->parent.a[i] = (uint32_t)-1;
        
        ///uresolved BUGs, if use kv_resize segfault; if use kv_malloc, work?????
        // kv_init(x->rGraph.a[i]); kv_resize(hc_edge, x->rGraph.a[i], link->a.a[i].e.n);
        kv_malloc(x->rGraph.a[i], link->a.a[i].e.n); 
        x->rGraph.a[i].n = link->a.a[i].e.n;

        if(x->rGraph.a[i].n)
        {
            for (k = 0; k < x->rGraph.a[i].n; k++)
            {
                ///kv_push(hc_edge, x->rGraph.a[i], link->a.a[i].e.a[k]);
                x->rGraph.a[i].a[k] = link->a.a[i].e.a[k];
                x->n_e++;
                
                if((x->rGraph.a[i].a[k].weight == 0) || IF_HOM(x->rGraph.a[i].a[k].uID, *bub) 
                   || IF_HOM(i, *bub) || (x->rGraph.a[i].a[k].del))
                {
                    x->rGraph.a[i].a[k].del = 1;
                    x->n_e--;
                }
            }
        }
    }

    hc_edge *p = NULL;
    for (i = 0; i < utg_num; i++)
    {
        v = i;
        for (k = 0; k < link->a.a[v].f.n; k++)
        {
            if(link->a.a[v].f.a[k].del) continue;
            u = link->a.a[v].f.a[k].uID;


            p = get_rGraph_edge(x, v, u); 
            if(p)
            {
                p->del = 1;
                x->n_e--;
            }


            p = get_rGraph_edge(x, u, v);
            if(p)
            {
                p->del = 1;
                x->n_e--;
            } 
        }
    }

    x->q = kdq_init(uint64_t);
    radix_sort_hc64(x->order.a, x->order.a + x->order.n);

    x->b_mer = asm_opt.bub_mer_length;
    ///fprintf(stderr, "[M::%s]\n",  __func__);
    ///exit(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, 0x20(%rsp)
movq %rsi, %r14
movq %rdi, %rbx
movq (%rsi), %r15
movq %r15, 0x148(%rdi)
leaq 0x160(%rdi), %rax
movq %rax, 0x18(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x160(%rdi)
movq %r15, 0xa0(%rdi)
movq %r15, %rdi
callq 0x2280
movq %rax, 0xa8(%rbx)
movq %r15, 0x98(%rbx)
movq %r15, 0xb8(%rbx)
movq %r15, %rdi
callq 0x2280
movq %rax, 0xc0(%rbx)
movq %r15, 0xb0(%rbx)
movq %r15, 0xd0(%rbx)
movq %r15, %rdi
callq 0x2280
movq %rax, 0xd8(%rbx)
movq %r15, 0xc8(%rbx)
movq %r15, 0xe8(%rbx)
movq %r15, %rdi
callq 0x2280
movq %rax, 0xf0(%rbx)
movq %r15, 0xe0(%rbx)
movq %r15, 0x20(%rbx)
leaq (,%r15,8), %r13
movq %r13, %rdi
callq 0x2280
movq %rax, 0x28(%rbx)
movq %r15, 0x18(%rbx)
movq %r15, 0x108(%rbx)
leaq (,%r15,4), %rdi
callq 0x2280
movq %rax, 0x110(%rbx)
movq %r15, 0x100(%rbx)
movq %r15, 0x120(%rbx)
movq %r13, %rdi
callq 0x2280
movq %rax, 0x128(%rbx)
movq %r15, 0x118(%rbx)
movq %r15, 0x8(%rbx)
imulq $0x18, %r15, %rdi
callq 0x2280
movq %rax, 0x10(%rbx)
movq %r15, (%rbx)
movq %r14, 0x8(%rsp)
movq 0x28(%r14), %rax
movq %rax, 0x130(%rbx)
leaq 0x30(%rbx), %rdi
leaq (%r15,%r15), %rsi
callq 0xfa585
movq %r15, 0x10(%rsp)
leaq 0x2(%r15), %rdx
xorl %eax, %eax
pushq $0x1
popq %rsi
incq %rax
movl %esi, %edi
movl %eax, %ecx
shll %cl, %edi
movslq %edi, %rcx
cmpq %rcx, %rdx
ja 0xffb26
movl %eax, %ecx
negb %cl
pushq $-0x1
popq %rdx
shrq %cl, %rdx
movq %rdx, 0x138(%rbx)
movq %rax, 0x140(%rbx)
xorl %r15d, %r15d
movq 0x8(%rsp), %r9
cmpq 0x10(%rsp), %r15
je 0xffcb8
movq 0x28(%rbx), %rax
movq 0x130(%rbx), %rcx
movq (%rcx,%r15,8), %rdx
movq %rdx, (%rax,%r15,8)
movb 0x140(%rbx), %cl
shlq %cl, %rdx
movq %rdx, (%rax,%r15,8)
movq 0x138(%rbx), %rcx
andq %r15, %rcx
orq %rdx, %rcx
movq %rcx, (%rax,%r15,8)
movq 0xa8(%rbx), %rax
xorl %ecx, %ecx
movb %cl, (%rax,%r15)
movq 0xc0(%rbx), %rax
movb %cl, (%rax,%r15)
movq 0xd8(%rbx), %rax
movb %cl, (%rax,%r15)
movq 0xf0(%rbx), %rax
movb %cl, (%rax,%r15)
movq 0x110(%rbx), %rax
orl $-0x1, (%rax,%r15,4)
movq 0x10(%rbx), %rbp
imulq $0x18, %r15, %r13
movq 0x10(%r9), %rax
imulq $0x30, %r15, %r12
movq (%rax,%r12), %r14
movq %r14, 0x8(%rbp,%r13)
imulq $0x28, %r14, %rdi
callq 0x2280
xorpd %xmm2, %xmm2
movq 0x20(%rsp), %r10
movq 0x8(%rsp), %r9
movq %rax, 0x10(%rbp,%r13)
movq %r14, (%rbp,%r13)
testq %r14, %r14
je 0xffcb0
xorl %eax, %eax
xorl %ecx, %ecx
cmpq %r14, %rcx
jae 0xffcb0
movq 0x10(%r9), %rdx
movq 0x10(%rdx,%r12), %rdx
movq 0x10(%rbp,%r13), %rsi
movq 0x20(%rdx,%rax), %rdi
movq %rdi, 0x20(%rsi,%rax)
movups (%rdx,%rax), %xmm0
movups 0x10(%rdx,%rax), %xmm1
movups %xmm1, 0x10(%rsi,%rax)
movups %xmm0, (%rsi,%rax)
incq 0x160(%rbx)
movq 0x10(%rbx), %rbp
movq 0x10(%rbp,%r13), %rdx
movsd (%rdx,%rax), %xmm0
ucomisd %xmm2, %xmm0
jne 0xffc64
jnp 0xffc8f
movq (%r10), %rdi
movq 0x80(%r10), %rsi
movl 0x8(%rdx,%rax), %r8d
movl (%rdi,%r8,4), %r8d
incq %rsi
cmpq %r8, %rsi
jb 0xffc8f
movl (%rdi,%r15,4), %edi
cmpq %rdi, %rsi
jb 0xffc8f
cmpb $0x0, 0x18(%rdx,%rax)
jns 0xffc9f
orb $-0x80, 0x18(%rdx,%rax)
decq 0x160(%rbx)
movq 0x10(%rbx), %rbp
incq %rcx
movq (%rbp,%r13), %r14
addq $0x28, %rax
jmp 0xffc14
incq %r15
jmp 0xffb57
xorl %r12d, %r12d
cmpq 0x10(%rsp), %r12
je 0xffd47
imulq $0x30, %r12, %rbp
pushq $0x18
popq %r15
xorl %r14d, %r14d
movq 0x10(%r9), %rax
cmpq 0x18(%rax,%rbp), %r14
jae 0xffd3f
addq %rbp, %rax
addq $0x18, %rax
movq 0x10(%rax), %rax
cmpb $0x0, (%rax,%r15)
js 0xffd36
movl -0x10(%rax,%r15), %r13d
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0xff998
testq %rax, %rax
je 0xffd12
orb $-0x80, 0x18(%rax)
movq 0x18(%rsp), %rax
decq (%rax)
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0xff998
testq %rax, %rax
movq 0x8(%rsp), %r9
je 0xffd36
orb $-0x80, 0x18(%rax)
movq 0x18(%rsp), %rax
decq (%rax)
incq %r14
addq $0x28, %r15
jmp 0xffcd1
incq %r12
jmp 0xffcbb
pushq $0x1
popq %rdi
pushq $0x20
popq %r14
movq %r14, %rsi
callq 0x2120
movq %rax, %r15
movabsq $0x800000000000000, %rax # imm = 0x800000000000000
movq %rax, (%r15)
movq $0x3, 0x10(%r15)
movq %r14, %rdi
callq 0x2280
movq %rax, 0x18(%r15)
movq %r15, 0xf8(%rbx)
movq 0x18(%rbx), %rax
movq 0x28(%rbx), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0xf116c
leaq 0x1539bf(%rip), %rax    # 0x253758
movl 0x90(%rax), %eax
movl %eax, 0x178(%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq