// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: rescue_useless_trio_nodes(ma_ug_t*, unsigned int, float, float, unsigned int)
void rescue_useless_trio_nodes(ma_ug_t *ug, uint32_t flag, float flag_rate, float used_rate, uint32_t min_occ)
{
    asg_t* nsg = ug->g; 
    uint32_t v, w, n_vtx = nsg->n_seq<<1, i, k, z;
    long long nodeLen, baseLen, max_stop_nodeLen, max_stop_baseLen;
    buf_t b; memset(&b, 0, sizeof(buf_t));

    for (v = 0; v < n_vtx; v++) {
        if(nsg->seq[v>>1].del) continue;
        if(nsg->seq[v>>1].c != ALTER_LABLE) continue;
        ///check if beg is the tig end
        if(get_real_length(nsg, v^1, NULL) == 1) {
            get_real_length(nsg, v^1, &w);
            if(get_real_length(nsg, w^1, NULL) == 1) continue;
        }

        b.b.n = 0; 
        get_unitig(nsg, ug, v, &w, &nodeLen, &baseLen, &max_stop_nodeLen, &max_stop_baseLen, 1, &b);
        recover_chain_nodes(&b, ug, flag, flag_rate, used_rate, min_occ);
        if(b.b.n > 1) {
            k = b.b.n>>1;
            for (i = 0; i < k; i++) {
                z = b.b.a[i]; b.b.a[i] = b.b.a[b.b.n-i-1]; b.b.a[b.b.n-i-1] = z;
            }
            recover_chain_nodes(&b, ug, flag, flag_rate, used_rate, min_occ);
        }
    }
    
    free(b.b.a);
    asg_cleanup(nsg);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movss %xmm0, -0x10(%rbp)
movss %xmm1, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movl %eax, -0x2c(%rbp)
leaq -0xc0(%rbp), %rdi
xorl %esi, %esi
movl $0x68, %edx
callq 0x2100
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jae 0x11fed4
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x24(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x11fd51
jmp 0x11fec6
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x24(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl 0x4(%rax,%rcx,8), %eax
cmpl $0x1, %eax
je 0x11fd6f
jmp 0x11fec6
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
xorl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x166b50
cmpl $0x1, %eax
jne 0x11fdb9
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
xorl $0x1, %esi
leaq -0x28(%rbp), %rdx
callq 0x166b50
movq -0x20(%rbp), %rdi
movl -0x28(%rbp), %esi
xorl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x166b50
cmpl $0x1, %eax
jne 0x11fdb7
jmp 0x11fec6
jmp 0x11fdb9
movq $0x0, -0x88(%rbp)
movq -0x20(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl -0x24(%rbp), %edx
leaq -0x28(%rbp), %rcx
leaq -0x40(%rbp), %r8
leaq -0x48(%rbp), %r9
leaq -0x50(%rbp), %r11
leaq -0x58(%rbp), %r10
leaq -0xc0(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x166c30
movq -0x8(%rbp), %rsi
movl -0xc(%rbp), %edx
movss -0x10(%rbp), %xmm0
movss -0x14(%rbp), %xmm1
movl -0x18(%rbp), %ecx
leaq -0xc0(%rbp), %rdi
callq 0x11f930
cmpq $0x1, -0x88(%rbp)
jbe 0x11fec4
movq -0x88(%rbp), %rax
shrq %rax
movl %eax, -0x34(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x34(%rbp), %eax
jae 0x11fea4
movq -0x78(%rbp), %rax
movl -0x30(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x38(%rbp)
movq -0x78(%rbp), %rax
movq -0x88(%rbp), %rcx
movl -0x30(%rbp), %edx
subq %rdx, %rcx
subq $0x1, %rcx
movl (%rax,%rcx,4), %edx
movq -0x78(%rbp), %rax
movl -0x30(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x38(%rbp), %edx
movq -0x78(%rbp), %rax
movq -0x88(%rbp), %rcx
movl -0x30(%rbp), %esi
subq %rsi, %rcx
subq $0x1, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x11fe47
movq -0x8(%rbp), %rsi
movl -0xc(%rbp), %edx
movss -0x10(%rbp), %xmm0
movss -0x14(%rbp), %xmm1
movl -0x18(%rbp), %ecx
leaq -0xc0(%rbp), %rdi
callq 0x11f930
jmp 0x11fec6
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x11fd26
movq -0x78(%rbp), %rdi
callq 0x2210
movq -0x20(%rbp), %rdi
callq 0xcdd10
addq $0xe0, %rsp
popq %rbp
retq
nop