// File: /workspace/github_cpp_makefile_star2_O1/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
movl %esi, %ebp
movq $0x0, (%rdx)
cmpq $0x0, 0x8(%rdx)
movq %rdi, 0x20(%rsp)
jne 0x17c331
movq $0x2, 0x8(%r14)
movq 0x10(%r14), %rdi
movl $0x8, %esi
callq 0x2370
movq 0x20(%rsp), %rdi
movq %rax, 0x10(%r14)
movq (%r14), %rcx
movq 0x10(%r14), %rdx
movq %rcx, %rax
incq %rax
movq %rax, (%r14)
movl %ebp, (%rdx,%rcx,4)
je 0x17c5e4
movl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
movq %r14, 0x28(%rsp)
movq 0x10(%r14), %rcx
leaq -0x1(%rax), %rdx
movq %rdx, (%r14)
movl -0x4(%rcx,%rax,4), %ecx
movq 0x10(%rdi), %rax
movq %rcx, 0x30(%rsp)
leaq (%rcx,%rcx,4), %rcx
cmpl $-0x8, (%rax,%rcx,8)
jae 0x17c5d8
leaq (%rax,%rcx,8), %rbx
xorl %r8d, %r8d
cmpq $0x0, 0x18(%rbx)
movl %r8d, 0x14(%rsp)
je 0x17c544
xorl %r12d, %r12d
movl $0xffffffff, 0x1c(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x18(%rsp) # imm = 0xFFFFFFFF
movl $0x0, 0x10(%rsp)
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movl $0x0, 0x8(%rsp)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0x20(%rbx), %rax
movl (%rax,%r12,8), %r15d
andq %r13, %r15
cmpq %r13, %r15
je 0x17c520
movq 0x10(%rdi), %rcx
leaq (%r15,%r15,4), %rdx
movl (%rcx,%rdx,8), %esi
andl $0x3, %esi
cmpl %r8d, %esi
jne 0x17c520
cmpl 0x18(%rdi), %r15d
je 0x17c520
cmpl 0x1c(%rdi), %r15d
je 0x17c520
leaq (%rcx,%rdx,8), %r13
movl 0x18(%r13), %edx
movq 0x8(%r13), %rsi
xorl %ecx, %ecx
cmpq %rdx, %rsi
jbe 0x17c44e
movq 0x20(%r13), %r9
movl (%r9,%rdx,8), %r8d
notl %r8d
testl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
je 0x17c433
movl %edx, %ebp
testl %ecx, %ecx
movl $0x1, %ecx
jne 0x17c43c
incl %edx
cmpq %rdx, %rsi
ja 0x17c418
jmp 0x17c443
movl $0x2, %ecx
movl %edx, %ebp
cmpl $0x1, %ecx
sete %cl
movl 0x14(%rsp), %r8d
testb %cl, %cl
je 0x17c484
movq 0x20(%r13), %rcx
movl %ebp, %edx
movl (%rcx,%rdx,8), %esi
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andl %r8d, %esi
cmpl 0x30(%rsp), %esi
jne 0x17c5f3
movl 0x8(%rsp), %esi
testl %esi, %esi
je 0x17c48f
movl 0x10(%rsp), %eax
addl 0x4(%rcx,%rdx,8), %eax
movl %eax, 0x10(%rsp)
jmp 0x17c4a6
movl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
jmp 0x17c520
movl 0x4(%rax,%r12,8), %eax
movl %eax, 0x10(%rsp)
movl %r15d, 0xc(%rsp)
movl %ebp, 0x18(%rsp)
movl %r12d, 0x1c(%rsp)
testl %esi, %esi
je 0x17c50f
cmpq $0x0, 0x18(%r13)
je 0x17c4f1
movl $0x1, %r14d
xorl %eax, %eax
movq 0x20(%r13), %rcx
movl (%rcx,%rax,8), %r8d
movl %r8d, %edx
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl %esi, %edx
cmpl %esi, %edx
je 0x17c4e5
movl 0x4(%rcx,%rax,8), %ecx
shrl $0x1f, %r8d
movl 0xc(%rsp), %esi
callq 0x18d628
movq 0x20(%rsp), %rdi
movl %r14d, %eax
incl %r14d
cmpq %rax, 0x18(%r13)
ja 0x17c4b9
movl 0x8(%rsp), %esi
testl %esi, %esi
movq 0x28(%rsp), %r14
je 0x17c50f
movl %r15d, %esi
callq 0x17bde8
movl 0x8(%rsp), %esi
movq 0x20(%rsp), %rdi
incl %esi
movl %esi, 0x8(%rsp)
movl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
movl 0x14(%rsp), %r8d
incl %r12d
cmpq %r12, 0x18(%rbx)
ja 0x17c3c2
cmpl $0x0, 0x8(%rsp)
sete %dl
movl 0x18(%rsp), %eax
movl 0x1c(%rsp), %ecx
movl 0x10(%rsp), %r9d
jmp 0x17c55b
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movb $0x1, %dl
xorl %r9d, %r9d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testb %dl, %dl
jne 0x17c5cb
movq 0x10(%rdi), %rdx
movl 0xc(%rsp), %esi
leaq (%rsi,%rsi,4), %rsi
movq 0x20(%rdx,%rsi,8), %rdx
movl %r9d, 0x4(%rdx,%rax,8)
movq 0x20(%rbx), %rax
movl %r9d, 0x4(%rax,%rcx,8)
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0x17c5b6
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
shlq $0x2, %rsi
callq 0x2370
movl 0x14(%rsp), %r8d
movq 0x20(%rsp), %rdi
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r14)
movl 0xc(%rsp), %edx
movl %edx, (%rcx,%rax,4)
incl %r8d
cmpl $0x4, %r8d
jne 0x17c382
movq (%r14), %rax
testq %rax, %rax
jne 0x17c355
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb599a(%rip), %rdi     # 0x231f94
leaq 0xb57ea(%rip), %rsi     # 0x231deb
leaq 0xb59d6(%rip), %rcx     # 0x231fde
movl $0x56f, %edx            # imm = 0x56F
callq 0x2110