// File: /workspace/github_cpp_makefile_star2_O2/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, %r13
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)
xorl %ebp, %ebp
movl %ebp, %ebp
cmpq %rbp, (%r13)
jbe 0xfd075
xorl %r14d, %r14d
imulq $0x30, %rbp, %r15
movl %r14d, %r14d
movq 0x10(%r13), %rax
cmpq %r14, (%rax,%r15)
jbe 0xfd06e
leaq (%rax,%r15), %rcx
movq 0x10(%rcx), %rcx
imulq $0x28, %r14, %r12
cmpq $-0x1, 0x10(%rcx,%r12)
jne 0xfd00c
addq %r12, %rcx
testb $0x7f, 0x18(%rcx)
jne 0xfd04c
movq 0x10(%rax,%r15), %rax
cmpq $-0x1, 0x20(%rax,%r12)
jne 0xfd029
addq %r12, %rax
testb $0x7f, 0x18(%rax)
jne 0xfd02e
cmpq $-0x1, 0x10(%rax)
je 0xfd02e
incl %r14d
jmp 0xfcfe2
movq 0x155fab(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0xee734(%rip), %rdi     # 0x1eb773
pushq $0x8
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
jmp 0xfd029
movq 0x155f8d(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0xeb746(%rip), %rdi     # 0x1e87a3
pushq $0x8
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq 0x10(%r13), %rax
jmp 0xfd00c
incl %ebp
jmp 0xfcfcf
movq 0x8(%rsp), %rax
movl 0x14(%rax), %r14d
movl %r14d, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
shlq $0x2, %rdx
movq %rbx, %rdi
movl $0xff, %esi
callq 0x20e0
xorl %r15d, %r15d
xorl %edi, %edi
xorl %eax, %eax
movl %r14d, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rcx, %r15
jae 0xfd203
cmpl $-0x1, (%rbx,%r15,4)
jne 0xfd1fb
testq %rax, %rax
jne 0xfd0cf
pushq $0x8
popq %rsi
callq 0x2370
movq %rax, %rdi
pushq $0x2
popq %rax
movl %r15d, (%rdi)
pushq $0x1
popq %r13
movq %r15, 0x18(%rsp)
testq %r13, %r13
je 0xfd1f2
movl -0x4(%rdi,%r13,4), %ecx
movl %r15d, (%rbx,%rcx,4)
movl -0x4(%rdi,%r13,4), %esi
decq %r13
addl %esi, %esi
movq 0x8(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq 0x28(%rdx), %rdx
movq %rsi, 0x20(%rsp)
movq (%rdx,%rsi,8), %rdx
movl %edx, %esi
shrq $0x20, %rdx
imulq $0x18, %rsi, %r14
imulq $0x18, %rdx, %rdx
leaq (%rcx,%rdx), %r15
addq $0x8, %r15
xorl %ebp, %ebp
cmpq %rbp, %r14
je 0xfd16f
movl (%r15,%rbp), %ecx
shrl %ecx
cmpl $-0x1, (%rbx,%rcx,4)
jne 0xfd169
cmpq %rax, %r13
jne 0xfd162
leaq (%rax,%rax), %r12
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %r12
leaq (,%r12,4), %rsi
callq 0x2370
movq %rax, %rdi
movl (%r15,%rbp), %ecx
shrl %ecx
movq %r12, %rax
movl %ecx, (%rdi,%r13,4)
incq %r13
addq $0x18, %rbp
jmp 0xfd125
movq 0x8(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq 0x28(%rdx), %rdx
movl 0x20(%rsp), %esi
movq 0x8(%rdx,%rsi,8), %rdx
movl %edx, %esi
shrq $0x20, %rdx
imulq $0x18, %rsi, %r14
imulq $0x18, %rdx, %rdx
leaq (%rcx,%rdx), %r15
addq $0x8, %r15
xorl %r12d, %r12d
cmpq %r12, %r14
je 0xfd1e8
movl (%r15,%r12), %ecx
shrl %ecx
cmpl $-0x1, (%rbx,%rcx,4)
jne 0xfd1e2
cmpq %rax, %r13
jne 0xfd1db
leaq (%rax,%rax), %rbp
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %rbp
leaq (,%rbp,4), %rsi
callq 0x2370
movq %rax, %rdi
movl (%r15,%r12), %ecx
shrl %ecx
movq %rbp, %rax
movl %ecx, (%rdi,%r13,4)
incq %r13
addq $0x18, %r12
jmp 0xfd19e
movq 0x18(%rsp), %r15
jmp 0xfd0db
movq 0x8(%rsp), %rcx
movl 0x14(%rcx), %r14d
incq %r15
jmp 0xfd09f
callq 0x2220
movq 0x8(%rsp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %ecx, %ecx
movq 0x10(%rsp), %r14
cmpq %rcx, %rax
je 0xfd234
movl (%rbx,%rcx,4), %edx
shlq $0x20, %rdx
addq %rcx, %rdx
movq %rdx, (%r14,%rcx,8)
incq %rcx
jmp 0xfd21c
leaq (%r14,%rax,8), %rsi
movq %r14, %rdi
callq 0xf116c
movq 0x8(%rsp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leal 0x1(%rax), %ecx
xorl %edi, %edi
pushq $0x1
popq %rdx
xorl %esi, %esi
cmpq %rcx, %rdx
je 0xfd297
movl %edi, %r8d
cmpq %rax, %rdx
je 0xfd272
movq (%r14,%r8,8), %r9
xorq (%r14,%rdx,8), %r9
shrq $0x20, %r9
je 0xfd292
movq %rsi, %rdi
shlq $0x20, %rdi
cmpq %rdx, %r8
jae 0xfd28e
movl (%r14,%r8,8), %r9d
orq %rdi, %r9
movq %r9, (%r14,%r8,8)
incq %r8
jmp 0xfd279
incl %esi
movl %edx, %edi
incq %rdx
jmp 0xfd257
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220