// File: /workspace/github_cpp_makefile_star2_O3/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 0x1c3c2a
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, %ebx
movq %rdi, %r14
movl %esi, %ecx
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rax
addq %rcx, %rax
xorl %ecx, %ecx
movsd 0x724ab(%rip), %xmm3    # 0x235d78
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %ebp, %ebp
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 0x1c396c
leaq (%r14,%rcx), %rdi
cmpq %rdx, %rsi
cmovaeq %rdx, %rsi
movl %esi, (%rdi)
movl %ebp, %esi
incl %ebp
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 0x1c38d4
testl %ebp, %ebp
je 0x1c3c19
movsd %xmm0, 0x10(%rsp)
movl %ebp, %ecx
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
movq %rcx, 0x18(%rsp)
addq %r14, %rsi
addq %rcx, %rsi
movq %r14, %rdi
callq 0x19ead4
cmpl $0x1, %ebp
je 0x1c3a04
movl %ebp, %eax
shrl %eax
decl %ebp
movq %r14, %rcx
movups (%rcx), %xmm0
movups 0xc(%rcx), %xmm1
movups %xmm1, 0x2c(%rsp)
movaps %xmm0, 0x20(%rsp)
movl %ebp, %edx
leaq (%rdx,%rdx,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rdx, %rsi
movups (%r14,%rsi), %xmm0
movupd 0xc(%r14,%rsi), %xmm1
movupd %xmm1, 0xc(%rcx)
movups %xmm0, (%rcx)
movups 0x2c(%rsp), %xmm0
movups %xmm0, 0xc(%r14,%rsi)
movaps 0x20(%rsp), %xmm0
movups %xmm0, (%r14,%rsi)
addq $0x1c, %rcx
decl %ebp
decq %rax
jne 0x1c39b2
xorl %ecx, %ecx
movsd 0x6db8a(%rip), %xmm0    # 0x231598
xorl %eax, %eax
movsd 0x10(%rsp), %xmm4
movl %ebx, 0xc(%rsp)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rsi
addq %rcx, %rsi
leaq (%r14,%rsi), %rdx
testl %eax, %eax
je 0x1c3ae2
movl 0x4(%r14,%rsi), %edi
movl 0x8(%r14,%rsi), %r8d
movl %r8d, %esi
subl %edi, %esi
xorps %xmm1, %xmm1
cvtsi2sd %rsi, %xmm1
mulsd %xmm4, %xmm1
movl %eax, %esi
leaq (%rsi,%rsi,8), %r9
leaq (%r9,%r9,2), %r9
addq %rsi, %r9
xorl %r10d, %r10d
movl 0x4(%r14,%r10), %r11d
movl 0x8(%r14,%r10), %ebp
cmpl %ebp, %r8d
movl %ebp, %r12d
cmovbl %r8d, %r12d
cmpl %r11d, %edi
movl %r11d, %r13d
cmoval %edi, %r13d
subl %r13d, %r12d
jbe 0x1c3ad3
movl (%r14,%r10), %r13d
movl (%rdx), %ebx
cmpl %ebx, %r13d
movl %ebx, %r15d
cmovbl %r13d, %r15d
cmoval %r13d, %ebx
xorps %xmm2, %xmm2
cvtsi2sd %r15, %xmm2
xorps %xmm3, %xmm3
cvtsi2sd %rbx, %xmm3
mulsd %xmm0, %xmm3
ucomisd %xmm2, %xmm3
jb 0x1c3ad3
xorps %xmm2, %xmm2
cvtsi2sd %r12, %xmm2
ucomisd %xmm1, %xmm2
ja 0x1c3b09
subl %r11d, %ebp
movl %ebp, %r11d
xorps %xmm3, %xmm3
cvtsi2sd %r11, %xmm3
mulsd %xmm4, %xmm3
ucomisd %xmm3, %xmm2
ja 0x1c3b09
addq $0x1c, %r10
cmpq %r10, %r9
jne 0x1c3a5c
movl 0xc(%rsp), %ebx
jmp 0x1c3ae4
xorl %esi, %esi
incl %eax
leaq (%rsi,%rsi,8), %rdi
leaq (%rdi,%rdi,2), %rdi
addq %rsi, %rdi
movupd (%rdx), %xmm1
movupd 0xc(%rdx), %xmm2
movupd %xmm2, 0xc(%r14,%rdi)
movupd %xmm1, (%r14,%rdi)
jmp 0x1c3b0d
movl 0xc(%rsp), %ebx
incq %rcx
cmpq 0x18(%rsp), %rcx
jne 0x1c3a1a
testl %eax, %eax
je 0x1c3c19
movl %eax, %ecx
leaq 0x3(%rcx), %rdx
decq %rcx
movq %rcx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
shrq $0x2, %rdx
imulq $0x70, %rdx, %rcx
movdqa 0x6d77a(%rip), %xmm1    # 0x2312c0
movdqa 0x6d782(%rip), %xmm2    # 0x2312d0
xorl %edx, %edx
movdqa 0x6d788(%rip), %xmm3    # 0x2312e0
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
movdqa 0x6d9c8(%rip), %xmm5    # 0x231530
movdqa %xmm2, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
movd %xmm6, %esi
notl %esi
testb $0x1, %sil
je 0x1c3ba1
movl %ebx, (%r14,%rdx)
pxor %xmm4, %xmm6
pextrw $0x4, %xmm6, %esi
testb $0x1, %sil
je 0x1c3bb5
movl %ebx, 0x1c(%r14,%rdx)
movdqa %xmm1, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
pxor %xmm4, %xmm6
pextrw $0x0, %xmm6, %esi
testb $0x1, %sil
je 0x1c3bf2
movl %ebx, 0x38(%r14,%rdx)
pextrw $0x4, %xmm6, %esi
testb $0x1, %sil
je 0x1c3c02
movl %ebx, 0x54(%r14,%rdx)
paddq %xmm5, %xmm2
paddq %xmm5, %xmm1
addq $0x70, %rdx
cmpq %rdx, %rcx
jne 0x1c3b68
jmp 0x1c3c1b
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
retq