// File: 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:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movsd %xmm0, -0x20(%rbp)
cmpl $0x0, -0x14(%rbp)
ja 0x2bb80b
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x2bbdb4
movl $0x0, -0x28(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x2bb9cd
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movl $0x0, (%rax)
movq -0x70(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x70(%rbp), %rcx
subl 0x4(%rcx), %eax
movl %eax, %eax
movq %rax, -0x58(%rbp)
movq -0x70(%rbp), %rax
movl 0x18(%rax), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, %eax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rcx
movq -0x58(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
shlq $0x0, %rax
cvtsi2sd %rax, %xmm1
cvtsi2sdq -0x60(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd 0xcafb0(%rip), %xmm2    # 0x386858
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x50(%rbp)
movq -0x70(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x70(%rbp), %rcx
subl 0x10(%rcx), %eax
movl %eax, %eax
movq %rax, -0x58(%rbp)
movq -0x70(%rbp), %rax
movl 0x18(%rax), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, %eax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rcx
movq -0x58(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
shlq $0x0, %rax
cvtsi2sd %rax, %xmm1
cvtsi2sdq -0x60(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd 0xcaf38(%rip), %xmm2    # 0x386858
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x48(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
jg 0x2bb948
movq -0x50(%rbp), %rax
movq %rax, -0xa0(%rbp)
jmp 0x2bb953
movq -0x48(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
jg 0x2bb967
jmp 0x2bb9bf
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x68(%rbp)
jl 0x2bb97b
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movl %eax, %ecx
movq -0x70(%rbp), %rax
movl %ecx, (%rax)
movq -0x70(%rbp), %rcx
movq -0x10(%rbp), %rax
movl -0x28(%rbp), %edx
movl %edx, %esi
addl $0x1, %esi
movl %esi, -0x28(%rbp)
movl %edx, %edx
imulq $0x1c, %rdx, %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)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2bb819
movl -0x28(%rbp), %eax
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
ja 0x2bb9e4
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x2bbdb4
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %eax
imulq $0x1c, %rax, %rax
addq %rax, %rsi
callq 0x27c310
movl $0x0, -0x24(%rbp)
movl -0x14(%rbp), %eax
shrl %eax
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
jae 0x2bbad4
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x94(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x8c(%rbp)
movq 0x10(%rax), %rcx
movq %rcx, -0x84(%rbp)
movl 0x18(%rax), %eax
movl %eax, -0x7c(%rbp)
movq -0x10(%rbp), %rcx
movl -0x14(%rbp), %eax
subl -0x24(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
imulq $0x1c, %rax, %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %edx
imulq $0x1c, %rdx, %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 -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
subl -0x24(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq -0x94(%rbp), %rcx
movq %rcx, (%rax)
movq -0x8c(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x84(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0x7c(%rbp), %ecx
movl %ecx, 0x18(%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2bba0a
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x2bbd7b
movq -0x10(%rbp), %rax
movl -0x2c(%rbp), %ecx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x70(%rbp), %rcx
subl 0x4(%rcx), %eax
movl %eax, -0x30(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
jae 0x2bbd21
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x78(%rbp), %rcx
cmpl 0x8(%rcx), %eax
ja 0x2bbb55
movq -0x70(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0xa4(%rbp)
jmp 0x2bbb62
movq -0x78(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0xa4(%rbp)
movl -0xa4(%rbp), %eax
movl %eax, -0xa8(%rbp)
movq -0x70(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x78(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jb 0x2bbb8d
movq -0x70(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0xac(%rbp)
jmp 0x2bbb9a
movq -0x78(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0xac(%rbp)
movl -0xa8(%rbp), %eax
movl -0xac(%rbp), %ecx
cmpl %ecx, %eax
jbe 0x2bbc24
movq -0x70(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x78(%rbp), %rcx
cmpl 0x8(%rcx), %eax
ja 0x2bbbc9
movq -0x70(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0xb0(%rbp)
jmp 0x2bbbd6
movq -0x78(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0xb0(%rbp)
movl -0xb0(%rbp), %eax
movl %eax, -0xb4(%rbp)
movq -0x70(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x78(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jb 0x2bbc01
movq -0x70(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0xb8(%rbp)
jmp 0x2bbc0e
movq -0x78(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0xb8(%rbp)
movl -0xb4(%rbp), %eax
movl -0xb8(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0xbc(%rbp)
jmp 0x2bbc2e
xorl %eax, %eax
movl %eax, -0xbc(%rbp)
jmp 0x2bbc2e
movl -0xbc(%rbp), %eax
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
jne 0x2bbc42
jmp 0x2bbd13
movq -0x78(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x78(%rbp), %rcx
subl 0x4(%rcx), %eax
movl %eax, -0x34(%rbp)
movq -0x78(%rbp), %rax
movl (%rax), %eax
movq -0x70(%rbp), %rcx
cmpl (%rcx), %eax
ja 0x2bbc6f
movq -0x78(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xc0(%rbp)
jmp 0x2bbc7b
movq -0x70(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xc0(%rbp)
movl -0xc0(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x78(%rbp), %rax
movl (%rax), %eax
movq -0x70(%rbp), %rcx
cmpl (%rcx), %eax
jb 0x2bbca0
movq -0x78(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xc4(%rbp)
jmp 0x2bbcac
movq -0x70(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xc4(%rbp)
movl -0xc4(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
cvtsi2sd %rax, %xmm1
movl -0x40(%rbp), %eax
cvtsi2sd %rax, %xmm0
movsd 0xc6553(%rip), %xmm2    # 0x382220
mulsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jb 0x2bbd11
movl -0x38(%rbp), %eax
cvtsi2sd %rax, %xmm0
movl -0x30(%rbp), %eax
cvtsi2sd %rax, %xmm1
mulsd -0x20(%rbp), %xmm1
ucomisd %xmm1, %xmm0
ja 0x2bbd0d
movl -0x38(%rbp), %eax
cvtsi2sd %rax, %xmm0
movl -0x34(%rbp), %eax
cvtsi2sd %rax, %xmm1
mulsd -0x20(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x2bbd0f
jmp 0x2bbd21
jmp 0x2bbd11
jmp 0x2bbd13
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2bbb18
movl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
jae 0x2bbd2b
jmp 0x2bbd6d
movq -0x10(%rbp), %rcx
movl -0x2c(%rbp), %eax
imulq $0x1c, %rax, %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movl -0x28(%rbp), %edx
movl %edx, %esi
addl $0x1, %esi
movl %esi, -0x28(%rbp)
movl %edx, %edx
imulq $0x1c, %rdx, %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)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2bbae2
movl -0x28(%rbp), %eax
movl %eax, -0x14(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x2bbdae
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %rax
movl -0x2c(%rbp), %edx
imulq $0x1c, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2bbd88
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq