// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: unitig_simi(unsigned int, unsigned int, ma_ug_t*, ma_hit_t_alloc*, R_to_U*, unsigned char*)
uint32_t unitig_simi(uint32_t x, uint32_t y, ma_ug_t* ug, ma_hit_t_alloc* reverse_sources, 
R_to_U* ruIndex, uint8_t* is_r_het)
{
    uint32_t k, j, uId, tn, is_Unitig, rId, ref_unitig, min_count, max_count, n_het, n_hom;
    ma_utg_t *nsu_x = NULL, *nsu_y = NULL, *nsu_query = NULL;
    nsu_x = &(ug->u.a[x]);
    nsu_y = &(ug->u.a[y]);

    if(nsu_x->n == 0 || nsu_y->n == 0) return UNAVAILABLE;

    if(nsu_x->n <= nsu_y->n)
    {
        nsu_query = nsu_x;
        ref_unitig = y;
    }
    else
    {
        nsu_query = nsu_y;
        ref_unitig = x;
    }
     
    min_count = max_count = n_het = n_hom = 0;
    for (k = 0; k < nsu_query->n; k++)
    {
        rId = nsu_query->a[k]>>33;
        if(reverse_sources[rId].length >= 0) min_count++;
        if((is_r_het[rId] & C_HET) || (is_r_het[rId] & P_HET)) n_het++;
        n_hom++;

        for (j = 0; j < reverse_sources[rId].length; j++)
        {
            tn = Get_tn(reverse_sources[rId].buffer[j]);
            get_R_to_U(ruIndex, tn, &uId, &is_Unitig);
            if(uId==(uint32_t)-1) continue;
            ///contained read
            if(is_Unitig == 0) get_R_to_U(ruIndex, uId, &uId, &is_Unitig);
            if(uId == (uint32_t)-1 || is_Unitig == 0) continue;
            if(uId == ref_unitig)
            {
                max_count++;
                break;
            }
        }
    }
    
    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
movq 0x10(%rdx), %r14
movl %edi, %edx
leaq (%rdx,%rdx,4), %rdx
movl 0x10(%r14,%rdx,8), %r10d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %r10d, %r10d
je 0xd4d6f
movl %esi, %r11d
leaq (%r11,%r11,4), %r11
leaq (%r14,%r11,8), %r11
movl 0x10(%r11), %ebx
testl %ebx, %ebx
je 0xd4d6f
cmpl %ebx, %r10d
cmoval %edi, %esi
leaq (%r14,%rdx,8), %rdi
cmovaq %r11, %rdi
movl 0x10(%rdi), %edx
testq %rdx, %rdx
je 0xd4d2a
movq 0x18(%rdi), %r10
xorl %r11d, %r11d
xorl %edi, %edi
movl $0x0, -0x4(%rsp)
movq (%r10,%r11,8), %r14
shrq $0x21, %r14
leaq (%r14,%r14,2), %rbx
movb (%r9,%r14), %bpl
andb $0x3, %bpl
cmpb $0x1, %bpl
sbbl $-0x1, %edi
movl 0xc(%rcx,%rbx,8), %r12d
testq %r12, %r12
je 0xd4d07
leaq (%rcx,%rbx,8), %rbx
movq (%rbx), %r14
movq (%r8), %r15
shlq $0x3, %r12
leaq (%r12,%r12,4), %r12
xorl %r13d, %r13d
movl 0xc(%r14,%r13), %ebx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpq %rbx, %r15
jbe 0xd4cb7
movq 0x8(%r8), %rax
movl (%rax,%rbx,4), %ebx
cmpl $-0x1, %ebx
je 0xd4cb7
movl %ebx, %ebp
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
testl %ebx, %ebx
setns %bl
jmp 0xd4cb9
xorl %ebx, %ebx
cmpl $-0x1, %ebp
je 0xd4cf8
testb %bl, %bl
je 0xd4ce9
movl %ebp, %ebx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpq %rbx, %r15
jbe 0xd4ce9
movq 0x8(%r8), %rax
movl (%rax,%rbx,4), %ebx
cmpl $-0x1, %ebx
je 0xd4ce9
movl %ebx, %ebp
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
testl %ebx, %ebx
setns %bl
jmp 0xd4ceb
xorl %ebx, %ebx
cmpl %esi, %ebp
jne 0xd4cf8
cmpl $-0x1, %ebp
je 0xd4cf8
testb %bl, %bl
je 0xd4d03
addq $0x28, %r13
cmpq %r13, %r12
jne 0xd4c8d
jmp 0xd4d07
incl -0x4(%rsp)
incq %r11
cmpq %rdx, %r11
jne 0xd4c4f
movl -0x4(%rsp), %eax
cvtsi2ss %rax, %xmm1
movl %edi, %eax
cvtsi2sd %rax, %xmm0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0xd4d33
xorl %edx, %edx
xorpd %xmm0, %xmm0
xorps %xmm1, %xmm1
testl %edx, %edx
je 0xd4d6f
movl %edx, %eax
cvtsi2ss %rax, %xmm2
leaq 0x1b5a13(%rip), %rcx    # 0x28a758
mulss 0x16c(%rcx), %xmm2
ucomiss %xmm2, %xmm1
jbe 0xd4d6a
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd 0x15073e(%rip), %xmm1   # 0x2254a0
xorl %eax, %eax
ucomisd %xmm1, %xmm0
jae 0xd4d6f
movl $0x1, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq