// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Hash_Table.cpp
// Function: filter_non_ovlp_chains(overlap_region*, long, long*)
int64_t filter_non_ovlp_chains(overlap_region *a, int64_t a_n, int64_t *n_v)
{
    int64_t k, i, n_mchain, omx, omy, opx, opy, ovx, ovy, os, oe; overlap_region *m, *p, t;
    for (k = n_mchain = (*n_v) = 0; k < a_n; k++) {
		m = &(a[k]); 
        omx = m->x_pos_e + 1 - m->x_pos_s;
        omy = m->y_pos_e + 1 - m->y_pos_s;
		for (i = 0; i < n_mchain; i++) {
			p = &(a[i]);
            opx = p->x_pos_e + 1 - p->x_pos_s;
            opy = p->y_pos_e + 1 - p->y_pos_s;

            os = ((m->x_pos_s>=p->x_pos_s)? m->x_pos_s:p->x_pos_s);
            oe = ((m->x_pos_e<=p->x_pos_e)? m->x_pos_e:p->x_pos_e) + 1;
			ovx = oe>os?oe-os:0;
            if((ovx > omx*0.1) || (ovx > opx*0.1)) break;

            os = ((m->y_pos_s>=p->y_pos_s)? m->y_pos_s:p->y_pos_s);
            oe = ((m->y_pos_e<=p->y_pos_e)? m->y_pos_e:p->y_pos_e) + 1;
			ovy = oe>os?oe-os:0;
			if((ovy > omy*0.1) || (ovy > opy*0.1)) break;
		}
		if(i < n_mchain) continue;

        if (n_mchain != k) {
            t = a[k]; a[k] = a[n_mchain]; a[n_mchain] = t;
        }
        (*n_v) += a[n_mchain].align_length;
		n_mchain++;
	}
	return n_mchain;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rsi, %r14
movq %rdi, %r15
movq %rdx, 0x10(%rsp)
andq $0x0, (%rdx)
xorl %ecx, %ecx
testq %rsi, %rsi
movl $0x0, %eax
movq %rax, 0x8(%rsp)
cmovleq %rcx, %r14
leaq 0x18(%rdi), %rax
movq %rax, 0x18(%rsp)
movsd 0x1cdf85(%rip), %xmm4   # 0x1e2bf0
xorl %r13d, %r13d
xorl %ebx, %ebx
cmpq %r14, %rbx
je 0x14e0c
imulq $0xa8, %rbx, %rax
leaq (%r15,%rax), %rbp
movl 0x4(%r15,%rax), %ecx
movl 0x8(%r15,%rax), %edx
movl %edx, %r8d
subl %ecx, %r8d
incl %r8d
movl 0x18(%r15,%rax), %esi
movl 0x14(%r15,%rax), %edi
movl %esi, %eax
subl %edi, %eax
incl %eax
cvtsi2sd %r8, %xmm0
cvtsi2sd %rax, %xmm1
mulsd %xmm4, %xmm0
mulsd %xmm4, %xmm1
testq %r13, %r13
movl $0x0, %r8d
cmovgq %r13, %r8
incq %r8
movq 0x18(%rsp), %r9
decq %r8
je 0x14d88
movl -0x14(%r9), %r10d
cmpl %r10d, %ecx
movl %r10d, %r12d
cmoval %ecx, %r12d
movl -0x10(%r9), %eax
cmpl %eax, %edx
movl %eax, %r11d
cmovbl %edx, %r11d
incl %r11d
cmpl %r12d, %r11d
ja 0x14d00
xorpd %xmm2, %xmm2
jmp 0x14d08
subq %r12, %r11
cvtsi2sd %r11, %xmm2
ucomisd %xmm0, %xmm2
ja 0x14e04
subl %r10d, %eax
incl %eax
cvtsi2sd %rax, %xmm3
mulsd %xmm4, %xmm3
ucomisd %xmm3, %xmm2
ja 0x14e04
movl -0x4(%r9), %r10d
cmpl %r10d, %edi
movl %r10d, %r12d
cmoval %edi, %r12d
movl (%r9), %r11d
cmpl %r11d, %esi
movl %r11d, %eax
cmovbl %esi, %eax
incl %eax
cmpl %r12d, %eax
ja 0x14d51
xorpd %xmm2, %xmm2
jmp 0x14d59
subq %r12, %rax
cvtsi2sd %rax, %xmm2
ucomisd %xmm1, %xmm2
ja 0x14e04
subl %r10d, %r11d
incl %r11d
movl %r11d, %eax
cvtsi2sd %rax, %xmm3
addq $0xa8, %r9
mulsd %xmm4, %xmm3
ucomisd %xmm3, %xmm2
jbe 0x14cce
jmp 0x14e04
cmpq %rbx, %r13
je 0x14de0
movl $0xa8, %edx
leaq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x2160
imulq $0xa8, %r13, %r12
addq %r15, %r12
movl $0xa8, %edx
movq %rbp, %rdi
movq %r12, %rsi
callq 0x2160
movl $0xa8, %edx
movq %r12, %rdi
leaq 0x20(%rsp), %rsi
callq 0x2160
movsd 0x1cde1d(%rip), %xmm4   # 0x1e2bf0
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x8(%rsp)
imulq $0xa8, %r13, %rax
movl 0x28(%r15,%rax), %eax
movq 0x8(%rsp), %rdx
addq %rax, %rdx
movq 0x10(%rsp), %rax
movq %rdx, 0x8(%rsp)
movq %rdx, (%rax)
incq %r13
incq %rbx
jmp 0x14c70
movq %r13, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq