// File: /workspace/github_cpp_makefile_star2_O2/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), %rax
movq %rax, 0x10(%rsp)
movq (%rcx), %rax
movq %rax, 0x8(%rsp)
movq (%rdi), %rcx
movl %esi, %r13d
shrl %r13d
andl $0x1, %r12d
movl %r12d, %eax
xorl $0x1, %eax
imulq $0x78, %r13, %rbp
leaq (%rcx,%rbp), %rdx
imulq $0x18, %rax, %rsi
movq 0x10(%rsi,%rdx), %rax
movq 0x20(%rsi,%rdx), %rdx
addq $0xc, %rdx
xorl %esi, %esi
xorl %edi, %edi
cmpq %rax, %rdi
jae 0x1d6adb
cmpq $0x1, %rsi
ja 0x1d6adb
cmpl $0x0, (%rdx)
js 0x1d6ad2
movl -0x4(%rdx), %r8d
shrl %r8d
imulq $0x78, %r8, %r8
cmpb $0x1, 0x70(%rcx,%r8)
adcq $0x0, %rsi
incq %rdi
addq $0x20, %rdx
jmp 0x1d6aad
xorl %eax, %eax
cmpq $0x1, %rsi
ja 0x1d6d62
movl 0x4(%rcx,%rbp), %eax
movl %eax, 0x4(%rsp)
movb $0x1, 0x70(%rcx,%rbp)
pushq $0x2
popq %rax
movq 0x8(%rsp), %rdx
cmpq 0x8(%r14), %rdx
jne 0x1d6b2a
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x10(%r14)
movq (%r14), %rdx
movq (%r15), %rcx
jmp 0x1d6b2e
movq 0x10(%r14), %rax
leaq 0x1(%rdx), %rsi
movq %rsi, (%r14)
movq %r13, (%rax,%rdx,8)
movl %r12d, %eax
addq %rbp, %rcx
imulq $0x18, %rax, %rax
movq 0x10(%rax,%rcx), %r12
movq 0x20(%rax,%rcx), %r13
addq $0x8, %r13
pushq $0x2
popq %rbp
subq $0x1, %r12
jb 0x1d6bbd
cmpl $0x0, 0x4(%r13)
js 0x1d6bb7
movq (%r15), %rax
movl (%r13), %ecx
movl %ecx, %edx
shrl %edx
imulq $0x78, %rdx, %rdx
cmpb $0x0, 0x70(%rax,%rdx)
jne 0x1d6bb7
movq (%rbx), %rdx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rdx
jne 0x1d6baa
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
cmoveq %rbp, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%rbx)
movl (%r13), %ecx
movq (%rbx), %rdx
movl %ecx, %ecx
leaq 0x1(%rdx), %rsi
movq %rsi, (%rbx)
movq %rcx, (%rax,%rdx,8)
addq $0x20, %r13
jmp 0x1d6b54
movq (%rbx), %rdx
cmpq 0x10(%rsp), %rdx
jbe 0x1d6d31
movq 0x10(%rbx), %rcx
leaq -0x1(%rdx), %rax
movq %rax, (%rbx)
movq -0x8(%rcx,%rdx,8), %rbp
movq (%r15), %rcx
movl %ebp, %r12d
shrl %r12d
imulq $0x78, %r12, %r13
cmpb $0x0, 0x70(%rcx,%r13)
movq %rax, %rdx
jne 0x1d6bc0
andl $0x1, %ebp
movq %rbp, %rdx
xorq $0x1, %rdx
leaq (%rcx,%r13), %rsi
imulq $0x18, %rdx, %rdi
movq 0x10(%rdi,%rsi), %rdx
movq 0x20(%rdi,%rsi), %rsi
addq $0xc, %rsi
xorl %r8d, %r8d
xorl %edi, %edi
testq %r8, %r8
jne 0x1d6c4d
cmpq %rdx, %rdi
jae 0x1d6c4d
cmpl $0x0, (%rsi)
js 0x1d6c41
movl -0x4(%rsi), %r8d
shrl %r8d
imulq $0x78, %r8, %r9
xorl %r8d, %r8d
cmpb $0x0, 0x70(%rcx,%r9)
sete %r8b
jmp 0x1d6c44
xorl %r8d, %r8d
incq %rdi
addq $0x20, %rsi
jmp 0x1d6c18
movq %rax, %rdx
testq %r8, %r8
jne 0x1d6bc0
movl 0x4(%rsp), %eax
addl 0x4(%rcx,%r13), %eax
movl %eax, 0x4(%rsp)
movb $0x1, 0x70(%rcx,%r13)
movq (%r14), %rdx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rdx
jne 0x1d6ca1
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r14)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r14)
movq (%r14), %rdx
movq (%r15), %rcx
leaq 0x1(%rdx), %rsi
movq %rsi, (%r14)
movq %r12, (%rax,%rdx,8)
addq %r13, %rcx
imulq $0x18, %rbp, %rax
movq 0x10(%rax,%rcx), %r12
movq 0x20(%rax,%rcx), %r13
addq $0x8, %r13
pushq $0x2
popq %rbp
subq $0x1, %r12
jb 0x1d6bbd
cmpl $0x0, 0x4(%r13)
js 0x1d6d2b
movq (%r15), %rax
movl (%r13), %ecx
movl %ecx, %edx
shrl %edx
imulq $0x78, %rdx, %rdx
cmpb $0x0, 0x70(%rax,%rdx)
jne 0x1d6d2b
movq (%rbx), %rdx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rdx
jne 0x1d6d1e
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
cmoveq %rbp, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%rbx)
movl (%r13), %ecx
movq (%rbx), %rdx
movl %ecx, %ecx
leaq 0x1(%rdx), %rsi
movq %rsi, (%rbx)
movq %rcx, (%rax,%rdx,8)
addq $0x20, %r13
jmp 0x1d6cc4
movq 0x8(%rsp), %r13
movq %r13, %r12
cmpq (%r14), %r12
jae 0x1d6d53
movq 0x10(%r14), %rax
movl (%rax,%r12,8), %esi
movq %r15, %rdi
callq 0x1c676d
incq %r12
jmp 0x1d6d39
movq %r13, (%r14)
movq 0x10(%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