// File: /workspace/github_cpp_makefile_star2_O3/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, %rbp
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rsp)
leaq 0x50(%rsp), %r15
xorl %r13d, %r13d
movl $0xc8, %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x20e0
movdqu 0x20(%rbp), %xmm0
movdqu %xmm0, 0x18(%r15)
movq 0x10(%rbp), %rax
movq %rax, -0x8(%r15)
movq 0x58(%rbp), %r12
addq $0x58, %rbp
movl $0x8, %esi
movq %r12, %rdi
callq 0x2120
movq %rax, %r14
movq %rax, 0x78(%r15)
movl $0x68, %esi
movq %r12, %rdi
callq 0x2120
movq %rax, 0x80(%r15)
testq %r12, %r12
je 0x1e05fb
xorl %ebx, %ebx
xorl %edi, %edi
xorl %esi, %esi
movl $0x1, %edx
callq 0x387f4
movq %rax, (%r14,%rbx,8)
incq %rbx
movq (%rbp), %r13
cmpq %r13, %rbx
jb 0x1e05dd
xorl %ebx, %ebx
leaq 0x48(%rsp), %r12
movq %rbp, 0x28(%rsp)
movq 0x68(%rsp), %rax
movl 0x14(%rax), %eax
addl %eax, %eax
movslq %eax, %rcx
movl %r13d, %edi
leaq 0x2f1(%rip), %rsi       # 0x1e090f
movq %r12, %rdx
callq 0x108f2c
movq $0x0, 0x8(%rsp)
cmpq $0x0, (%rbp)
je 0x1e0737
movq %rbx, 0x20(%rsp)
movl $0x58, %r14d
movq 0xd0(%rsp), %rax
xorl %r13d, %r13d
movq (%rax,%r14), %rbx
movq %rbx, 0x40(%rsp)
movq -0x10(%rax,%r14), %r15
movq %r15, 0x30(%rsp)
movq -0x8(%rax,%r14), %r12
movq %r12, 0x38(%rsp)
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
leaq 0x8(%rsp), %rdx
callq 0x1df5f8
movq 0xd0(%rsp), %rax
movq %rbx, (%rax,%r14)
movq %r15, -0x10(%rax,%r14)
movq %r12, -0x8(%rax,%r14)
incq %r13
addq $0x68, %r14
cmpq (%rbp), %r13
jb 0x1e0650
movq 0x8(%rsp), %r15
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %r13
testq %r15, %r15
je 0x1e0748
xorl %r12d, %r12d
movq %r15, %rbp
movq 0xd0(%rsp), %rax
movq (%r13,%r12,8), %rcx
movl %ecx, %edx
shrq $0x20, %rcx
imulq $0x68, %rcx, %rcx
movq 0x58(%rax,%rcx), %rax
movq (%rax,%rdx,8), %rbx
cmpl $-0x1, %ebx
jne 0x1e08f0
cmpq %r14, %rbp
jne 0x1e0715
leaq (,%rbp,2), %r14
testq %rbp, %rbp
movl $0x2, %eax
cmoveq %rax, %r14
leaq (,%r14,8), %rsi
movq %r13, %rdi
callq 0x2370
movq %rax, %r13
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
andq %rax, %rbx
addq %r12, %rbx
movq %rbx, (%r13,%rbp,8)
incq %rbp
incq %r12
cmpq %r15, %r12
jne 0x1e06c0
jmp 0x1e074d
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %r13
xorl %r15d, %r15d
xorl %ebp, %ebp
jmp 0x1e0757
xorl %r15d, %r15d
xorl %ebp, %ebp
movq 0x20(%rsp), %rbx
leaq 0x48(%rsp), %r12
movq %r13, 0x18(%rsp)
movq %rbp, 0x8(%rsp)
movq %r14, 0x10(%rsp)
leaq (,%r15,8), %r14
addq %r13, %r14
leaq (,%rbp,8), %rsi
addq %r13, %rsi
subq %r15, %rbp
movq %r14, %rdi
callq 0x19dd99
movq 0x68(%rsp), %rdi
movq %r13, %rsi
movq %r14, %rcx
movq %rbp, %r8
movq %r12, %r9
callq 0x1dffd5
movq 0x28(%rsp), %rbp
movq (%rbp), %r13
testq %r13, %r13
je 0x1e0864
leaq 0x1(%r13), %rcx
andq $-0x2, %rcx
leaq -0x1(%r13), %rdx
movq %rdx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movq 0xd0(%rsp), %rdx
movl $0xb0, %esi
addq %rsi, %rdx
movdqa 0x50b03(%rip), %xmm5    # 0x2312e0
pxor %xmm5, %xmm0
movdqa 0x50ae7(%rip), %xmm1    # 0x2312d0
pcmpeqd %xmm6, %xmm6
movdqa 0x50d0b(%rip), %xmm7    # 0x231500
movdqa %xmm1, %xmm2
pxor %xmm5, %xmm2
movdqa %xmm2, %xmm3
pcmpgtd %xmm0, %xmm3
pcmpeqd %xmm0, %xmm2
pshufd $0xf5, %xmm2, %xmm4     # xmm4 = xmm2[1,1,3,3]
pand %xmm3, %xmm4
pshufd $0xf5, %xmm3, %xmm2     # xmm2 = xmm3[1,1,3,3]
por %xmm4, %xmm2
movd %xmm2, %esi
notl %esi
testb $0x1, %sil
je 0x1e082f
movq $0x0, -0x68(%rdx)
pxor %xmm6, %xmm2
pextrw $0x4, %xmm2, %esi
testb $0x1, %sil
je 0x1e0845
movq $0x0, (%rdx)
paddq %xmm7, %xmm1
addq $0xd0, %rdx
addq $-0x2, %rcx
jne 0x1e07f5
addq %rax, %rbx
testq %rax, %rax
jne 0x1e0607
jmp 0x1e0878
addq %rax, %rbx
movl $0x0, %r13d
testq %rax, %rax
jne 0x1e0607
jmp 0x1e0895
leaq 0x48(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
leaq 0xd0(%rsp), %rdx
movq %rbp, %rcx
callq 0x29962
movq 0xc8(%rsp), %rdi
callq 0x2220
movq 0xd0(%rsp), %rdi
callq 0x2220
movq 0x18(%rsp), %rdi
callq 0x2220
movq 0xb4720(%rip), %rax     # 0x294fe0
movq (%rax), %rdi
leaq 0x635b7(%rip), %rsi     # 0x243e81
leaq 0x635d3(%rip), %rdx     # 0x243ea4
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 0x63515(%rip), %rdi     # 0x243e0c
leaq 0x5f35d(%rip), %rsi     # 0x23fc5b
leaq 0x63552(%rip), %rcx     # 0x243e57
movl $0x4bea, %edx           # imm = 0x4BEA
callq 0x2110