// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/inter.cpp
// Function: rm_dup_aln(u_trans_t*, unsigned long, asg64_v*, double)
void rm_dup_aln(u_trans_t *u, uint64_t u_n, asg64_v *b, double dup_cut)
{
	if(u_n <= 0) return;
	uint64_t k, m, s, e, dp, old_dp, z, zs, ze, l, os, oe, ovq, cut; u_trans_t t;
	b->n = 0;
	for (k = 0; k < u_n; k++) {
		s = u[k].qs; e = u[k].qe; u[k].occ = 0;
		kv_push(uint64_t, *b, (s<<1)); 
		kv_push(uint64_t, *b, (e<<1|1));
	}
	radix_sort_gfa64(b->a, b->a + b->n);

	for (k = dp = old_dp = m = 0, s = e = (uint64_t)-1; k < b->n; k++) {
		old_dp = dp;
        //if a[j] is qe
        if (b->a[k]&1) --dp;
        else ++dp;

		if (old_dp < 2 && dp >= 2) {///old_dp < dp, b.a[k] is qs
            s = b->a[k]>>1;
        } else if (old_dp >= 2 && dp < 2) {///old_dp > min_dp, b.a[k] is qe
            e = b->a[k]>>1;
			if(e > s) b->a[m++] = (s<<32)|e;///non-unique region
        }
	}

	b->n = m;
	for (k = m = 0; k < u_n; k++) {
		l = 0; s = u[k].qs; e = u[k].qe; 
		cut = (e - s)*dup_cut; 
		if(!(u[k].f)) {//unreliable
			for (z = 0; z < b->n; z++) {
				zs = (b->a[z]>>32); ze = ((uint32_t)b->a[z]);
				if(zs >= e) break;
				if(ze <= s) continue;
				os = MAX(s, zs); oe = MIN(e, ze);
				ovq = ((oe > os)? (oe - os):0);
				l += ovq;
				if(l > cut) break;
			}
		}
		if(((l <= 0) || (l <= cut)) && (l < (e - s))) {
			if(m != k) { t = u[m]; u[m] = u[k]; u[k] = t;}
			m++;
		}
	}

	for (k = m; k < u_n; k++) u[k].del = 1;///delete 

	for (k = b->n = 0; k < m; k++) {
		dp = u[k].nw; dp <<= 32; dp |= k; kv_push(uint64_t, *b, dp);
	}
	radix_sort_gfa64(b->a, b->a + b->n); old_dp = 0;
	for (k = 0; k < b->n; k++) {
		assert(!u[((uint32_t)b->a[k])].del);
		for (z = 0; z < b->n; z++) {
			if(k == z) continue;
			if(u[((uint32_t)b->a[z])].del) continue;
			if(u[((uint32_t)b->a[k])].qs >= u[((uint32_t)b->a[z])].qs && u[((uint32_t)b->a[k])].qe <= u[((uint32_t)b->a[z])].qe) break;
		}
		if(z < b->n) {
			u[((uint32_t)b->a[k])].del = 1; old_dp++;
		}
	}

	if(old_dp) {
		for (k = m = 0; k < u_n; k++) {
			if(u[k].del) continue;
			if(m != k) { t = u[m]; u[m] = u[k]; u[k] = t;}
			m++;
		}
	}


	///for debug is there is any contained overlaps in u[0, m)
	for (k = 0; k < m; k++) {
		for (z = 0; z < m; z++) {
			if(k == z) continue;
			if(u[k].qs >= u[z].qs && u[k].qe <= u[z].qe) break;
		}
		assert(z >= m);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %xmm0, 0x10(%rsp)
testq %rsi, %rsi
je 0x18d26f
movq %rdx, %r15
movq %rdi, %rbx
andq $0x0, (%rdx)
movq %rdi, %r12
movq %rsi, 0x8(%rsp)
movq %rsi, %rbp
subq $0x1, %rbp
jb 0x18ce5b
movl (%r12), %r14d
movl 0x4(%r12), %r13d
andl $0x0, 0x18(%r12)
movq (%r15), %rcx
movq 0x10(%r15), %rax
cmpq 0x8(%r15), %rcx
jne 0x18ce03
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r15)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r15)
movq (%r15), %rcx
addq %r14, %r14
leaq 0x1(%rcx), %rdx
movq %rdx, (%r15)
movq %r14, (%rax,%rcx,8)
movq (%r15), %rcx
cmpq 0x8(%r15), %rcx
jne 0x18ce3f
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r15)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r15)
movq (%r15), %rcx
leaq 0x1(,%r13,2), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r15)
movq %rdx, (%rax,%rcx,8)
addq $0x30, %r12
jmp 0x18cdb8
movq (%r15), %rax
movq 0x10(%r15), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x156b0d
pushq $-0x1
popq %rax
xorl %esi, %esi
xorl %ecx, %ecx
xorl %edx, %edx
cmpq (%r15), %rdx
jae 0x18ceeb
movq %rsi, %r9
movq 0x10(%r15), %r8
movq (%r8,%rdx,8), %rdi
movl %edi, %esi
andl $0x1, %esi
negq %rsi
orq $0x1, %rsi
addq %r9, %rsi
cmpq $0x2, %r9
setb %r10b
cmpq $0x2, %rsi
setae %r11b
andb %r10b, %r11b
cmpb $0x1, %r11b
jne 0x18ceb4
shrq %rdi
movq %rdi, %rax
jmp 0x18cee6
cmpq $0x2, %r9
setae %r9b
cmpq $0x2, %rsi
setb %r10b
andb %r9b, %r10b
cmpb $0x1, %r10b
jne 0x18cee6
shrq %rdi
cmpq %rax, %rdi
jbe 0x18cee6
movq %rax, %r9
shlq $0x20, %r9
orq %r9, %rdi
movq %rdi, (%r8,%rcx,8)
incq %rcx
incq %rdx
jmp 0x18ce74
movq %rcx, (%r15)
xorl %r12d, %r12d
movq 0x56377(%rip), %xmm0    # 0x1e3270
movapd 0x5637f(%rip), %xmm1    # 0x1e3280
movsd 0x5638f(%rip), %xmm5    # 0x1e3298
xorl %eax, %eax
cmpq 0x8(%rsp), %rax
je 0x18d055
imulq $0x30, %rax, %rcx
movl (%rbx,%rcx), %esi
movl 0x4(%rbx,%rcx), %edi
movq %rdi, %rdx
subq %rsi, %rdx
movq %rdx, %xmm2
punpckldq %xmm0, %xmm2    # xmm2 = xmm2[0],xmm0[0],xmm2[1],xmm0[1]
subpd %xmm1, %xmm2
movapd %xmm2, %xmm3
unpckhpd %xmm2, %xmm3            # xmm3 = xmm3[1],xmm2[1]
addsd %xmm2, %xmm3
mulsd 0x10(%rsp), %xmm3
cvttsd2si %xmm3, %r9
movq %r9, %r10
sarq $0x3f, %r10
subsd %xmm5, %xmm3
cvttsd2si %xmm3, %r8
andq %r10, %r8
orq %r9, %r8
testb $0x3f, 0x28(%rbx,%rcx)
je 0x18cff6
xorl %r9d, %r9d
testq %r9, %r9
sete %sil
cmpq %r8, %r9
setbe %dil
orb %sil, %dil
cmpb $0x1, %dil
jne 0x18cfee
cmpq %rdx, %r9
jae 0x18cfee
cmpq %rax, %r12
je 0x18cfeb
addq %rbx, %rcx
imulq $0x30, %r12, %rdx
movups (%rbx,%rdx), %xmm2
movups 0x10(%rbx,%rdx), %xmm3
movups 0x20(%rbx,%rdx), %xmm4
movaps %xmm4, 0x40(%rsp)
movaps %xmm3, 0x30(%rsp)
movaps %xmm2, 0x20(%rsp)
movups (%rcx), %xmm2
movups 0x10(%rcx), %xmm3
movups 0x20(%rcx), %xmm4
movups %xmm4, 0x20(%rbx,%rdx)
movups %xmm3, 0x10(%rbx,%rdx)
movups %xmm2, (%rbx,%rdx)
movapd 0x20(%rsp), %xmm2
movapd 0x30(%rsp), %xmm3
movaps 0x40(%rsp), %xmm4
movups %xmm4, 0x20(%rcx)
movupd %xmm3, 0x10(%rcx)
movupd %xmm2, (%rcx)
incq %r12
incq %rax
jmp 0x18cf0b
movq (%r15), %r10
xorl %r11d, %r11d
xorl %r9d, %r9d
cmpq %r11, %r10
je 0x18cf6f
movq 0x10(%r15), %r14
movq (%r14,%r11,8), %r13
movq %r13, %r14
shrq $0x20, %r14
cmpq %rdi, %r14
jae 0x18cf6f
movl %r13d, %r13d
cmpl %esi, %r13d
jbe 0x18d050
cmpq %rsi, %r14
cmovbeq %rsi, %r14
cmpq %rdi, %r13
jb 0x18d037
movq %rdi, %r13
subq %r14, %r13
movl $0x0, %r14d
cmovaeq %r13, %r14
addq %r14, %r9
cmpq %r8, %r9
ja 0x18cf6f
incq %r11
jmp 0x18cfff
imulq $0x30, %r12, %rax
addq %rbx, %rax
addq $0x28, %rax
movq %r12, %rcx
cmpq 0x8(%rsp), %rcx
jae 0x18d076
orb $-0x80, (%rax)
incq %rcx
addq $0x30, %rax
jmp 0x18d063
andq $0x0, (%r15)
leaq 0x20(%rbx), %rbp
xorl %r13d, %r13d
cmpq %r13, %r12
je 0x18d11c
movsd (%rbp), %xmm1
movapd %xmm1, %xmm0
subsd %xmm5, %xmm0
movq (%r15), %rcx
movq 0x10(%r15), %rax
cmpq 0x8(%r15), %rcx
jne 0x18d0e9
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r15)
shlq $0x3, %rsi
movq %rax, %rdi
movapd %xmm0, 0x10(%rsp)
movapd %xmm1, 0x50(%rsp)
callq 0x2370
movapd 0x50(%rsp), %xmm1
movapd 0x10(%rsp), %xmm0
movsd 0x561b6(%rip), %xmm5    # 0x1e3298
movq %rax, 0x10(%r15)
movq (%r15), %rcx
cvttsd2si %xmm1, %rdx
movq %rdx, %rsi
sarq $0x3f, %rsi
cvttsd2si %xmm0, %rdi
andl %esi, %edi
orl %edi, %edx
shlq $0x20, %rdx
orq %r13, %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r15)
movq %rdx, (%rax,%rcx,8)
incq %r13
addq $0x30, %rbp
jmp 0x18d081
movq (%r15), %rax
movq 0x10(%r15), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x156b0d
xorl %eax, %eax
xorl %ecx, %ecx
movq (%r15), %rdx
cmpq %rdx, %rcx
jae 0x18d1a2
movq 0x10(%r15), %rsi
movl (%rsi,%rcx,8), %edi
imulq $0x30, %rdi, %r8
movb 0x28(%rbx,%r8), %dil
testb %dil, %dil
js 0x18d29d
leaq (%rbx,%r8), %r9
addq $0x28, %r9
addq %rbx, %r8
xorl %r10d, %r10d
cmpq %r10, %rdx
je 0x18d19d
cmpq %r10, %rcx
je 0x18d18e
movl (%rsi,%r10,8), %r11d
imulq $0x30, %r11, %r11
cmpb $0x0, 0x28(%rbx,%r11)
js 0x18d18e
addq %rbx, %r11
movl (%r8), %ebp
cmpl (%r11), %ebp
jb 0x18d18e
movl 0x4(%r8), %ebp
cmpl 0x4(%r11), %ebp
jbe 0x18d193
incq %r10
jmp 0x18d15f
orb $-0x80, %dil
movb %dil, (%r9)
incq %rax
incq %rcx
jmp 0x18d130
testq %rax, %rax
je 0x18d22e
xorl %r12d, %r12d
movq %rbx, %rax
xorl %ecx, %ecx
movq 0x8(%rsp), %rsi
cmpq %rcx, %rsi
je 0x18d22e
cmpb $0x0, 0x28(%rax)
js 0x18d225
cmpq %r12, %rcx
je 0x18d222
imulq $0x30, %r12, %rdx
movups (%rbx,%rdx), %xmm0
movups 0x10(%rbx,%rdx), %xmm1
movups 0x20(%rbx,%rdx), %xmm2
movaps %xmm2, 0x40(%rsp)
movaps %xmm1, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movups %xmm2, 0x20(%rbx,%rdx)
movups %xmm1, 0x10(%rbx,%rdx)
movups %xmm0, (%rbx,%rdx)
movdqa 0x20(%rsp), %xmm0
movapd 0x30(%rsp), %xmm1
movapd 0x40(%rsp), %xmm2
movupd %xmm2, 0x20(%rax)
movupd %xmm1, 0x10(%rax)
movdqu %xmm0, (%rax)
incq %r12
incq %rcx
addq $0x30, %rax
jmp 0x18d1b8
leaq 0x4(%rbx), %rax
xorl %ecx, %ecx
cmpq %r12, %rcx
je 0x18d26f
imulq $0x30, %rcx, %rdx
addq %rbx, %rdx
movq %rax, %rsi
xorl %edi, %edi
cmpq %rdi, %r12
je 0x18d26a
cmpq %rdi, %rcx
je 0x18d261
movl (%rdx), %r8d
cmpl -0x4(%rsi), %r8d
jb 0x18d261
movl 0x4(%rdx), %r8d
cmpl (%rsi), %r8d
jbe 0x18d27e
incq %rdi
addq $0x30, %rsi
jmp 0x18d245
incq %rcx
jmp 0x18d234
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x68302(%rip), %rdi     # 0x1f5587
leaq 0x64897(%rip), %rsi     # 0x1f1b23
leaq 0x682ba(%rip), %rcx     # 0x1f554d
movl $0x449b, %edx           # imm = 0x449B
callq 0x2110
leaq 0x6828d(%rip), %rdi     # 0x1f5531
leaq 0x64878(%rip), %rsi     # 0x1f1b23
leaq 0x6829b(%rip), %rcx     # 0x1f554d
movl $0x4481, %edx           # imm = 0x4481
callq 0x2110