// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Purge_Dups.cpp
// Function: get_pair_hap_similarity_by_base(ma_utg_t*, asg_t*, unsigned int, ma_hit_t_alloc*, R_to_U*, long long, long long, double*, double*)
void get_pair_hap_similarity_by_base(ma_utg_t *xReads, asg_t *read_g, uint32_t target_uId, 
ma_hit_t_alloc* reverse_sources, R_to_U* ruIndex, long long xBegPos, long long xEndPos, 
double* Match, double* Total)
{
    uint32_t i, j, qn, tn, is_Unitig, uId, min_count = 0, max_count = 0;
    long long offset, r_beg, r_end, ovlp;
    
    for (i = 0, offset = 0; i < xReads->n; i++)
    {
        qn = xReads->a[i]>>33;
        r_beg = offset; r_end = offset + (long long)(read_g->seq[qn].len) - 1;
        offset += (uint32_t)xReads->a[i];
        
        ovlp = (long long)(MIN(r_end, xEndPos)) - (long long)(MAX(r_beg, xBegPos)) + 1;
        if(ovlp <= 0) continue;

        if(reverse_sources[qn].length > 0) min_count++;
        if(reverse_sources[qn].length == 0) continue;
        for (j = 0; j < reverse_sources[qn].length; j++)
        {
            tn = Get_tn(reverse_sources[qn].buffer[j]);
            if(read_g->seq[tn].del == 1)
            {
                get_R_to_U(ruIndex, tn, &tn, &is_Unitig);
                if(tn == (uint32_t)-1 || is_Unitig == 1 || read_g->seq[tn].del == 1) continue;
            }


            get_R_to_U(ruIndex, tn, &uId, &is_Unitig);
            if(uId!=(uint32_t)-1 && is_Unitig == 1 && uId == target_uId)
            {
                max_count++;
                break;
            }
        }
    }

    (*Match) = max_count;
    (*Total) = min_count;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, 0x40(%rsp)
movl %edx, 0x18(%rsp)
movq 0x90(%rsp), %rax
movq 0x88(%rsp), %rdx
cmpl $0x0, 0x10(%rdi)
je 0x10ac45
movq %rsi, %r12
movq 0x80(%rsp), %r8
xorl %r13d, %r13d
xorl %r10d, %r10d
xorl %r15d, %r15d
movl $0x0, 0xc(%rsp)
movq %r9, 0x30(%rsp)
movq %rcx, 0x28(%rsp)
movq %rdi, 0x20(%rsp)
movq 0x18(%rdi), %rax
movq (%rax,%r13,8), %r11
movq %r11, %rax
shrq $0x21, %rax
movq 0x20(%r12), %rdx
movl (%rdx,%rax,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
leaq (%r15,%rdx), %rsi
decq %rsi
cmpq %r8, %rsi
cmovgeq %r8, %rsi
cmpq %r9, %r15
movq %r9, %rdx
cmovgq %r15, %rdx
cmpq %rdx, %rsi
jl 0x10ac0d
leaq (%rax,%rax,2), %rax
movl 0xc(%rcx,%rax,8), %edx
xorl %esi, %esi
testl %edx, %edx
setne %dl
je 0x10ac0d
movq %r11, 0x38(%rsp)
movb %dl, %sil
addl %esi, %r10d
movl %r10d, 0x10(%rsp)
leaq (%rcx,%rax,8), %rbx
movl $0xc, %ebp
xorl %r14d, %r14d
movq (%rbx), %rax
movl (%rax,%rbp), %esi
movl %esi, 0x14(%rsp)
movq 0x20(%r12), %rax
cmpl $0x0, (%rax,%rsi,8)
js 0x10ab9f
movq 0x40(%rsp), %rdi
leaq 0x1c(%rsp), %rdx
leaq 0x8(%rsp), %rcx
callq 0xa3c62
movl 0x1c(%rsp), %eax
cmpl 0x18(%rsp), %eax
jne 0x10abd3
cmpl $-0x1, %eax
je 0x10abd3
cmpl $0x1, 0x8(%rsp)
jne 0x10abd3
jmp 0x10abe8
movq 0x40(%rsp), %rdi
leaq 0x14(%rsp), %rdx
leaq 0x8(%rsp), %rcx
callq 0xa3c62
movl 0x14(%rsp), %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %rsi
je 0x10abd3
cmpl $0x1, 0x8(%rsp)
je 0x10abd3
movq 0x20(%r12), %rax
cmpl $0x0, (%rax,%rsi,8)
jns 0x10ab73
incq %r14
movl 0xc(%rbx), %eax
addq $0x28, %rbp
cmpq %rax, %r14
jb 0x10ab5e
jmp 0x10abec
incl 0xc(%rsp)
movq 0x30(%rsp), %r9
movq 0x28(%rsp), %rcx
movq 0x20(%rsp), %rdi
movq 0x80(%rsp), %r8
movl 0x10(%rsp), %r10d
movq 0x38(%rsp), %r11
movl %r11d, %eax
addq %rax, %r15
incq %r13
movl 0x10(%rdi), %eax
cmpq %rax, %r13
jb 0x10aaef
movl 0xc(%rsp), %eax
cvtsi2sd %rax, %xmm0
movl %r10d, %eax
cvtsi2sd %rax, %xmm1
movq 0x90(%rsp), %rax
movq 0x88(%rsp), %rdx
jmp 0x10ac4d
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
movsd %xmm0, (%rdx)
movsd %xmm1, (%rax)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq