// File: /workspace/github_cpp_makefile_star2_O2/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, %r14
movl %edx, 0x18(%rsp)
movq %rsi, %r12
movq 0x80(%rsp), %r8
xorl %r10d, %r10d
movl $0x0, 0xc(%rsp)
xorl %r15d, %r15d
xorl %r11d, %r11d
movq %r9, 0x30(%rsp)
movq %rcx, 0x28(%rsp)
movq %rdi, 0x20(%rsp)
movl 0x10(%rdi), %eax
cmpq %rax, %r10
jae 0xc8526
movq 0x18(%rdi), %rax
movq (%rax,%r10,8), %r13
movq %r13, %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 0xc8518
imulq $0x18, %rax, %rbx
movl 0xc(%rcx,%rbx), %eax
xorl %esi, %esi
testl %eax, %eax
setne %dl
je 0xc8518
movq %r13, 0x38(%rsp)
movq %r10, 0x40(%rsp)
addq %rcx, %rbx
movb %dl, %sil
addl %esi, %r11d
movl %r11d, 0x10(%rsp)
pushq $0xc
popq %r13
xorl %ebp, %ebp
movl %eax, %eax
cmpq %rax, %rbp
jae 0xc84f2
movq (%rbx), %rax
movl (%rax,%r13), %esi
movl %esi, 0x14(%rsp)
movq 0x20(%r12), %rax
cmpl $0x0, (%rax,%rsi,8)
js 0xc84ad
movq %r14, %rdi
leaq 0x1c(%rsp), %rdx
leaq 0x8(%rsp), %rcx
callq 0x6c2a2
movl 0x1c(%rsp), %eax
cmpl 0x18(%rsp), %eax
jne 0xc84df
cmpl $-0x1, %eax
je 0xc84df
cmpl $0x1, 0x8(%rsp)
jne 0xc84df
jmp 0xc84ee
movq %r14, %rdi
leaq 0x14(%rsp), %rdx
leaq 0x8(%rsp), %rcx
callq 0x6c2a2
movl 0x14(%rsp), %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %rsi
je 0xc84df
cmpl $0x1, 0x8(%rsp)
je 0xc84df
movq 0x20(%r12), %rax
cmpl $0x0, (%rax,%rsi,8)
jns 0xc8483
incq %rbp
movl 0xc(%rbx), %eax
addq $0x28, %r13
jmp 0xc8462
incl 0xc(%rsp)
movq 0x30(%rsp), %r9
movq 0x28(%rsp), %rcx
movq 0x20(%rsp), %rdi
movq 0x80(%rsp), %r8
movq 0x40(%rsp), %r10
movl 0x10(%rsp), %r11d
movq 0x38(%rsp), %r13
movl %r13d, %eax
addq %rax, %r15
incq %r10
jmp 0xc83e5
movl 0xc(%rsp), %eax
cvtsi2sd %rax, %xmm0
movq 0x88(%rsp), %rax
movsd %xmm0, (%rax)
movl %r11d, %eax
cvtsi2sd %rax, %xmm0
movq 0x90(%rsp), %rax
movsd %xmm0, (%rax)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq