// File: /workspace/github_cpp_makefile_star2_O1/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, %rbp
movq %rsi, %r14
movq %rdi, %rbx
movq (%rsi), %r15
movq %r15, 0x148(%rdi)
leaq 0x160(%rdi), %rax
movq %rax, 0x18(%rsp)
xorl %r13d, %r13d
movq %r13, 0x98(%rdi)
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 %r13, 0xb0(%rbx)
movq %r15, 0xb8(%rbx)
movq %r15, %rdi
callq 0x2280
movq %rax, 0xc0(%rbx)
movq %r15, 0xb0(%rbx)
movq %r13, 0xc8(%rbx)
movq %r15, 0xd0(%rbx)
movq %r15, %rdi
callq 0x2280
movq %rax, 0xd8(%rbx)
movq %r15, 0xc8(%rbx)
movq %r13, 0xe0(%rbx)
movq %r15, 0xe8(%rbx)
movq %r15, %rdi
callq 0x2280
movq %rax, 0xf0(%rbx)
movq %r15, 0xe0(%rbx)
movq %r13, 0x18(%rbx)
movq %r15, 0x20(%rbx)
leaq (,%r15,8), %r12
movq %r12, %rdi
callq 0x2280
movq %rax, 0x28(%rbx)
movq %r15, 0x18(%rbx)
movq %r13, 0x100(%rbx)
movq %r15, 0x108(%rbx)
leaq (,%r15,4), %rdi
callq 0x2280
movq %rax, 0x110(%rbx)
movq %r15, 0x100(%rbx)
movq %r13, 0x118(%rbx)
movq %r15, 0x120(%rbx)
movq %r12, %rdi
callq 0x2280
movq %rax, 0x128(%rbx)
movq %r15, 0x118(%rbx)
movq %r13, (%rbx)
movq %r15, 0x8(%rbx)
leaq (%r12,%r12,2), %rdi
callq 0x2280
movq %rax, 0x10(%rbx)
movq %r15, (%rbx)
movq %r14, 0x10(%rsp)
movq 0x28(%r14), %rax
movq %rax, 0x130(%rbx)
leaq 0x30(%rbx), %rdi
leaq (%r15,%r15), %rsi
callq 0x13bb82
movq %r15, 0x8(%rsp)
leaq 0x2(%r15), %rax
incq %r13
movl $0x1, %edx
movl %r13d, %ecx
shll %cl, %edx
movslq %edx, %rcx
cmpq %rcx, %rax
ja 0x14162d
movl %r13d, %ecx
negb %cl
movq $-0x1, %rax
shrq %cl, %rax
movq %rax, 0x138(%rbx)
movq %r13, 0x140(%rbx)
cmpq $0x0, 0x8(%rsp)
movq 0x10(%rsp), %r10
je 0x14188f
xorl %r15d, %r15d
movq %rbp, 0x20(%rsp)
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
movl $0xffffffff, (%rax,%r15,4) # imm = 0xFFFFFFFF
movq 0x10(%rbx), %r14
leaq (%r15,%r15,2), %r13
movq $0x0, (%r14,%r13,8)
movq 0x10(%r10), %rax
movq %r13, %r12
shlq $0x4, %r12
movq (%rax,%r12), %rbp
movq %rbp, 0x8(%r14,%r13,8)
leaq (,%rbp,8), %rax
leaq (%rax,%rax,4), %rdi
callq 0x2280
xorpd %xmm2, %xmm2
movq 0x10(%rsp), %r10
movq %rax, 0x10(%r14,%r13,8)
movq %rbp, (%r14,%r13,8)
testq %rbp, %rbp
movq 0x20(%rsp), %rbp
je 0x1417ef
movq 0x10(%rbx), %rsi
cmpq $0x0, (%rsi,%r13,8)
je 0x1417ef
leaq (,%r15,8), %rax
leaq (%rax,%rax,2), %rax
xorl %ecx, %ecx
xorl %edx, %edx
movq 0x10(%r10), %rdi
movq 0x10(%rdi,%r12), %rdi
movq 0x10(%rsi,%rax), %rsi
movq 0x20(%rdi,%rcx), %r8
movq %r8, 0x20(%rsi,%rcx)
movups (%rdi,%rcx), %xmm0
movups 0x10(%rdi,%rcx), %xmm1
movups %xmm1, 0x10(%rsi,%rcx)
movups %xmm0, (%rsi,%rcx)
incq 0x160(%rbx)
movq 0x10(%rbx), %rsi
movq 0x10(%rsi,%rax), %rsi
movsd (%rsi,%rcx), %xmm0
ucomisd %xmm2, %xmm0
jne 0x1417a1
jnp 0x1417cd
movq (%rbp), %r8
movq 0x80(%rbp), %rdi
movl 0x8(%rsi,%rcx), %r9d
movl (%r8,%r9,4), %r9d
incq %rdi
cmpq %r9, %rdi
jb 0x1417cd
movl (%r8,%r15,4), %r8d
cmpq %r8, %rdi
jb 0x1417cd
cmpb $0x0, 0x18(%rsi,%rcx)
jns 0x1417da
orb $-0x80, 0x18(%rsi,%rcx)
movq 0x18(%rsp), %rsi
decq (%rsi)
incq %rdx
movq 0x10(%rbx), %rsi
addq $0x28, %rcx
cmpq (%rsi,%r13,8), %rdx
jb 0x14175a
incq %r15
cmpq 0x8(%rsp), %r15
jne 0x141678
xorl %r12d, %r12d
movq 0x10(%r10), %rax
leaq (%r12,%r12,2), %r15
shlq $0x4, %r15
cmpq $0x0, 0x18(%rax,%r15)
je 0x141881
movl $0x18, %ebp
xorl %r14d, %r14d
movq 0x28(%rax,%r15), %rax
cmpb $0x0, (%rax,%rbp)
js 0x14186f
movl -0x10(%rax,%rbp), %r13d
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x14147f
testq %rax, %rax
je 0x14184b
orb $-0x80, 0x18(%rax)
movq 0x18(%rsp), %rax
decq (%rax)
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x14147f
testq %rax, %rax
movq 0x10(%rsp), %r10
je 0x14186f
orb $-0x80, 0x18(%rax)
movq 0x18(%rsp), %rax
decq (%rax)
incq %r14
movq 0x10(%r10), %rax
addq $0x28, %rbp
cmpq 0x18(%rax,%r15), %r14
jb 0x14181c
incq %r12
cmpq 0x8(%rsp), %r12
jne 0x141800
movl $0x1, %edi
movl $0x20, %esi
callq 0x2120
movq %rax, %r14
movabsq $0x3ffffffffffffff, %rax # imm = 0x3FFFFFFFFFFFFFF
andq (%r14), %rax
btsq $0x3b, %rax
movq %rax, (%r14)
movq $0x3, 0x10(%r14)
movl $0x20, %edi
callq 0x2280
movq %rax, 0x18(%r14)
movq %r14, 0xf8(%rbx)
movq 0x18(%rbx), %rax
movq 0x28(%rbx), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x13180d
leaq 0x148e6d(%rip), %rax    # 0x28a758
movl 0x90(%rax), %eax
movl %eax, 0x178(%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq