// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edi
shlq $0x2, %rdi
callq 0x2270
movq %rax, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edi
shlq $0x3, %rdi
callq 0x2270
movq %rax, -0x60(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1d13d0
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x1c(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jae 0x1d13c0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl -0x20(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpq $-0x1, 0x10(%rax)
jne 0x1d131b
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl -0x20(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movb 0x18(%rax), %al
andb $0x7f, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x1d1319
movq 0x1f2cd8(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x1b5fbf(%rip), %rsi    # 0x3872d1
movb $0x0, %al
callq 0x22a0
jmp 0x1d131b
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl -0x20(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpq $-0x1, 0x20(%rax)
jne 0x1d13b0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl -0x20(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movb 0x18(%rax), %al
andb $0x7f, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x1d1396
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl -0x20(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpq $-0x1, 0x10(%rax)
jne 0x1d13ae
movq 0x1f2c43(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x1b90a4(%rip), %rsi    # 0x38a44b
movb $0x0, %al
callq 0x22a0
jmp 0x1d13b0
jmp 0x1d13b2
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x1d128f
jmp 0x1d13c2
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1d1278
movq -0x58(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edx
shlq $0x2, %rdx
movl $0xff, %esi
callq 0x2100
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0x1d16c0
movq -0x58(%rbp), %rax
movl -0x1c(%rbp), %ecx
cmpl $-0x1, (%rax,%rcx,4)
je 0x1d1423
jmp 0x1d16b2
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
jne 0x1d1471
cmpq $0x0, -0x48(%rbp)
je 0x1d1449
movq -0x48(%rbp), %rax
shlq %rax
movq %rax, -0x70(%rbp)
jmp 0x1d1454
movl $0x2, %eax
movq %rax, -0x70(%rbp)
jmp 0x1d1454
movq -0x70(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, -0x40(%rbp)
movl -0x1c(%rbp), %edx
movq -0x40(%rbp), %rax
movq -0x50(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x50(%rbp)
movl %edx, (%rax,%rcx,4)
jmp 0x1d148c
cmpq $0x0, -0x50(%rbp)
jbe 0x1d16b0
movq -0x50(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x50(%rbp)
movl -0x1c(%rbp), %edx
movq -0x58(%rbp), %rax
movq -0x40(%rbp), %rcx
movq -0x50(%rbp), %rsi
movl (%rcx,%rsi,4), %ecx
movl %edx, (%rax,%rcx,4)
movq -0x40(%rbp), %rax
movq -0x50(%rbp), %rcx
movl (%rax,%rcx,4), %eax
shll %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x24(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x24(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x28(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x28(%rbp), %eax
jae 0x1d15b5
movq -0x58(%rbp), %rax
movq -0x38(%rbp), %rcx
movl -0x20(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
cmpl $-0x1, (%rax,%rcx,4)
je 0x1d1534
jmp 0x1d15a7
jmp 0x1d1536
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
jne 0x1d157c
cmpq $0x0, -0x48(%rbp)
je 0x1d1554
movq -0x48(%rbp), %rax
shlq %rax
movq %rax, -0x78(%rbp)
jmp 0x1d155f
movl $0x2, %eax
movq %rax, -0x78(%rbp)
jmp 0x1d155f
movq -0x78(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movl -0x20(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %edx
shrl %edx
movq -0x40(%rbp), %rax
movq -0x50(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x50(%rbp)
movl %edx, (%rax,%rcx,4)
jmp 0x1d15a7
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x1d1507
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x24(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x24(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x28(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x28(%rbp), %eax
jae 0x1d16ab
movq -0x58(%rbp), %rax
movq -0x38(%rbp), %rcx
movl -0x20(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
cmpl $-0x1, (%rax,%rcx,4)
je 0x1d162a
jmp 0x1d169d
jmp 0x1d162c
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
jne 0x1d1672
cmpq $0x0, -0x48(%rbp)
je 0x1d164a
movq -0x48(%rbp), %rax
shlq %rax
movq %rax, -0x80(%rbp)
jmp 0x1d1655
movl $0x2, %eax
movq %rax, -0x80(%rbp)
jmp 0x1d1655
movq -0x80(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movl -0x20(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %edx
shrl %edx
movq -0x40(%rbp), %rax
movq -0x50(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x50(%rbp)
movl %edx, (%rax,%rcx,4)
jmp 0x1d169d
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x1d15fd
jmp 0x1d148c
jmp 0x1d16b2
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1d13f9
movq -0x40(%rbp), %rdi
callq 0x2210
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0x1d1710
movq -0x58(%rbp), %rax
movl -0x1c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, %edx
shlq $0x20, %rdx
movl -0x1c(%rbp), %eax
orq %rax, %rdx
movq -0x60(%rbp), %rax
movl -0x1c(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1d16d0
movq -0x60(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cltq
shlq $0x3, %rax
addq %rax, %rsi
callq 0x1ba0f0
movl $0x1, -0x1c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
ja 0x1d17f2
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
je 0x1d1796
movq -0x60(%rbp), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq -0x60(%rbp), %rcx
movl -0x2c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
je 0x1d17e2
movl -0x2c(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jae 0x1d17d3
movl -0x30(%rbp), %eax
movl %eax, %edx
shlq $0x20, %rdx
movq -0x60(%rbp), %rax
movl -0x64(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
orq %rax, %rdx
movq -0x60(%rbp), %rax
movl -0x64(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x1d179c
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x1d17e4
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1d1747
movq -0x58(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x2100
movl $0x1, -0x1c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
ja 0x1d1884
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
je 0x1d1871
movq -0x60(%rbp), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq -0x60(%rbp), %rcx
movl -0x2c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
je 0x1d1877
movl -0x1c(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x1d1879
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1d1826
movq -0x58(%rbp), %rdi
callq 0x2210
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)