// File: /workspace/github_cpp_makefile_star2_O3/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 $0x38, %rsp
movq %rcx, 0x10(%rsp)
movq %rdx, 0x30(%rsp)
testq %rsi, %rsi
jle 0x1ad452
movq %rsi, %r8
leaq 0x1c(%rdi), %r10
leaq -0x1c(%rdi), %r9
movl $0x1, %ebp
xorl %r14d, %r14d
movq %rsi, 0x8(%rsp)
movq %rdi, (%rsp)
leaq (%r14,%r14,8), %rax
leaq (%rax,%rax,2), %r13
addq %r14, %r13
movslq 0xc(%rdi,%r13), %rdx
testq %rdx, %rdx
js 0x1ad3e9
movq 0x30(%rsp), %rax
movq 0x40(%rax), %rax
cmpb $0x0, (%rax,%rdx)
je 0x1ad3e9
addq %rdi, %r13
leaq 0x1(%r14), %rbx
cmpq %r8, %rbx
movq %r10, 0x28(%rsp)
movq %r9, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
jge 0x1ad35f
movl 0x8(%r13), %r15d
subl $-0x80, %r15d
movq %r10, %r12
cmpl %r15d, 0x8(%r12)
ja 0x1ad35f
cmpl $-0x1, (%r12)
je 0x1ad353
movl 0xc(%r12), %esi
testl %esi, %esi
jns 0x1ad353
movl 0x4(%r12), %eax
subl $-0x80, %eax
cmpl %eax, 0x4(%r13)
ja 0x1ad353
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movq 0x10(%rsp), %rdi
movl $0x1, %ecx
callq 0x1a9fdf
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %r9
movq 0x28(%rsp), %r10
movq (%rsp), %rdi
movq 0x8(%rsp), %r8
testl %eax, %eax
je 0x1ad353
movl $0xffffffff, (%r12)     # imm = 0xFFFFFFFF
incq %rbx
addq $0x1c, %r12
cmpq %r8, %rbx
jl 0x1ad2f5
testq %r14, %r14
je 0x1ad3e9
movl 0x4(%r13), %ebx
movq %r9, %r15
movq %rbp, %r12
movl 0x8(%r15), %eax
leal 0x80(%rax), %ecx
cmpl %ebx, %ecx
jbe 0x1ad3e9
cmpl $-0x1, (%r15)
je 0x1ad3dc
movl 0xc(%r15), %esi
testl %esi, %esi
jns 0x1ad3dc
movl 0x4(%r15), %ecx
subl $-0x80, %ecx
cmpl %ecx, %ebx
ja 0x1ad3dc
movl 0x8(%r13), %ecx
subl $-0x80, %ecx
cmpl %eax, %ecx
jb 0x1ad3dc
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movq 0x10(%rsp), %rdi
movl $0x1, %ecx
callq 0x1a9fdf
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %r9
movq 0x28(%rsp), %r10
movq (%rsp), %rdi
movq 0x8(%rsp), %r8
testl %eax, %eax
je 0x1ad3dc
movl $0xffffffff, (%r15)     # imm = 0xFFFFFFFF
decq %r12
addq $-0x1c, %r15
cmpq $0x1, %r12
jg 0x1ad372
incq %r14
addq $0x1c, %r10
incq %rbp
addq $0x1c, %r9
cmpq %r8, %r14
jne 0x1ad2a3
testq %r8, %r8
jle 0x1ad452
xorl %eax, %eax
movq %rdi, %rcx
xorl %edx, %edx
cmpl $-0x1, (%rcx)
je 0x1ad444
cmpq %rax, %rdx
je 0x1ad431
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 0x1ad40c
jmp 0x1ad454
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq