// File: /workspace/github_cpp_makefile_star2_O1/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, (%rsp)
testq %rsi, %rsi
je 0x1d0464
movq %rdx, %r14
movq %rdi, %rbx
movq $0x0, (%rdx)
movq %rdi, %r13
movq %rsi, 0x20(%rsp)
movq %rsi, %rbp
movl (%r13), %r15d
movl 0x4(%r13), %r12d
movl $0x0, 0x18(%r13)
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0x1cff28
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x10(%r14)
addq %r15, %r15
movq (%r14), %rax
movq 0x10(%r14), %rdi
leaq 0x1(%rax), %rcx
movq %rcx, (%r14)
movq %r15, (%rdi,%rax,8)
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0x1cff67
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x10(%r14)
leaq 0x1(,%r12,2), %rax
movq (%r14), %rcx
movq 0x10(%r14), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r14)
movq %rax, (%rdx,%rcx,8)
addq $0x30, %r13
decq %rbp
jne 0x1cfeea
movq (%r14), %rax
movq 0x10(%r14), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x194fef
cmpq $0x0, (%r14)
je 0x1d002d
movq 0x10(%r14), %rcx
movq $-0x1, %rsi
xorl %edx, %edx
xorl %eax, %eax
xorl %edi, %edi
movq %rdi, %r9
movq (%rcx,%rdx,8), %r8
movl %r8d, %edi
andl $0x1, %edi
negq %rdi
orq $0x1, %rdi
addq %r9, %rdi
cmpq $0x2, %r9
setb %r10b
cmpq $0x2, %rdi
setae %r11b
andb %r10b, %r11b
cmpb $0x1, %r11b
jne 0x1cfff1
shrq %r8
movq %r8, %rsi
jmp 0x1d0023
cmpq $0x2, %r9
setae %r9b
cmpq $0x2, %rdi
setb %r10b
andb %r9b, %r10b
cmpb $0x1, %r10b
jne 0x1d0023
shrq %r8
cmpq %rsi, %r8
jbe 0x1d0023
movq %rsi, %r9
shlq $0x20, %r9
orq %r9, %r8
movq %r8, (%rcx,%rax,8)
incq %rax
incq %rdx
cmpq (%r14), %rdx
jb 0x1cffb9
jmp 0x1d002f
xorl %eax, %eax
movq %rax, (%r14)
movq 0x20(%rsp), %rax
cmpq $0x1, %rax
adcq $0x0, %rax
movq %rax, 0x18(%rsp)
xorl %eax, %eax
movq 0x551f2(%rip), %xmm0    # 0x225240
movapd 0x551fa(%rip), %xmm1    # 0x225250
movsd 0x5520a(%rip), %xmm5    # 0x225268
xorl %r12d, %r12d
leaq (%rax,%rax,2), %rcx
shlq $0x4, %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 (%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 0x1d0150
xorl %r9d, %r9d
testq %r9, %r9
sete %sil
cmpq %r8, %r9
setbe %dil
orb %sil, %dil
cmpb $0x1, %dil
jne 0x1d0140
cmpq %rdx, %r9
jae 0x1d0140
cmpq %rax, %r12
je 0x1d013d
addq %rbx, %rcx
leaq (%r12,%r12,2), %rdx
shlq $0x4, %rdx
movups (%rbx,%rdx), %xmm2
movups 0x10(%rbx,%rdx), %xmm3
movups 0x20(%rbx,%rdx), %xmm4
movaps %xmm4, 0x50(%rsp)
movaps %xmm3, 0x40(%rsp)
movaps %xmm2, 0x30(%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 0x30(%rsp), %xmm2
movapd 0x40(%rsp), %xmm3
movaps 0x50(%rsp), %xmm4
movups %xmm4, 0x20(%rcx)
movupd %xmm3, 0x10(%rcx)
movupd %xmm2, (%rcx)
incq %r12
incq %rax
cmpq 0x18(%rsp), %rax
jne 0x1d0061
jmp 0x1d01b5
movq (%r14), %r10
testq %r10, %r10
je 0x1d00ba
movq 0x10(%r14), %r11
xorl %r9d, %r9d
xorl %ebp, %ebp
movq (%r11,%rbp,8), %r13
movq %r13, %r15
shrq $0x20, %r15
cmpq %rdi, %r15
jae 0x1d00bd
movl %r13d, %r13d
cmpl %esi, %r13d
jbe 0x1d01a8
cmpq %rsi, %r15
cmovbeq %rsi, %r15
cmpq %rdi, %r13
cmovaeq %rdi, %r13
subq %r15, %r13
movl $0x0, %r15d
cmovaeq %r13, %r15
addq %r15, %r9
cmpq %r8, %r9
ja 0x1d00bd
incq %rbp
cmpq %rbp, %r10
jne 0x1d0165
jmp 0x1d00bd
movq 0x20(%rsp), %rcx
subq %r12, %rcx
jbe 0x1d01da
leaq (%r12,%r12,2), %rax
shlq $0x4, %rax
addq %rbx, %rax
addq $0x28, %rax
orb $-0x80, (%rax)
addq $0x30, %rax
decq %rcx
jne 0x1d01ce
movq $0x0, (%r14)
testq %r12, %r12
je 0x1d0288
leaq 0x20(%rbx), %r15
xorl %ebp, %ebp
movl $0x2, %r13d
movsd (%r15), %xmm1
movapd %xmm1, %xmm0
subsd %xmm5, %xmm0
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0x1d024a
leaq (%rax,%rax), %rsi
testq %rax, %rax
cmoveq %r13, %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
shlq $0x3, %rsi
movapd %xmm0, (%rsp)
movapd %xmm1, 0x20(%rsp)
callq 0x2370
movapd 0x20(%rsp), %xmm1
movapd (%rsp), %xmm0
movsd 0x55022(%rip), %xmm5    # 0x225268
movq %rax, 0x10(%r14)
cvttsd2si %xmm1, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
cvttsd2si %xmm0, %rdx
andl %ecx, %edx
orl %edx, %eax
shlq $0x20, %rax
orq %rbp, %rax
movq (%r14), %rcx
movq 0x10(%r14), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r14)
movq %rax, (%rdx,%rcx,8)
incq %rbp
addq $0x30, %r15
cmpq %rbp, %r12
jne 0x1d01f6
movq (%r14), %rax
movq 0x10(%r14), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x194fef
movq (%r14), %rsi
testq %rsi, %rsi
je 0x1d03f0
xorl %eax, %eax
xorl %edx, %edx
movq $0x0, (%rsp)
movq 0x10(%r14), %r8
movl (%r8,%rdx,8), %edi
leaq (%rdi,%rdi,2), %r9
shlq $0x4, %r9
movb 0x28(%rbx,%r9), %dil
testb %dil, %dil
js 0x1d0473
leaq (%rbx,%r9), %r10
addq $0x28, %r10
addq %rbx, %r9
cmpq $0x1, %rsi
movl $0x0, %r11d
sbbq %rsi, %r11
movb $0x1, %bpl
movl $0x1, %r15d
leaq (%rax,%r15), %r13
cmpq $0x1, %r13
je 0x1d0325
movl -0x8(%r8,%r15,8), %r13d
leaq (%r13,%r13,2), %r13
shlq $0x4, %r13
cmpb $0x0, 0x28(%rbx,%r13)
js 0x1d0325
addq %rbx, %r13
movl (%r9), %ecx
cmpl (%r13), %ecx
jb 0x1d0325
movl 0x4(%r9), %ecx
cmpl 0x4(%r13), %ecx
jbe 0x1d0350
cmpq %rsi, %r15
setb %bpl
leaq (%r11,%r15), %rcx
incq %rcx
incq %r15
cmpq $0x1, %rcx
jne 0x1d02ef
incq %rdx
movq (%r14), %rsi
decq %rax
cmpq %rsi, %rdx
jb 0x1d02b0
jmp 0x1d0363
testb $0x1, %bpl
je 0x1d033c
orb $-0x80, %dil
movb %dil, (%r10)
incq (%rsp)
jmp 0x1d033c
cmpq $0x0, (%rsp)
je 0x1d03f0
xorl %eax, %eax
movq %rbx, %rcx
xorl %r12d, %r12d
cmpb $0x0, 0x28(%rcx)
js 0x1d03e2
cmpq %r12, %rax
je 0x1d03df
leaq (%r12,%r12,2), %rdx
shlq $0x4, %rdx
movups (%rbx,%rdx), %xmm0
movups 0x10(%rbx,%rdx), %xmm1
movups 0x20(%rbx,%rdx), %xmm2
movaps %xmm2, 0x50(%rsp)
movaps %xmm1, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups 0x20(%rcx), %xmm2
movups %xmm2, 0x20(%rbx,%rdx)
movups %xmm1, 0x10(%rbx,%rdx)
movups %xmm0, (%rbx,%rdx)
movdqa 0x30(%rsp), %xmm0
movapd 0x40(%rsp), %xmm1
movapd 0x50(%rsp), %xmm2
movupd %xmm2, 0x20(%rcx)
movupd %xmm1, 0x10(%rcx)
movdqu %xmm0, (%rcx)
incq %r12
incq %rax
addq $0x30, %rcx
cmpq %rax, 0x18(%rsp)
jne 0x1d0376
testq %r12, %r12
je 0x1d0464
movq %r12, %rax
negq %rax
leaq 0x4(%rbx), %rcx
xorl %edx, %edx
xorl %esi, %esi
leaq (%rsi,%rsi,2), %rdi
shlq $0x4, %rdi
addq %rbx, %rdi
movb $0x1, %r9b
movl $0x1, %r8d
movq %rcx, %r10
leaq (%rdx,%r8), %r11
cmpq $0x1, %r11
je 0x1d0436
movl (%rdi), %r11d
cmpl -0x4(%r10), %r11d
jb 0x1d0436
movl 0x4(%rdi), %r11d
cmpl (%r10), %r11d
jbe 0x1d0453
cmpq %r12, %r8
setb %r9b
leaq (%rax,%r8), %r11
incq %r11
incq %r8
addq $0x30, %r10
cmpq $0x1, %r11
jne 0x1d041a
jmp 0x1d0459
testb $0x1, %r9b
jne 0x1d0492
incq %rsi
decq %rdx
cmpq %r12, %rsi
jne 0x1d0403
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x66f1f(%rip), %rdi     # 0x237399
leaq 0x6350a(%rip), %rsi     # 0x23398b
leaq 0x66f2d(%rip), %rcx     # 0x2373b5
movl $0x4481, %edx           # imm = 0x4481
callq 0x2110
leaq 0x66f56(%rip), %rdi     # 0x2373ef
leaq 0x634eb(%rip), %rsi     # 0x23398b
leaq 0x66f0e(%rip), %rcx     # 0x2373b5
movl $0x449b, %edx           # imm = 0x449B
callq 0x2110