// File: chhylp123[P]hifiasm/inter.cpp
// Function: work_rg_contain_dedup(uldat_t*)
uint64_t work_rg_contain_dedup(uldat_t *sl)
{
	utepdat_t s; uint64_t i, occ, ou_n, m, *srt, srt_n, *idx, idx_n, tot; 
	asg64_v ou, bu; kv_init(ou); memset(&s, 0, sizeof(s));
	s.id = 0; s.uopt = sl->uopt; s.rg = sl->rg; s.opt = sl->opt; ///s.ug = sl->ug; s.uu = sl->uu; 
	//  CALLOC(s.buf, sl->n_thread); CALLOC(s.gdp, sl->n_thread); CALLOC(s.mzs, sl->n_thread); 
	CALLOC(s.hab, sl->n_thread); CALLOC(s.ll, sl->n_thread); ///CALLOC(s.sps, sl->n_thread); 

	for (i = 0; i < sl->n_thread; ++i) {
		s.hab[i] = ha_ovec_init(0, 0, 1); ///s.buf[i] = mg_tbuf_init();
	}

	// detect_outlier_len("+++work_ul_gchains");

	//debug
    // overall_zdbg = init_mul_debug_prt_t(UL_INF.n);
	occ = 1; tot = 0;
	while (occ) {
		kt_for(sl->n_thread, worker_for_contain_dedup, &s, (s.rg->n_seq<<1));
		for (i = ou.n = 0; i < sl->n_thread; ++i) {
			copy_asg_arr(bu, s.ll[i].srt.a);
			update_contain_dedup_arr(&bu, i, &ou);
			copy_asg_arr(s.ll[i].srt.a, bu);
		}
		ou_n = ou.n;
		for (i = 0; i < ou_n; i++) {
			assert(((uint32_t)s.ll[ou.a[i]>>32].srt.a.a[(uint32_t)ou.a[i]]) == ((uint32_t)-1));
			m = s.ll[ou.a[i]>>32].srt.a.a[(uint32_t)ou.a[i]]>>32; m <<= 32; m += i;
			kv_push(uint64_t, ou, m);
		}
		// fprintf(stderr, "[M::%s::] ou_n::%lu, ou.n::%u\n", __func__, ou_n, (uint32_t)ou.n); 
		idx = ou.a; idx_n = ou_n; srt = ou.a + ou_n; srt_n = ou.n - ou_n;
		radix_sort_gfa64(srt, srt + srt_n);
		// print_debug_gfa((asg_t *)s.rg, NULL, s.uopt->coverage_cut, "UL.dirty.debug", s.uopt->sources, s.uopt->ruIndex, s.uopt->max_hang, s.uopt->min_ovlp, 0, 0, 0);
		occ = asg_clean_idx_tig((asg_t *)s.rg, idx, idx_n, srt, srt_n, &s);
		for (i = 0; i < sl->n_thread; ++i) s.ll[i].srt.a.n = 0;
		tot += occ;
		// fprintf(stderr, "[M::%s::] idx_n::%lu, srt_n::%lu, occ::%lu\n", __func__, idx_n, srt_n, occ); 
	}
	

	

	// detect_outlier_len("---work_ul_gchains");

	for (i = 0; i < sl->n_thread; ++i) {
		s.sum_len += s.hab[i]->num_read_base; s.n += s.hab[i]->num_correct_base;
		// hc_gdpchain_destroy(&(s.gdp[i])); kv_destroy(s.mzs[i]); mg_tbuf_destroy(s.buf[i]); 
		ha_ovec_destroy(s.hab[i]); hc_glchain_destroy(&(s.ll[i])); ///kv_destroy(s.sps[i]);
	}

	// free(s.buf); free(s.gdp); free(s.mzs); 
	free(s.hab); free(s.ll); kv_destroy(ou); ///free(s.sps);
	fprintf(stderr, "[M::%s::] # duplicated reads::%lu\n", __func__, tot); 
	// exit(1);
	return tot;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x8(%rbp)
movq $0x0, -0x130(%rbp)
movq $0x0, -0x138(%rbp)
movq $0x0, -0x128(%rbp)
leaq -0xd8(%rbp), %rdi
xorl %esi, %esi
movl $0xd0, %edx
callq 0x2100
movq $0x0, -0x88(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0xb0(%rbp)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0xb8(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xd8(%rbp)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rdi
movl $0x8, %esi
callq 0x2140
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rdi
movl $0x68, %esi
callq 0x2140
movq %rax, -0x50(%rbp)
movq $0x0, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x58(%rcx), %rax
jae 0x2efc67
xorl %esi, %esi
movl $0x1, %edx
movl %esi, %edi
callq 0x14c90
movq %rax, %rdx
movq -0x58(%rbp), %rax
movq -0xe0(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0xe0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xe0(%rbp)
jmp 0x2efc22
movq $0x1, -0xe8(%rbp)
movq $0x0, -0x120(%rbp)
cmpq $0x0, -0xe8(%rbp)
je 0x2f005f
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl %eax, %edi
movq -0xb8(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movslq %eax, %rcx
leaq 0x4b0(%rip), %rsi       # 0x2f0160
leaq -0xd8(%rbp), %rdx
callq 0x16d710
movq $0x0, -0x138(%rbp)
movq $0x0, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x58(%rcx), %rax
jae 0x2efdb4
movq -0x50(%rbp), %rax
imulq $0x68, -0xe0(%rbp), %rcx
addq %rcx, %rax
movq 0x58(%rax), %rax
movq %rax, -0x140(%rbp)
movq -0x50(%rbp), %rax
imulq $0x68, -0xe0(%rbp), %rcx
addq %rcx, %rax
movq 0x48(%rax), %rax
movq %rax, -0x150(%rbp)
movq -0x50(%rbp), %rax
imulq $0x68, -0xe0(%rbp), %rcx
addq %rcx, %rax
movq 0x50(%rax), %rax
movq %rax, -0x148(%rbp)
movq -0xe0(%rbp), %rsi
leaq -0x150(%rbp), %rdi
leaq -0x138(%rbp), %rdx
callq 0x2ee1a0
movq -0x140(%rbp), %rcx
movq -0x50(%rbp), %rax
imulq $0x68, -0xe0(%rbp), %rdx
addq %rdx, %rax
movq %rcx, 0x58(%rax)
movq -0x150(%rbp), %rcx
movq -0x50(%rbp), %rax
imulq $0x68, -0xe0(%rbp), %rdx
addq %rdx, %rax
movq %rcx, 0x48(%rax)
movq -0x148(%rbp), %rcx
movq -0x50(%rbp), %rax
imulq $0x68, -0xe0(%rbp), %rdx
addq %rdx, %rax
movq %rcx, 0x50(%rax)
movq -0xe0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xe0(%rbp)
jmp 0x2efcd2
movq -0x138(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq $0x0, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
cmpq -0xf0(%rbp), %rax
jae 0x2eff5a
movq -0x50(%rbp), %rax
movq -0x128(%rbp), %rcx
movq -0xe0(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq 0x58(%rax), %rax
movq -0x128(%rbp), %rcx
movq -0xe0(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
cmpl $-0x1, %eax
jne 0x2efe25
jmp 0x2efe44
leaq 0xa4bb4(%rip), %rdi     # 0x3949e0
leaq 0xa09fc(%rip), %rsi     # 0x39082f
movl $0x4bea, %edx           # imm = 0x4BEA
leaq 0xa4bec(%rip), %rcx     # 0x394a2b
callq 0x2130
movq -0x50(%rbp), %rax
movq -0x128(%rbp), %rcx
movq -0xe0(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq 0x58(%rax), %rax
movq -0x128(%rbp), %rcx
movq -0xe0(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq %rax, -0xf8(%rbp)
movq -0xf8(%rbp), %rax
shlq $0x20, %rax
movq %rax, -0xf8(%rbp)
movq -0xe0(%rbp), %rax
addq -0xf8(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0x138(%rbp), %rax
cmpq -0x130(%rbp), %rax
jne 0x2eff1a
cmpq $0x0, -0x130(%rbp)
je 0x2efee0
movq -0x130(%rbp), %rax
shlq %rax
movq %rax, -0x158(%rbp)
jmp 0x2efeee
movl $0x2, %eax
movq %rax, -0x158(%rbp)
jmp 0x2efeee
movq -0x158(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0x128(%rbp), %rdi
movq -0x130(%rbp), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, -0x128(%rbp)
movq -0xf8(%rbp), %rdx
movq -0x128(%rbp), %rax
movq -0x138(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x138(%rbp)
movq %rdx, (%rax,%rcx,8)
jmp 0x2eff43
movq -0xe0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xe0(%rbp)
jmp 0x2efdcd
movq -0x128(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0xf0(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x128(%rbp), %rax
movq -0xf0(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x100(%rbp)
movq -0x138(%rbp), %rax
subq -0xf0(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x100(%rbp), %rdi
movq -0x100(%rbp), %rsi
movq -0x108(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x27a9b0
movq -0xb8(%rbp), %rdi
movq -0x110(%rbp), %rsi
movq -0x118(%rbp), %rdx
movq -0x100(%rbp), %rcx
movq -0x108(%rbp), %r8
leaq -0xd8(%rbp), %r9
callq 0x2ef340
movq %rax, -0xe8(%rbp)
movq $0x0, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x58(%rcx), %rax
jae 0x2f0045
movq -0x50(%rbp), %rax
imulq $0x68, -0xe0(%rbp), %rcx
addq %rcx, %rax
movq $0x0, 0x48(%rax)
movq -0xe0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xe0(%rbp)
jmp 0x2f0009
movq -0xe8(%rbp), %rax
addq -0x120(%rbp), %rax
movq %rax, -0x120(%rbp)
jmp 0x2efc7d
movq $0x0, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x58(%rcx), %rax
jae 0x2f010a
movq -0x58(%rbp), %rax
movq -0xe0(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0xf0(%rax), %rcx
movslq -0x98(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x98(%rbp)
movq -0x58(%rbp), %rax
movq -0xe0(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0xf8(%rax), %rcx
movslq -0xa0(%rbp), %rax
addq %rcx, %rax
movl %eax, -0xa0(%rbp)
movq -0x58(%rbp), %rax
movq -0xe0(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x14f00
movq -0x50(%rbp), %rdi
imulq $0x68, -0xe0(%rbp), %rax
addq %rax, %rdi
callq 0x282c10
movq -0xe0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xe0(%rbp)
jmp 0x2f006a
movq -0x58(%rbp), %rdi
callq 0x2210
movq -0x50(%rbp), %rdi
callq 0x2210
movq -0x128(%rbp), %rdi
callq 0x2210
movq 0xd3eb1(%rip), %rax     # 0x3c3fe0
movq (%rax), %rdi
movq -0x120(%rbp), %rcx
leaq 0xa4915(%rip), %rsi     # 0x394a55
leaq 0xa4931(%rip), %rdx     # 0x394a78
movb $0x0, %al
callq 0x22a0
movq -0x120(%rbp), %rax
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
nop