// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: get_end_match_length(ma_hit_t*, UC_Read*, UC_Read*, unsigned int*, unsigned int*)
void get_end_match_length(ma_hit_t* edge, UC_Read* query, UC_Read* target,
uint32_t* left, uint32_t* right)
{
    (*left) = (*right) = 0;

    uint32_t query_beg, query_end, target_beg, target_end, targetLen, oLen;
    long long i;
    targetLen = Get_READ_LENGTH(R_INF, Get_tn(*edge));
    query_beg = Get_qs(*edge);
    query_end = Get_qe(*edge)-1;
    recover_UC_Read(query, &R_INF, Get_qn(*edge));
    
    if(edge->rev)
    {
        target_beg = targetLen-(Get_te(*edge)-1)-1;
        target_end = targetLen-Get_ts(*edge)-1;
        recover_UC_Read_RC(target, &R_INF, Get_tn(*edge));
    }
    else
    {
        target_beg = Get_ts(*edge);
        target_end = Get_te(*edge)-1;
        recover_UC_Read(target, &R_INF, Get_tn(*edge));
    }

    oLen = Get_qe(*edge) - Get_qs(*edge);
    /***************************left*******************************/
    for (i = 0; i < oLen; i++)
    {
        if(query->seq[query_beg+i]!=target->seq[target_beg+i]) break;
        (*left)++;
    }
    /***************************left*******************************/

    /***************************right*******************************/
    for (i = 0; i < oLen; i++)
    {
        if(query->seq[query_end-i]!=target->seq[target_end-i]) break;
        (*right)++;
    }
    /***************************right*******************************/
    
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
leaq 0x2f6429(%rip), %rax    # 0x3c52d0
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rcx
movl 0xc(%rcx), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
subl $0x1, %eax
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, %eax
movl %eax, %edx
leaq 0x2f63e6(%rip), %rsi    # 0x3c52d0
callq 0xa380
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x1f, %rax
andq $0x1, %rax
cmpl $0x0, %eax
je 0xcef44
movl -0x3c(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x14(%rcx), %ecx
subl $0x1, %ecx
subl %ecx, %eax
subl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x3c(%rbp), %eax
movq -0x8(%rbp), %rcx
subl 0x10(%rcx), %eax
subl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, %edx
leaq 0x2f6393(%rip), %rsi    # 0x3c52d0
callq 0xa500
jmp 0xcef74
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
subl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, %edx
leaq 0x2f6361(%rip), %rsi    # 0x3c52d0
callq 0xa380
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
subl %ecx, %eax
movl %eax, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
movl -0x40(%rbp), %ecx
cmpq %rcx, %rax
jge 0xcefde
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x2c(%rbp), %ecx
addq -0x48(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movq -0x18(%rbp), %rcx
movq (%rcx), %rcx
movl -0x34(%rbp), %edx
addq -0x48(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0xcefc5
jmp 0xcefde
movq -0x20(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0xcef8f
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
movl -0x40(%rbp), %ecx
cmpq %rcx, %rax
jge 0xcf035
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x30(%rbp), %ecx
subq -0x48(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movq -0x18(%rbp), %rcx
movq (%rcx), %rcx
movl -0x38(%rbp), %edx
subq -0x48(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0xcf01c
jmp 0xcf035
movq -0x28(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0xcefe6
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)