// File: /workspace/github_cpp_makefile_star2_O2/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 %r9, -0x8(%rsp)
movq 0x10(%rdx), %r14
movl %edi, %eax
imulq $0x28, %rax, %r11
movl 0x10(%r14,%r11), %r10d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %r10d, %r10d
je 0x992ac
movl %esi, %r9d
imulq $0x28, %r9, %r9
addq %r14, %r9
movl 0x10(%r9), %ebx
testl %ebx, %ebx
je 0x992ac
addq %r11, %r14
cmpl %ebx, %r10d
cmoval %edi, %esi
cmovaq %r9, %r14
movl 0x10(%r14), %edx
xorl %r10d, %r10d
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl $0x0, -0xc(%rsp)
xorl %edi, %edi
cmpq %rdx, %r10
je 0x9925d
movq %r14, %rbp
movq 0x18(%r14), %rax
movq (%rax,%r10,8), %rax
shrq $0x21, %rax
imulq $0x18, %rax, %r9
incq %r10
movq -0x8(%rsp), %r11
movb (%r11,%rax), %al
andb $0x3, %al
cmpb $0x1, %al
sbbl $-0x1, %edi
leaq (%rcx,%r9), %r14
movl 0xc(%rcx,%r9), %eax
imulq $0x28, %rax, %r15
xorl %r12d, %r12d
cmpq %r12, %r15
je 0x99255
movq (%r14), %rax
movl 0xc(%rax,%r12), %r9d
movq (%r8), %r11
cmpq %r9, %r11
jbe 0x9924b
movq 0x8(%r8), %rax
movl (%rax,%r9,4), %r13d
cmpq %rbx, %r13
je 0x9924b
movl %r13d, %r9d
andl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
testl %r13d, %r13d
js 0x99238
cmpq %r9, %r11
jbe 0x9922b
movl (%rax,%r9,4), %eax
cmpl $-0x1, %eax
je 0x9922b
movl %eax, %r9d
andl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
testl %eax, %eax
setns %r11b
jmp 0x9923b
xorl %r11d, %r11d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, %r9d
jmp 0x9923b
xorl %r11d, %r11d
cmpl %esi, %r9d
jne 0x9924b
cmpl $-0x1, %r9d
je 0x9924b
testb %r11b, %r11b
je 0x99251
addq $0x28, %r12
jmp 0x991da
incl -0xc(%rsp)
movq %rbp, %r14
jmp 0x9919b
testq %rdx, %rdx
je 0x992a7
movl -0xc(%rsp), %eax
cvtsi2ss %rax, %xmm0
cvtsi2ss %rdx, %xmm1
leaq 0x1ba4e1(%rip), %rax    # 0x253758
mulss 0x16c(%rax), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x992a0
movl %edi, %eax
cvtsi2sd %rax, %xmm0
cvtsi2sd %rdx, %xmm1
mulsd 0x14a258(%rip), %xmm1   # 0x1e34f0
xorl %eax, %eax
ucomisd %xmm1, %xmm0
jae 0x992ac
movl $0x1, %eax
jmp 0x992ac
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq