// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/hic.cpp
// Function: update_dis_connected_gfa(asg_t*, hc_links*, MT*)
void update_dis_connected_gfa(asg_t *sg, hc_links *link, MT *M)
{
    uint32_t i, m, v, nv, x, y;
    asg_arc_t *av = NULL;
	kvec_t(uint32_t) stack; kv_init(stack);
    uint32_t *flag = NULL; MALLOC(flag, sg->n_seq);
    uint64_t *group = NULL; MALLOC(group, sg->n_seq);

    for (i = 0; i < link->a.n; i++)
    {
        for (m = 0; m < link->a.a[i].e.n; m++)
        {
            if(link->a.a[i].e.a[m].dis == (uint64_t)-1)
            {
                if(link->a.a[i].e.a[m].is_cc != 0)
                {
                    fprintf(stderr, "ERROR 1\n");
                }
            }

            if(link->a.a[i].e.a[m].occ == (uint64_t)-1)
            {
                if(link->a.a[i].e.a[m].is_cc != 0 || link->a.a[i].e.a[m].dis == (uint64_t)-1)
                {
                    fprintf(stderr, "ERROR 2\n");
                }
            }
        }
    }


    memset(flag, -1, sg->n_seq*sizeof(uint32_t));
	// connected componets
	for (i = 0; i < sg->n_seq; ++i) {
		if (flag[i] != (uint32_t)-1) continue;
		stack.n = 0;
		kv_push(uint32_t, stack, i);
		while (stack.n > 0) {
			stack.n--;
			flag[stack.a[stack.n]] = i;///group id

            v = (stack.a[stack.n])<<1;
            av = asg_arc_a(sg, v);
            nv = asg_arc_n(sg, v);
			for (m = 0; m < nv; ++m) {
				if (flag[av[m].v>>1] != (uint32_t)-1) continue;
				kv_push(uint32_t, stack, av[m].v>>1);
			}

            v++;
            av = asg_arc_a(sg, v);
            nv = asg_arc_n(sg, v);
			for (m = 0; m < nv; ++m) {
				if (flag[av[m].v>>1] != (uint32_t)-1) continue;
				kv_push(uint32_t, stack, av[m].v>>1);
			}
		}
	}
	kv_destroy(stack);



	// precalculate the size of each group
	for (i = 0; i < sg->n_seq; ++i)
		group[i] = (uint64_t)flag[i] << 32 | i;
    radix_sort_hc64(group, group + sg->n_seq);
	for (i = 1, x = y = 0; i <= sg->n_seq; ++i) {
		if (i == sg->n_seq || (group[i]>>32) != (group[x]>>32)) {
			uint32_t j;
			for (j = x; j < i; ++j)
				group[j] = (uint64_t)y << 32 | (uint32_t)group[j];///(group id)|first element in this group
			++y, x = i;
		}
	}

    memset(flag, 0, sg->n_seq*sizeof(uint32_t));
    for (i = 1, x = y = 0; i <= sg->n_seq; ++i) 
    {
		if (i == sg->n_seq || (group[i]>>32) != (group[x]>>32)) 
        {
			x = i;
		}
	}


	free(flag);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r12
movq %rdi, 0x8(%rsp)
movl 0x14(%rdi), %r14d
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
leaq (,%r14,4), %rdi
callq 0x2280
movq %rax, %rbx
shlq $0x3, %r14
movq %r14, %rdi
callq 0x2280
movq %rax, 0x10(%rsp)
cmpq $0x0, (%r12)
je 0x13ea25
xorl %r14d, %r14d
movq 0x10(%r12), %rax
leaq (%r14,%r14,2), %r15
shlq $0x4, %r15
cmpq $0x0, (%rax,%r15)
je 0x13ea18
movl $0x1, %ebp
xorl %ecx, %ecx
movq 0x10(%rax,%r15), %rax
leaq (%rcx,%rcx,4), %r13
cmpq $-0x1, 0x10(%rax,%r13,8)
jne 0x13e9d6
leaq (%rax,%r13,8), %rax
testb $0x7f, 0x18(%rax)
jne 0x13ea11
movq 0x10(%r12), %rax
movq 0x10(%rax,%r15), %rax
cmpq $-0x1, 0x20(%rax,%r13,8)
jne 0x13e9f9
leaq (%rax,%r13,8), %rax
testb $0x7f, 0x18(%rax)
jne 0x13ea0a
cmpq $-0x1, 0x10(%rax)
je 0x13ea0a
movl %ebp, %ecx
movq 0x10(%r12), %rax
incl %ebp
cmpq %rcx, (%rax,%r15)
ja 0x13e9bb
jmp 0x13ea18
callq 0x1cafc
jmp 0x13e9f9
callq 0x1cae0
jmp 0x13e9d6
incl %r14d
cmpq %r14, (%r12)
ja 0x13e9a0
movq 0x8(%rsp), %r15
movl 0x14(%r15), %r14d
movl %r14d, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
shlq $0x2, %rdx
movq %rbx, %rdi
movl $0xff, %esi
callq 0x20e0
testl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
je 0x13ebcd
xorl %r12d, %r12d
xorl %eax, %eax
xorl %edi, %edi
cmpl $-0x1, (%rbx,%r12,4)
jne 0x13ebb0
testq %rax, %rax
jne 0x13ea7e
movl $0x8, %esi
callq 0x2370
movq %rax, %rdi
movl $0x2, %eax
movl %r12d, (%rdi)
movl $0x1, %ebp
movq %r12, 0x18(%rsp)
movl -0x4(%rdi,%rbp,4), %ecx
movl %r12d, (%rbx,%rcx,4)
movl -0x4(%rdi,%rbp,4), %edx
decq %rbp
addl %edx, %edx
movq 0x28(%r15), %rcx
movq %rdx, 0x20(%rsp)
movq (%rcx,%rdx,8), %rcx
testl %ecx, %ecx
je 0x13eb1a
movq 0x8(%r15), %rdx
movq %rcx, %rsi
shrq $0x20, %rsi
movl %ecx, %ecx
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %r12
addq $0x8, %r12
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %r15
xorl %r13d, %r13d
movl (%r12,%r13), %ecx
shrl %ecx
cmpl $-0x1, (%rbx,%rcx,4)
jne 0x13eb11
cmpq %rax, %rbp
jne 0x13eb05
leaq (%rax,%rax), %r14
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %r14
leaq (,%r14,4), %rsi
callq 0x2370
movq %rax, %rdi
movq %r14, %rax
movl (%r12,%r13), %ecx
shrl %ecx
movl %ecx, (%rdi,%rbp,4)
incq %rbp
addq $0x18, %r13
cmpq %r13, %r15
jne 0x13ead1
movq 0x8(%rsp), %rsi
movq 0x28(%rsi), %rcx
movl 0x20(%rsp), %edx
movq 0x8(%rcx,%rdx,8), %rcx
testl %ecx, %ecx
je 0x13eb9d
movq 0x8(%rsi), %rdx
movq %rcx, %rsi
shrq $0x20, %rsi
movl %ecx, %ecx
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %r14
addq $0x8, %r14
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %r15
xorl %r12d, %r12d
movl (%r14,%r12), %ecx
shrl %ecx
cmpl $-0x1, (%rbx,%rcx,4)
jne 0x13eb94
cmpq %rax, %rbp
jne 0x13eb88
leaq (%rax,%rax), %r13
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %r13
leaq (,%r13,4), %rsi
callq 0x2370
movq %rax, %rdi
movq %r13, %rax
movl (%r14,%r12), %ecx
shrl %ecx
movl %ecx, (%rdi,%rbp,4)
incq %rbp
addq $0x18, %r12
cmpq %r12, %r15
jne 0x13eb54
testq %rbp, %rbp
movq 0x8(%rsp), %r15
movq 0x18(%rsp), %r12
jne 0x13ea8b
incq %r12
movl 0x14(%r15), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rcx, %r12
movq 0x10(%rsp), %r14
jb 0x13ea5c
jmp 0x13ebd4
xorl %edi, %edi
movq 0x10(%rsp), %r14
callq 0x2220
movl 0x14(%r15), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
je 0x13ebfc
xorl %ecx, %ecx
movl (%rbx,%rcx,4), %edx
shlq $0x20, %rdx
addq %rcx, %rdx
movq %rdx, (%r14,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x13ebe6
movl %eax, %eax
leaq (%r14,%rax,8), %rsi
movq %r14, %rdi
callq 0x13180d
movl 0x14(%r15), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
je 0x13ec64
leal 0x1(%rax), %ecx
xorl %edx, %edx
movl $0x1, %esi
xorl %r8d, %r8d
movl %r8d, %edi
cmpq %rax, %rsi
je 0x13ec38
movq (%r14,%rdi,8), %r9
xorq (%r14,%rsi,8), %r9
shrq $0x20, %r9
je 0x13ec5c
cmpq %rdi, %rsi
jbe 0x13ec57
movq %rdx, %r8
shlq $0x20, %r8
movl (%r14,%rdi,8), %r9d
orq %r8, %r9
movq %r9, (%r14,%rdi,8)
incq %rdi
cmpq %rdi, %rsi
jne 0x13ec44
incl %edx
movl %esi, %r8d
incq %rsi
cmpq %rcx, %rsi
jne 0x13ec22
movl %eax, %edx
shlq $0x2, %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x20e0
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220