// File: 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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x10(%rbp), %rax
jge 0x29507e
movq -0x8(%rbp), %rax
imulq $0x1c, -0x28(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl 0xc(%rax), %eax
andl $0x80000000, %eax       # imm = 0x80000000
cmpl $0x0, %eax
je 0x294e4c
jmp 0x29506d
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x40(%rbp), %rcx
movl 0xc(%rcx), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x294e69
jmp 0x29506d
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x10(%rbp), %rax
jge 0x294f6d
movq -0x8(%rbp), %rax
imulq $0x1c, -0x38(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq -0x40(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl $0x80, %ecx
cmpl %ecx, %eax
jbe 0x294ea8
jmp 0x294f6d
movq -0x8(%rbp), %rax
imulq $0x1c, -0x38(%rbp), %rcx
addq %rcx, %rax
cmpl $-0x1, (%rax)
jne 0x294ebe
jmp 0x294f5c
movq -0x8(%rbp), %rax
imulq $0x1c, -0x38(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
andl $0x80000000, %eax       # imm = 0x80000000
cmpl $0x0, %eax
jne 0x294edc
jmp 0x294f5c
movq -0x40(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x8(%rbp), %rcx
imulq $0x1c, -0x38(%rbp), %rdx
addq %rdx, %rcx
movl 0x4(%rcx), %ecx
addl $0x80, %ecx
cmpl %ecx, %eax
ja 0x294f5a
movq -0x40(%rbp), %rax
movl 0x8(%rax), %eax
addl $0x80, %eax
movq -0x8(%rbp), %rcx
imulq $0x1c, -0x38(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
jb 0x294f5a
movq -0x20(%rbp), %rdi
movq -0x8(%rbp), %rax
imulq $0x1c, -0x38(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %esi
shll %esi
shrl %esi
movq -0x40(%rbp), %rax
movl 0xc(%rax), %edx
movl $0x1, %ecx
callq 0x28fce0
cmpl $0x0, %eax
je 0x294f58
movq -0x8(%rbp), %rax
imulq $0x1c, -0x38(%rbp), %rcx
addq %rcx, %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
jmp 0x294f5a
jmp 0x294f5c
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x294e75
movq -0x28(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jl 0x29506b
movq -0x8(%rbp), %rax
imulq $0x1c, -0x38(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
addl $0x80, %eax
movq -0x40(%rbp), %rcx
cmpl 0x4(%rcx), %eax
ja 0x294fa6
jmp 0x29506b
movq -0x8(%rbp), %rax
imulq $0x1c, -0x38(%rbp), %rcx
addq %rcx, %rax
cmpl $-0x1, (%rax)
jne 0x294fbc
jmp 0x29505a
movq -0x8(%rbp), %rax
imulq $0x1c, -0x38(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
andl $0x80000000, %eax       # imm = 0x80000000
cmpl $0x0, %eax
jne 0x294fda
jmp 0x29505a
movq -0x40(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x8(%rbp), %rcx
imulq $0x1c, -0x38(%rbp), %rdx
addq %rdx, %rcx
movl 0x4(%rcx), %ecx
addl $0x80, %ecx
cmpl %ecx, %eax
ja 0x295058
movq -0x40(%rbp), %rax
movl 0x8(%rax), %eax
addl $0x80, %eax
movq -0x8(%rbp), %rcx
imulq $0x1c, -0x38(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
jb 0x295058
movq -0x20(%rbp), %rdi
movq -0x8(%rbp), %rax
imulq $0x1c, -0x38(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %esi
shll %esi
shrl %esi
movq -0x40(%rbp), %rax
movl 0xc(%rax), %edx
movl $0x1, %ecx
callq 0x28fce0
cmpl $0x0, %eax
je 0x295056
movq -0x8(%rbp), %rax
imulq $0x1c, -0x38(%rbp), %rcx
addq %rcx, %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
jmp 0x295058
jmp 0x29505a
movq -0x38(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x294f79
jmp 0x29506d
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x294e18
movq $0x0, -0x30(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x10(%rbp), %rax
jge 0x295132
movq -0x8(%rbp), %rax
imulq $0x1c, -0x28(%rbp), %rcx
addq %rcx, %rax
cmpl $-0x1, (%rax)
jne 0x2950af
jmp 0x295121
movq -0x28(%rbp), %rax
cmpq -0x30(%rbp), %rax
je 0x2950ed
movq -0x8(%rbp), %rcx
imulq $0x1c, -0x28(%rbp), %rax
addq %rax, %rcx
movq -0x8(%rbp), %rax
imulq $0x1c, -0x30(%rbp), %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rax)
movl 0x18(%rcx), %ecx
movl %ecx, 0x18(%rax)
movq -0x8(%rbp), %rax
imulq $0x1c, -0x30(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
shll %ecx
movl %ecx, 0xc(%rax)
movq -0x8(%rbp), %rax
imulq $0x1c, -0x30(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
shrl %ecx
movl %ecx, 0xc(%rax)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x29508e
movq -0x30(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)