// File: /workspace/github_cpp_makefile_star2_O1/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 0x1b9e03
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %r14
movl %esi, %ecx
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rax
addq %rcx, %rax
xorl %ecx, %ecx
movsd 0x7002d(%rip), %xmm3    # 0x229b80
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
xorl %ebx, %ebx
movl $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
xorps %xmm1, %xmm1
cvtsi2sd %rsi, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %r8d, %xmm2
mulsd %xmm3, %xmm2
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %r9
subl 0x10(%r14,%rcx), %edi
subq %r8, %rdi
xorps %xmm1, %xmm1
cvtsi2sd %rdi, %xmm1
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %rsi
cmpq %rsi, %r9
cmovlq %r9, %rsi
testq %rsi, %rsi
jle 0x1b9bf3
leaq (%r14,%rcx), %rdi
cmpq %r10, %rsi
cmovgeq %r10, %rsi
movl %esi, (%rdi)
movl %ebx, %esi
incl %ebx
leaq (%rsi,%rsi,8), %r8
leaq (%r8,%r8,2), %r8
addq %rsi, %r8
movups 0xc(%rdi), %xmm1
movups %xmm1, 0xc(%r14,%r8)
movupd (%rdi), %xmm1
movupd %xmm1, (%r14,%r8)
addq $0x1c, %rcx
cmpq %rcx, %rax
jne 0x1b9b5b
testl %ebx, %ebx
je 0x1b9e06
movsd %xmm0, 0x10(%rsp)
movl %edx, 0x4(%rsp)
movl %ebx, %esi
leaq (%rsi,%rsi,8), %rax
leaq (%rax,%rax,2), %rax
addq %r14, %rsi
addq %rax, %rsi
movq %r14, %rdi
callq 0x195d3d
cmpl $0x1, %ebx
je 0x1b9ca3
movl %ebx, %edx
shrl %edx
cmpl $0x1, %edx
adcl $0x0, %edx
leal -0x1(%rbx), %eax
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdx, %rcx
xorl %edx, %edx
movups (%r14,%rdx), %xmm0
movups 0xc(%r14,%rdx), %xmm1
movups %xmm1, 0x2c(%rsp)
movaps %xmm0, 0x20(%rsp)
movl %eax, %esi
leaq (%rsi,%rsi,8), %rdi
leaq (%rdi,%rdi,2), %rdi
addq %rsi, %rdi
movups (%r14,%rdi), %xmm0
movupd 0xc(%r14,%rdi), %xmm1
movupd %xmm1, 0xc(%r14,%rdx)
movups %xmm0, (%r14,%rdx)
movups 0x2c(%rsp), %xmm0
movups %xmm0, 0xc(%r14,%rdi)
movaps 0x20(%rsp), %xmm0
movups %xmm0, (%r14,%rdi)
addq $0x1c, %rdx
decl %eax
cmpq %rdx, %rcx
jne 0x1b9c49
cmpl $0x1, %ebx
adcl $0x0, %ebx
xorl %ecx, %ecx
movsd 0x6b7e5(%rip), %xmm0    # 0x225498
xorl %edx, %edx
xorl %eax, %eax
movsd 0x10(%rsp), %xmm4
movq %rbx, 0x18(%rsp)
leaq (%rdx,%rdx,8), %rsi
leaq (%rsi,%rsi,2), %r9
addq %rdx, %r9
leaq (%r14,%r9), %rsi
movl %eax, %edi
movq %rdi, 0x8(%rsp)
movl %eax, (%rsp)
testl %eax, %eax
je 0x1b9d9c
movl 0x4(%r14,%r9), %r8d
movl 0x8(%r14,%r9), %r9d
movl %r9d, %r10d
subl %r8d, %r10d
xorps %xmm1, %xmm1
cvtsi2sd %r10, %xmm1
mulsd %xmm4, %xmm1
movq 0x8(%rsp), %rax
leaq (%rax,%rax,8), %r10
leaq (%r10,%r10,2), %r10
addq %rax, %r10
xorl %r11d, %r11d
movl 0x4(%r14,%r11), %ebx
movl 0x8(%r14,%r11), %r12d
cmpl %r12d, %r9d
movl %r12d, %r13d
cmovbl %r9d, %r13d
cmpl %ebx, %r8d
movl %ebx, %ebp
cmoval %r8d, %ebp
subl %ebp, %r13d
cmovbl %ecx, %r13d
jbe 0x1b9d8f
movl (%r14,%r11), %ebp
movl (%rsi), %r15d
cmpl %r15d, %ebp
movl %r15d, %edi
cmovbl %ebp, %edi
cmoval %ebp, %r15d
xorps %xmm2, %xmm2
cvtsi2sd %rdi, %xmm2
xorps %xmm3, %xmm3
cvtsi2sd %r15, %xmm3
mulsd %xmm0, %xmm3
ucomisd %xmm2, %xmm3
jb 0x1b9d8f
movl %r13d, %edi
xorps %xmm2, %xmm2
cvtsi2sd %rdi, %xmm2
ucomisd %xmm1, %xmm2
ja 0x1b9dc9
subl %ebx, %r12d
movl %r12d, %edi
xorps %xmm3, %xmm3
cvtsi2sd %rdi, %xmm3
mulsd %xmm4, %xmm3
ucomisd %xmm3, %xmm2
ja 0x1b9dc9
addq $0x1c, %r11
cmpq %r11, %r10
jne 0x1b9d12
movl (%rsp), %eax
incl %eax
movq 0x8(%rsp), %r8
leaq (%r8,%r8,8), %rdi
leaq (%rdi,%rdi,2), %rdi
addq %r8, %rdi
movupd (%rsi), %xmm1
movupd 0xc(%rsi), %xmm2
movupd %xmm2, 0xc(%r14,%rdi)
movupd %xmm1, (%r14,%rdi)
jmp 0x1b9dcc
movl (%rsp), %eax
incq %rdx
movq 0x18(%rsp), %rbx
cmpq %rbx, %rdx
jne 0x1b9cc2
testl %eax, %eax
je 0x1b9e08
movl %eax, %edx
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdx, %rcx
xorl %edx, %edx
movl 0x4(%rsp), %esi
movl %esi, (%r14,%rdx)
addq $0x1c, %rdx
cmpq %rdx, %rcx
jne 0x1b9df4
jmp 0x1b9e08
xorl %eax, %eax
retq
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq