// File: /workspace/github_cpp_makefile_star2_O1/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, %r15
movl %r8d, %r14d
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 0x3c(%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 0x10109f
addq $0x20, %rsp
cmpl $0x7, %eax
je 0x1018ea
leaq 0x3c(%rsp), %rcx
leaq 0x70(%rsp), %r8
leaq 0x68(%rsp), %r9
movq %rbx, 0x8(%rsp)
movq %rbx, %rdi
movq %r12, 0x30(%rsp)
movq %r12, %rsi
movl %r14d, %edx
movq 0xc8(%rsp), %rbx
pushq %rbx
movl 0xf0(%rsp), %eax
pushq %rax
pushq %rbp
leaq 0x78(%rsp), %rax
pushq %rax
callq 0x10109f
addq $0x20, %rsp
cmpl $0x7, %eax
je 0x1018ea
movq 0x78(%rsp), %rax
movl 0xe0(%rsp), %ecx
cmpq %rcx, %rax
jle 0x1018ea
movq 0x70(%rsp), %rdx
cmpq %rcx, %rdx
jle 0x1018ea
movq 0xd0(%rsp), %r14
cmpq %rdx, %rax
movq %rbx, %rdx
movq 0xc0(%rsp), %r13
cmovgq %r13, %rdx
cmovgq %rbx, %r13
movq 0x38(%rdx), %rcx
movq 0x30(%rsp), %rax
testq %rax, %rax
movq %r15, 0x18(%rsp)
movq %rdx, 0x20(%rsp)
je 0x101901
movq %r13, (%rsp)
testq %rcx, %rcx
je 0x101779
xorl %r13d, %r13d
movq 0x10(%rsp), %r12
movq 0x10(%rax), %rax
movq 0x48(%rdx), %rcx
movl (%rcx,%r13,4), %ecx
shrl %ecx
leaq (%rcx,%rcx,4), %rcx
cmpl $0x0, 0x10(%rax,%rcx,8)
je 0x101768
leaq (%rax,%rcx,8), %rbx
xorl %ebp, %ebp
movq 0x18(%rbx), %rax
movq (%rax,%rbp,8), %rsi
shrq $0x21, %rsi
movq 0x48(%rdx), %rax
movl (%rax,%r13,4), %edx
shrl %edx
movq 0x20(%r12), %rax
leaq (%rax,%rsi,8), %r8
addq $0x4, %r8
movq %r14, %rdi
movl $0x1, %ecx
callq 0xa1cd4
movq 0x20(%rsp), %rdx
incq %rbp
movl 0x10(%rbx), %eax
cmpq %rax, %rbp
jb 0x101728
incl %r13d
movq 0x38(%rdx), %rcx
cmpq %r13, %rcx
movq 0x30(%rsp), %rax
ja 0x101709
movq %rcx, 0x28(%rsp)
movq (%rsp), %rcx
movq 0x38(%rcx), %rdx
movq %rdx, 0x50(%rsp)
testq %rdx, %rdx
je 0x101a66
movq 0x10(%rax), %rdi
movq 0x48(%rcx), %rax
movq %rax, 0x48(%rsp)
xorl %ecx, %ecx
xorl %r10d, %r10d
xorl %edx, %edx
xorl %esi, %esi
movl $0x0, (%rsp)
movq %rdi, 0x40(%rsp)
movq 0x48(%rsp), %rax
movl (%rax,%rcx,4), %eax
shrl %eax
leaq (%rax,%rax,4), %rax
movl 0x10(%rdi,%rax,8), %ebp
testq %rbp, %rbp
je 0x1018d5
movq %rcx, 0x58(%rsp)
movq %r10, 0x8(%rsp)
leaq (%rdi,%rax,8), %rax
movq 0x18(%rax), %r10
xorl %r8d, %r8d
movq (%r10,%r8,8), %rdi
shrq $0x21, %rdi
leaq (%rdi,%rdi,2), %rax
movl 0xc(%r15,%rax,8), %r11d
xorl %r9d, %r9d
testq %r11, %r11
setne %cl
movq 0xd8(%rsp), %rbx
movb (%rbx,%rdi), %dil
andb $0x3, %dil
cmpb $0x1, %dil
sbbl $-0x1, %edx
testq %r11, %r11
je 0x1018b1
leaq (%r15,%rax,8), %rax
movq (%rax), %rdi
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
shlq $0x3, %r11
leaq (%r11,%r11,4), %r13
xorl %r11d, %r11d
movl 0xc(%rdi,%r11), %r15d
cmpl $0x0, (%rax,%r15,8)
movl %r15d, %ebx
js 0x10185e
movl %ebx, %ebx
cmpq %rbx, (%r14)
jbe 0x10189e
movq 0x8(%r14), %r15
cmpl $-0x2, (%r15,%rbx,4)
jg 0x10189e
jmp 0x1018a9
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpq %r15, (%r14)
jbe 0x101885
movq 0x8(%r14), %r12
movl (%r12,%r15,4), %r15d
cmpl $-0x1, %r15d
je 0x101885
movl %r15d, %ebx
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
shrl $0x1f, %r15d
jmp 0x101888
xorl %r15d, %r15d
cmpl $-0x1, %ebx
sete %r12b
orb %r15b, %r12b
jne 0x10189e
movl %ebx, %r15d
cmpl $0x0, (%rax,%r15,8)
jns 0x10184a
addq $0x28, %r11
cmpq %r11, %r13
jne 0x10183b
jmp 0x1018ac
incl (%rsp)
movq 0x18(%rsp), %r15
movb %cl, %r9b
addl %r9d, %esi
incq %r8
cmpq %rbp, %r8
jne 0x1017e6
movq 0x8(%rsp), %r10
addl %ebp, %r10d
movq 0x40(%rsp), %rdi
movq 0x58(%rsp), %rcx
incq %rcx
movl %ecx, %eax
cmpq %rax, 0x50(%rsp)
ja 0x1017b6
jmp 0x101a74
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %rcx, %rcx
movq 0x10(%rsp), %r12
je 0x10194c
movl $0x1, %ebx
xorl %eax, %eax
movq 0x48(%rdx), %rcx
movl (%rcx,%rax,4), %esi
shrl %esi
movq 0x20(%r12), %rax
leaq (%rax,%rsi,8), %r8
addq $0x4, %r8
movq %r14, %rdi
movl $0x1, %edx
movl $0x1, %ecx
callq 0xa1cd4
movq 0x20(%rsp), %rdx
movl %ebx, %eax
movq 0x38(%rdx), %rcx
incl %ebx
cmpq %rax, %rcx
ja 0x101912
movq %rcx, 0x28(%rsp)
movq 0x38(%r13), %r8
testq %r8, %r8
je 0x101ae7
movq 0x48(%r13), %rax
movq %rax, 0x10(%rsp)
xorl %r10d, %r10d
xorl %edx, %edx
xorl %esi, %esi
movl $0x0, (%rsp)
movq 0x8(%rsp), %r12
movq %r10, %r9
movq 0x10(%rsp), %rax
movl (%rax,%r10,4), %edi
shrl %edi
leaq (%rdi,%rdi,2), %rax
movl 0xc(%r15,%rax,8), %r11d
xorl %r10d, %r10d
testq %r11, %r11
setne %cl
movq 0xd8(%rsp), %rbx
movb (%rbx,%rdi), %dil
andb $0x3, %dil
cmpb $0x1, %dil
sbbl $-0x1, %edx
testq %r11, %r11
je 0x101a49
leaq (%r15,%rax,8), %rax
movq (%rax), %rdi
movq 0x20(%r12), %rax
shlq $0x3, %r11
leaq (%r11,%r11,4), %r11
xorl %r12d, %r12d
movl 0xc(%rdi,%r12), %r15d
cmpl $0x0, (%rax,%r15,8)
movl %r15d, %ebx
js 0x1019f4
movl %ebx, %ebx
cmpq %rbx, (%r14)
jbe 0x101a31
movq 0x8(%r14), %r15
cmpl $-0x2, (%r15,%rbx,4)
jg 0x101a31
jmp 0x101a3c
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpq %r15, (%r14)
jbe 0x101a19
movq 0x8(%r14), %r13
movl (%r13,%r15,4), %ebp
cmpl $-0x1, %ebp
je 0x101a19
movl %ebp, %ebx
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
shrl $0x1f, %ebp
jmp 0x101a1b
xorl %ebp, %ebp
cmpl $-0x1, %ebx
sete %r15b
orb %bpl, %r15b
jne 0x101a31
movl %ebx, %r15d
cmpl $0x0, (%rax,%r15,8)
jns 0x1019e0
addq $0x28, %r12
cmpq %r12, %r11
jne 0x1019d1
jmp 0x101a3f
incl (%rsp)
movq 0x18(%rsp), %r15
movq 0x8(%rsp), %r12
movb %cl, %r10b
addl %r10d, %esi
movq %r9, %r10
incq %r10
movl %r10d, %eax
cmpq %rax, %r8
ja 0x10197a
jmp 0x101af5
movl $0x0, (%rsp)
xorl %esi, %esi
xorl %edx, %edx
xorl %r10d, %r10d
movq 0x28(%rsp), %r15
testq %r15, %r15
je 0x101b28
movq %r10, %r12
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x20(%rsp), %rcx
movq 0x48(%rcx), %rcx
xorl %edi, %edi
movl (%rcx,%rdi,4), %r8d
shrl %r8d
leaq (%r8,%r8,4), %r8
cmpl $0x0, 0x10(%rax,%r8,8)
je 0x101ad7
leaq (%rax,%r8,8), %r8
movq 0x18(%r8), %r9
movq 0x8(%r14), %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 0x101abb
incq %rdi
movl %edi, %r8d
cmpq %r8, %r15
ja 0x101a99
movq %r12, %r10
jmp 0x101b28
movl $0x0, (%rsp)
xorl %esi, %esi
xorl %edx, %edx
xorl %r10d, %r10d
movq 0x28(%rsp), %r9
testq %r9, %r9
je 0x101b28
movq 0x20(%rsp), %rax
movq 0x48(%rax), %rax
movq 0x8(%r14), %rcx
xorl %edi, %edi
movl (%rax,%rdi,4), %r8d
shrl %r8d
movl $0xffffffff, (%rcx,%r8,4) # imm = 0xFFFFFFFF
incq %rdi
movl %edi, %r8d
cmpq %r8, %r9
ja 0x101b0e
testl %esi, %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
je 0x1018ef
movl (%rsp), %eax
cvtsi2ss %rax, %xmm0
movl %esi, %eax
cvtsi2ss %rax, %xmm1
leaq 0x188c0d(%rip), %rax    # 0x28a758
mulss 0x16c(%rax), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x101b81
movl %edx, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movl %r10d, %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd 0x12392b(%rip), %xmm1   # 0x2254a0
xorl %eax, %eax
ucomisd %xmm1, %xmm0
jae 0x1018ef
movl $0x1, %eax
jmp 0x1018ef