// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/inter.cpp
// Function: filter_sec_trans_ovlp(ul_ov_t*, unsigned int, unsigned int, double)
uint32_t filter_sec_trans_ovlp(ul_ov_t *a, uint32_t a_n, uint32_t qn, double sec_rate)
{
	if(a_n <= 0) return a_n;
	uint32_t i, m, k, oz, op, ovlp, min_sc, max_sc; int64_t nw[2], ml, uml, msc; ul_ov_t *z, *p, t;
	for (i = m = 0; i < a_n; i++) {
		z = &(a[i]); z->qn = 0;
		ml = z->qe - z->qs; uml = z->sec; ml -= uml;
		nw[0] = (ml*CHAIN_MATCH) - (uml*CHAIN_UNMATCH);
		ml = z->te - z->ts; uml = z->sec; ml -= uml;
		nw[1] = (ml*CHAIN_MATCH) - (uml*CHAIN_UNMATCH);
		msc = MIN(nw[0], nw[1]);
		if(msc <= 0) continue;
		if(msc >= UINT32_MAX) msc = UINT32_MAX;
		z->qn = msc; 
		a[m++] = (*z);
	}
	a_n = m;
	if(a_n <= 0) return a_n;
	radix_sort_ul_ov_srt_qn(a, a + a_n);//sort by scores
	for (i = 0, m = (a_n>>1); i < m; i++) {
		t = a[i]; a[i] = a[a_n-i-1]; a[a_n-i-1] = t;
	}

	for (k = m = 0; k < a_n; k++) {
		z = &a[k]; oz = z->qe - z->qs; ///current chain
		for (i = 0; i < m; i++) {
			p = &(a[i]);
			ovlp = ((MIN(z->qe, p->qe) > MAX(z->qs, p->qs))? (MIN(z->qe, p->qe) - MAX(z->qs, p->qs)):0);
			if(ovlp == 0) continue;
			op = p->qe - p->qs;
			min_sc = MIN(p->qn, z->qn); max_sc = MAX(p->qn, z->qn);
			if(min_sc <= (max_sc*0.95)) {
				if((ovlp > (oz*sec_rate)) || (ovlp > (op*sec_rate))) break;
			}
		}
		if(i < m) continue;
		a[m++] = a[k]; 
	}
	a_n = m;
	for (k = 0; k < a_n; k++) a[k].qn = qn;
	return a_n;
}

// Assembly:
testl %esi, %esi
je 0x17882e
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r14
movl %edx, 0x4(%rsp)
movl %esi, %eax
imulq $0x1c, %rax, %rax
xorl %ecx, %ecx
movsd 0x6f65a(%rip), %xmm3    # 0x1e7c78
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %ebp, %ebp
movl %ebp, %r15d
cmpq %rcx, %rax
je 0x1786bd
andl $0x0, (%r14,%rcx)
movl 0x8(%r14,%rcx), %esi
movl 0x14(%r14,%rcx), %edi
subl 0x4(%r14,%rcx), %esi
movl 0x18(%r14,%rcx), %r8d
andl $0x3fffffff, %r8d       # imm = 0x3FFFFFFF
subq %r8, %rsi
cvtsi2sd %rsi, %xmm1
cvtsi2sd %r8d, %xmm2
mulsd %xmm3, %xmm2
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %r9
subl 0x10(%r14,%rcx), %edi
subq %r8, %rdi
cvtsi2sd %rdi, %xmm1
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %rsi
cmpq %rsi, %r9
cmovlq %r9, %rsi
testq %rsi, %rsi
jle 0x1786b4
cmpq %rdx, %rsi
cmovaeq %rdx, %rsi
leaq (%r14,%rcx), %rdi
movl %esi, (%rdi)
incl %ebp
imulq $0x1c, %r15, %rsi
movups 0xc(%rdi), %xmm1
movups %xmm1, 0xc(%r14,%rsi)
movupd (%rdi), %xmm1
movupd %xmm1, (%r14,%rsi)
addq $0x1c, %rcx
jmp 0x178625
testl %ebp, %ebp
je 0x178831
imulq $0x1c, %r15, %rsi
addq %r14, %rsi
movq %r14, %rdi
movsd %xmm0, 0x8(%rsp)
callq 0x15775d
movsd 0x8(%rsp), %xmm4
movl %ebp, %eax
shrl %eax
imulq $0x1c, %rax, %rax
decl %ebp
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x178741
movups (%r14,%rcx), %xmm0
movups 0xc(%r14,%rcx), %xmm1
movups %xmm1, 0x1c(%rsp)
movaps %xmm0, 0x10(%rsp)
movl %ebp, %edx
imulq $0x1c, %rdx, %rdx
movups (%r14,%rdx), %xmm0
movupd 0xc(%r14,%rdx), %xmm1
movupd %xmm1, 0xc(%r14,%rcx)
movups %xmm0, (%r14,%rcx)
movups 0x1c(%rsp), %xmm0
movups %xmm0, 0xc(%r14,%rdx)
movaps 0x10(%rsp), %xmm0
movups %xmm0, (%r14,%rdx)
addq $0x1c, %rcx
decl %ebp
jmp 0x1786ec
xorl %ecx, %ecx
movsd 0x6ad9d(%rip), %xmm0    # 0x1e34e8
xorl %eax, %eax
movl %eax, %r8d
cmpq %r15, %rcx
je 0x178815
imulq $0x1c, %rcx, %rdi
movl 0x4(%r14,%rdi), %edx
movl 0x8(%r14,%rdi), %esi
movl %esi, %r9d
subl %edx, %r9d
cvtsi2sd %r9, %xmm1
addq %r14, %rdi
mulsd %xmm4, %xmm1
imulq $0x1c, %r8, %r8
xorl %r9d, %r9d
cmpq %r9, %r8
je 0x1787f5
movl 0x4(%r14,%r9), %r10d
movl 0x8(%r14,%r9), %r11d
cmpl %r11d, %esi
movl %r11d, %r12d
cmovbl %esi, %r12d
cmpl %r10d, %edx
movl %r10d, %ebp
cmoval %edx, %ebp
subl %ebp, %r12d
jbe 0x1787ef
movl (%r14,%r9), %ebp
movl (%rdi), %r13d
cmpl %r13d, %ebp
movl %r13d, %ebx
cmovbl %ebp, %ebx
cmoval %ebp, %r13d
cvtsi2sd %rbx, %xmm2
cvtsi2sd %r13, %xmm3
mulsd %xmm0, %xmm3
ucomisd %xmm2, %xmm3
jb 0x1787ef
cvtsi2sd %r12, %xmm2
ucomisd %xmm1, %xmm2
ja 0x17880d
subl %r10d, %r11d
movl %r11d, %r10d
cvtsi2sd %r10, %xmm3
mulsd %xmm4, %xmm3
ucomisd %xmm3, %xmm2
ja 0x17880d
addq $0x1c, %r9
jmp 0x178780
incl %eax
movupd (%rdi), %xmm1
movupd 0xc(%rdi), %xmm2
movupd %xmm2, 0xc(%r14,%r8)
movupd %xmm1, (%r14,%r8)
incq %rcx
jmp 0x17874d
imulq $0x1c, %r8, %rcx
xorl %edx, %edx
movl 0x4(%rsp), %esi
cmpq %rdx, %rcx
je 0x178833
movl %esi, (%r14,%rdx)
addq $0x1c, %rdx
jmp 0x17881f
xorl %eax, %eax
retq
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq