// File: /workspace/github_cpp_makefile_star2_O3/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), %rdi
movl %esi, %eax
shrl %eax
movl %esi, %r9d
andl $0x1, %r9d
imulq $0x78, %rax, %r13
leaq (%rdi,%r13), %rcx
movq %r9, 0x38(%rsp)
leaq (%r9,%r9,2), %r9
movq 0x20(%rcx,%r9,8), %rax
movl 0x10(%rcx,%r9,8), %r9d
testq %r9, %r9
je 0x216e49
shlq $0x5, %r9
xorl %r10d, %r10d
xorl %ecx, %ecx
movl 0xc(%rax,%r10), %r11d
notl %r11d
shrl $0x1f, %r11d
addl %r11d, %ecx
addq $0x20, %r10
cmpq %r10, %r9
jne 0x216e2f
jmp 0x216e4b
xorl %ecx, %ecx
movl %ebp, %r9d
shrl %r9d
movl %ebp, %r10d
andl $0x1, %r10d
imulq $0x78, %r9, %r12
addq %r12, %rdi
movq %r10, 0x40(%rsp)
leaq (%r10,%r10,2), %r9
movl 0x10(%rdi,%r9,8), %r10d
testq %r10, %r10
je 0x21725a
movq 0x20(%rdi,%r9,8), %r9
shlq $0x5, %r10
xorl %r11d, %r11d
xorl %edi, %edi
movl 0xc(%r9,%r11), %r15d
notl %r15d
shrl $0x1f, %r15d
addl %r15d, %edi
addq $0x20, %r11
cmpq %r11, %r10
jne 0x216e84
testl %ecx, %ecx
je 0x21725a
testl %edi, %edi
je 0x21725a
movl %edx, %edx
shlq $0x5, %rdx
cmpl $0x0, 0xc(%rax,%rdx)
js 0x217279
movl %r8d, %r8d
shlq $0x5, %r8
cmpl $0x0, 0xc(%r9,%r8)
js 0x217279
addq %rdx, %rax
cmpl $0x0, 0x10(%rax)
je 0x217298
addq %r8, %r9
cmpl $0x0, 0x10(%r9)
je 0x217298
cmpl $0x1, %ecx
jne 0x216ef9
cmpl $0x1, %edi
je 0x21724b
movq %r8, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
movq %r13, 0x28(%rsp)
movq %r12, 0x30(%rsp)
movq $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 0x22d1ab
movq (%r14), %rax
testq %rax, %rax
je 0x2172b7
movq 0x10(%r14), %rcx
movl %ebp, %edx
cmpq %rdx, -0x8(%rcx,%rax,8)
jne 0x2172b7
movq (%rbx), %rcx
movl $0x1, %ebp
xorl %r12d, %r12d
movl $0x2, %r13d
xorl %eax, %eax
movq 0x10(%r14), %rdx
movq (%rdx,%rax,8), %rax
shrq %rax
movq 0x28(%rbx), %rdx
movl %eax, %eax
imulq $0x78, %rax, %r15
movl (%rcx,%r15), %ecx
leaq (%rcx,%rcx,2), %r8
leaq (%rdx,%r8,8), %rax
movq 0x8(%rax), %rdi
cmpq 0x10(%rax), %rdi
jne 0x216fc7
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
cmoveq %r13, %rsi
movq %rsi, 0x10(%rdx,%r8,8)
movq (%rax), %rdi
shlq $0x2, %rsi
callq 0x2370
movq (%rbx), %rcx
movq 0x28(%rbx), %rdx
movl (%rcx,%r15), %ecx
leaq (%rcx,%rcx,2), %rsi
movq %rax, (%rdx,%rsi,8)
movq 0x8(%rdx,%rsi,8), %rdi
jmp 0x216fca
movq (%rax), %rax
movq 0x8(%rbx), %rsi
leaq (%rcx,%rcx,2), %rcx
leaq 0x1(%rdi), %r8
movq %r8, 0x8(%rdx,%rcx,8)
movl %esi, (%rax,%rdi,4)
movq %rbx, %rdi
callq 0x213670
movq (%rbx), %rcx
movq (%rcx,%r15), %rdx
movq %rdx, (%rax)
movl 0x8(%rcx,%r15), %edx
movl %edx, 0x8(%rax)
movb 0x71(%rcx,%r15), %dl
movb %dl, 0x71(%rax)
movb $0x0, 0x70(%rax)
movq %r12, 0x28(%rax)
movq %r12, 0x10(%rax)
movq %r12, 0x58(%rax)
movq %r12, 0x40(%rax)
movl %ebp, %eax
movq (%r14), %rdx
incl %ebp
cmpq %rax, %rdx
ja 0x216f66
cmpq $0x2, %rdx
jb 0x2170b1
movq 0x10(%rsp), %rax
leal (%rax,%rax), %r12d
movl $0x1, %r15d
xorl %r13d, %r13d
movq 0x10(%r14), %rax
movl %r13d, %ebp
movl (%rax,%rbp,8), %esi
movl (%rax,%r15,8), %edx
movl %esi, %ecx
andl $0x1, %ecx
addl %r12d, %ecx
movl %edx, %eax
andl $0x1, %eax
leal (%r12,%rax), %r8d
addl $0x2, %r8d
movq %rbx, %rdi
callq 0x216b98
movq 0x10(%r14), %rax
movl (%rax,%r15,8), %ecx
movl %ecx, %esi
xorl $0x1, %esi
movl (%rax,%rbp,8), %r8d
movl %r8d, %edx
xorl $0x1, %edx
andl $0x1, %ecx
addl %r12d, %ecx
addl $0x2, %ecx
xorl $0x1, %ecx
andl $0x1, %r8d
addl %r12d, %r8d
xorl $0x1, %r8d
movq %rbx, %rdi
callq 0x216b98
leal 0x2(%r13), %r15d
incl %r13d
addl $0x2, %r12d
cmpq %r15, (%r14)
ja 0x217040
movq (%rbx), %rax
movq 0x28(%rsp), %r12
addq %r12, %rax
movq 0x38(%rsp), %rcx
shll $0x3, %ecx
leaq (%rcx,%rcx,2), %r15
movq 0x20(%rax,%r15), %rax
movq 0x18(%rsp), %rcx
movl 0x4(%rax,%rcx), %esi
movl 0x8(%rax,%rcx), %edx
movq %rcx, %rbp
movl %esi, %eax
andl $0x1, %eax
movq 0x10(%rsp), %r13
leal (%rax,%r13,2), %ecx
movq %rbx, %rdi
movl %edx, %r8d
callq 0x216b98
addq (%rbx), %r12
movq 0x20(%r12,%r15), %r12
movl 0x4(%r12,%rbp), %eax
movl 0x8(%r12,%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 0x216b98
addl (%r14), %r13d
movq (%rbx), %rax
movq 0x30(%rsp), %r15
addq %r15, %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,%r13,2), %ecx
addl $-0x2, %ecx
movq %rbx, %rdi
movl %edx, %r8d
callq 0x216b98
addq (%rbx), %r15
movq 0x20(%r15,%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,%r13,2), %r8d
addl $-0x2, %r8d
xorl $0x1, %r8d
movq %rbx, %rdi
movl %ecx, %esi
callq 0x216b98
movq 0x18(%rsp), %rcx
orb $-0x80, 0xf(%r12,%rcx)
movl 0x4(%r12,%rcx), %eax
movl 0x8(%r12,%rcx), %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 0x2171d9
xorl %edx, %edx
jmp 0x2171ef
leaq 0x28(%rcx), %rsi
xorl %edx, %edx
incq %rdx
movl (%rsi), %edi
xorl %eax, %edi
addq $0x20, %rsi
cmpl $0x1, %edi
jne 0x2171df
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 0x21722c
xorl %edx, %edx
jmp 0x217242
leaq 0x28(%rcx), %rsi
xorl %edx, %edx
incq %rdx
movl (%rsi), %edi
xorl %eax, %edi
addq $0x20, %rsi
cmpl $0x1, %edi
jne 0x217232
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 0x313c2(%rip), %rdi     # 0x248623
leaq 0x2e3a1(%rip), %rsi     # 0x245609
leaq 0x313bd(%rip), %rcx     # 0x24862c
movl $0x2d93, %edx           # imm = 0x2D93
callq 0x2110
leaq 0x31402(%rip), %rdi     # 0x248682
leaq 0x2e382(%rip), %rsi     # 0x245609
leaq 0x3139e(%rip), %rcx     # 0x24862c
movl $0x2d94, %edx           # imm = 0x2D94
callq 0x2110
leaq 0x31406(%rip), %rdi     # 0x2486a5
leaq 0x2e363(%rip), %rsi     # 0x245609
leaq 0x3137f(%rip), %rcx     # 0x24862c
movl $0x2d95, %edx           # imm = 0x2D95
callq 0x2110
leaq 0x31402(%rip), %rdi     # 0x2486c0
leaq 0x2e344(%rip), %rsi     # 0x245609
leaq 0x31360(%rip), %rcx     # 0x24862c
movl $0x2d9e, %edx           # imm = 0x2D9E
callq 0x2110