// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: dedup_sort_contains(ul_ov_t*, long, ul_contain*, ug_opt_t const*)
int64_t dedup_sort_contains(ul_ov_t *a, int64_t a_n, ul_contain *ct, const ug_opt_t *uopt)
{
	int64_t k, l, ci; ul_ov_t *z = NULL;
	for (k = 0; k < a_n; k++) {
		z = &(a[k]);
		if(z->tn&((uint32_t)(0x80000000))) continue;///contained alignment
		if(ct->is_c.a[z->tn] == 0) continue;

		for (ci = k+1; ci < a_n; ci++) {
			if(a[ci].qe > z->qe + G_CHAIN_INDEL) break;///128 is for indel
			if(a[ci].qn == (uint32_t)-1) continue;
			if(!(a[ci].tn&((uint32_t)(0x80000000)))) continue;
			if(z->qs <= a[ci].qs + G_CHAIN_INDEL && z->qe + G_CHAIN_INDEL >= a[ci].qe) {
				if(check_contain_pair(uopt, (a[ci].tn<<1)>>1, z->tn,  1)) {
					a[ci].qn = (uint32_t)-1;
				}
			}
		}

		for (ci = k-1; ci >= 0; ci--) {
			if(a[ci].qe + G_CHAIN_INDEL <= z->qs) break;
			if(a[ci].qn == (uint32_t)-1) continue;
			if(!(a[ci].tn&((uint32_t)(0x80000000)))) continue;
			if(z->qs <= a[ci].qs + G_CHAIN_INDEL && z->qe + G_CHAIN_INDEL >= a[ci].qe) {
				if(check_contain_pair(uopt, (a[ci].tn<<1)>>1, z->tn,  1)) {
					a[ci].qn = (uint32_t)-1;
				}
			}
		}
	}
	for (k = l = 0; k < a_n; k++) {
		if(a[k].qn == (uint32_t)-1) continue;
		if(k != l) a[l] = a[k];
		a[l].tn <<= 1; a[l].tn >>= 1;
		++l;
	}
	return l;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, 0x10(%rsp)
movq %rdx, 0x20(%rsp)
movq %rsi, %r8
testq %rsi, %rsi
jle 0x1a41c4
leaq 0x1c(%rdi), %r9
leaq -0x1c(%rdi), %rbx
movl $0x1, %r13d
xorl %r12d, %r12d
movq %r8, 0x8(%rsp)
movq %rdi, (%rsp)
leaq (%r12,%r12,8), %rax
leaq (%rax,%rax,2), %r14
addq %r12, %r14
movslq 0xc(%rdi,%r14), %rax
testq %rax, %rax
js 0x1a41ad
movq 0x20(%rsp), %rcx
movq 0x40(%rcx), %rcx
cmpb $0x0, (%rcx,%rax)
je 0x1a41ad
addq %rdi, %r14
leaq 0x1(%r12), %r15
cmpq %r8, %r15
movq %r9, 0x18(%rsp)
jge 0x1a4130
movq %r9, %rbp
movl 0x8(%r14), %eax
subl $-0x80, %eax
cmpl %eax, 0x8(%rbp)
ja 0x1a4130
cmpl $-0x1, (%rbp)
je 0x1a4124
movl 0xc(%rbp), %esi
testl %esi, %esi
jns 0x1a4124
movl 0x4(%rbp), %eax
subl $-0x80, %eax
cmpl %eax, 0x4(%r14)
ja 0x1a4124
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movl 0xc(%r14), %edx
movq 0x10(%rsp), %rdi
movl $0x1, %ecx
callq 0x1a1266
movq 0x18(%rsp), %r9
movq (%rsp), %rdi
movq 0x8(%rsp), %r8
testl %eax, %eax
je 0x1a4124
movl $0xffffffff, (%rbp)     # imm = 0xFFFFFFFF
incq %r15
addq $0x1c, %rbp
cmpq %r8, %r15
jl 0x1a40cd
testq %r12, %r12
je 0x1a41ad
movq %rbx, %rbp
movq %r13, %r15
movl 0x8(%rbp), %eax
leal 0x80(%rax), %edx
movl 0x4(%r14), %ecx
cmpl %ecx, %edx
jbe 0x1a41ad
cmpl $-0x1, (%rbp)
je 0x1a41a0
movl 0xc(%rbp), %esi
testl %esi, %esi
jns 0x1a41a0
movl 0x4(%rbp), %edx
subl $-0x80, %edx
cmpl %edx, %ecx
ja 0x1a41a0
movl 0x8(%r14), %ecx
subl $-0x80, %ecx
cmpl %eax, %ecx
jb 0x1a41a0
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movl 0xc(%r14), %edx
movq 0x10(%rsp), %rdi
movl $0x1, %ecx
callq 0x1a1266
movq 0x18(%rsp), %r9
movq (%rsp), %rdi
movq 0x8(%rsp), %r8
testl %eax, %eax
je 0x1a41a0
movl $0xffffffff, (%rbp)     # imm = 0xFFFFFFFF
decq %r15
addq $-0x1c, %rbp
cmpq $0x1, %r15
jg 0x1a413b
incq %r12
addq $0x1c, %r9
incq %r13
addq $0x1c, %rbx
cmpq %r8, %r12
jne 0x1a408c
xorl %eax, %eax
testq %r8, %r8
jle 0x1a4214
movq %rdi, %rcx
xorl %edx, %edx
cmpl $-0x1, (%rcx)
je 0x1a4208
cmpq %rax, %rdx
je 0x1a41f5
leaq (%rax,%rax,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rax, %rsi
movups (%rcx), %xmm0
movups 0xc(%rcx), %xmm1
movups %xmm1, 0xc(%rdi,%rsi)
movups %xmm0, (%rdi,%rsi)
leaq (%rax,%rax,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rax, %rsi
andb $0x7f, 0xf(%rdi,%rsi)
incq %rax
incq %rdx
addq $0x1c, %rcx
cmpq %rdx, %r8
jne 0x1a41d0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq