// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: asg_arc_del_self_circle_untig(asg_t*, long long, int)
long long asg_arc_del_self_circle_untig(asg_t *g, long long circleLen, int is_drop)
{
    uint32_t v, w, n_vtx = g->n_seq * 2, n_reduced = 0, convex, flag;
    long long ll;
    asg_arc_t *aw;
    uint32_t nw, k;
    for (v = 0; v < n_vtx; ++v) 
    {
        uint32_t i, n_arc = 0, nv = asg_arc_n(g, v);
        asg_arc_t *av = asg_arc_a(g, v);
        ///some node could be deleted
        if (g->seq[v>>1].del) continue;
        if(is_drop && g->seq[v>>1].c == ALTER_LABLE) continue;

        n_arc = get_real_length(g, v, NULL);
        if (n_arc != 1) continue;

        for (i = 0; i < nv; i++)
        {
            ///actually there is just one un-del edge
            if (!av[i].del)
            {    
                flag = detect_single_path_with_dels_by_length(g, v, &convex, &ll, NULL, circleLen);
                if(ll > circleLen || flag == LONG_TIPS)
                {
                    break;
                }
                if(flag == LOOP)
                {
                    break;
                }
                if(flag != END_TIPS && flag != LONG_TIPS)
                {
                    w = v^1;
                    n_arc = get_real_length(g, w, NULL);
                    if(n_arc == 0)
                    {
                        break;
                    }
                    aw = asg_arc_a(g, w);
                    nw = asg_arc_n(g, w);
                    for (k = 0; k < nw; k++)
                    {
                        if ((!aw[k].del) && (aw[k].v == (convex^1)))
                        {
                            aw[k].del = 1;
                            asg_arc_del(g, aw[k].v^1, aw[k].ul>>32^1, 1);
                            n_reduced++;
                        }
                    }
                }
            }
        }
    }

    if (n_reduced) {
        asg_cleanup(g);
        asg_symm(g);
    }

    if(VERBOSE >= 1)
    {
        fprintf(stderr, "[M::%s] removed %d self-circles\n", 
        __func__, n_reduced);
    }

    return n_reduced;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %r14
movl 0x14(%rdi), %eax
addl %eax, %eax
movq %rax, 0x30(%rsp)
xorl %r12d, %r12d
leaq 0xc(%rsp), %r13
movl $0x0, 0x8(%rsp)
movl %edx, 0x4(%rsp)
movq %rsi, 0x18(%rsp)
cmpq 0x30(%rsp), %r12
je 0xaaf7d
movq 0x20(%r14), %rax
movl %r12d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0xaaf75
movq 0x28(%r14), %rdx
movq (%rdx,%r12,8), %rbx
movq %rbx, %rdx
shrq $0x20, %rdx
imulq $0x18, %rdx, %rdx
addq 0x8(%r14), %rdx
movq %rdx, 0x10(%rsp)
testl %ebp, %ebp
je 0xaae3c
cmpb $0x1, 0x4(%rax,%rcx,8)
je 0xaaf75
movq %r14, %rdi
movl %r12d, %esi
xorl %edx, %edx
callq 0xc2e7a
cmpl $0x1, %eax
jne 0xaaf75
movl %r12d, %eax
xorl $0x1, %eax
movq %rax, 0x28(%rsp)
movl %ebx, %eax
movq %rax, 0x38(%rsp)
xorl %ebp, %ebp
movq 0x10(%rsp), %rbx
movq %r12, 0x20(%rsp)
cmpq 0x38(%rsp), %rbp
je 0xaaf71
imulq $0x18, %rbp, %rax
cmpl $0x0, 0xc(%rbx,%rax)
js 0xaaf69
movq %r14, %rdi
movl %r12d, %esi
movq %r13, %rdx
leaq 0x40(%rsp), %rcx
xorl %r8d, %r8d
movq %r15, %r9
callq 0xaac6e
cmpq %r15, 0x40(%rsp)
jg 0xaaf71
cmpl $0x5, %eax
je 0xaaf69
testl %eax, %eax
je 0xaaf71
cmpl $0x7, %eax
je 0xaaf71
movq %r14, %rdi
movq 0x28(%rsp), %rbx
movl %ebx, %esi
xorl %edx, %edx
callq 0xc2e7a
testl %eax, %eax
je 0xaaf71
movq 0x8(%r14), %rax
movq %r14, %r13
movq 0x28(%r14), %rcx
movq (%rcx,%rbx,8), %rcx
movl %ecx, %edx
shrq $0x20, %rcx
movl 0xc(%rsp), %r14d
imulq $0x18, %rdx, %r12
imulq $0x18, %rcx, %rcx
leaq (%rax,%rcx), %r15
addq $0xc, %r15
xorl %ebx, %ebx
cmpq %rbx, %r12
je 0xaaf52
movl (%r15,%rbx), %eax
testl %eax, %eax
js 0xaaf4c
movl -0x4(%r15,%rbx), %esi
movl %r14d, %ecx
xorl %esi, %ecx
cmpl $0x1, %ecx
jne 0xaaf4c
orl $0x80000000, %eax       # imm = 0x80000000
movl %eax, (%r15,%rbx)
xorl $0x1, %esi
movl -0x8(%r15,%rbx), %edx
xorl $0x1, %edx
movq %r13, %rdi
pushq $0x1
popq %rcx
callq 0x6db50
incl 0x8(%rsp)
addq $0x18, %rbx
jmp 0xaaf0d
movq %r13, %r14
movq 0x18(%rsp), %r15
movq 0x20(%rsp), %r12
leaq 0xc(%rsp), %r13
movq 0x10(%rsp), %rbx
incq %rbp
jmp 0xaae70
movl 0x4(%rsp), %ebp
incq %r12
jmp 0xaadf3
cmpl $0x0, 0x8(%rsp)
je 0xaaf94
movq %r14, %rdi
callq 0x694eb
movq %r14, %rdi
callq 0x69638
movl 0x8(%rsp), %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq