// File: 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
movq %rsp, %rbp
pushq %rbx
subq $0xc8, %rsp
movl 0x20(%rbp), %eax
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
cmpl $0x1, 0x20(%rbp)
je 0x117b7e
cmpl $0x2, 0x20(%rbp)
je 0x117b7e
jmp 0x117ec7
leaq -0x4c(%rbp), %rdi
xorl %esi, %esi
movl $0x14, %edx
callq 0x2100
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
movl $0x14, %edx
callq 0x2100
movq $0x0, -0x88(%rbp)
movq $0x0, -0x90(%rbp)
movq 0x18(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rax
movq -0x38(%rbp), %rcx
imulq $0x18, (%rcx), %rcx
addq %rcx, %rax
movl 0x8(%rax), %edx
movl 0x10(%rbp), %r10d
movq 0x18(%rbp), %rax
leaq -0x94(%rbp), %rcx
leaq -0x70(%rbp), %r8
leaq -0x68(%rbp), %r9
leaq -0x78(%rbp), %rbx
leaq -0x80(%rbp), %r11
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x166c30
movl %eax, -0x9c(%rbp)
cmpl $0x5, -0x9c(%rbp)
je 0x117c25
jmp 0x117ec7
movq 0x18(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x4c(%rbp), %rdx
callq 0x116420
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl %eax, -0xa0(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movl %eax, -0xa4(%rbp)
movl $0x0, -0x98(%rbp)
movl -0x98(%rbp), %eax
cmpl -0x24(%rbp), %eax
jae 0x117ea9
movq -0x20(%rbp), %rax
movl -0x98(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x117c8a
jmp 0x117e95
movl -0x98(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpq (%rcx), %rax
jne 0x117c9e
jmp 0x117e95
movq 0x18(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rax
movl -0x98(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %edx
movl 0x10(%rbp), %r10d
movq 0x18(%rbp), %rax
leaq -0x94(%rbp), %rcx
leaq -0x70(%rbp), %r8
leaq -0x68(%rbp), %r9
leaq -0x78(%rbp), %rbx
leaq -0x80(%rbp), %r11
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x166c30
movl %eax, -0x9c(%rbp)
cmpl $0x5, -0x9c(%rbp)
je 0x117d11
jmp 0x117ec7
cvtsi2sdq -0x68(%rbp), %xmm1
movq -0x30(%rbp), %rax
cvtsi2sdq (%rax), %xmm2
movsd 0x26a508(%rip), %xmm0   # 0x382230
mulsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x117d37
jmp 0x117e95
movq 0x18(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0x116420
cmpl $0x1, 0x20(%rbp)
jne 0x117da8
movl -0x4c(%rbp), %eax
movl -0x48(%rbp), %ecx
movl -0x40(%rbp), %edx
subq %rdx, %rax
subq %rcx, %rax
movq %rax, -0x88(%rbp)
movl -0x60(%rbp), %eax
movl -0x5c(%rbp), %ecx
movl -0x54(%rbp), %edx
subq %rdx, %rax
subq %rcx, %rax
movq %rax, -0x90(%rbp)
movl -0x5c(%rbp), %ecx
movl -0x54(%rbp), %eax
addl %ecx, %eax
cvtsi2sd %rax, %xmm0
movl -0x50(%rbp), %eax
cvtsi2sd %rax, %xmm1
movsd 0x26a4d1(%rip), %xmm2   # 0x382268
mulsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jb 0x117da6
jmp 0x117e95
jmp 0x117da8
cmpl $0x2, 0x20(%rbp)
jne 0x117e08
movl -0x4c(%rbp), %ecx
movl -0x48(%rbp), %eax
movl -0x40(%rbp), %edx
subq %rdx, %rax
subq %rcx, %rax
movq %rax, -0x88(%rbp)
movl -0x60(%rbp), %ecx
movl -0x5c(%rbp), %eax
movl -0x54(%rbp), %edx
subq %rdx, %rax
subq %rcx, %rax
movq %rax, -0x90(%rbp)
movl -0x60(%rbp), %ecx
movl -0x54(%rbp), %eax
addl %ecx, %eax
cvtsi2sd %rax, %xmm0
movl -0x50(%rbp), %eax
cvtsi2sd %rax, %xmm1
movsd 0x26a471(%rip), %xmm2   # 0x382268
mulsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jb 0x117e06
jmp 0x117e95
jmp 0x117e08
movq -0x90(%rbp), %rax
cmpq -0x88(%rbp), %rax
jle 0x117e46
movq -0x60(%rbp), %rax
movq %rax, -0x4c(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x44(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x98(%rbp), %eax
movl %eax, -0xa0(%rbp)
movq -0x68(%rbp), %rax
movl %eax, -0xa4(%rbp)
jmp 0x117e93
movq -0x90(%rbp), %rax
cmpq -0x88(%rbp), %rax
jne 0x117e91
movq -0x68(%rbp), %rax
movl -0xa4(%rbp), %ecx
cmpq %rcx, %rax
jle 0x117e91
movq -0x60(%rbp), %rax
movq %rax, -0x4c(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x44(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x98(%rbp), %eax
movl %eax, -0xa0(%rbp)
movq -0x68(%rbp), %rax
movl %eax, -0xa4(%rbp)
jmp 0x117e93
jmp 0x117e95
movl -0x98(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x98(%rbp)
jmp 0x117c5a
movl -0xa0(%rbp), %eax
movl %eax, %ecx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movl -0xa4(%rbp), %eax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
addq $0xc8, %rsp
popq %rbx
popq %rbp
retq
nopw %cs:(%rax,%rax)