// File: /workspace/github_cpp_makefile_star2_O2/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 $0x78, %rsp
movq %r9, 0x30(%rsp)
movl %r8d, %r12d
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %rbp
movl 0xd8(%rsp), %r11d
movq 0xb8(%rsp), %rax
andq $0x0, 0x38(%rax)
movq 0xb0(%rsp), %r10
andq $0x0, 0x38(%r10)
leaq 0x50(%rsp), %r15
leaq 0x58(%rsp), %rbx
leaq 0x2c(%rsp), %rax
leaq 0x70(%rsp), %r8
leaq 0x60(%rsp), %r9
movl %ecx, %edx
movq %rax, %rcx
pushq %r10
pushq %r11
pushq %r15
pushq %rbx
callq 0xc2ebf
addq $0x20, %rsp
cmpl $0x7, %eax
je 0xc3497
leaq 0x2c(%rsp), %rcx
leaq 0x68(%rsp), %r8
leaq 0x60(%rsp), %r9
movq %rbp, %rdi
movq %r14, 0x20(%rsp)
movq %r14, %rsi
movl %r12d, %edx
movq 0xb8(%rsp), %r12
pushq %r12
movl 0xe0(%rsp), %eax
pushq %rax
leaq 0x60(%rsp), %rax
pushq %rax
leaq 0x70(%rsp), %rax
pushq %rax
callq 0xc2ebf
addq $0x20, %rsp
cmpl $0x7, %eax
je 0xc3497
movq 0x70(%rsp), %rax
movl 0xd0(%rsp), %ecx
cmpq %rcx, %rax
jle 0xc3497
movq 0x68(%rsp), %rdx
cmpq %rcx, %rdx
jle 0xc3497
movq 0xc0(%rsp), %r15
cmpq %rdx, %rax
movq %r12, %r10
movq 0xb0(%rsp), %r14
cmovaq %r14, %r10
cmovaq %r12, %r14
movq %r14, 0x10(%rsp)
cmpq $0x0, 0x20(%rsp)
movq %r10, 0x8(%rsp)
je 0xc3616
xorl %r12d, %r12d
pushq $0x1
popq %rbp
movl %r12d, %r12d
movq 0x38(%r10), %rax
cmpq %r12, %rax
jbe 0xc34a9
movq 0x48(%r10), %rax
movl (%rax,%r12,4), %eax
shrl %eax
imulq $0x28, %rax, %rbx
movq 0x20(%rsp), %rax
addq 0x10(%rax), %rbx
xorl %r14d, %r14d
movl 0x10(%rbx), %eax
cmpq %rax, %r14
jae 0xc348d
movq 0x18(%rbx), %rax
movq (%rax,%r14,8), %rsi
shrq $0x21, %rsi
movq 0x8(%rsp), %rax
movq 0x48(%rax), %rax
movl (%rax,%r12,4), %edx
shrl %edx
movq 0x20(%r13), %rax
leaq (%rax,%rsi,8), %r8
addq $0x4, %r8
movq %r15, %rdi
movl %ebp, %ecx
callq 0x6ab56
incq %r14
jmp 0xc344f
incl %r12d
movq 0x8(%rsp), %r10
jmp 0xc3429
pushq $-0x1
popq %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, 0x38(%rsp)
movq 0x10(%rsp), %rax
movq 0x38(%rax), %rax
movq %rax, 0x40(%rsp)
xorl %r8d, %r8d
xorl %r9d, %r9d
xorl %esi, %esi
xorl %ecx, %ecx
movq $0x0, 0x18(%rsp)
movl %r8d, %r8d
cmpq %r8, 0x40(%rsp)
movq 0x20(%rsp), %r11
jbe 0xc35c2
movq 0x10(%r11), %rax
movq 0x10(%rsp), %rdx
movq 0x48(%rdx), %rdi
movq %r8, 0x48(%rsp)
movl (%rdi,%r8,4), %edi
shrl %edi
imulq $0x28, %rdi, %rdi
leaq (%rax,%rdi), %r11
movl 0x10(%rax,%rdi), %r10d
xorl %ebp, %ebp
cmpq %r10, %rbp
je 0xc35a3
movq 0x18(%r11), %rax
movq (%rax,%rbp,8), %rax
shrq $0x21, %rax
imulq $0x18, %rax, %rdi
movq 0x30(%rsp), %rdx
movl 0xc(%rdx,%rdi), %r8d
cmpq $0x1, %r8
sbbl $-0x1, %esi
leaq (%rdx,%rdi), %r12
movq 0xc8(%rsp), %rdx
movb (%rdx,%rax), %al
andb $0x3, %al
cmpb $0x1, %al
sbbl $-0x1, %ecx
imulq $0x28, %r8, %r8
xorl %eax, %eax
cmpq %rax, %r8
je 0xc359b
movq (%r12), %rdi
movl 0xc(%rdi,%rax), %ebx
movq 0x20(%r13), %rdi
cmpl $0x0, (%rdi,%rbx,8)
movq (%r15), %r14
js 0xc357a
cmpq %rbx, %r14
jbe 0xc3592
movq 0x8(%r15), %rdx
cmpl $-0x2, (%rdx,%rbx,4)
jg 0xc3592
jmp 0xc3598
cmpq %rbx, %r14
jbe 0xc3592
movq 0x8(%r15), %rdx
movslq (%rdx,%rbx,4), %rbx
testq %rbx, %rbx
js 0xc3592
cmpl $0x0, (%rdi,%rbx,8)
jns 0xc3569
addq $0x28, %rax
jmp 0xc354f
incl %r9d
incq %rbp
jmp 0xc3509
movq 0x18(%rsp), %rax
addl %r10d, %eax
movq %rax, 0x18(%rsp)
movq 0x48(%rsp), %r8
incl %r8d
movq 0x8(%rsp), %r10
jmp 0xc34cf
xorl %eax, %eax
movq 0x18(%rsp), %r12
movq %r9, %r13
movq 0x38(%rsp), %rbx
movl %eax, %eax
cmpq %rax, %rbx
jbe 0xc3730
movq 0x48(%r10), %rdx
movl (%rdx,%rax,4), %edx
shrl %edx
imulq $0x28, %rdx, %r8
addq 0x10(%r11), %r8
xorl %r9d, %r9d
movl 0x10(%r8), %edx
cmpq %rdx, %r9
jae 0xc3612
movq 0x18(%r8), %rdx
movq (%rdx,%r9,8), %rdx
movq 0x8(%r15), %rdi
shrq $0x21, %rdx
orl $-0x1, (%rdi,%rdx,4)
incq %r9
jmp 0xc35f0
incl %eax
jmp 0xc35d1
xorl %eax, %eax
pushq $0x1
popq %r14
movl %eax, %ebx
movq 0x38(%r10), %rdi
cmpq %rbx, %rdi
jbe 0xc3654
movq 0x48(%r10), %rax
movl (%rax,%rbx,4), %esi
shrl %esi
movq 0x20(%r13), %rax
leaq (%rax,%rsi,8), %r8
addq $0x4, %r8
movq %r15, %rdi
movl %r14d, %edx
movl %r14d, %ecx
callq 0x6ab56
movq 0x8(%rsp), %r10
leal 0x1(%rbx), %eax
jmp 0xc361c
movq 0x10(%rsp), %rax
movq 0x38(%rax), %r12
xorl %r13d, %r13d
xorl %r8d, %r8d
xorl %esi, %esi
xorl %ecx, %ecx
movl %r8d, %eax
cmpq %rax, %r12
jbe 0xc3711
movq 0x10(%rsp), %rdx
movq 0x48(%rdx), %rdx
movl (%rdx,%rax,4), %edx
shrl %edx
imulq $0x18, %rdx, %r8
movq 0x30(%rsp), %r9
movl 0xc(%r9,%r8), %r10d
cmpq $0x1, %r10
sbbl $-0x1, %esi
movq 0xc8(%rsp), %r11
movb (%r11,%rdx), %dl
andb $0x3, %dl
cmpb $0x1, %dl
sbbl $-0x1, %ecx
addq %r8, %r9
leal 0x1(%rax), %r8d
imulq $0x28, %r10, %r10
xorl %eax, %eax
cmpq %rax, %r10
je 0xc3707
movq (%r9), %rdx
movl 0xc(%rdx,%rax), %r11d
movq 0x20(%rbp), %r14
cmpl $0x0, (%r14,%r11,8)
movq (%r15), %rbx
js 0xc36e5
cmpq %r11, %rbx
jbe 0xc36fe
movq 0x8(%r15), %rdx
cmpl $-0x2, (%rdx,%r11,4)
jg 0xc36fe
jmp 0xc3704
cmpq %r11, %rbx
jbe 0xc36fe
movq 0x8(%r15), %rdx
movslq (%rdx,%r11,4), %r11
testq %r11, %r11
js 0xc36fe
cmpl $0x0, (%r14,%r11,8)
jns 0xc36d3
addq $0x28, %rax
jmp 0xc36b8
incl %r13d
movq 0x8(%rsp), %r10
jmp 0xc3667
xorl %eax, %eax
movl %eax, %eax
cmpq %rax, %rdi
jbe 0xc3730
movq 0x48(%r10), %rdx
movl (%rdx,%rax,4), %edx
shrl %edx
movq 0x8(%r15), %r8
orl $-0x1, (%r8,%rdx,4)
incl %eax
jmp 0xc3713
testl %esi, %esi
pushq $-0x1
popq %rax
je 0xc349a
movl %r13d, %eax
cvtsi2ss %rax, %xmm0
movl %esi, %eax
cvtsi2ss %rax, %xmm1
leaq 0x190007(%rip), %rax    # 0x253758
mulss 0x16c(%rax), %xmm1
ucomiss %xmm1, %xmm0
jbe 0xc3781
movl %ecx, %eax
cvtsi2sd %rax, %xmm0
movl %r12d, %eax
cvtsi2sd %rax, %xmm1
mulsd 0x11fd7b(%rip), %xmm1   # 0x1e34f0
xorl %eax, %eax
ucomisd %xmm1, %xmm0
jae 0xc349a
pushq $0x1
jmp 0xc3499