// File: /workspace/github_cpp_makefile_star2_O1/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 %edx, 0xc(%rsp)
movq %rdi, %rbx
movl 0x14(%rdi), %eax
addl %eax, %eax
je 0x1ed634
movl %esi, %r15d
movl %eax, %r13d
xorl %r12d, %r12d
xorl %r14d, %r14d
movq 0x20(%rbx), %rax
movl %r12d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0x1ed626
movq 0x28(%rbx), %rcx
movl %r12d, %ebp
xorq $0x1, %rbp
movq (%rcx,%rbp,8), %rdx
testl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
je 0x1ed626
movq 0x8(%rbx), %rax
movq %rdx, %rsi
shrq $0x20, %rsi
movl %edx, %edx
leaq (%rsi,%rsi,2), %rsi
leaq (%rax,%rsi,8), %rdi
addq $0xc, %rdi
xorl %esi, %esi
cmpl $0x0, (%rdi)
js 0x1ed499
testl %esi, %esi
movl $0x1, %esi
jne 0x1ed4a4
addq $0x18, %rdi
decq %rdx
jne 0x1ed48b
jmp 0x1ed4a9
movl $0x2, %esi
cmpl $0x2, %esi
jb 0x1ed626
movq (%rcx,%r12,8), %rcx
testl %ecx, %ecx
je 0x1ed626
movq %rcx, %rdx
shrq $0x20, %rdx
movl %ecx, %esi
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %rax
addq $0xc, %rax
shlq $0x3, %rsi
leaq (%rsi,%rsi,2), %rdx
xorl %edi, %edi
xorl %esi, %esi
cmpl $0x0, (%rax,%rdi)
js 0x1ed4ee
testl %esi, %esi
movl $0x1, %esi
jne 0x1ed4f9
addq $0x18, %rdi
cmpq %rdi, %rdx
jne 0x1ed4df
jmp 0x1ed4fe
movl $0x2, %esi
cmpl $0x1, %esi
jne 0x1ed626
cmpl $0x1, %ecx
adcl $0x0, %ecx
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %edx, %edx
cmpl $0x0, (%rax,%rdx)
jns 0x1ed52b
addq $0x18, %rdx
cmpq %rdx, %rcx
jne 0x1ed517
jmp 0x1ed626
movq %rbx, %rdi
movl %r12d, %esi
leaq 0x14(%rsp), %rdx
leaq 0x10(%rsp), %rcx
xorl %r8d, %r8d
movl %r15d, %r9d
callq 0x1e51e1
movl %eax, %ecx
notl %ecx
testb $0x5, %cl
je 0x1ed626
testl %eax, %eax
je 0x1ed626
cmpl %r15d, 0x10(%rsp)
ja 0x1ed626
movq 0x28(%rbx), %rax
movq (%rax,%rbp,8), %rdx
testl %edx, %edx
je 0x1ed626
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 0x1ed61a
leaq (%rax,%rdi,8), %rdi
movl 0x8(%rdi), %r9d
movl %ecx, %r10d
xorl %r9d, %r10d
cmpl $0x1, %r10d
jne 0x1ed61a
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 0x1ed617
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 0x1ed60e
orb $-0x80, 0x3(%r9,%r10)
addq $0x18, %r10
cmpq %r10, %r8
jne 0x1ed5fa
incl %r14d
incq %rsi
cmpq %rdx, %rsi
jne 0x1ed591
incq %r12
cmpq %r13, %r12
jne 0x1ed442
jmp 0x1ed637
xorl %r14d, %r14d
testl %r14d, %r14d
sete %al
cmpl $0x0, 0xc(%rsp)
sete %cl
orb %al, %cl
jne 0x1ed651
movq %rbx, %rdi
callq 0xa02fa
movl %r14d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq