// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: check_different_haps(asg_t*, ma_ug_t*, asg_t*, unsigned int, unsigned int, ma_hit_t_alloc*, buf_t*, buf_t*, R_to_U*, unsigned char*, unsigned int, unsigned int)
inline uint32_t check_different_haps(asg_t *nsg, ma_ug_t *ug, asg_t *read_sg, 
uint32_t v_0, uint32_t v_1, ma_hit_t_alloc* reverse_sources, buf_t* b_0, buf_t* b_1, 
R_to_U* ruIndex, uint8_t* is_r_het, uint32_t min_edge_length, uint32_t stops_threshold)
{
	uint32_t vEnd, qn, tn, j, is_Unitig, uId;
	long long ELen_0, ELen_1, tmp, max_stop_nodeLen, max_stop_baseLen;

	b_0->b.n = b_1->b.n = 0;
	if(get_unitig(nsg, ug, v_0, &vEnd, &ELen_0, &tmp, &max_stop_nodeLen, &max_stop_baseLen, 
	stops_threshold, b_0) == LOOP)
	{
		return UNAVAILABLE;
	}
	if(get_unitig(nsg, ug, v_1, &vEnd, &ELen_1, &tmp, &max_stop_nodeLen, &max_stop_baseLen, 
	stops_threshold, b_1) == LOOP)
	{
		return UNAVAILABLE;
	}
	if(ELen_0<=min_edge_length || ELen_1<=min_edge_length) return UNAVAILABLE;

	rIdContig b_max, b_min;
	b_max.b_0 = b_min.b_0 = NULL;
	b_max.offset = b_max.readI = b_max.untigI = 0;
	b_min.offset = b_min.readI = b_min.untigI = 0;

	if(ELen_0<=ELen_1)
	{
        b_min.b_0 = b_0;
        b_max.b_0 = b_1;
    }
    else
    {
        b_min.b_0 = b_1;
        b_max.b_0 = b_0;
    }

	uint32_t max_count = 0, min_count = 0, n_het = 0, n_hom = 0;
	ma_utg_t *node_min = NULL, *node_max = NULL;
	if(ug != NULL)
	{
		/*****************************label all unitigs****************************************/
		for (b_max.untigI = 0; b_max.untigI < b_max.b_0->b.n; b_max.untigI++)
		{
			node_max = &(ug->u.a[b_max.b_0->b.a[b_max.untigI]>>1]);
			///each read
			for (b_max.readI = 0; b_max.readI < node_max->n; b_max.readI++)
			{
				qn = (node_max->a[b_max.readI]>>33);
				set_R_to_U(ruIndex, qn, (b_max.b_0->b.a[b_max.untigI]>>1), 1, &(read_sg->seq[qn].c));
			}
		}
		/*****************************label all unitigs****************************************/

		///each unitig
		for (b_min.untigI = 0; b_min.untigI < b_min.b_0->b.n; b_min.untigI++)
		{
			
			node_min = &(ug->u.a[(b_min.b_0->b.a[b_min.untigI]>>1)]);

			///each read
			for (b_min.readI = 0; b_min.readI < node_min->n; b_min.readI++)
        	{
				qn = node_min->a[b_min.readI]>>33;

				/************************BUG: don't forget****************************/
				if(reverse_sources[qn].length > 0) min_count++;
                if((is_r_het[qn] & C_HET) || (is_r_het[qn] & P_HET)) n_het++;
                n_hom++;
				/************************BUG: don't forget****************************/
				for (j = 0; j < (long long)reverse_sources[qn].length; j++)
				{
					tn = Get_tn(reverse_sources[qn].buffer[j]);
					if(read_sg->seq[tn].del == 1)
					{
						get_R_to_U(ruIndex, tn, &tn, &is_Unitig);
						if(tn == (uint32_t)-1 || is_Unitig == 1 || read_sg->seq[tn].del == 1) continue;
					}

					get_R_to_U(ruIndex, tn, &uId, &is_Unitig);
					if(uId!=(uint32_t)-1 && is_Unitig == 1)
					{
                        // if(v_0==510 && v_1==67) fprintf(stderr, "###untigI-%u, readI-%um, un-%u\n", b_min.untigI, b_min.readI, (uint32_t)node_min->n);
						max_count++;
						break;
					}
				}
			}
		}
		/*****************************label all unitigs****************************************/
		for (b_max.untigI = 0; b_max.untigI < b_max.b_0->b.n; b_max.untigI++)
		{
			node_max = &(ug->u.a[b_max.b_0->b.a[b_max.untigI]>>1]);
			///each read
			for (b_max.readI = 0; b_max.readI < node_max->n; b_max.readI++)
			{
				qn = (node_max->a[b_max.readI]>>33);
				ruIndex->index[qn] = (uint32_t)-1;
			}
		}
		/*****************************label all unitigs****************************************/
	}
	else
	{
		/*****************************label all reads****************************************/
		for (b_max.untigI = 0; b_max.untigI < b_max.b_0->b.n; b_max.untigI++)
		{
			qn = (b_max.b_0->b.a[b_max.untigI]>>1);
			set_R_to_U(ruIndex, qn, 1, 1, &(read_sg->seq[qn].c));
		}
		/*****************************label all reads****************************************/

		///each read
		for (b_min.untigI = 0; b_min.untigI < b_min.b_0->b.n; b_min.untigI++)
		{
			qn = (b_min.b_0->b.a[b_min.untigI]>>1);

			/************************BUG: don't forget****************************/
			if(reverse_sources[qn].length > 0) min_count++;
			if((is_r_het[qn] & C_HET) || (is_r_het[qn] & P_HET)) n_het++;
            n_hom++;
			/************************BUG: don't forget****************************/

			for (j = 0; j < (long long)reverse_sources[qn].length; j++)
        	{
            	tn = Get_tn(reverse_sources[qn].buffer[j]);
				if(nsg->seq[tn].del == 1)
				{
					get_R_to_U(ruIndex, tn, &tn, &is_Unitig);
					if(tn == (uint32_t)-1 || is_Unitig == 1 || nsg->seq[tn].del == 1) continue;
				}


				get_R_to_U(ruIndex, tn, &uId, &is_Unitig);
				if(uId!=(uint32_t)-1 && is_Unitig == 1)
				{
					max_count++;
					break;
				}
			}
		}

		/*****************************label all reads****************************************/
		for (b_max.untigI = 0; b_max.untigI < b_max.b_0->b.n; b_max.untigI++)
		{
			qn = (b_max.b_0->b.a[b_max.untigI]>>1);
			ruIndex->index[qn] = (uint32_t)-1;
		}
		/*****************************label all reads****************************************/
	}

	if(min_count == 0) return UNAVAILABLE;
	if(max_count > min_count*asm_opt.purge_simi_thres && n_het >= n_hom*HET_HOM_RATE) return PLOID;
	return NON_PLOID;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r9, %r14
movl %r8d, %r15d
movq %rdx, 0x10(%rsp)
movq %rsi, %r12
movq %rdi, %rbx
movl 0xe8(%rsp), %r11d
movq 0xc8(%rsp), %rdx
movq 0xc0(%rsp), %r10
xorl %eax, %eax
movq %rax, 0x38(%rdx)
movq %rax, 0x38(%r10)
leaq 0x80(%rsp), %rbp
leaq 0x60(%rsp), %r13
leaq 0x34(%rsp), %rax
leaq 0x78(%rsp), %r8
leaq 0x68(%rsp), %r9
movl %ecx, %edx
movq %rax, %rcx
pushq %r10
pushq %r11
pushq %rbp
pushq %r13
callq 0x1053a7
addq $0x20, %rsp
cmpl $0x7, %eax
je 0x105ac1
leaq 0x34(%rsp), %rcx
leaq 0x70(%rsp), %r8
leaq 0x68(%rsp), %r9
movq %rbx, 0x8(%rsp)
movq %rbx, %rdi
movq %r12, 0x28(%rsp)
movq %r12, %rsi
movl %r15d, %edx
movq 0xc8(%rsp), %rbx
pushq %rbx
movl 0xf0(%rsp), %eax
pushq %rax
pushq %rbp
leaq 0x78(%rsp), %rax
pushq %rax
callq 0x1053a7
addq $0x20, %rsp
cmpl $0x7, %eax
je 0x105ac1
movq 0x78(%rsp), %rax
movl 0xe0(%rsp), %ecx
cmpq %rcx, %rax
jle 0x105ac1
movq 0x70(%rsp), %rdx
cmpq %rcx, %rdx
jle 0x105ac1
cmpq %rdx, %rax
movq %rbx, %r8
movq 0xc0(%rsp), %r13
cmovaq %r13, %r8
cmovaq %rbx, %r13
movq 0xd0(%rsp), %r15
movq 0x38(%r8), %rsi
movq 0x28(%rsp), %rdx
testq %rdx, %rdx
movq %r14, 0x18(%rsp)
movq %r8, 0x20(%rsp)
je 0x105ad8
movq %r13, (%rsp)
xorl %r13d, %r13d
testq %rsi, %rsi
je 0x105b39
movq 0x10(%rsp), %r12
movq 0x10(%rdx), %rax
movq 0x48(%r8), %rcx
movl (%rcx,%r13,4), %ecx
shrl %ecx
leaq (%rcx,%rcx,4), %rcx
cmpl $0x0, 0x10(%rax,%rcx,8)
je 0x105ab7
leaq (%rax,%rcx,8), %rbx
xorl %ebp, %ebp
movq 0x18(%rbx), %rax
movq (%rax,%rbp,8), %rsi
shrq $0x21, %rsi
movq 0x48(%r8), %rax
movl (%rax,%r13,4), %edx
shrl %edx
movq 0x20(%r12), %rax
leaq (%rax,%rsi,8), %r8
addq $0x4, %r8
movq %r15, %rdi
movl $0x1, %ecx
callq 0xa27e9
movq 0x20(%rsp), %r8
incq %rbp
movl 0x10(%rbx), %eax
cmpq %rax, %rbp
jb 0x105a6e
movq 0x38(%r8), %rsi
movq 0x28(%rsp), %rdx
incl %r13d
cmpq %r13, %rsi
ja 0x105a4f
jmp 0x105b3b
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq $0x0, (%rsp)
testq %rsi, %rsi
je 0x105d03
movl $0x1, %ebx
xorl %eax, %eax
movq 0x10(%rsp), %r12
movq 0x8(%rsp), %rbp
movq 0x48(%r8), %rcx
movl (%rcx,%rax,4), %esi
shrl %esi
movq 0x20(%r12), %rax
leaq (%rax,%rsi,8), %r8
addq $0x4, %r8
movq %r15, %rdi
movl $0x1, %edx
movl $0x1, %ecx
callq 0xa27e9
movq 0x20(%rsp), %r8
movl %ebx, %eax
movq 0x38(%r8), %rsi
incl %ebx
cmpq %rax, %rsi
ja 0x105afa
jmp 0x105d0a
xorl %esi, %esi
movq %rsi, 0x38(%rsp)
movq (%rsp), %rax
movq 0x38(%rax), %rcx
movq %rcx, 0x50(%rsp)
testq %rcx, %rcx
je 0x105c84
movq 0x10(%rdx), %rsi
movq 0x48(%rax), %rax
movq %rax, 0x48(%rsp)
xorl %edi, %edi
xorl %r13d, %r13d
xorl %ecx, %ecx
xorl %edx, %edx
movq $0x0, (%rsp)
movq %rsi, 0x40(%rsp)
movq 0x48(%rsp), %rax
movl (%rax,%rdi,4), %eax
shrl %eax
leaq (%rax,%rax,4), %rax
movl 0x10(%rsi,%rax,8), %r11d
testq %r11, %r11
je 0x105c72
movq %rdi, 0x58(%rsp)
movq %r13, 0x8(%rsp)
leaq (%rsi,%rax,8), %rax
movq 0x18(%rax), %r13
xorl %r9d, %r9d
movq (%r13,%r9,8), %rsi
shrq $0x21, %rsi
leaq (%rsi,%rsi,2), %rax
movl 0xc(%r14,%rax,8), %r10d
xorl %edi, %edi
testq %r10, %r10
setne %r8b
movq 0xd8(%rsp), %rbx
movb (%rbx,%rsi), %sil
andb $0x3, %sil
cmpb $0x1, %sil
sbbl $-0x1, %ecx
testq %r10, %r10
je 0x105c4f
leaq (%r14,%rax,8), %rax
movq (%rax), %rsi
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movq (%r15), %rbp
shlq $0x3, %r10
leaq (%r10,%r10,4), %r10
xorl %ebx, %ebx
movl 0xc(%rsi,%rbx), %r14d
cmpl $0x0, (%rax,%r14,8)
js 0x105c1c
cmpq %r14, %rbp
jbe 0x105c35
movq 0x8(%r15), %r12
cmpl $-0x2, (%r12,%r14,4)
jg 0x105c35
jmp 0x105c40
cmpq %r14, %rbp
jbe 0x105c35
movq 0x8(%r15), %r12
movslq (%r12,%r14,4), %r14
testq %r14, %r14
js 0x105c35
cmpl $0x0, (%rax,%r14,8)
jns 0x105c0a
addq $0x28, %rbx
cmpq %rbx, %r10
jne 0x105bfe
jmp 0x105c4a
movq (%rsp), %rax
incl %eax
movq %rax, (%rsp)
movq 0x18(%rsp), %r14
movb %r8b, %dil
addl %edi, %edx
incq %r9
cmpq %r11, %r9
jne 0x105baa
movq 0x8(%rsp), %r13
addl %r11d, %r13d
movq 0x40(%rsp), %rsi
movq 0x58(%rsp), %rdi
incq %rdi
movl %edi, %eax
cmpq %rax, 0x50(%rsp)
ja 0x105b79
jmp 0x105c93
movq $0x0, (%rsp)
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r13d, %r13d
cmpq $0x0, 0x38(%rsp)
je 0x105e39
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x20(%rsp), %rsi
movq 0x48(%rsi), %rsi
xorl %edi, %edi
movl (%rsi,%rdi,4), %r8d
shrl %r8d
leaq (%r8,%r8,4), %r8
cmpl $0x0, 0x10(%rax,%r8,8)
je 0x105cf1
leaq (%rax,%r8,8), %r8
movq 0x18(%r8), %r9
movq 0x8(%r15), %r10
xorl %r11d, %r11d
movq (%r9,%r11,8), %rbx
shrq $0x21, %rbx
movl $0xffffffff, (%r10,%rbx,4) # imm = 0xFFFFFFFF
incq %r11
movl 0x10(%r8), %ebx
cmpq %rbx, %r11
jb 0x105cd5
incq %rdi
movl %edi, %r8d
cmpq %r8, 0x38(%rsp)
ja 0x105cb3
jmp 0x105e39
xorl %esi, %esi
movq 0x8(%rsp), %rbp
movq 0x38(%r13), %rdi
movl $0x0, %edx
movl $0x0, %ecx
movq %r13, %rax
movl $0x0, %r13d
movq %rdi, 0x10(%rsp)
testq %rdi, %rdi
je 0x105e0f
movq 0x48(%rax), %r8
xorl %r13d, %r13d
xorl %ecx, %ecx
xorl %edx, %edx
movq $0x0, (%rsp)
movl (%r8,%r13,4), %r11d
shrl %r11d
leaq (%r11,%r11,2), %rax
movl 0xc(%r14,%rax,8), %ebx
xorl %r9d, %r9d
testq %rbx, %rbx
setne %r10b
movq 0xd8(%rsp), %r12
movb (%r12,%r11), %r11b
andb $0x3, %r11b
cmpb $0x1, %r11b
sbbl $-0x1, %ecx
testq %rbx, %rbx
je 0x105df3
movq %r13, %rdi
leaq (%r14,%rax,8), %rax
movq (%rax), %r11
movq 0x20(%rbp), %rax
movq (%r15), %r12
shlq $0x3, %rbx
leaq (%rbx,%rbx,4), %r13
xorl %ebx, %ebx
movl 0xc(%r11,%rbx), %r14d
cmpl $0x0, (%rax,%r14,8)
js 0x105db7
cmpq %r14, %r12
jbe 0x105dd6
movq 0x8(%r15), %rbp
cmpl $-0x2, (%rbp,%r14,4)
movq 0x8(%rsp), %rbp
jg 0x105dd6
jmp 0x105de1
cmpq %r14, %r12
jbe 0x105dd6
movq 0x8(%r15), %rbp
movslq (%rbp,%r14,4), %r14
movq 0x8(%rsp), %rbp
testq %r14, %r14
js 0x105dd6
cmpl $0x0, (%rax,%r14,8)
jns 0x105d9f
addq $0x28, %rbx
cmpq %rbx, %r13
jne 0x105d93
jmp 0x105deb
movq (%rsp), %rax
incl %eax
movq %rax, (%rsp)
movq 0x18(%rsp), %r14
movq %rdi, %r13
movb %r10b, %r9b
addl %r9d, %edx
incq %r13
movl %r13d, %eax
cmpq %rax, 0x10(%rsp)
ja 0x105d42
movq 0x20(%rsp), %r8
testq %rsi, %rsi
je 0x105e39
movq 0x48(%r8), %rax
movq 0x8(%r15), %rdi
xorl %r8d, %r8d
movl (%rax,%r8,4), %r9d
shrl %r9d
movl $0xffffffff, (%rdi,%r9,4) # imm = 0xFFFFFFFF
incq %r8
movl %r8d, %r9d
cmpq %r9, %rsi
ja 0x105e1f
testl %edx, %edx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
je 0x105ac6
movl (%rsp), %eax
cvtsi2ss %rax, %xmm0
movl %edx, %eax
cvtsi2ss %rax, %xmm1
leaq 0x18f8fc(%rip), %rax    # 0x295758
mulss 0x16c(%rax), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x105e92
movl %ecx, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movl %r13d, %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd 0x12b71a(%rip), %xmm1   # 0x2315a0
xorl %eax, %eax
ucomisd %xmm1, %xmm0
jae 0x105ac6
movl $0x1, %eax
jmp 0x105ac6