// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: test_het_aln(ma_ug_t*, unsigned long, u_trans_t*, unsigned long, st_mt_t*, overlap_region_alloc*, unsigned long)
uint32_t test_het_aln(ma_ug_t *ug, uint64_t rid, u_trans_t *a, uint64_t a_n, st_mt_t *sp, overlap_region_alloc* ol, uint64_t len)
{
	uint64_t k, s, e, z, l = 0; 
	for (k = sp->n = 0; k < a_n; k++) {
		if(a[k].del) continue;
		// if(rid == 56 || rid == 160) {
		// 	fprintf(stderr, "[rid::%lu]\tutg%.6u%c\t%u\t%u\t%u\t%c\tutg%.6u%c\t%u\t%u\t%u\tnw::%f\tf::%u\n", rid, 
		// 		a[k].qn+1, "lc"[ug->u.a[a[k].qn].circ], ug->u.a[a[k].qn].len, a[k].qs, a[k].qe, "+-"[a[k].rev],
		// 		a[k].tn+1, "lc"[ug->u.a[a[k].tn].circ], ug->u.a[a[k].tn].len, a[k].ts, a[k].te, a[k].nw, a[k].f);
		// }
		kv_push(uint64_t, *sp, (((uint64_t)a[k].qs)<<32)|((uint64_t)a[k].qe));
	}
	for (k = 0; k < ol->length; k++) {
		// if(b->olist.list[k].non_homopolymer_errors == 0) continue;///exact match is not trans
		s = ol->list[k].x_pos_s; e = ol->list[k].x_pos_e+1;
		kv_push(uint64_t, *sp, (((uint64_t)s)<<32)|((uint64_t)e));
	}

	if(sp->n > 1) {
		radix_sort_gfa64(sp->a, sp->a + sp->n);
		for (k = z = 0; k < sp->n; k++) {
			s = sp->a[k]>>32; e = (uint32_t)sp->a[k];
			if(z > 0 && s <= ((uint32_t)sp->a[z-1])) {
				if(e > ((uint32_t)sp->a[z-1])) {
					sp->a[z-1] >>= 32; sp->a[z-1] <<= 32; sp->a[z-1] |= e;
				}
			} else {
				sp->a[z++] = sp->a[k];
			}
		}
		sp->n = z;
	}
	for (k = l = 0; k < sp->n; k++) l += (((uint32_t)sp->a[k]) - (sp->a[k]>>32));

	// if(rid == 7) {
		// fprintf(stderr, "\n[M::%s] utg%.6lu%c, rid::%lu, l::%lu, len::%lu, sp->n::%u\n", 
		// __func__, rid+1, "lc"[ug->u.a[rid].circ], rid, l, len, (uint32_t)sp->n);
	// 	for (k = 0; k < a_n; k++) {
	// 		if(a[k].del) continue;
	// 		fprintf(stderr, "0\tutg%.6u%c\t%u\t%u\t%u\t%c\tutg%.6u%c\t%u\t%u\t%u\tnw::%f\tf::%u\n", 
	// 				a[k].qn+1, "lc"[ug->u.a[a[k].qn].circ], ug->u.a[a[k].qn].len, 
	// 				a[k].qs, a[k].qe, "+-"[a[k].rev],
	// 				a[k].tn+1, "lc"[ug->u.a[a[k].tn].circ], ug->u.a[a[k].tn].len, 
	// 				a[k].ts, a[k].te, a[k].nw, a[k].f);
	// 	}
	// 	for (k = 0; k < ol->length; k++) {
	// 		overlap_region *z = &(ol->list[k]);
	// 		fprintf(stderr, "1\tutg%.6u%c\t%u\t%u\t%u\t%c\tutg%.6u%c\t%u\t%u\t%u\n", 
	// 			z->x_id+1, "lc"[ug->u.a[z->x_id].circ], ug->u.a[z->x_id].len, 
	// 			z->x_pos_s, z->x_pos_e+1, "+-"[z->y_pos_strand],
	// 			z->y_id+1, "lc"[ug->u.a[z->y_id].circ], ug->u.a[z->y_id].len, 
	// 			z->y_pos_s, z->y_pos_e+1);
	// 	}
	// 	for (k = 0; k < sp->n; k++) {
	// 		fprintf(stderr, "in::[%lu, %u)\n", (sp->a[k]>>32), ((uint32_t)sp->a[k]));
	// 	}
	// }
	if((l > 0) && (l >= (len*0.8))) return 1;
	// fprintf(stderr, "\n[M::%s] utg%.6lu%c, rid::%lu, l::%lu, len::%lu, sp->n::%u\n", 
	// 	__func__, rid+1, "lc"[ug->u.a[rid].circ], rid, l, len, (uint32_t)sp->n);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r9, %r14
movq %r8, %rbx
movq $0x0, (%r8)
testq %rcx, %rcx
je 0x1bb27b
movq %rcx, %r15
movq %rdx, %r12
movl $0x2, %r13d
cmpb $0x0, 0x28(%r12)
js 0x1bb272
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0x1bb250
leaq (%rax,%rax), %rsi
testq %rax, %rax
cmoveq %r13, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x10(%rbx)
movl (%r12), %eax
movl 0x4(%r12), %ecx
shlq $0x20, %rax
orq %rax, %rcx
movq (%rbx), %rax
movq 0x10(%rbx), %rdx
leaq 0x1(%rax), %rsi
movq %rsi, (%rbx)
movq %rcx, (%rdx,%rax,8)
addq $0x30, %r12
decq %r15
jne 0x1bb21f
cmpq $0x0, 0x10(%r14)
je 0x1bb2f1
movl $0x8, %r15d
xorl %r12d, %r12d
movq (%r14), %rax
movl -0x4(%rax,%r15), %ebp
movl (%rax,%r15), %r13d
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0x1bb2c5
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x10(%rbx)
incl %r13d
shlq $0x20, %rbp
orq %r13, %rbp
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movq %rbp, (%rcx,%rax,8)
incq %r12
addq $0xa8, %r15
cmpq 0x10(%r14), %r12
jb 0x1bb28b
movq (%rbx), %rax
cmpq $0x2, %rax
jb 0x1bb367
movq 0x10(%rbx), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x194fef
cmpq $0x0, (%rbx)
je 0x1bb362
movq 0x10(%rbx), %rcx
xorl %eax, %eax
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
xorl %esi, %esi
movq (%rcx,%rsi,8), %r8
testq %rax, %rax
je 0x1bb339
movq %r8, %r9
shrq $0x20, %r9
movq -0x8(%rcx,%rax,8), %rdi
cmpl %edi, %r9d
jbe 0x1bb34a
movq %r8, (%rcx,%rax,8)
incq %rax
incq %rsi
cmpq (%rbx), %rsi
jb 0x1bb31f
jmp 0x1bb364
movl %r8d, %r8d
movl %edi, %r9d
cmpl %r9d, %r8d
jbe 0x1bb340
andq %rdx, %rdi
orq %r8, %rdi
movq %rdi, -0x8(%rcx,%rax,8)
jmp 0x1bb340
xorl %eax, %eax
movq %rax, (%rbx)
movq (%rbx), %rcx
testq %rcx, %rcx
je 0x1bb392
movq 0x10(%rbx), %rdx
xorl %eax, %eax
xorl %esi, %esi
movq (%rdx,%rsi,8), %rdi
movl %edi, %r8d
shrq $0x20, %rdi
subq %rdi, %rax
addq %r8, %rax
incq %rsi
cmpq %rsi, %rcx
jne 0x1bb377
jmp 0x1bb394
xorl %eax, %eax
testq %rax, %rax
je 0x1bb3ef
movq %rax, %xmm0
movq 0x69e9a(%rip), %xmm1    # 0x225240
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x69e9e(%rip), %xmm2    # 0x225250
subpd %xmm2, %xmm0
movq 0x40(%rsp), %xmm3
punpckldq %xmm1, %xmm3    # xmm3 = xmm3[0],xmm1[0],xmm3[1],xmm1[1]
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
subpd %xmm2, %xmm3
movapd %xmm3, %xmm2
unpckhpd %xmm3, %xmm2            # xmm2 = xmm2[1],xmm3[1]
addsd %xmm3, %xmm2
mulsd 0x6a0d0(%rip), %xmm2    # 0x2254b0
addsd %xmm0, %xmm1
movl $0x1, %eax
ucomisd %xmm2, %xmm1
jae 0x1bb3f1
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq