// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: renew_longest_tip_by_drop(asg_t*, ma_ug_t*, asg_arc_t*, unsigned int, long long*, long long*, unsigned int, buf_t*, unsigned int)
void renew_longest_tip_by_drop(asg_t *g, ma_ug_t *ug, asg_arc_t *av, uint32_t nv,
long long* base_maxLen, long long* base_maxLen_i, uint32_t stops_threshold, buf_t* b, 
uint32_t trio_flag)
{
    if(trio_flag != FATHER && trio_flag != MOTHER) return;
    Trio_counter max, cur;
    memset(&max, 0, sizeof(Trio_counter));
    memset(&cur, 0, sizeof(Trio_counter));
    long long ll, tmp, max_stop_nodeLen, max_stop_baseLen, max_weight = 0, cur_weight = 0;
    uint32_t convex, i, return_flag, best_tip_i, best_tip_len;
    
    b->b.n = 0;
    return_flag = get_unitig(g, ug, av[(*base_maxLen_i)].v, &convex, &tmp, &ll, 
    &max_stop_nodeLen, &max_stop_baseLen, stops_threshold, b);
    if(return_flag!=END_TIPS) return;


    get_trio_labs(b, ug, &max);
    ///means this unitig might be at current haplotype
    ///if(max.drop_occ<(max.total*TRIO_DROP_THRES)) return;


    best_tip_i = (*base_maxLen_i);
    best_tip_len = (*base_maxLen);

    for (i = 0; i < nv; i++)
    {
        if(av[i].del) continue;
        if(i==(*base_maxLen_i)) continue;

        b->b.n = 0;
        return_flag = get_unitig(g, ug, av[i].v, &convex, &tmp, &ll, 
        &max_stop_nodeLen, &max_stop_baseLen, stops_threshold, b);

        if(return_flag!=END_TIPS) return;
        ///this tip should be long enough
        if(ll<(TRIO_DROP_LENGTH_THRES*(*base_maxLen))) continue;

        get_trio_labs(b, ug, &cur);

        if(trio_flag == FATHER)
        {
            max_weight = (long long)max.father_occ - (long long)max.drop_occ - (long long)max.mother_occ;
            cur_weight = (long long)cur.father_occ - (long long)cur.drop_occ - (long long)cur.mother_occ;
            ///this unitig is very likly at another haplotype, ignore it
            if((cur.drop_occ+cur.mother_occ)>=(cur.total*TRIO_DROP_THRES)) continue;
        }

        if(trio_flag == MOTHER)
        {
            max_weight = (long long)max.mother_occ - (long long)max.drop_occ - (long long)max.father_occ;
            cur_weight = (long long)cur.mother_occ - (long long)cur.drop_occ - (long long)cur.father_occ;
            ///this unitig is very likly at another haplotype, ignore it
            if((cur.drop_occ+cur.father_occ)>=(cur.total*TRIO_DROP_THRES)) continue;
        }


        if(cur_weight > max_weight)
        {
            max = cur;
            best_tip_i = i;
            best_tip_len = ll;
        }
        else if(cur_weight == max_weight && ll>best_tip_len)
        {
            max = cur;
            best_tip_i = i;
            best_tip_len = ll;
        }
    }

    (*base_maxLen_i) = best_tip_i;
    (*base_maxLen) = best_tip_len;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %r8, 0x68(%rsp)
movl 0xe0(%rsp), %eax
addl $-0x3, %eax
cmpl $-0x2, %eax
jb 0xce4a6
movq %r9, %r12
movl %ecx, %ebp
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %r13
movq 0xd8(%rsp), %r10
movl 0xd0(%rsp), %r11d
xorpd %xmm0, %xmm0
movapd %xmm0, 0x40(%rsp)
xorl %eax, %eax
movl %eax, 0x50(%rsp)
movapd %xmm0, 0x20(%rsp)
movl %eax, 0x30(%rsp)
movq $0x0, 0x38(%r10)
movq (%r9), %rax
leaq (%rax,%rax,2), %rax
movl 0x8(%rdx,%rax,8), %edx
leaq 0x80(%rsp), %rax
leaq 0x88(%rsp), %rbx
leaq 0x74(%rsp), %rcx
leaq 0x90(%rsp), %r8
leaq 0x78(%rsp), %r9
pushq %r10
pushq %r11
pushq %rax
pushq %rbx
callq 0x10109f
addq $0x20, %rsp
cmpl $0x5, %eax
jne 0xce4a6
leaq 0x40(%rsp), %rdx
movq 0xd8(%rsp), %rdi
movq %r14, %rsi
callq 0xcc948
movl (%r12), %eax
movl %eax, 0x1c(%rsp)
movq 0x68(%rsp), %rax
movl (%rax), %eax
movl %eax, 0xc(%rsp)
testl %ebp, %ebp
je 0xce492
movl %ebp, %ebp
addq $0xc, %r15
xorl %ebx, %ebx
movq $0x0, 0x58(%rsp)
movq $0x0, 0x60(%rsp)
movq %r12, 0x10(%rsp)
cmpl $0x0, (%r15)
js 0xce482
cmpq (%r12), %rbx
je 0xce482
movq 0xd8(%rsp), %rax
movq $0x0, 0x38(%rax)
movl -0x4(%r15), %edx
movq %r13, %rdi
movq %r14, %rsi
leaq 0x74(%rsp), %rcx
leaq 0x90(%rsp), %r8
leaq 0x78(%rsp), %r9
pushq %rax
movl 0xd8(%rsp), %eax
pushq %rax
leaq 0x90(%rsp), %rax
pushq %rax
leaq 0xa0(%rsp), %rax
pushq %rax
callq 0x10109f
addq $0x20, %rsp
cmpl $0x5, %eax
jne 0xce4a6
movq %r13, %r12
movq 0x78(%rsp), %r13
xorps %xmm0, %xmm0
cvtsi2sd %r13, %xmm0
movq 0x68(%rsp), %rax
xorps %xmm1, %xmm1
cvtsi2sdq (%rax), %xmm1
mulsd 0x157154(%rip), %xmm1   # 0x2254b0
ucomisd %xmm0, %xmm1
ja 0xce47a
movq 0xd8(%rsp), %rdi
movq %r14, %rsi
leaq 0x20(%rsp), %rdx
callq 0xcc948
movl 0xe0(%rsp), %eax
cmpl $0x1, %eax
jne 0xce3de
movl 0x40(%rsp), %edx
movl 0x44(%rsp), %eax
movl 0x4c(%rsp), %ecx
addq %rcx, %rax
subq %rax, %rdx
movq %rdx, 0x60(%rsp)
movl 0x20(%rsp), %esi
movl 0x24(%rsp), %eax
movl 0x2c(%rsp), %ecx
leal (%rax,%rcx), %edx
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
addq %rax, %rcx
movl 0x30(%rsp), %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
subq %rcx, %rsi
movq %rsi, 0x58(%rsp)
mulsd 0x157124(%rip), %xmm1   # 0x2254f8
ucomisd %xmm1, %xmm0
jae 0xce47a
movl 0xe0(%rsp), %eax
cmpl $0x2, %eax
jne 0xce43d
movl 0x40(%rsp), %eax
movl 0x44(%rsp), %edx
movl 0x4c(%rsp), %ecx
addq %rcx, %rax
subq %rax, %rdx
movq %rdx, 0x60(%rsp)
movl 0x20(%rsp), %eax
movl 0x24(%rsp), %esi
movl 0x2c(%rsp), %ecx
leal (%rax,%rcx), %edx
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
addq %rax, %rcx
movl 0x30(%rsp), %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
subq %rcx, %rsi
movq %rsi, 0x58(%rsp)
mulsd 0x1570c1(%rip), %xmm1   # 0x2254f8
ucomisd %xmm1, %xmm0
jae 0xce47a
movq 0x58(%rsp), %rax
cmpq 0x60(%rsp), %rax
jg 0xce45d
sete %al
movl 0xc(%rsp), %ecx
cmpq %rcx, %r13
setg %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xce47a
movl 0x30(%rsp), %eax
movl %eax, 0x50(%rsp)
movapd 0x20(%rsp), %xmm0
movapd %xmm0, 0x40(%rsp)
movl %ebx, 0x1c(%rsp)
movl %r13d, 0xc(%rsp)
movq %r12, %r13
movq 0x10(%rsp), %r12
incq %rbx
addq $0x18, %r15
cmpq %rbx, %rbp
jne 0xce2ca
movl 0x1c(%rsp), %eax
movq %rax, (%r12)
movl 0xc(%rsp), %eax
movq 0x68(%rsp), %rcx
movq %rax, (%rcx)
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq