// File: /workspace/github_cpp_makefile_star2_O1/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 $0x128, %rsp            # imm = 0x128
movq %rdi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
leaq 0x58(%rsp), %r14
movl $0xd0, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x20e0
movq 0x28(%rbx), %rax
movq %rax, 0x28(%r14)
movq 0x20(%rbx), %rax
movq %rax, 0x20(%r14)
movq 0x10(%rbx), %rax
movq %rax, (%r14)
movq 0x58(%rbx), %r15
movl $0x8, %esi
movq %r15, %rdi
callq 0x2120
movq %rax, 0x80(%r14)
movl $0x68, %esi
movq %r15, %rdi
callq 0x2120
movq %rax, 0x88(%r14)
movq %rbx, 0x8(%rsp)
cmpq $0x0, 0x58(%rbx)
je 0x1d6733
xorl %r14d, %r14d
xorl %edi, %edi
xorl %esi, %esi
movl $0x1, %edx
callq 0x39240
movq 0xd8(%rsp), %rcx
movq %rax, (%rcx,%r14,8)
incq %r14
movq 0x8(%rsp), %rax
cmpq 0x58(%rax), %r14
jb 0x1d670b
xorl %r12d, %r12d
leaq 0x58(%rsp), %r14
leaq 0x40(%rsp), %rbx
leaq 0x10(%rsp), %r13
movq %r12, 0x30(%rsp)
movq 0x8(%rsp), %r15
movl 0x58(%r15), %edi
movq 0x78(%rsp), %rax
movl 0x14(%rax), %eax
addl %eax, %eax
movslq %eax, %rcx
leaq 0x295(%rip), %rsi       # 0x1d69fc
movq %r14, %rdx
callq 0x1047b4
movq $0x0, 0x10(%rsp)
cmpq $0x0, 0x58(%r15)
je 0x1d67f0
movq %r13, %r12
movl $0x58, %r14d
xorl %r15d, %r15d
movq 0xe0(%rsp), %rax
movq (%rax,%r14), %rcx
movq %rcx, 0x38(%rsp)
movq %rcx, 0x50(%rsp)
movq -0x10(%rax,%r14), %r13
movq %r13, 0x40(%rsp)
movq -0x8(%rax,%r14), %rbp
movq %rbp, 0x48(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x1d5679
movq 0xe0(%rsp), %rax
movq 0x38(%rsp), %rcx
movq %rcx, (%rax,%r14)
movq %r13, -0x10(%rax,%r14)
movq %rbp, -0x8(%rax,%r14)
incq %r15
addq $0x68, %r14
movq 0x8(%rsp), %rax
cmpq 0x58(%rax), %r15
jb 0x1d678b
movq 0x10(%rsp), %r13
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %r15
testq %r13, %r13
je 0x1d688f
leaq (,%r13,8), %r14
xorl %r12d, %r12d
leaq (%r12,%r13), %rcx
movq 0xe0(%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), %rbp
cmpl $-0x1, %ebp
jne 0x1d69ce
cmpq %rax, %rcx
jne 0x1d686a
leaq (%rax,%rax), %rbx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rbx
leaq (,%rbx,8), %rsi
movq %r15, %rdi
callq 0x2370
movq %rax, %r15
movq %rbx, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rcx, %rbp
addq %r12, %rbp
leaq (%r15,%r14), %rcx
movq %rbp, (%rcx,%r12,8)
incq %r12
cmpq %r12, %r13
jne 0x1d6813
addq %r13, %r12
jmp 0x1d6892
movq %r13, %r12
movq %r15, 0x20(%rsp)
movq %r12, 0x10(%rsp)
movq %rax, 0x18(%rsp)
leaq (%r15,%r13,8), %r14
leaq (%r15,%r12,8), %rsi
subq %r13, %r12
movq %r14, %rdi
callq 0x194fef
movq 0x78(%rsp), %rdi
movq %r15, %rsi
movq %r14, %rcx
movq %r12, %r8
leaq 0x58(%rsp), %r14
movq %r14, %r9
callq 0x1d60c2
movq 0x8(%rsp), %rcx
movq 0x58(%rcx), %rcx
testq %rcx, %rcx
leaq 0x40(%rsp), %rbx
leaq 0x10(%rsp), %r13
je 0x1d6903
movq 0xe0(%rsp), %rdx
addq $0x48, %rdx
movq $0x0, (%rdx)
addq $0x68, %rdx
decq %rcx
jne 0x1d68f3
movq 0x30(%rsp), %r12
addq %rax, %r12
testq %rax, %rax
jne 0x1d6745
movq 0x8(%rsp), %rax
cmpq $0x0, 0x58(%rax)
je 0x1d6973
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0xd8(%rsp), %rax
movq (%rax,%r15,8), %rdi
movl 0xf0(%rdi), %eax
addl %eax, 0x98(%rsp)
movl 0xf8(%rdi), %eax
addl %eax, 0x90(%rsp)
callq 0x395cd
movq 0xe0(%rsp), %rdi
addq %r14, %rdi
callq 0x19912e
incq %r15
addq $0x68, %r14
movq 0x8(%rsp), %rax
cmpq 0x58(%rax), %r15
jb 0x1d6926
movq 0xd8(%rsp), %rdi
callq 0x2220
movq 0xe0(%rsp), %rdi
callq 0x2220
movq 0x20(%rsp), %rdi
callq 0x2220
movq 0xb3642(%rip), %rax     # 0x289fe0
movq (%rax), %rdi
leaq 0x61209(%rip), %rsi     # 0x237bb1
leaq 0x61225(%rip), %rdx     # 0x237bd4
movq %r12, %rcx
xorl %eax, %eax
callq 0x22b0
movq %r12, %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, 0x20(%rsp)
movq %rcx, 0x10(%rsp)
movq %rax, 0x18(%rsp)
leaq 0x61158(%rip), %rdi     # 0x237b3c
leaq 0x5cfa0(%rip), %rsi     # 0x23398b
leaq 0x61195(%rip), %rcx     # 0x237b87
movl $0x4bea, %edx           # imm = 0x4BEA
callq 0x2110