// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x8(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0xc(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x11f729
movq -0x70(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jne 0x11f735
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x11f91f
movq -0x68(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x70(%rbp), %rcx
cmpl 0x10(%rcx), %eax
ja 0x11f755
movq -0x68(%rbp), %rax
movq %rax, -0x78(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x4c(%rbp)
jmp 0x11f763
movq -0x70(%rbp), %rax
movq %rax, -0x78(%rbp)
movl -0x8(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl $0x0, -0x5c(%rbp)
movl $0x0, -0x58(%rbp)
movl $0x0, -0x54(%rbp)
movl $0x0, -0x50(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x78(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x11f8ba
movq -0x78(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x34(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movl %eax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0xc(%rax)
jb 0x11f7c9
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
movq -0x30(%rbp), %rax
movl -0x48(%rbp), %ecx
movzbl (%rax,%rcx), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x11f7ef
movq -0x30(%rbp), %rax
movl -0x48(%rbp), %ecx
movzbl (%rax,%rcx), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x11f7f8
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x20(%rbp), %rcx
movl -0x48(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl 0xc(%rcx), %eax
jae 0x11f8aa
movq -0x20(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl -0x38(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x28(%rbp), %rdi
movl -0x40(%rbp), %esi
leaq -0x3c(%rbp), %rdx
leaq -0x44(%rbp), %rcx
callq 0xd3d50
cmpl $-0x1, -0x3c(%rbp)
jne 0x11f85f
jmp 0x11f89c
cmpl $0x0, -0x44(%rbp)
jne 0x11f879
movq -0x28(%rbp), %rdi
movl -0x3c(%rbp), %esi
leaq -0x3c(%rbp), %rdx
leaq -0x44(%rbp), %rcx
callq 0xd3d50
cmpl $-0x1, -0x3c(%rbp)
je 0x11f885
cmpl $0x0, -0x44(%rbp)
jne 0x11f887
jmp 0x11f89c
movl -0x3c(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jne 0x11f89a
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x11f8aa
jmp 0x11f89c
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x11f808
jmp 0x11f8ac
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x11f786
cmpl $0x0, -0x50(%rbp)
jne 0x11f8c9
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x11f91f
movl -0x54(%rbp), %eax
cvtsi2ss %rax, %xmm0
movl -0x50(%rbp), %eax
cvtsi2ss %rax, %xmm1
leaq 0x2a4f18(%rip), %rax    # 0x3c47f8
mulss 0x16c(%rax), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x11f918
movl -0x58(%rbp), %eax
cvtsi2sd %rax, %xmm0
movl -0x5c(%rbp), %eax
cvtsi2sd %rax, %xmm1
movsd 0x262923(%rip), %xmm2   # 0x382228
mulsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jb 0x11f918
movl $0x0, -0x4(%rbp)
jmp 0x11f91f
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)