// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: usg_tip_del(usg_t*, unsigned int, asg64_v*, asg64_v*)
int usg_tip_del(usg_t *g, uint32_t v, asg64_v *z_a, asg64_v *z_b)
{
    uint64_t a_n = z_a->n, b_n = z_b->n, kv, nv, i; 
    int32_t n_ext = 0; usg_arc_t *av;

    av = usg_arc_a(g, v^1); nv = usg_arc_n(g, v^1);
    for (i = kv = 0; i < nv && kv <= 1; i++) {
        if (av[i].del || g->a[av[i].v>>1].del) continue;
        kv++; 
    }
    if(kv > 1) return 0;
    n_ext += g->a[v>>1].occ; g->a[v>>1].del = 1; kv_push(uint64_t, *z_b, v>>1);

    av = usg_arc_a(g, v); nv = usg_arc_n(g, v);
    for (i = 0; i < nv; i++) {
        if (av[i].del || g->a[av[i].v>>1].del) continue;
        kv_push(uint64_t, *z_a, av[i].v);
    }   

    while (z_a->n > a_n) {
        v = z_a->a[--z_a->n]; if(g->a[v>>1].del) continue;

        av = usg_arc_a(g, v^1); nv = usg_arc_n(g, v^1);
        for (i = kv = 0; i < nv && kv < 1; i++) {
            if (av[i].del || g->a[av[i].v>>1].del) continue;
            kv++; 
        }
        if(kv > 0) continue;
        n_ext += g->a[v>>1].occ; g->a[v>>1].del = 1; kv_push(uint64_t, *z_b, v>>1);

        av = usg_arc_a(g, v); nv = usg_arc_n(g, v);
        for (i = 0; i < nv; i++) {
            if (av[i].del || g->a[av[i].v>>1].del) continue;
            kv_push(uint64_t, *z_a, av[i].v);
        }        
    }

    for (i = b_n; i < z_b->n; i++) usg_seq_del(g, z_b->a[i]);
    z_b->n = b_n; z_a->n = a_n;
    return n_ext;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r14
movq %rdx, %rbx
movl %esi, %r12d
movq %rdi, %r15
movq (%rdx), %r11
movq (%rcx), %rax
movq %rax, 0x10(%rsp)
movq (%rdi), %r9
movl %esi, %r13d
shrl %r13d
andl $0x1, %r12d
movl %r12d, %ecx
xorl $0x1, %ecx
imulq $0x78, %r13, %rbp
leaq (%r9,%rbp), %rdx
leaq (%rcx,%rcx,2), %rsi
movq 0x10(%rdx,%rsi,8), %rcx
testq %rcx, %rcx
je 0x21a91d
movq 0x20(%rdx,%rsi,8), %rdx
addq $0xc, %rdx
movl $0x1, %edi
xorl %esi, %esi
cmpl $0x0, (%rdx)
js 0x21a8ff
movl -0x4(%rdx), %r8d
shrl %r8d
imulq $0x78, %r8, %r8
cmpb $0x1, 0x70(%r9,%r8)
adcq $0x0, %rsi
cmpq %rcx, %rdi
jae 0x21a911
incq %rdi
addq $0x20, %rdx
cmpq $0x2, %rsi
jb 0x21a8e5
xorl %eax, %eax
cmpq $0x1, %rsi
ja 0x21abc1
movl 0x4(%r9,%rbp), %eax
movl %eax, 0x4(%rsp)
movb $0x1, 0x70(%r9,%rbp)
movq 0x8(%r14), %rax
cmpq %rax, 0x10(%rsp)
movq %r11, 0x8(%rsp)
jne 0x21a966
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
shlq $0x3, %rsi
callq 0x2370
movq 0x8(%rsp), %r11
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r14)
movq %r13, (%rcx,%rax,8)
addq (%r15), %rbp
movl %r12d, %eax
leaq (%rax,%rax,2), %rax
movq 0x10(%rbp,%rax,8), %r12
testq %r12, %r12
je 0x21ab81
movq 0x20(%rbp,%rax,8), %r13
addq $0x8, %r13
movl $0x2, %ebp
cmpl $0x0, 0x4(%r13)
js 0x21a9fd
movq (%r15), %rax
movl (%r13), %ecx
shrl %ecx
imulq $0x78, %rcx, %rcx
cmpb $0x0, 0x70(%rax,%rcx)
jne 0x21a9fd
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0x21a9e7
leaq (%rax,%rax), %rsi
testq %rax, %rax
cmoveq %rbp, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x3, %rsi
callq 0x2370
movq 0x8(%rsp), %r11
movq %rax, 0x10(%rbx)
movl (%r13), %eax
movq (%rbx), %rcx
movq 0x10(%rbx), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rbx)
movq %rax, (%rdx,%rcx,8)
addq $0x20, %r13
decq %r12
jne 0x21a99e
jmp 0x21ab81
movq 0x10(%rbx), %rdx
movq (%r15), %rcx
movq %rax, %rsi
decq %rax
movq %rax, (%rbx)
movq -0x8(%rdx,%rsi,8), %r12
movl %r12d, %r13d
shrl %r13d
imulq $0x78, %r13, %rbp
cmpb $0x0, 0x70(%rcx,%rbp)
jne 0x21aa96
andl $0x1, %r12d
movq %r12, %rsi
xorq $0x1, %rsi
leaq (%rcx,%rbp), %rdi
leaq (%rsi,%rsi,2), %r8
movq 0x10(%rdi,%r8,8), %rsi
testq %rsi, %rsi
je 0x21aaa4
movq 0x20(%rdi,%r8,8), %rdi
addq $0xc, %rdi
movl $0x1, %r8d
cmpl $0x0, (%rdi)
js 0x21aa79
movl -0x4(%rdi), %r9d
shrl %r9d
imulq $0x78, %r9, %r9
cmpb $0x0, 0x70(%rcx,%r9)
setne %r9b
jmp 0x21aa7c
movb $0x1, %r9b
testb %r9b, %r9b
je 0x21aa91
leaq 0x1(%r8), %r10
addq $0x20, %rdi
cmpq %rsi, %r8
movq %r10, %r8
jb 0x21aa5d
testb %r9b, %r9b
jne 0x21aaa4
cmpq %r11, %rax
ja 0x21aa12
jmp 0x21ab8d
movl 0x4(%rsp), %eax
addl 0x4(%rcx,%rbp), %eax
movl %eax, 0x4(%rsp)
movb $0x1, 0x70(%rcx,%rbp)
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0x21aae8
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
shlq $0x3, %rsi
callq 0x2370
movq 0x8(%rsp), %r11
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r14)
movq %r13, (%rcx,%rax,8)
addq (%r15), %rbp
leaq (%r12,%r12,2), %rax
movq 0x10(%rbp,%rax,8), %r12
testq %r12, %r12
je 0x21ab81
movq 0x20(%rbp,%rax,8), %r13
addq $0x8, %r13
cmpl $0x0, 0x4(%r13)
js 0x21ab78
movq (%r15), %rax
movl (%r13), %ecx
shrl %ecx
imulq $0x78, %rcx, %rcx
cmpb $0x0, 0x70(%rax,%rcx)
jne 0x21ab78
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0x21ab62
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x3, %rsi
callq 0x2370
movq 0x8(%rsp), %r11
movq %rax, 0x10(%rbx)
movl (%r13), %eax
movq (%rbx), %rcx
movq 0x10(%rbx), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rbx)
movq %rax, (%rdx,%rcx,8)
addq $0x20, %r13
decq %r12
jne 0x21ab14
movq (%rbx), %rax
cmpq %r11, %rax
ja 0x21aa0b
movq 0x10(%rsp), %r13
cmpq (%r14), %r13
jae 0x21abb2
movq %r13, %r12
movq 0x10(%r14), %rax
movl (%rax,%r12,8), %esi
movq %r15, %rdi
callq 0x208f6d
incq %r12
cmpq (%r14), %r12
jb 0x21ab9a
movq %r13, (%r14)
movq 0x8(%rsp), %rax
movq %rax, (%rbx)
movl 0x4(%rsp), %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq