// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl %edx, (%rsp)
movss %xmm1, 0x8(%rsp)
movss %xmm0, 0x4(%rsp)
movq 0x18(%rdi), %rbx
movl 0x14(%rbx), %r13d
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x70(%rsp)
addl %r13d, %r13d
je 0xd529e
movl %esi, %r14d
movq %rdi, %r15
xorl %r12d, %r12d
movq 0x20(%rbx), %rax
movl %r12d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0xd5292
cmpb $0x1, 0x4(%rax,%rcx,8)
jne 0xd5292
movl %r12d, %ecx
xorl $0x1, %ecx
movq 0x28(%rbx), %rax
movq (%rax,%rcx,8), %rcx
movq %rcx, %rdx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rdx
je 0xd51cb
movq 0x8(%rbx), %rdi
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rsi
leaq (%rdi,%rsi,8), %rdi
addq $0xc, %rdi
leaq (,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
movl (%rdi,%r8), %r10d
notl %r10d
shrl $0x1f, %r10d
addl %r10d, %r9d
addq $0x18, %r8
cmpq %r8, %rcx
jne 0xd512f
cmpl $0x1, %r9d
jne 0xd51cb
testq %rdx, %rdx
je 0xd5176
movq 0x8(%rbx), %rdx
leaq (%rdx,%rsi,8), %rdx
addq $0xc, %rdx
xorl %esi, %esi
cmpl $0x0, (%rdx,%rsi)
js 0xd516d
movl -0x4(%rdx,%rsi), %edi
movl %edi, 0xc(%rsp)
addq $0x18, %rsi
cmpq %rsi, %rcx
jne 0xd515f
movl 0xc(%rsp), %ecx
xorq $0x1, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
andq %rdx, %rcx
je 0xd51cb
movq 0x8(%rbx), %rdx
shrq $0x20, %rax
leaq (%rax,%rax,2), %rax
leaq (%rdx,%rax,8), %rax
addq $0xc, %rax
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %edx, %edx
xorl %esi, %esi
movl (%rax,%rdx), %edi
notl %edi
shrl $0x1f, %edi
addl %edi, %esi
addq $0x18, %rdx
cmpq %rdx, %rcx
jne 0xd51af
cmpl $0x1, %esi
je 0xd5292
movq $0x0, 0x48(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
movl %r12d, %edx
leaq 0xc(%rsp), %rcx
leaq 0x90(%rsp), %r8
leaq 0x88(%rsp), %r9
leaq 0x10(%rsp), %rbp
pushq %rbp
pushq $0x1
leaq 0x88(%rsp), %rax
pushq %rax
leaq 0x98(%rsp), %rax
pushq %rax
callq 0x10109f
addq $0x20, %rsp
movq %rbp, %rdi
movq %r15, %rsi
movl %r14d, %edx
movss 0x4(%rsp), %xmm0
movss 0x8(%rsp), %xmm1
movl (%rsp), %ecx
callq 0xd4d7a
movq 0x48(%rsp), %rdx
cmpq $0x2, %rdx
jb 0xd5292
movq %rdx, %rcx
shrq %rcx
testl %ecx, %ecx
je 0xd5273
movq 0x58(%rsp), %rax
movl %ecx, %ecx
leaq (%rax,%rdx,4), %rdx
addq $-0x4, %rdx
negq %rcx
xorl %esi, %esi
movl (%rax), %edi
movl (%rdx,%rsi,4), %r8d
movl %r8d, (%rax)
movl %edi, (%rdx,%rsi,4)
addq $0x4, %rax
decq %rsi
cmpq %rsi, %rcx
jne 0xd525b
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
movl %r14d, %edx
movss 0x4(%rsp), %xmm0
movss 0x8(%rsp), %xmm1
movl (%rsp), %ecx
callq 0xd4d7a
incl %r12d
cmpl %r13d, %r12d
jne 0xd50cc
movq 0x58(%rsp), %rdi
callq 0x2220
movq %rbx, %rdi
callq 0xa02fa
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq