// File: chhylp123[P]hifiasm/hic.cpp
// Function: update_ug_by_tigs(asg_t*, hc_links*)
void update_ug_by_tigs(asg_t *sg, hc_links *link)
{
    uint32_t i, m, v, nv, x, y, qn, tn;
    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);
    kvec_t_u32_warp buf; kv_init(buf.a);


    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;
		}
	}


    for (i = 0; i < link->a.n; i++)
    {
        qn = i; 
        for (m = 0; m < link->a.a[i].e.n; m++)
        {
            link->a.a[i].e.a[m].occ = 0;
            link->a.a[i].e.a[m].is_cc = 0;
            tn = link->a.a[i].e.a[m].uID;
            if((group[qn]>>32) == (group[tn]>>32))
            {
                link->a.a[i].e.a[m].is_cc = 1;
            }
        }
    }


    for (i = 1, x = 0; i <= sg->n_seq; ++i) 
    {
		if (i == sg->n_seq || (group[i]>>32) != (group[x]>>32)) 
        {
            append_tig_link(group, x, i - x, link, sg, &buf);
			x = i;
		}
	}

    free(flag); kv_destroy(buf.a);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%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)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
movq $0x0, -0x70(%rbp)
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, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0x1d2110
movq -0x58(%rbp), %rax
movl -0x14(%rbp), %ecx
cmpl $-0x1, (%rax,%rcx,4)
je 0x1d1e58
jmp 0x1d2102
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
jne 0x1d1eaf
cmpq $0x0, -0x48(%rbp)
je 0x1d1e81
movq -0x48(%rbp), %rax
shlq %rax
movq %rax, -0x90(%rbp)
jmp 0x1d1e8f
movl $0x2, %eax
movq %rax, -0x90(%rbp)
jmp 0x1d1e8f
movq -0x90(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, -0x40(%rbp)
movl -0x14(%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 0x1d1eca
cmpq $0x0, -0x50(%rbp)
jbe 0x1d2100
movq -0x50(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x50(%rbp)
movl -0x14(%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, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x1c(%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 -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x20(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x20(%rbp), %eax
jae 0x1d1ffc
movq -0x58(%rbp), %rax
movq -0x38(%rbp), %rcx
movl -0x18(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
cmpl $-0x1, (%rax,%rcx,4)
je 0x1d1f72
jmp 0x1d1fee
jmp 0x1d1f74
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
jne 0x1d1fc3
cmpq $0x0, -0x48(%rbp)
je 0x1d1f95
movq -0x48(%rbp), %rax
shlq %rax
movq %rax, -0x98(%rbp)
jmp 0x1d1fa3
movl $0x2, %eax
movq %rax, -0x98(%rbp)
jmp 0x1d1fa3
movq -0x98(%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 -0x18(%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 0x1d1fee
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x1d1f45
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x1c(%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 -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x20(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x20(%rbp), %eax
jae 0x1d20fb
movq -0x58(%rbp), %rax
movq -0x38(%rbp), %rcx
movl -0x18(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
cmpl $-0x1, (%rax,%rcx,4)
je 0x1d2071
jmp 0x1d20ed
jmp 0x1d2073
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
jne 0x1d20c2
cmpq $0x0, -0x48(%rbp)
je 0x1d2094
movq -0x48(%rbp), %rax
shlq %rax
movq %rax, -0xa0(%rbp)
jmp 0x1d20a2
movl $0x2, %eax
movq %rax, -0xa0(%rbp)
jmp 0x1d20a2
movq -0xa0(%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 -0x18(%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 0x1d20ed
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x1d2044
jmp 0x1d1eca
jmp 0x1d2102
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1d1e2e
movq -0x40(%rbp), %rdi
callq 0x2210
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0x1d2160
movq -0x58(%rbp), %rax
movl -0x14(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, %edx
shlq $0x20, %rdx
movl -0x14(%rbp), %eax
orq %rax, %rdx
movq -0x60(%rbp), %rax
movl -0x14(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1d2120
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, -0x14(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
ja 0x1d2254
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
je 0x1d21e6
movq -0x60(%rbp), %rax
movl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq -0x60(%rbp), %rcx
movl -0x24(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
je 0x1d2244
movl -0x24(%rbp), %eax
movl %eax, -0x84(%rbp)
movl -0x84(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x1d2235
movl -0x28(%rbp), %eax
movl %eax, %edx
shlq $0x20, %rdx
movq -0x60(%rbp), %rax
movl -0x84(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
orq %rax, %rdx
movq -0x60(%rbp), %rax
movl -0x84(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x1d21ef
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x1d2246
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1d2197
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1d237f
movl -0x14(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x14(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jae 0x1d236f
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x14(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl -0x18(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq $0x0, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x14(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl -0x18(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movb 0x18(%rax), %cl
andb $-0x80, %cl
orb $0x0, %cl
movb %cl, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x14(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl -0x18(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x60(%rbp), %rax
movl -0x2c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq -0x60(%rbp), %rcx
movl -0x30(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
jne 0x1d235f
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x14(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl -0x18(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movb 0x18(%rax), %cl
andb $-0x80, %cl
orb $0x1, %cl
movb %cl, 0x18(%rax)
jmp 0x1d2361
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x1d2278
jmp 0x1d2371
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1d225b
movl $0x1, -0x14(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
ja 0x1d2409
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
je 0x1d23d8
movq -0x60(%rbp), %rax
movl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq -0x60(%rbp), %rcx
movl -0x24(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
je 0x1d23fc
movq -0x60(%rbp), %rdi
movl -0x24(%rbp), %esi
movl -0x14(%rbp), %edx
subl -0x24(%rbp), %edx
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %r8
leaq -0x80(%rbp), %r9
callq 0x1d18a0
movl -0x14(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x1d23fe
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1d238d
movq -0x58(%rbp), %rdi
callq 0x2210
movq -0x70(%rbp), %rdi
callq 0x2210
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)