// File: /workspace/github_cpp_makefile_star2_O3/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 $0x38, %rsp
movl %edx, 0x8(%rsp)
movq %rsi, 0x18(%rsp)
movl 0x14(%rdi), %eax
xorl %ebx, %ebx
addl %eax, %eax
je 0xe95ec
movq %rdi, %r14
movl %eax, %eax
movq %rax, 0x20(%rsp)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %r12d, %r12d
movq 0x20(%r14), %rdx
movl %r12d, %esi
shrl %esi
cmpl $0x0, (%rdx,%rsi,8)
js 0xe95b7
movq 0x28(%r14), %rax
movq (%rax,%r12,8), %rax
movq 0x8(%r14), %rcx
cmpl $0x0, 0x8(%rsp)
je 0xe93ec
cmpb $0x1, 0x4(%rdx,%rsi,8)
je 0xe95b7
movq %rax, %rdx
andq %rbp, %rdx
je 0xe95b7
movq %rax, %rsi
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %rsi
leaq (%rcx,%rsi,8), %r13
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %rcx
xorl %edx, %edx
xorl %esi, %esi
movl 0xc(%r13,%rdx), %edi
notl %edi
shrl $0x1f, %edi
addl %edi, %esi
addq $0x18, %rdx
cmpq %rdx, %rcx
jne 0xe9413
cmpl $0x1, %esi
jne 0xe95b7
movl %eax, %ecx
testq %rcx, %rcx
je 0xe95b7
movl %r12d, %ecx
xorq $0x1, %rcx
movq %rcx, 0x10(%rsp)
movl %eax, %eax
movq %rax, 0x28(%rsp)
xorl %r15d, %r15d
leaq (%r15,%r15,2), %rax
cmpl $0x0, 0xc(%r13,%rax,8)
js 0xe95a2
movq %r14, %rdi
movl %r12d, %esi
leaq 0xc(%rsp), %rdx
leaq 0x30(%rsp), %rcx
xorl %r8d, %r8d
movq 0x18(%rsp), %rbp
movq %rbp, %r9
callq 0xe9125
cmpq %rbp, 0x30(%rsp)
jg 0xe95b2
cmpl $0x5, %eax
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
je 0xe95a2
testl %eax, %eax
je 0xe95b7
cmpl $0x7, %eax
je 0xe95b7
movq 0x28(%r14), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
movq %rdx, %rcx
andq %rbp, %rcx
je 0xe95b7
movq 0x8(%r14), %rax
movq %rdx, %rsi
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %rsi
leaq (%rax,%rsi,8), %rax
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %esi, %esi
xorl %edi, %edi
movl 0xc(%rax,%rsi), %r8d
notl %r8d
shrl $0x1f, %r8d
addl %r8d, %edi
addq $0x18, %rsi
cmpq %rsi, %rcx
jne 0xe94e4
testl %edi, %edi
je 0xe95b7
testl %edx, %edx
je 0xe95a2
movl 0xc(%rsp), %ecx
movl %edx, %edx
xorl %esi, %esi
leaq (%rsi,%rsi,2), %rdi
movl 0xc(%rax,%rdi,8), %r8d
testl %r8d, %r8d
js 0xe9596
leaq (%rax,%rdi,8), %rdi
movl 0x8(%rdi), %r9d
movl %ecx, %r10d
xorl %r9d, %r10d
cmpl $0x1, %r10d
jne 0xe9596
orl $0x80000000, %r8d       # imm = 0x80000000
movl %r8d, 0xc(%rdi)
xorq $0x1, %r9
movq 0x28(%r14), %r8
movq (%r8,%r9,8), %r9
movq %r9, %r8
andq %rbp, %r8
je 0xe9594
movl 0x4(%rdi), %edi
movq 0x8(%r14), %r10
shrq $0x20, %r9
shlq $0x3, %r8
leaq (%r8,%r8,2), %r8
leaq (%r9,%r9,2), %r9
leaq (%r10,%r9,8), %r9
addq $0xc, %r9
xorl %r10d, %r10d
movl -0x4(%r9,%r10), %r11d
xorl %edi, %r11d
cmpl $0x1, %r11d
jne 0xe958b
orb $-0x80, 0x3(%r9,%r10)
addq $0x18, %r10
cmpq %r10, %r8
jne 0xe9577
incl %ebx
incq %rsi
cmpq %rdx, %rsi
jne 0xe9514
incq %r15
cmpq 0x28(%rsp), %r15
jne 0xe9452
jmp 0xe95b7
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
incq %r12
cmpq 0x20(%rsp), %r12
jne 0xe93bb
testl %ebx, %ebx
je 0xe95ea
movq %r14, %rdi
callq 0xa0a7d
movq %r14, %rdi
callq 0xa0ab6
movq %r14, %rdi
callq 0xa0b79
orb $-0x80, 0x17(%r14)
movl %ebx, %ebx
jmp 0xe95ec
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq