// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: update_dual_junction(usg_t*, unsigned int, unsigned int, unsigned int, unsigned int, asg64_v*)
void update_dual_junction(usg_t *g, uint32_t v, uint32_t v_id, uint32_t w, uint32_t w_id, asg64_v *buf)
{
    usg_arc_t *av, *aw, *z; uint32_t k, nv, nw, kv, kw, nid, pnid; usg_seq_t *s; 
    av = usg_arc_a(g, v); nv = usg_arc_n(g, v);
    for (k = kv = 0; k < nv; k++) {
        if(av[k].del) continue;
        kv++;
    }

    aw = usg_arc_a(g, w); nw = usg_arc_n(g, w);
    for (k = kw = 0; k < nw; k++) {
        if(aw[k].del) continue;
        kw++;
    }
    assert(kv && kw); 
    assert((!av[v_id].del) && (!aw[w_id].del));
    assert(av[v_id].ou && aw[w_id].ou);
    if(kv == 1 && kw == 1) return;///no need to 
    
    buf->n = 0; pnid = g->n;
    get_usg_unitig(g, v^1, NULL, NULL, NULL, NULL, buf); 
    // if(!(buf->n > 0 && buf->a[buf->n-1] == w)) {
    //     fprintf(stderr, "[M::%s::] buf->n::%u, v>>1::%u, v&1::%u, kv::%u, w>>1::%u, w&1::%u, kw::%u\n", __func__, 
    //             (uint32_t)buf->n, v>>1, v&1, kv, w>>1, w&1, kw);
    // }
    assert(buf->n > 0 && buf->a[buf->n-1] == w);

    for (k = 0; k < buf->n; k++) {
        nid = buf->a[k]>>1; 
        kv_push(uint32_t, g->mp.a[g->a[nid].mm], g->n); s = push_usg_t_node(g, g->n); 
        s->mm = g->a[nid].mm; s->occ = g->a[nid].occ; s->len = g->a[nid].len; s->telo = g->a[nid].telo; s->del = 0;
        s->arc[0].n = s->arc[1].n = 0; s->arc_mm[0].n = s->arc_mm[1].n = 0;
    }
    
    for (k = 0; k + 1 < buf->n; k++) {
        remap_gen_arcs(g, buf->a[k], buf->a[k+1], (((pnid+k)<<1)|(buf->a[k]&1)), (((pnid+k+1)<<1)|(buf->a[k+1]&1)));
        remap_gen_arcs(g, buf->a[k+1]^1, buf->a[k]^1, (((pnid+k+1)<<1)|(buf->a[k+1]&1))^1, (((pnid+k)<<1)|(buf->a[k]&1))^1);
    }

    //av might be changed
    av = usg_arc_a(g, v); 
    remap_gen_arcs(g, av[v_id].ul>>32, av[v_id].v, (pnid<<1)|((av[v_id].ul>>32)&1), av[v_id].v);
    av = usg_arc_a(g, v); 
    remap_gen_arcs(g, av[v_id].v^1, (av[v_id].ul>>32)^1, av[v_id].v^1, ((pnid<<1)|((av[v_id].ul>>32)&1))^1);

    pnid = pnid + buf->n - 1;
    //aw might be changed
    aw = usg_arc_a(g, w); 
    remap_gen_arcs(g, aw[w_id].ul>>32, aw[w_id].v, (pnid<<1)|((aw[w_id].ul>>32)&1), aw[w_id].v);
    aw = usg_arc_a(g, w);
    remap_gen_arcs(g, aw[w_id].v^1, (aw[w_id].ul>>32)^1, aw[w_id].v^1, ((pnid<<1)|((aw[w_id].ul>>32)&1))^1);

    ///drop edges from the current node
    av[v_id].del = 1; z = get_usg_arc(g, av[v_id].v^1, (av[v_id].ul>>32)^1); z->del = 1;
    aw[w_id].del = 1; z = get_usg_arc(g, aw[w_id].v^1, (aw[w_id].ul>>32)^1); z->del = 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, %r14
movl %ecx, %ebp
movq %rdi, %rbx
movq (%rdi), %r9
movl %esi, %eax
shrl %eax
movl %esi, %ecx
andl $0x1, %ecx
imulq $0x78, %rax, %rax
movq %rax, 0x38(%rsp)
addq %r9, %rax
imulq $0x18, %rcx, %rdi
movq 0x20(%rdi,%rax), %rcx
movq %rdi, 0x30(%rsp)
movl 0x10(%rdi,%rax), %edi
shlq $0x5, %rdi
xorl %r10d, %r10d
xorl %eax, %eax
cmpq %r10, %rdi
je 0x1c8bc3
movl 0xc(%rcx,%r10), %r11d
notl %r11d
shrl $0x1f, %r11d
addl %r11d, %eax
addq $0x20, %r10
jmp 0x1c8ba9
movl %ebp, %edi
shrl %edi
movl %ebp, %r10d
andl $0x1, %r10d
imulq $0x78, %rdi, %r12
addq %r12, %r9
imulq $0x18, %r10, %r10
movq 0x20(%r10,%r9), %rdi
movq %r10, 0x40(%rsp)
movl 0x10(%r10,%r9), %r10d
shlq $0x5, %r10
xorl %r11d, %r11d
xorl %r9d, %r9d
cmpq %r11, %r10
je 0x1c8c0c
movl 0xc(%rdi,%r11), %r15d
notl %r15d
shrl $0x1f, %r15d
addl %r15d, %r9d
addq $0x20, %r11
jmp 0x1c8bf2
testl %eax, %eax
je 0x1c8f7e
testl %r9d, %r9d
je 0x1c8f7e
movl %edx, %r13d
shlq $0x5, %r13
cmpl $0x0, 0xc(%rcx,%r13)
js 0x1c8f40
movl %r8d, %edx
shlq $0x5, %rdx
cmpl $0x0, 0xc(%rdi,%rdx)
js 0x1c8f40
addq %r13, %rcx
cmpl $0x0, 0x10(%rcx)
je 0x1c8f5f
addq %rdx, %rdi
cmpl $0x0, 0x10(%rdi)
je 0x1c8f5f
cmpl $0x1, %eax
jne 0x1c8c6b
cmpl $0x1, %r9d
je 0x1c8f31
movq %rdx, 0x20(%rsp)
movq %r12, 0x28(%rsp)
andq $0x0, (%r14)
movq 0x8(%rbx), %rax
movq %rax, 0x10(%rsp)
xorl $0x1, %esi
movq %r14, (%rsp)
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x1dee72
movq (%r14), %rax
testq %rax, %rax
je 0x1c8f9d
movq 0x10(%r14), %rcx
movl %ebp, %edx
cmpq %rdx, -0x8(%rcx,%rax,8)
jne 0x1c8f9d
xorl %ebp, %ebp
pushq $0x2
popq %r15
movl %ebp, %ebp
cmpq %rbp, %rax
jbe 0x1c8d8a
movq 0x10(%r14), %rax
movq (%rax,%rbp,8), %rax
shrq %rax
movq (%rbx), %rdx
movq 0x28(%rbx), %rcx
movl %eax, %eax
imulq $0x78, %rax, %r12
movl (%rdx,%r12), %edx
imulq $0x18, %rdx, %r8
leaq (%rcx,%r8), %rax
movq 0x8(%rcx,%r8), %rdi
cmpq 0x10(%rcx,%r8), %rdi
jne 0x1c8d2f
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
cmoveq %r15, %rsi
movq %rsi, 0x10(%rcx,%r8)
movq (%rax), %rdi
shlq $0x2, %rsi
callq 0x2370
movq (%rbx), %rdx
movq 0x28(%rbx), %rcx
movl (%rdx,%r12), %edx
imulq $0x18, %rdx, %rsi
movq %rax, (%rcx,%rsi)
movq 0x8(%rcx,%rsi), %rdi
jmp 0x1c8d32
movq (%rax), %rax
movq 0x8(%rbx), %rsi
imulq $0x18, %rdx, %rdx
leaq 0x1(%rdi), %r8
movq %r8, 0x8(%rcx,%rdx)
movl %esi, (%rax,%rdi,4)
movq %rbx, %rdi
callq 0x1c5ba9
movq (%rbx), %rcx
movq (%rcx,%r12), %rdx
movq %rdx, (%rax)
movl 0x8(%rcx,%r12), %edx
movl %edx, 0x8(%rax)
movb 0x71(%rcx,%r12), %cl
movb %cl, 0x71(%rax)
movb $0x0, 0x70(%rax)
andq $0x0, 0x28(%rax)
andq $0x0, 0x10(%rax)
andq $0x0, 0x58(%rax)
andq $0x0, 0x40(%rax)
incl %ebp
movq (%r14), %rax
jmp 0x1c8cbe
movq 0x10(%rsp), %rcx
leal (%rcx,%rcx), %r15d
xorl %ecx, %ecx
leal 0x1(%rcx), %r12d
cmpq %r12, %rax
jbe 0x1c8e0a
movq 0x10(%r14), %rax
movl %ecx, %ebp
movl (%rax,%rbp,8), %esi
movl (%rax,%r12,8), %edx
movl %esi, %ecx
andl $0x1, %ecx
addl %r15d, %ecx
movl %edx, %eax
andl $0x1, %eax
leal (%r15,%rax), %r8d
addl $0x2, %r8d
movq %rbx, %rdi
callq 0x1c8957
movq 0x10(%r14), %rax
movl (%rax,%r12,8), %ecx
movl %ecx, %esi
xorl $0x1, %esi
movl (%rax,%rbp,8), %r8d
movl %r8d, %edx
xorl $0x1, %edx
andl $0x1, %ecx
addl %r15d, %ecx
addl $0x2, %ecx
xorl $0x1, %ecx
andl $0x1, %r8d
addl %r15d, %r8d
xorl $0x1, %r8d
movq %rbx, %rdi
callq 0x1c8957
movq (%r14), %rax
addl $0x2, %r15d
movl %r12d, %ecx
jmp 0x1c8d95
movq (%rbx), %rax
movq 0x38(%rsp), %r15
addq %r15, %rax
movq 0x30(%rsp), %r12
movq 0x20(%r12,%rax), %rax
movl 0x4(%rax,%r13), %esi
movl 0x8(%rax,%r13), %edx
movl %esi, %eax
andl $0x1, %eax
movq %r13, %rbp
movq 0x10(%rsp), %r13
leal (%rax,%r13,2), %ecx
movq %rbx, %rdi
movl %edx, %r8d
callq 0x1c8957
addq (%rbx), %r15
movq 0x20(%r12,%r15), %r15
movq %rbp, 0x18(%rsp)
movl 0x4(%r15,%rbp), %eax
movl 0x8(%r15,%rbp), %ecx
xorl $0x1, %ecx
movl %eax, %edx
xorl $0x1, %edx
andl $0x1, %eax
leal (%rax,%r13,2), %r8d
xorl $0x1, %r8d
movq %rbx, %rdi
movl %ecx, %esi
callq 0x1c8957
addl (%r14), %r13d
movq (%rbx), %rax
movq 0x28(%rsp), %r14
addq %r14, %rax
movq 0x40(%rsp), %r12
movq 0x20(%r12,%rax), %rax
movq 0x20(%rsp), %rbp
movl 0x4(%rax,%rbp), %esi
movl 0x8(%rax,%rbp), %edx
movl %esi, %eax
andl $0x1, %eax
leal (%rax,%r13,2), %ecx
addl $-0x2, %ecx
movq %rbx, %rdi
movl %edx, %r8d
callq 0x1c8957
addq (%rbx), %r14
movq 0x20(%r12,%r14), %r14
movl 0x4(%r14,%rbp), %eax
movl 0x8(%r14,%rbp), %ecx
xorl $0x1, %ecx
movl %eax, %edx
xorl $0x1, %edx
andl $0x1, %eax
leal (%rax,%r13,2), %r8d
addl $-0x2, %r8d
xorl $0x1, %r8d
movq %rbx, %rdi
movl %ecx, %esi
callq 0x1c8957
movq 0x18(%rsp), %rax
orb $-0x80, 0xf(%r15,%rax)
movl 0x4(%r15,%rax), %edx
movl 0x8(%r15,%rax), %esi
xorl $0x1, %esi
xorl $0x1, %edx
movq %rbx, %rdi
callq 0x1dee3b
orb $-0x80, 0xf(%rax)
orb $-0x80, 0xf(%r14,%rbp)
movl 0x4(%r14,%rbp), %edx
movl 0x8(%r14,%rbp), %esi
xorl $0x1, %esi
xorl $0x1, %edx
movq %rbx, %rdi
callq 0x1dee3b
orb $-0x80, 0xf(%rax)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x316fa(%rip), %rdi     # 0x1fa641
leaq 0x2e58b(%rip), %rsi     # 0x1f74d9
leaq 0x31696(%rip), %rcx     # 0x1fa5eb
movl $0x2d94, %edx           # imm = 0x2D94
callq 0x2110
leaq 0x316fe(%rip), %rdi     # 0x1fa664
leaq 0x2e56c(%rip), %rsi     # 0x1f74d9
leaq 0x31677(%rip), %rcx     # 0x1fa5eb
movl $0x2d95, %edx           # imm = 0x2D95
callq 0x2110
leaq 0x3165d(%rip), %rdi     # 0x1fa5e2
leaq 0x2e54d(%rip), %rsi     # 0x1f74d9
leaq 0x31658(%rip), %rcx     # 0x1fa5eb
movl $0x2d93, %edx           # imm = 0x2D93
callq 0x2110
leaq 0x316db(%rip), %rdi     # 0x1fa67f
leaq 0x2e52e(%rip), %rsi     # 0x1f74d9
leaq 0x31639(%rip), %rcx     # 0x1fa5eb
movl $0x2d9e, %edx           # imm = 0x2D9E
callq 0x2110