// File: /workspace/github_cpp_makefile_star2_O2/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 $0x28, %rsp
movl %edx, 0xc(%rsp)
movl %esi, 0x4(%rsp)
movq %rdi, %rbx
movl 0x14(%rdi), %r15d
addl %r15d, %r15d
xorl %r12d, %r12d
pushq $0x1
popq %r13
xorl %ebp, %ebp
cmpq %r15, %r12
je 0x1aca72
movq 0x20(%rbx), %rax
movl %r12d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0x1aca6a
movq 0x28(%rbx), %rcx
movl %r12d, %r14d
xorq $0x1, %r14
movq (%rcx,%r14,8), %rdx
testl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
je 0x1aca6a
movq 0x8(%rbx), %rax
movq %rdx, %rsi
shrq $0x20, %rsi
movl %edx, %edx
imulq $0x18, %rdx, %rdx
imulq $0x18, %rsi, %rsi
addq %rax, %rsi
addq $0xc, %rsi
xorl %edi, %edi
xorl %r8d, %r8d
cmpq %rdi, %rdx
je 0x1aca6a
cmpl $0x0, (%rsi,%rdi)
js 0x1ac92d
testl %r8d, %r8d
movl %r13d, %r8d
jne 0x1ac933
addq $0x18, %rdi
jmp 0x1ac916
movq (%rcx,%r12,8), %rcx
testl %ecx, %ecx
je 0x1aca6a
movq %rcx, %rdx
shrq $0x20, %rdx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
addq $0xc, %rax
xorl %edx, %edx
xorl %esi, %esi
cmpq %rdx, %rcx
je 0x1ac977
cmpl $0x0, (%rax,%rdx)
js 0x1ac971
testl %esi, %esi
movl %r13d, %esi
jne 0x1aca6a
addq $0x18, %rdx
jmp 0x1ac95b
cmpl $0x1, %esi
jne 0x1aca6a
addq $0x18, %rcx
xorl %edx, %edx
leaq 0x18(%rdx), %rsi
cmpq %rsi, %rcx
je 0x1aca6a
cmpl $0x0, (%rax,%rdx)
movq %rsi, %rdx
js 0x1ac986
movq %rbx, %rdi
movl %r12d, %esi
leaq 0x14(%rsp), %rdx
leaq 0x10(%rsp), %rcx
xorl %r8d, %r8d
movl 0x4(%rsp), %r9d
callq 0x1a5520
movl %eax, %ecx
notl %ecx
testb $0x5, %cl
je 0x1aca6a
testl %eax, %eax
je 0x1aca6a
movl 0x4(%rsp), %eax
cmpl %eax, 0x10(%rsp)
ja 0x1aca6a
movl %ebp, 0x8(%rsp)
movq 0x8(%rbx), %rax
movq 0x28(%rbx), %rcx
movq (%rcx,%r14,8), %rcx
movl %ecx, %edx
shrq $0x20, %rcx
movl 0x14(%rsp), %edi
imulq $0x18, %rdx, %rdx
imulq $0x18, %rcx, %rcx
leaq (%rax,%rcx), %r14
addq $0xc, %r14
xorl %ebp, %ebp
movq %r15, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
cmpq %rbp, %rdx
je 0x1aca66
movl (%r14,%rbp), %eax
testl %eax, %eax
js 0x1aca60
movl -0x4(%r14,%rbp), %esi
movl %edi, %ecx
xorl %esi, %ecx
cmpl $0x1, %ecx
jne 0x1aca60
orl $0x80000000, %eax       # imm = 0x80000000
movl %eax, (%r14,%rbp)
xorl $0x1, %esi
movl -0x8(%r14,%rbp), %edx
xorl $0x1, %edx
movl %edi, %r15d
movq %rbx, %rdi
movl %r13d, %ecx
callq 0x1abbde
movq 0x18(%rsp), %rdx
movl %r15d, %edi
movq 0x20(%rsp), %r15
incl 0x8(%rsp)
addq $0x18, %rbp
jmp 0x1aca12
movl 0x8(%rsp), %ebp
incq %r12
jmp 0x1ac8be
cmpl $0x0, 0xc(%rsp)
je 0x1aca85
testl %ebp, %ebp
je 0x1aca85
movq %rbx, %rdi
callq 0x694eb
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq