// File: /workspace/github_cpp_makefile_star2_O3/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
movl %r14d, %r15d
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
leaq (,%r15,4), %r13
movq %r13, %rdi
callq 0x2280
movq %rax, %rbx
leaq (,%r15,8), %rdi
callq 0x2280
movq %rax, 0x10(%rsp)
movq (%r12), %rcx
testq %rcx, %rcx
je 0x14468b
movq 0x10(%r12), %rax
xorl %r14d, %r14d
leaq (%r14,%r14,2), %rbp
shlq $0x4, %rbp
cmpq $0x0, (%rax,%rbp)
je 0x144665
movl $0x1, %r13d
xorl %edx, %edx
movq 0x10(%rax,%rbp), %rcx
leaq (%rdx,%rdx,4), %r15
cmpq $-0x1, 0x10(%rcx,%r15,8)
jne 0x1445e7
leaq (%rcx,%r15,8), %rdx
testb $0x7f, 0x18(%rdx)
jne 0x144635
cmpq $-0x1, 0x20(%rcx,%r15,8)
jne 0x144600
leaq (%rcx,%r15,8), %rcx
testb $0x7f, 0x18(%rcx)
jne 0x14460e
cmpq $-0x1, 0x10(%rcx)
je 0x14460e
movl %r13d, %edx
incl %r13d
cmpq %rdx, (%rax,%rbp)
ja 0x1445cc
jmp 0x144661
movq 0x1509cb(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
movl $0x8, %esi
movl $0x1, %edx
leaq 0xf526a(%rip), %rdi     # 0x239893
callq 0x2410
movq 0x10(%r12), %rax
jmp 0x144600
movq 0x1509a4(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
movl $0x8, %esi
movl $0x1, %edx
leaq 0xf2253(%rip), %rdi     # 0x2368a3
callq 0x2410
movq 0x10(%r12), %rax
movq 0x10(%rax,%rbp), %rcx
jmp 0x1445e7
movq (%r12), %rcx
incl %r14d
cmpq %r14, %rcx
ja 0x1445b1
movq 0x8(%rsp), %rax
movl 0x14(%rax), %r14d
movl %r14d, %r15d
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
movq %r15, %r13
shlq $0x2, %r13
movq %rbx, %rdi
movl $0xff, %esi
movq %r13, %rdx
callq 0x20e0
testl %r15d, %r15d
je 0x144820
xorl %r15d, %r15d
xorl %ebp, %ebp
xorl %edi, %edi
cmpl $-0x1, (%rbx,%r15,4)
jne 0x14480a
testq %rbp, %rbp
jne 0x1446cd
movl $0x8, %esi
callq 0x2370
movq %rax, %rdi
movl $0x2, %ebp
movl %r15d, (%rdi)
movl $0x1, %r14d
movq %r15, 0x18(%rsp)
movl -0x4(%rdi,%r14,4), %eax
movl %r15d, (%rbx,%rax,4)
movl -0x4(%rdi,%r14,4), %esi
decq %r14
addl %esi, %esi
movq 0x8(%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x28(%rcx), %rcx
movq (%rcx,%rsi,8), %rdx
testl %edx, %edx
je 0x144781
movq %rsi, 0x20(%rsp)
movq %rdx, %rcx
shrq $0x20, %rcx
movl %edx, %edx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %r15
addq $0x8, %r15
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %r13
xorl %r12d, %r12d
movl (%r15,%r12), %eax
shrl %eax
cmpl $-0x1, (%rbx,%rax,4)
jne 0x144766
cmpq %rbp, %r14
jne 0x14475f
leaq (%r14,%r14), %rbp
testq %r14, %r14
movl $0x2, %eax
cmoveq %rax, %rbp
leaq (,%rbp,4), %rsi
callq 0x2370
movq %rax, %rdi
movl (%r15,%r12), %eax
shrl %eax
movl %eax, (%rdi,%r14,4)
incq %r14
addq $0x18, %r12
cmpq %r12, %r13
jne 0x144728
movq 0x8(%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x28(%rcx), %rcx
movq 0x20(%rsp), %rsi
movl %esi, %edx
movq 0x8(%rcx,%rdx,8), %rcx
testl %ecx, %ecx
je 0x1447f3
movq %rcx, %rdx
shrq $0x20, %rdx
movl %ecx, %ecx
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %r12
addq $0x8, %r12
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %r15
xorl %r13d, %r13d
movl (%r12,%r13), %eax
shrl %eax
cmpl $-0x1, (%rbx,%rax,4)
jne 0x1447ea
cmpq %rbp, %r14
jne 0x1447e3
leaq (%r14,%r14), %rbp
testq %r14, %r14
movl $0x2, %eax
cmoveq %rax, %rbp
leaq (,%rbp,4), %rsi
callq 0x2370
movq %rax, %rdi
movl (%r12,%r13), %eax
shrl %eax
movl %eax, (%rdi,%r14,4)
incq %r14
addq $0x18, %r13
cmpq %r13, %r15
jne 0x1447ac
testq %r14, %r14
movq 0x18(%rsp), %r15
jne 0x1446db
movq 0x8(%rsp), %rax
movl 0x14(%rax), %r14d
incq %r15
movl %r14d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, %r15
jb 0x1446ab
jmp 0x144822
xorl %edi, %edi
callq 0x2220
movq 0x8(%rsp), %rax
movl 0x14(%rax), %eax
andq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
je 0x144856
xorl %ecx, %ecx
movq 0x10(%rsp), %r14
movl (%rbx,%rcx,4), %edx
shlq $0x20, %rdx
addq %rcx, %rdx
movq %rdx, (%r14,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x14483e
jmp 0x14485d
xorl %eax, %eax
movq 0x10(%rsp), %r14
leaq (%r14,%rax,8), %rsi
movq %r14, %rdi
callq 0x1379f9
movq 0x8(%rsp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
je 0x1448c7
leal 0x1(%rax), %ecx
xorl %edx, %edx
movl $0x1, %esi
xorl %r8d, %r8d
movl %r8d, %edi
cmpq %rax, %rsi
je 0x14489b
movq (%r14,%rdi,8), %r9
xorq (%r14,%rsi,8), %r9
shrq $0x20, %r9
je 0x1448bf
cmpq %rsi, %rdi
jae 0x1448ba
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 0x1448a7
incl %edx
movl %esi, %r8d
incq %rsi
cmpq %rcx, %rsi
jne 0x144885
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220