// File: /workspace/github_cpp_makefile_star2_O1/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), %r10
movl %esi, %eax
shrl %eax
movl %esi, %ecx
andl $0x1, %ecx
imulq $0x78, %rax, %r13
leaq (%r10,%r13), %rax
movq %rcx, 0x10(%rsp)
leaq (%rcx,%rcx,2), %rdi
movq 0x20(%rax,%rdi,8), %rcx
movl 0x10(%rax,%rdi,8), %r9d
xorl %eax, %eax
movl $0x0, %edi
testq %r9, %r9
je 0x20baeb
shlq $0x5, %r9
xorl %r11d, %r11d
xorl %edi, %edi
movl 0xc(%rcx,%r11), %r15d
notl %r15d
shrl $0x1f, %r15d
addl %r15d, %edi
addq $0x20, %r11
cmpq %r11, %r9
jne 0x20bad3
movl %ebp, %r9d
shrl %r9d
movl %ebp, %r11d
andl $0x1, %r11d
imulq $0x78, %r9, %r12
addq %r12, %r10
movq %r11, 0x40(%rsp)
leaq (%r11,%r11,2), %r11
movq 0x20(%r10,%r11,8), %r9
movl 0x10(%r10,%r11,8), %r10d
testq %r10, %r10
je 0x20bb38
shlq $0x5, %r10
xorl %r11d, %r11d
xorl %eax, %eax
movl 0xc(%r9,%r11), %r15d
notl %r15d
shrl $0x1f, %r15d
addl %r15d, %eax
addq $0x20, %r11
cmpq %r11, %r10
jne 0x20bb20
testl %edi, %edi
je 0x20bf55
testl %eax, %eax
je 0x20bf55
movl %edx, %edx
shlq $0x5, %rdx
cmpl $0x0, 0xc(%rcx,%rdx)
js 0x20bf17
movl %r8d, %r8d
shlq $0x5, %r8
cmpl $0x0, 0xc(%r9,%r8)
js 0x20bf17
addq %rdx, %rcx
cmpl $0x0, 0x10(%rcx)
je 0x20bf36
addq %r8, %r9
cmpl $0x0, 0x10(%r9)
je 0x20bf36
cmpl $0x1, %edi
jne 0x20bb95
cmpl $0x1, %eax
je 0x20bf08
movq %r8, 0x20(%rsp)
movq %rdx, 0x28(%rsp)
movq %r13, 0x30(%rsp)
movq %r12, 0x38(%rsp)
movq $0x0, (%r14)
movq 0x8(%rbx), %rax
movq %rax, 0x18(%rsp)
xorl $0x1, %esi
movq %r14, (%rsp)
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x221b0b
movq (%r14), %rax
testq %rax, %rax
je 0x20bf74
movq 0x10(%r14), %rcx
movl %ebp, %edx
cmpq %rdx, -0x8(%rcx,%rax,8)
jne 0x20bf74
cmpq $0x0, (%r14)
je 0x20bcdd
movl $0x1, %ebp
xorl %r15d, %r15d
movl $0x2, %r13d
xorl %eax, %eax
movq 0x10(%r14), %rcx
movq (%rcx,%rax,8), %rcx
shrq %rcx
movq (%rbx), %rdx
movq 0x28(%rbx), %rax
movl %ecx, %ecx
imulq $0x78, %rcx, %r12
movl (%rdx,%r12), %ecx
leaq (%rcx,%rcx,2), %rdx
movq 0x10(%rax,%rdx,8), %rcx
cmpq %rcx, 0x8(%rax,%rdx,8)
jne 0x20bc6b
leaq (%rax,%rdx,8), %rax
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
cmoveq %r13, %rdx
movq %rdx, 0x10(%rax)
movq (%rax), %rdi
movq 0x10(%rax), %rsi
shlq $0x2, %rsi
callq 0x2370
movq (%rbx), %rcx
movq 0x28(%rbx), %rdx
movl (%rcx,%r12), %ecx
leaq (%rcx,%rcx,2), %rcx
movq %rax, (%rdx,%rcx,8)
movq (%rbx), %rax
movq 0x8(%rbx), %rsi
movq 0x28(%rbx), %rcx
movl (%rax,%r12), %eax
leaq (%rax,%rax,2), %rax
movq (%rcx,%rax,8), %rdx
movq 0x8(%rcx,%rax,8), %rdi
leaq 0x1(%rdi), %r8
movq %r8, 0x8(%rcx,%rax,8)
movl %esi, (%rdx,%rdi,4)
movq %rbx, %rdi
callq 0x20817b
movq (%rbx), %rcx
movl (%rcx,%r12), %edx
movl %edx, (%rax)
movl 0x4(%rcx,%r12), %edx
movl %edx, 0x4(%rax)
movl 0x8(%rcx,%r12), %edx
movl %edx, 0x8(%rax)
movb 0x71(%rcx,%r12), %cl
movb %cl, 0x71(%rax)
movb $0x0, 0x70(%rax)
movq %r15, 0x28(%rax)
movq %r15, 0x10(%rax)
movq %r15, 0x58(%rax)
movq %r15, 0x40(%rax)
movl %ebp, %eax
incl %ebp
cmpq %rax, (%r14)
ja 0x20bc09
cmpq $0x2, (%r14)
jb 0x20bd6a
movq 0x18(%rsp), %rax
leal (%rax,%rax), %r15d
movl $0x1, %r12d
xorl %r13d, %r13d
movq 0x10(%r14), %rax
movl %r13d, %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 0x20b836
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 0x20b836
leal 0x2(%r13), %r12d
incl %r13d
addl $0x2, %r15d
cmpq %r12, (%r14)
ja 0x20bcf9
movq (%rbx), %rax
movq 0x30(%rsp), %r12
addq %r12, %rax
movq 0x10(%rsp), %rcx
shll $0x3, %ecx
leaq (%rcx,%rcx,2), %rbp
movq 0x20(%rax,%rbp), %rax
movq 0x28(%rsp), %r13
movl 0x4(%rax,%r13), %esi
movl 0x8(%rax,%r13), %edx
movl %esi, %eax
andl $0x1, %eax
movq 0x18(%rsp), %r15
leal (%rax,%r15,2), %ecx
movq %rbx, %rdi
movl %edx, %r8d
callq 0x20b836
addq (%rbx), %r12
movq 0x20(%r12,%rbp), %rcx
movq %rcx, 0x10(%rsp)
movl 0x4(%rcx,%r13), %eax
movl 0x8(%rcx,%r13), %ecx
xorl $0x1, %ecx
movl %eax, %edx
xorl $0x1, %edx
andl $0x1, %eax
leal (%rax,%r15,2), %r8d
xorl $0x1, %r8d
movq %rbx, %rdi
movl %ecx, %esi
callq 0x20b836
addl (%r14), %r15d
movq (%rbx), %rax
movq 0x38(%rsp), %r12
addq %r12, %rax
movq 0x40(%rsp), %rcx
shll $0x3, %ecx
leaq (%rcx,%rcx,2), %r14
movq 0x20(%rax,%r14), %rax
movq 0x20(%rsp), %rbp
movl 0x4(%rax,%rbp), %esi
movl 0x8(%rax,%rbp), %edx
movl %esi, %eax
andl $0x1, %eax
leal (%rax,%r15,2), %ecx
addl $-0x2, %ecx
movq %rbx, %rdi
movl %edx, %r8d
callq 0x20b836
addq (%rbx), %r12
movq 0x20(%r12,%r14), %rax
leaq (%rax,%rbp), %r14
movl 0x4(%rax,%rbp), %esi
movl 0x8(%rax,%rbp), %ecx
xorl $0x1, %ecx
movl %esi, %edx
xorl $0x1, %edx
andl $0x1, %esi
leal (%rsi,%r15,2), %r8d
addl $-0x2, %r8d
xorl $0x1, %r8d
movq %rbx, %rdi
movl %ecx, %esi
callq 0x20b836
movq 0x10(%rsp), %rcx
orb $-0x80, 0xf(%rcx,%r13)
movl 0x4(%rcx,%r13), %eax
movl 0x8(%rcx,%r13), %ecx
movl %ecx, %edx
notl %edx
shrl %ecx
andl $0x1, %edx
imulq $0x78, %rcx, %rcx
addq (%rbx), %rcx
leaq (%rdx,%rdx,2), %rdx
movq 0x20(%rcx,%rdx,8), %rcx
movl 0x8(%rcx), %edx
xorl %eax, %edx
cmpl $0x1, %edx
jne 0x20be96
xorl %edx, %edx
jmp 0x20beac
leaq 0x28(%rcx), %rsi
xorl %edx, %edx
incq %rdx
movl (%rsi), %edi
xorl %eax, %edi
addq $0x20, %rsi
cmpl $0x1, %edi
jne 0x20be9c
shlq $0x5, %rdx
orb $-0x80, 0xf(%rcx,%rdx)
orb $-0x80, 0xf(%r14)
movl 0x4(%r14), %eax
movl 0x8(%r14), %ecx
movl %ecx, %edx
notl %edx
shrl %ecx
andl $0x1, %edx
imulq $0x78, %rcx, %rcx
addq (%rbx), %rcx
leaq (%rdx,%rdx,2), %rdx
movq 0x20(%rcx,%rdx,8), %rcx
movl 0x8(%rcx), %edx
xorl %eax, %edx
cmpl $0x1, %edx
jne 0x20bee9
xorl %edx, %edx
jmp 0x20beff
leaq 0x28(%rcx), %rsi
xorl %edx, %edx
incq %rdx
movl (%rsi), %edi
xorl %eax, %edi
addq $0x20, %rsi
cmpl $0x1, %edi
jne 0x20beef
shlq $0x5, %rdx
orb $-0x80, 0xf(%rcx,%rdx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x30480(%rip), %rdi     # 0x23c39e
leaq 0x2d400(%rip), %rsi     # 0x239325
leaq 0x3041c(%rip), %rcx     # 0x23c348
movl $0x2d94, %edx           # imm = 0x2D94
callq 0x2110
leaq 0x30484(%rip), %rdi     # 0x23c3c1
leaq 0x2d3e1(%rip), %rsi     # 0x239325
leaq 0x303fd(%rip), %rcx     # 0x23c348
movl $0x2d95, %edx           # imm = 0x2D95
callq 0x2110
leaq 0x303e3(%rip), %rdi     # 0x23c33f
leaq 0x2d3c2(%rip), %rsi     # 0x239325
leaq 0x303de(%rip), %rcx     # 0x23c348
movl $0x2d93, %edx           # imm = 0x2D93
callq 0x2110
leaq 0x30461(%rip), %rdi     # 0x23c3dc
leaq 0x2d3a3(%rip), %rsi     # 0x239325
leaq 0x303bf(%rip), %rcx     # 0x23c348
movl $0x2d9e, %edx           # imm = 0x2D9E
callq 0x2110