// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/ecovlp.cpp
// Function: merge_cns_g_ou(cns_gfa*, unsigned int, asg32_v*)
void merge_cns_g_ou(cns_gfa *cns, uint32_t v0, asg32_v* b32)
{
    cns_t *av, *aw; uint32_t v, bp, vk, wk, wka, w, wn, nn, mn, wh, mn_k[2];

    b32->n = 0;
    kv_push(uint32_t, *b32, v0);
    while (b32->n) {
        v = b32->a[--b32->n];
        if(del_cns_nn((*cns), v)) continue;
    
        av = &((*cns).a[v]);
        for (bp = 0; bp < 4; bp++) {
            //nn: number of node; wh: weight
            nn = wh = 0; mn = mn_k[0] = mn_k[1] = wka = (uint32_t)-1;
            for (vk = 0; vk < av->arc.nou; vk++) {///ou-edge of v
                if(del_cns_arc((*av), vk)) continue;
                w = av->arc.a[vk].v; aw = &((*cns).a[w]);
                if(aw->c != bp) continue;
                if(w == cns->si || w == cns->ei) continue;

                for (wk = aw->arc.nou, wn = 0; wk < aw->arc.n; wk++) {///in-edge of w
                    if(del_cns_arc((*aw), wk)) continue;
                    wn++; wka = wk; if(wn > 1) break;
                }

                if(wn != 1) continue;
                
                assert(aw->arc.a[wka].v == v);


                ///deal with in-edge of w
                if(nn == 0) {
                    mn = w; mn_k[0] = vk; mn_k[1] = wka;
                    wh = av->arc.a[vk].sc;
                    ///not sure if we should set these edges as visited
                    // av->arc.a[vk].f = 1; aw->arc.a[wka].f = 1;
                } else {
                    wh += aw->arc.a[wka].sc;
                }


                ///deal with ou-edge of w
                ///all edges from w, should be move to mn
                if(nn > 0) {///not sure if we should set these edges as visited; affect when nn == 0
                    for (wk = 0; wk < aw->arc.nou; wk++) {
                        if(del_cns_arc((*aw), wk)) continue;
                        ///previously, w -> aw->arc.a[wk].v
                        ///currently, mn -> aw->arc.a[wk].v 
                        /// if(nn == 0), then mn = w
                        gen_mm_cns_arc(cns, mn, aw->arc.a[wk].v, aw->arc.a[wk].sc/**(nn?(aw->arc.a[wk].sc):(0))**/, aw->arc.a[wk].f);///not sure if we should set these edges as visited
                    }
                }

                ///mn != w
                if(nn > 0) del_cns_g_nn(cns, w);

                nn++;
            }

            if(nn) {
                aw = &((*cns).a[mn]);
                // fprintf(stderr, "\n[M::%s] nn::%u, mn::%u\n", __func__, nn, mn);
                // fprintf(stderr, "[M::%s] vi::%u, vn::%u\n", __func__, mn_k[0], (uint32_t)av->arc.n);
                // fprintf(stderr, "[M::%s] wi::%u, wn::%u\n", __func__, mn_k[1], (uint32_t)aw->arc.n);

                av->arc.a[mn_k[0]].sc = aw->arc.a[mn_k[1]].sc = wh;
                // merge_cns_g_in(cns_gfa *cns, uint32_t v, asg32_v* b32)
                kv_push(uint32_t, *b32, mn);
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %r14
andq $0x0, (%rdx)
movl %esi, %ebp
cmpq $0x0, 0x8(%rdx)
movq %rdi, 0x18(%rsp)
je 0x13f6d8
movq 0x10(%r14), %rax
xorl %edx, %edx
jmp 0x13f6f8
movq $0x2, 0x8(%r14)
movq 0x10(%r14), %rdi
pushq $0x8
popq %rsi
callq 0x2370
movq 0x18(%rsp), %rdi
movq %rax, 0x10(%r14)
movq (%r14), %rdx
leaq 0x1(%rdx), %rcx
movq %rcx, (%r14)
movl %ebp, (%rax,%rdx,4)
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movq %r14, 0x28(%rsp)
testq %rcx, %rcx
je 0x13f96e
movq 0x10(%r14), %rax
leaq -0x1(%rcx), %rdx
movq %rdx, (%r14)
movl -0x4(%rax,%rcx,4), %eax
movq 0x10(%rdi), %r12
movq %rax, 0x30(%rsp)
imulq $0x28, %rax, %rax
cmpl $-0x9, (%r12,%rax)
movq %rdx, %rcx
ja 0x13f70d
addq %rax, %r12
xorl %r10d, %r10d
cmpl $0x4, %r10d
je 0x13f966
xorl %ebx, %ebx
pushq $-0x1
popq %rax
movl %eax, %ebp
movl $0x0, 0xc(%rsp)
movl %eax, 0x4(%rsp)
movl $0x0, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movl %eax, 0x14(%rsp)
movl %r10d, (%rsp)
movl %ebx, %eax
cmpq %rax, 0x18(%r12)
jbe 0x13f8de
movq 0x20(%r12), %rdx
movl (%rdx,%rax,8), %r15d
andq %r8, %r15
cmpq %r8, %r15
je 0x13f8d7
movq 0x10(%rdi), %r13
imulq $0x28, %r15, %rcx
movl (%r13,%rcx), %esi
andl $0x3, %esi
cmpl %r10d, %esi
jne 0x13f8d7
cmpl 0x18(%rdi), %r15d
je 0x13f8d7
cmpl 0x1c(%rdi), %r15d
je 0x13f8d7
addq %rcx, %r13
movq 0x8(%r13), %rsi
movq 0x18(%r13), %rcx
xorl %r11d, %r11d
movl %ecx, %r8d
movl %r8d, %r9d
cmpq %r9, %rsi
jbe 0x13f804
movq 0x20(%r13), %r10
movl (%r10,%r9,8), %r9d
notl %r9d
testl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
je 0x13f7ff
movl %r8d, %ebp
testl %r11d, %r11d
pushq $0x1
popq %r11
jne 0x13f882
incl %r8d
jmp 0x13f7d3
cmpl $0x1, %r11d
jne 0x13f885
movq 0x20(%r13), %rsi
movl %ebp, %r9d
movl (%rsi,%r9,8), %r8d
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
andl %r10d, %r8d
cmpl 0x30(%rsp), %r8d
movl (%rsp), %r10d
jne 0x13f97d
cmpl $0x0, 0xc(%rsp)
je 0x13f8b8
movl 0x4(%rsi,%r9,8), %eax
movl %eax, 0x24(%rsp)
xorl %r14d, %r14d
movl %r14d, %r14d
cmpq %r14, %rcx
jbe 0x13f891
movq 0x20(%r13), %rax
movl (%rax,%r14,8), %r8d
movl %r8d, %edx
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl %esi, %edx
cmpl %esi, %edx
je 0x13f87d
movl 0x4(%rax,%r14,8), %ecx
shrl $0x1f, %r8d
movl 0x4(%rsp), %esi
callq 0x14f1ee
movq 0x18(%rsp), %rdi
movq 0x18(%r13), %rcx
incl %r14d
jmp 0x13f844
movl %r8d, %ebp
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movl (%rsp), %r10d
jmp 0x13f8d7
movl 0x24(%rsp), %eax
addl %eax, 0x8(%rsp)
movl %r15d, %esi
callq 0x13f229
movl (%rsp), %r10d
movq 0x18(%rsp), %rdi
movl 0x4(%rsp), %eax
movl %eax, %r15d
movq 0x28(%rsp), %r14
jmp 0x13f8c8
movl 0x4(%rdx,%rax,8), %eax
movl %eax, 0x8(%rsp)
movl %ebx, 0x14(%rsp)
movl %ebp, 0x10(%rsp)
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
incl 0xc(%rsp)
movl %r15d, 0x4(%rsp)
incl %ebx
jmp 0x13f773
cmpl $0x0, 0xc(%rsp)
je 0x13f95e
movq 0x10(%rdi), %rax
movl 0x4(%rsp), %ecx
imulq $0x28, %rcx, %rcx
movq 0x20(%rax,%rcx), %rax
movl 0x10(%rsp), %ecx
movl 0x8(%rsp), %edx
movl %edx, 0x4(%rax,%rcx,8)
movq 0x20(%r12), %rax
movl 0x14(%rsp), %ecx
movl %edx, 0x4(%rax,%rcx,8)
movq (%r14), %rcx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rcx
jne 0x13f950
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movl (%rsp), %r10d
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movq 0x18(%rsp), %rdi
movq %rax, 0x10(%r14)
movq (%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r14)
movl 0x4(%rsp), %edx
movl %edx, (%rax,%rcx,4)
incl %r10d
jmp 0x13f742
movq (%r14), %rcx
jmp 0x13f70d
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb0720(%rip), %rdi     # 0x1f00a4
leaq 0xb0570(%rip), %rsi     # 0x1efefb
leaq 0xb075c(%rip), %rcx     # 0x1f00ee
movl $0x56f, %edx            # imm = 0x56F
callq 0x2110