// File: /workspace/github_cpp_makefile_star2_O3/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, %r12
movl %esi, %ebp
movq $0x0, (%rdx)
cmpq $0x0, 0x8(%rdx)
movq %rdi, 0x10(%rsp)
je 0x18300c
movq 0x10(%r12), %rax
movl %ebp, (%rax)
movl $0x1, %ecx
jmp 0x183045
movq $0x2, 0x8(%r12)
movq 0x10(%r12), %rdi
movl $0x8, %esi
callq 0x2370
movq 0x10(%rsp), %rdi
movq %rax, 0x10(%r12)
movq (%r12), %rdx
movq %rdx, %rcx
incq %rcx
movq %rcx, (%r12)
movl %ebp, (%rax,%rdx,4)
je 0x1832f2
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
movq %r12, 0x28(%rsp)
movq 0x10(%r12), %rax
leaq -0x1(%rcx), %rsi
movq %rsi, (%r12)
movl -0x4(%rax,%rcx,4), %ecx
movq 0x10(%rdi), %rax
movq %rcx, 0x30(%rsp)
leaq (%rcx,%rcx,4), %rdx
cmpl $-0x9, (%rax,%rdx,8)
movq %rsi, %rcx
ja 0x1832e9
leaq (%rax,%rdx,8), %rbx
xorl %r14d, %r14d
movq 0x18(%rbx), %rax
testq %rax, %rax
je 0x1832d8
xorl %ebp, %ebp
movl $0xffffffff, 0x24(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x20(%rsp) # imm = 0xFFFFFFFF
movl $0x0, 0x4(%rsp)
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movl $0x0, 0x1c(%rsp)
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl %r14d, 0x8(%rsp)
movq 0x20(%rbx), %rsi
movl (%rsi,%rbp,8), %r15d
andq %r10, %r15
cmpq %r10, %r15
je 0x1830f4
movq 0x10(%rdi), %rcx
leaq (%r15,%r15,4), %r9
movl (%rcx,%r9,8), %r8d
andl $0x3, %r8d
cmpl %r14d, %r8d
jne 0x1830f4
cmpl 0x18(%rdi), %r15d
je 0x1830f4
cmpl 0x1c(%rdi), %r15d
jne 0x183106
movl %edx, %r13d
incl %ebp
movl %r13d, %edx
cmpq %rbp, %rax
ja 0x1830c3
jmp 0x183254
leaq (%rcx,%r9,8), %r14
movq 0x8(%r14), %r9
movq 0x18(%r14), %rcx
movl %ecx, %r11d
cmpq %r11, %r9
jbe 0x183167
movq 0x20(%r14), %r8
movb $0x1, %r10b
xorl %edi, %edi
movl %ecx, %r12d
movl %r12d, %r13d
movl (%r8,%r11,8), %r11d
notl %r11d
testl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
jne 0x183146
incl %r13d
movq %r13, %r11
cmpq %r13, %r9
ja 0x183129
jmp 0x18316f
testb $0x1, %r10b
je 0x183214
leal 0x1(%r13), %r11d
movb $0x1, %dil
xorl %r10d, %r10d
movl %r13d, %edx
movl %r11d, %r12d
cmpq %r11, %r9
ja 0x183126
jmp 0x18317c
movl %edx, %r13d
jmp 0x18324a
movl %edx, %r13d
testb $0x1, %dil
je 0x183211
movq 0x20(%r14), %rdx
movl %r13d, %edi
movl (%rdx,%rdi,8), %r8d
movl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
andl %r9d, %r8d
cmpl 0x30(%rsp), %r8d
jne 0x183301
cmpl $0x0, 0x1c(%rsp)
je 0x183220
movl 0x4(%rsp), %eax
addl 0x4(%rdx,%rdi,8), %eax
movl %eax, 0x4(%rsp)
testq %rcx, %rcx
movq 0x10(%rsp), %rdi
je 0x1831fe
movl $0x1, %r12d
xorl %eax, %eax
movq 0x20(%r14), %rsi
movl (%rsi,%rax,8), %r8d
movl %r8d, %edx
movl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
andl %r9d, %edx
cmpl %r9d, %edx
je 0x1831f3
movl 0x4(%rsi,%rax,8), %ecx
shrl $0x1f, %r8d
movl 0xc(%rsp), %esi
callq 0x196448
movq 0x10(%rsp), %rdi
movq 0x18(%r14), %rcx
movl %r12d, %eax
incl %r12d
cmpq %rax, %rcx
ja 0x1831c0
movl %r15d, %esi
callq 0x182ac0
movq 0x10(%rsp), %rdi
movq 0x18(%rbx), %rax
jmp 0x18323b
movl %edx, %r13d
movq 0x28(%rsp), %r12
movq 0x10(%rsp), %rdi
jmp 0x183244
movl 0x4(%rsi,%rbp,8), %ecx
movl %ecx, 0x4(%rsp)
movl %ebp, 0x24(%rsp)
movl %r13d, 0x20(%rsp)
movl %r15d, 0xc(%rsp)
movq 0x10(%rsp), %rdi
incl 0x1c(%rsp)
movq 0x28(%rsp), %r12
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
movl 0x8(%rsp), %r14d
jmp 0x1830f7
cmpl $0x0, 0x1c(%rsp)
je 0x1832d8
movl 0x24(%rsp), %eax
movl 0x20(%rsp), %ecx
movq 0x10(%rdi), %rdx
movl 0xc(%rsp), %esi
leaq (%rsi,%rsi,4), %rsi
movq 0x20(%rdx,%rsi,8), %rdx
movl 0x4(%rsp), %esi
movl %esi, 0x4(%rdx,%rcx,8)
movq 0x20(%rbx), %rcx
movl %esi, 0x4(%rcx,%rax,8)
movq (%r12), %rcx
movq 0x10(%r12), %rax
cmpq 0x8(%r12), %rcx
jne 0x1832c9
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r12)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
movq 0x10(%rsp), %rdi
movq %rax, 0x10(%r12)
movq (%r12), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r12)
movl 0xc(%rsp), %edx
movl %edx, (%rax,%rcx,4)
incl %r14d
cmpl $0x4, %r14d
jne 0x183082
movq (%r12), %rcx
testq %rcx, %rcx
jne 0x183050
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xbaedc(%rip), %rdi     # 0x23e1e4
leaq 0xbad2c(%rip), %rsi     # 0x23e03b
leaq 0xbaf18(%rip), %rcx     # 0x23e22e
movl $0x56f, %edx            # imm = 0x56F
callq 0x2110