// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: asg_cut_semi_circ(asg_t*, unsigned int, unsigned int)
uint32_t asg_cut_semi_circ(asg_t *g, uint32_t lim_len, uint32_t is_clean)
{
    uint32_t v, t, k, e, ss, i, n_vtx = g->n_seq<<1, nv, kv, nw, cnt = 0;
    asg_arc_t *av, *aw;

    for (v = 0; v < n_vtx; ++v) {
        if (g->seq[v>>1].del) continue;

        av = asg_arc_a(g, v^1); nv = asg_arc_n(g, v^1);
        if(nv <= 1) continue;
        for (i = kv = 0; i < nv; ++i) {
            if(av[i].del) continue;
            kv++; if(kv > 1) break;
        }
        if(kv <= 1) continue;

        av = asg_arc_a(g, v); nv = asg_arc_n(g, v);
        if(nv < 1) continue;
        for (i = kv = 0; i < nv; ++i) {
            if(av[i].del) continue;
            kv++; if(kv > 1) break;
        }
        if(kv != 1) continue;

        for (i = 0; i < nv; ++i) {
            if(av[i].del) continue;
            t = follow_limit_path(g, v, &e, &ss, NULL, lim_len);
            if(ss > lim_len || t == LONG_TIPS || t == LOOP || t == END_TIPS) break;//as kv == 1
            aw = asg_arc_a(g, v^1); nw = asg_arc_n(g, v^1);
            for (k = 0; k < nw; k++) {
                if (aw[k].del) continue;
                if (aw[k].v == (e^1)) {
                    aw[k].del = 1;
                    asg_arc_del(g, aw[k].v^1, (aw[k].ul>>32)^1, 1);
                    cnt++;
                }
            }
            break; //as kv == 1
        }
    }

    if(cnt > 0 && is_clean) asg_cleanup(g);
    return cnt;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl 0x14(%rdi), %eax
addl %eax, %eax
je 0x1f83f7
movl %esi, %r15d
movq %rdi, %rbx
movl %edx, 0xc(%rsp)
movl %eax, %r13d
xorl %r12d, %r12d
xorl %ebp, %ebp
movq 0x20(%rbx), %rax
movl %r12d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0x1f8250
movq 0x28(%rbx), %rax
movl %r12d, %r14d
xorq $0x1, %r14
movq (%rax,%r14,8), %rdx
testl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
je 0x1f8250
movq 0x8(%rbx), %rcx
movq %rdx, %rsi
shrq $0x20, %rsi
movl %edx, %edx
leaq (%rsi,%rsi,2), %rsi
leaq (%rcx,%rsi,8), %rsi
addq $0xc, %rsi
xorl %edi, %edi
cmpl $0x0, (%rsi)
js 0x1f8247
testl %edi, %edi
movl $0x1, %edi
jne 0x1f825d
addq $0x18, %rsi
decq %rdx
jne 0x1f8239
incq %r12
cmpq %r13, %r12
jne 0x1f81f8
jmp 0x1f83dc
movq (%rax,%r12,8), %rax
testl %eax, %eax
je 0x1f8250
movq %rax, %rsi
shrq $0x20, %rsi
movl %eax, %eax
movq %rax, %rdx
negq %rdx
leaq (%rsi,%rsi,2), %rsi
leaq (%rcx,%rsi,8), %rcx
addq $0xc, %rcx
movb $0x1, %dil
xorl %esi, %esi
xorl %r8d, %r8d
leaq (%rsi,%rsi,2), %r9
incq %rsi
leaq (%rcx,%r9,8), %r9
cmpl $0x0, (%r9)
jns 0x1f82af
addq $0x18, %r9
leaq (%rdx,%rsi), %r10
incq %r10
incq %rsi
cmpq $0x1, %r10
jne 0x1f8293
jmp 0x1f82c4
testb $0x1, %dil
je 0x1f8250
movb $0x1, %r8b
xorl %edi, %edi
movq %rdx, %r9
addq %rsi, %r9
jne 0x1f8288
jmp 0x1f82ca
testb $0x1, %r8b
je 0x1f8250
cmpl $0x0, (%rcx)
jns 0x1f82dd
addq $0x18, %rcx
decq %rax
jne 0x1f82ca
jmp 0x1f8250
movq %rbx, %rdi
movl %r12d, %esi
leaq 0x14(%rsp), %rdx
leaq 0x10(%rsp), %rcx
xorl %r8d, %r8d
movl %r15d, %r9d
callq 0x1efbd9
movl %eax, %ecx
notl %ecx
testb $0x5, %cl
je 0x1f8250
testl %eax, %eax
je 0x1f8250
cmpl %r15d, 0x10(%rsp)
ja 0x1f8250
movq 0x28(%rbx), %rax
movq (%rax,%r14,8), %rdx
testl %edx, %edx
je 0x1f8250
movq %rdx, %rax
shrq $0x20, %rax
leaq (%rax,%rax,2), %rax
shlq $0x3, %rax
addq 0x8(%rbx), %rax
movl 0x14(%rsp), %ecx
movl %edx, %edx
xorl %esi, %esi
leaq (%rsi,%rsi,2), %rdi
movl 0xc(%rax,%rdi,8), %r8d
testl %r8d, %r8d
js 0x1f83cb
leaq (%rax,%rdi,8), %rdi
movl 0x8(%rdi), %r9d
movl %ecx, %r10d
xorl %r9d, %r10d
cmpl $0x1, %r10d
jne 0x1f83cb
orl $0x80000000, %r8d       # imm = 0x80000000
movl %r8d, 0xc(%rdi)
xorq $0x1, %r9
movq 0x28(%rbx), %r8
movq (%r8,%r9,8), %r9
movq %r9, %r8
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
andq %r10, %r8
je 0x1f83c9
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 0x1f83c0
orb $-0x80, 0x3(%r9,%r10)
addq $0x18, %r10
cmpq %r10, %r8
jne 0x1f83ac
incl %ebp
incq %rsi
cmpq %rdx, %rsi
jne 0x1f8343
jmp 0x1f8250
testl %ebp, %ebp
sete %al
cmpl $0x0, 0xc(%rsp)
sete %cl
orb %al, %cl
jne 0x1f83f9
movq %rbx, %rdi
callq 0xa0a7d
jmp 0x1f83f9
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq