// File: /workspace/github_cpp_makefile_star2_O3/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)
leaq (,%r13,2), %rdi
addq %r13, %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 0x14198e
movq %r15, 0x8(%rsp)
leaq 0x2(%r15), %rdx
xorl %eax, %eax
incq %rax
movl $0x1, %esi
movl %eax, %ecx
shll %cl, %esi
movslq %esi, %rcx
cmpq %rcx, %rdx
ja 0x147285
movl %eax, %ecx
negb %cl
movq $-0x1, %rdx
shrq %cl, %rdx
movq %rdx, 0x138(%rbx)
movq %rax, 0x140(%rbx)
cmpq $0x0, 0x8(%rsp)
movq 0x10(%rsp), %r10
je 0x1474c7
xorl %r15d, %r15d
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), %r12
movq 0x10(%r10), %rax
leaq (%r15,%r15,2), %r13
movq %r13, %rbp
shlq $0x4, %rbp
movq (%rax,%rbp), %r14
movq %r14, 0x8(%r12,%r13,8)
leaq (,%r14,8), %rax
leaq (%rax,%rax,4), %rdi
callq 0x2280
xorpd %xmm2, %xmm2
movq 0x10(%rsp), %r10
movq %rax, 0x10(%r12,%r13,8)
movq %r14, (%r12,%r13,8)
testq %r14, %r14
movq 0x20(%rsp), %r11
je 0x147427
leaq (,%r15,8), %rax
leaq (%rax,%rax,2), %rax
xorl %ecx, %ecx
xorl %edx, %edx
movq 0x10(%r10), %rsi
movq 0x10(%rsi,%rbp), %rsi
movq 0x10(%r12,%rax), %rdi
movq 0x20(%rsi,%rcx), %r8
movq %r8, 0x20(%rdi,%rcx)
movups (%rsi,%rcx), %xmm0
movups 0x10(%rsi,%rcx), %xmm1
movups %xmm1, 0x10(%rdi,%rcx)
movups %xmm0, (%rdi,%rcx)
incq 0x160(%rbx)
movq 0x10(%rbx), %r12
movq 0x10(%r12,%rax), %rsi
movsd (%rsi,%rcx), %xmm0
ucomisd %xmm2, %xmm0
jne 0x1473db
jnp 0x147406
movq (%r11), %r8
movq 0x80(%r11), %rdi
movl 0x8(%rsi,%rcx), %r9d
movl (%r8,%r9,4), %r9d
incq %rdi
cmpq %r9, %rdi
jb 0x147406
movl (%r8,%r15,4), %r8d
cmpq %r8, %rdi
jb 0x147406
cmpb $0x0, 0x18(%rsi,%rcx)
jns 0x147416
orb $-0x80, 0x18(%rsi,%rcx)
decq 0x160(%rbx)
movq 0x10(%rbx), %r12
incq %rdx
addq $0x28, %rcx
cmpq (%r12,%r13,8), %rdx
jb 0x147394
incq %r15
cmpq 0x8(%rsp), %r15
jne 0x1472c9
movq 0x10(%r10), %rax
xorl %r12d, %r12d
leaq (%r12,%r12,2), %r15
shlq $0x4, %r15
cmpq $0x0, 0x18(%rax,%r15)
je 0x1474b9
movl $0x18, %ebp
xorl %r14d, %r14d
movq 0x28(%rax,%r15), %rax
cmpb $0x0, (%rax,%rbp)
js 0x1474a7
movl -0x10(%rax,%rbp), %r13d
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x147100
testq %rax, %rax
je 0x147483
orb $-0x80, 0x18(%rax)
movq 0x18(%rsp), %rax
decq (%rax)
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x147100
testq %rax, %rax
movq 0x10(%rsp), %r10
je 0x1474a7
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 0x147454
incq %r12
cmpq 0x8(%rsp), %r12
jne 0x14743c
movl $0x1, %edi
movl $0x20, %esi
callq 0x2120
movq %rax, %r14
movabsq $0x800000000000000, %rax # imm = 0x800000000000000
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 0x1379f9
leaq 0x14e23d(%rip), %rax    # 0x295758
movl 0x90(%rax), %eax
movl %eax, 0x178(%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq