// File: /workspace/github_cpp_makefile_star2_O1/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, 0x20(%rsp)
movq %rdi, %rbx
movl 0x14(%rdi), %eax
addl %eax, %eax
je 0xe7dc2
movl %eax, %eax
movq %rax, 0x18(%rsp)
xorl %r15d, %r15d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
xorl %ebp, %ebp
movq 0x20(%rbx), %rdx
movl %r15d, %esi
shrl %esi
cmpl $0x0, (%rdx,%rsi,8)
js 0xe7db2
movq 0x28(%rbx), %rax
movq (%rax,%r15,8), %rax
movq 0x8(%rbx), %rcx
cmpl $0x0, 0x8(%rsp)
je 0xe7bca
cmpb $0x1, 0x4(%rdx,%rsi,8)
je 0xe7db2
movq %rax, %rdx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
xorl %esi, %esi
movq %rax, %r8
andq %r13, %r8
je 0xe7c10
leaq (%rcx,%rdx,8), %rdi
addq $0xc, %rdi
shlq $0x3, %r8
leaq (%r8,%r8,2), %r8
xorl %r9d, %r9d
movl (%rdi,%r9), %r10d
notl %r10d
shrl $0x1f, %r10d
addl %r10d, %esi
addq $0x18, %r9
cmpq %r9, %r8
jne 0xe7bf2
cmpl $0x1, %esi
sete %sil
testb %sil, %sil
je 0xe7db2
movl %eax, %esi
testq %rsi, %rsi
je 0xe7db2
leaq (%rcx,%rdx,8), %r12
movl %r15d, %ecx
xorq $0x1, %rcx
movq %rcx, 0x10(%rsp)
movl %eax, %eax
movq %rax, 0x28(%rsp)
xorl %r14d, %r14d
leaq (%r14,%r14,2), %rax
cmpl $0x0, 0xc(%r12,%rax,8)
js 0xe7d9c
movq %rbx, %rdi
movl %r15d, %esi
leaq 0xc(%rsp), %rdx
leaq 0x30(%rsp), %rcx
xorl %r8d, %r8d
movq 0x20(%rsp), %r13
movq %r13, %r9
callq 0xe7909
cmpq %r13, 0x30(%rsp)
jg 0xe7dac
cmpl $0x5, %eax
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
je 0xe7d9c
testl %eax, %eax
je 0xe7db2
cmpl $0x7, %eax
je 0xe7db2
movq 0x28(%rbx), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
movq %rdx, %rsi
andq %r13, %rsi
je 0xe7db2
movq 0x8(%rbx), %rcx
movq %rdx, %rax
shrq $0x20, %rax
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rcx
addq $0xc, %rcx
shlq $0x3, %rsi
leaq (%rsi,%rsi,2), %rsi
xorl %edi, %edi
xorl %r8d, %r8d
movl (%rcx,%rdi), %r9d
notl %r9d
shrl $0x1f, %r9d
addl %r9d, %r8d
addq $0x18, %rdi
cmpq %rdi, %rsi
jne 0xe7cd6
testl %r8d, %r8d
je 0xe7db2
testl %edx, %edx
je 0xe7d9c
shlq $0x3, %rax
addq 0x8(%rbx), %rax
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 0xe7d90
leaq (%rax,%rdi,8), %rdi
movl 0x8(%rdi), %r9d
movl %ecx, %r10d
xorl %r9d, %r10d
cmpl $0x1, %r10d
jne 0xe7d90
orl $0x80000000, %r8d       # imm = 0x80000000
movl %r8d, 0xc(%rdi)
xorq $0x1, %r9
movq 0x28(%rbx), %r8
movq (%r8,%r9,8), %r9
movq %r9, %r8
andq %r13, %r8
je 0xe7d8e
movl 0x4(%rdi), %edi
movq 0x8(%rbx), %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 0xe7d85
orb $-0x80, 0x3(%r9,%r10)
addq $0x18, %r10
cmpq %r10, %r8
jne 0xe7d71
incl %ebp
incq %rsi
cmpq %rdx, %rsi
jne 0xe7d0e
incq %r14
cmpq 0x28(%rsp), %r14
jne 0xe7c3e
jmp 0xe7db2
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
incq %r15
cmpq 0x18(%rsp), %r15
jne 0xe7b99
jmp 0xe7dc4
xorl %ebp, %ebp
testl %ebp, %ebp
je 0xe7de4
movq %rbx, %rdi
callq 0xa02fa
movq %rbx, %rdi
callq 0xa0333
movq %rbx, %rdi
callq 0xa03e9
orb $-0x80, 0x17(%rbx)
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq