// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rdi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
leaq 0x50(%rsp), %r12
xorl %r13d, %r13d
movl $0xc8, %edx
movq %r12, %rdi
xorl %esi, %esi
callq 0x20e0
movups 0x20(%rbx), %xmm0
movups %xmm0, 0x18(%r12)
movq 0x10(%rbx), %rax
movq %rax, -0x8(%r12)
movq %rbx, 0x8(%rsp)
movq 0x58(%rbx), %r15
pushq $0x8
popq %rsi
movq %r15, %rdi
callq 0x2120
movq %rax, %r14
movq %rax, 0x78(%r12)
pushq $0x68
popq %rsi
movq %r15, %rdi
callq 0x2120
movq %rax, 0x80(%r12)
pushq $0x1
popq %rbp
cmpq %r15, %r13
jae 0x1931f0
xorl %edi, %edi
xorl %esi, %esi
movl %ebp, %edx
callq 0xc44b
movq %rax, (%r14,%r13,8)
incq %r13
movq 0x8(%rsp), %rax
movq 0x58(%rax), %r15
jmp 0x1931ce
pushq $0x1
popq %rax
xorl %ebx, %ebx
leaq 0x48(%rsp), %r14
movq 0x8(%rsp), %rbp
testq %rax, %rax
je 0x1933ad
movq %rbx, 0x28(%rsp)
movq 0x68(%rsp), %rax
movl 0x14(%rax), %eax
addl %eax, %eax
movslq %eax, %rcx
movl %r15d, %edi
leaq 0x24e(%rip), %rsi       # 0x193472
movq %r14, %rdx
callq 0xc67c0
andq $0x0, 0x10(%rsp)
pushq $0x58
popq %rbx
xorl %r15d, %r15d
cmpq 0x58(%rbp), %r15
jae 0x193294
movq 0xd0(%rsp), %rax
movq (%rax,%rbx), %r14
movq %r14, 0x40(%rsp)
movq -0x10(%rax,%rbx), %r12
movq %r12, 0x30(%rsp)
movq -0x8(%rax,%rbx), %r13
movq %r13, 0x38(%rsp)
leaq 0x30(%rsp), %rdi
movq %r15, %rsi
leaq 0x10(%rsp), %rdx
callq 0x192377
movq 0xd0(%rsp), %rax
movq %r14, (%rax,%rbx)
movq %r12, -0x10(%rax,%rbx)
movq %r13, -0x8(%rax,%rbx)
incq %r15
addq $0x68, %rbx
jmp 0x193238
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %r15
leaq (,%r14,8), %r8
movq %r8, %r13
negq %r13
xorl %r12d, %r12d
leaq (%r14,%r12), %rcx
cmpq %r12, %r14
je 0x193341
movq 0xd0(%rsp), %rdx
movq (%r15,%r12,8), %rsi
movl %esi, %edi
shrq $0x20, %rsi
imulq $0x68, %rsi, %rsi
movq 0x58(%rdx,%rsi), %rdx
movq (%rdx,%rdi,8), %rbx
cmpl $-0x1, %ebx
jne 0x193453
cmpq %rax, %rcx
jne 0x19331d
leaq (%rax,%rax), %rbp
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %rbp
leaq (,%rbp,8), %rsi
movq %r15, %rdi
movq %r8, %r15
callq 0x2370
movq %r15, %r8
movq %rax, %r15
movq %rbp, %rax
movq 0x8(%rsp), %rbp
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rcx, %rbx
addq %r12, %rbx
leaq (%r15,%r8), %rcx
movq %rbx, (%rcx,%r12,8)
incq %r12
addq $-0x8, %r13
jmp 0x1932b4
movq %r15, 0x20(%rsp)
movq %rcx, 0x10(%rsp)
movq %rax, 0x18(%rsp)
leaq (%r15,%r14,8), %r14
movq %r15, %rsi
subq %r13, %rsi
movq %r14, %rdi
callq 0x156b0d
movq 0x68(%rsp), %rdi
movq %r15, %rsi
movq %r14, %rcx
movq %r12, %r8
leaq 0x48(%rsp), %r14
movq %r14, %r9
callq 0x192c6b
movq 0x58(%rbp), %r15
movq 0xd0(%rsp), %rcx
addq $0x48, %rcx
movq %r15, %rdx
movq 0x28(%rsp), %rbx
subq $0x1, %rdx
jb 0x1933a5
andq $0x0, (%rcx)
addq $0x68, %rcx
jmp 0x193395
addq %rax, %rbx
jmp 0x1931ff
xorl %r14d, %r14d
xorl %r12d, %r12d
movq 0xc8(%rsp), %rdi
cmpq %r15, %r12
jae 0x193400
movq (%rdi,%r12,8), %rdi
movl 0xf0(%rdi), %eax
addl %eax, 0x88(%rsp)
movl 0xf8(%rdi), %eax
addl %eax, 0x80(%rsp)
callq 0xc5d1
movq 0xd0(%rsp), %rdi
addq %r14, %rdi
callq 0x15a8d7
incq %r12
movq 0x58(%rbp), %r15
addq $0x68, %r14
jmp 0x1933b3
callq 0x2220
movq 0xd0(%rsp), %rdi
callq 0x2220
movq 0x20(%rsp), %rdi
callq 0x2220
movq 0xbfbbd(%rip), %rax     # 0x252fe0
movq (%rax), %rdi
leaq 0x6291c(%rip), %rsi     # 0x1f5d49
leaq 0x62938(%rip), %rdx     # 0x1f5d6c
movq %rbx, %rcx
xorl %eax, %eax
callq 0x22b0
movq %rbx, %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6287a(%rip), %rdi     # 0x1f5cd4
leaq 0x5e6c2(%rip), %rsi     # 0x1f1b23
leaq 0x628b7(%rip), %rcx     # 0x1f5d1f
movl $0x4bea, %edx           # imm = 0x4BEA
callq 0x2110