// File: /workspace/github_cpp_makefile_star2_O2/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, 0x28(%rsp)
movq %rsi, %r15
xorl %r11d, %r11d
testq %rsi, %rsi
movl $0x0, %r8d
cmovgq %rsi, %r8
leaq 0x1c(%rdi), %r13
leaq -0x1c(%rdi), %r10
pushq $0x1
popq %r12
movq %rdi, 0x18(%rsp)
movq %rsi, 0x8(%rsp)
movq %r8, 0x30(%rsp)
cmpq %r8, %r11
je 0x164b1e
imulq $0x1c, %r11, %rbx
movslq 0xc(%rdi,%rbx), %rax
testq %rax, %rax
js 0x164b06
movq 0x28(%rsp), %rcx
movq 0x40(%rcx), %rcx
cmpb $0x0, (%rcx,%rax)
je 0x164b06
addq %rdi, %rbx
movq %r13, %r14
movq %r12, %rbp
movq %r12, 0x20(%rsp)
cmpq %r15, %rbp
jge 0x164a85
movl 0x8(%rbx), %eax
subl $-0x80, %eax
cmpl %eax, 0x8(%r14)
ja 0x164a85
cmpl $-0x1, (%r14)
je 0x164a7c
movl 0xc(%r14), %esi
testl %esi, %esi
jns 0x164a7c
movl 0x4(%r14), %eax
subl $-0x80, %eax
cmpl %eax, 0x4(%rbx)
ja 0x164a7c
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movl 0xc(%rbx), %edx
movq 0x10(%rsp), %rdi
pushq $0x1
popq %rcx
movq %r10, %r15
movq %r11, %r12
callq 0x162035
movq %r12, %r11
movq 0x20(%rsp), %r12
movq %r15, %r10
movq 0x8(%rsp), %r15
movq 0x18(%rsp), %rdi
testl %eax, %eax
je 0x164a7c
orl $-0x1, (%r14)
incq %rbp
addq $0x1c, %r14
jmp 0x164a18
movq %r10, %r14
movq %r11, %rbp
testq %rbp, %rbp
jle 0x164b06
movl 0x8(%r14), %eax
leal 0x80(%rax), %edx
movl 0x4(%rbx), %ecx
cmpl %ecx, %edx
jbe 0x164b06
cmpl $-0x1, (%r14)
je 0x164afd
movl 0xc(%r14), %esi
testl %esi, %esi
jns 0x164afd
movl 0x4(%r14), %edx
subl $-0x80, %edx
cmpl %edx, %ecx
ja 0x164afd
movl 0x8(%rbx), %ecx
subl $-0x80, %ecx
cmpl %eax, %ecx
jb 0x164afd
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movl 0xc(%rbx), %edx
movq 0x10(%rsp), %rdi
pushq $0x1
popq %rcx
movq %r10, %r15
movq %r11, %r12
callq 0x162035
movq %r12, %r11
movq 0x20(%rsp), %r12
movq %r15, %r10
movq 0x8(%rsp), %r15
movq 0x18(%rsp), %rdi
testl %eax, %eax
je 0x164afd
orl $-0x1, (%r14)
addq $-0x1c, %r14
decq %rbp
jmp 0x164a8b
incq %r11
incq %r12
addq $0x1c, %r13
addq $0x1c, %r10
movq 0x30(%rsp), %r8
jmp 0x1649dc
xorl %ecx, %ecx
movq %rdi, %rdx
xorl %eax, %eax
cmpq %rcx, %r8
je 0x164b5d
cmpl $-0x1, (%rdx)
je 0x164b54
cmpq %rax, %rcx
je 0x164b48
imulq $0x1c, %rax, %rsi
movups (%rdx), %xmm0
movups 0xc(%rdx), %xmm1
movups %xmm1, 0xc(%rdi,%rsi)
movups %xmm0, (%rdi,%rsi)
imulq $0x1c, %rax, %rsi
andb $0x7f, 0xf(%rdi,%rsi)
incq %rax
incq %rcx
addq $0x1c, %rdx
jmp 0x164b25
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq