// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/ecovlp.cpp
// Function: merge_cns_g_in(cns_gfa*, unsigned int, asg32_v*)
void merge_cns_g_in(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 = av->arc.nou; vk < av->arc.n; vk++) {///in-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 = wn = 0; wk < aw->arc.nou; wk++) {///out-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 out-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 in-edge of w
                ///all edges to 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 = aw->arc.nou; wk < aw->arc.n; wk++) {
                        if(del_cns_arc((*aw), wk)) continue;
                        ///previously, aw->arc.a[wk].v -> w
                        ///currently, aw->arc.a[wk].v -> mn
                        /// if(nn == 0), then mn = w
                        gen_mm_cns_arc(cns, aw->arc.a[wk].v, mn, 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]);
                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, %rbx
andq $0x0, (%rdx)
movl %esi, %ebp
cmpq $0x0, 0x8(%rdx)
movq %rdi, 0x18(%rsp)
je 0x13f409
movq 0x10(%rbx), %rax
xorl %edx, %edx
jmp 0x13f429
movq $0x2, 0x8(%rbx)
movq 0x10(%rbx), %rdi
pushq $0x8
popq %rsi
callq 0x2370
movq 0x18(%rsp), %rdi
movq %rax, 0x10(%rbx)
movq (%rbx), %rdx
leaq 0x1(%rdx), %rcx
movq %rcx, (%rbx)
movl %ebp, (%rax,%rdx,4)
movl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
pushq $0x1
popq %r10
movq %rbx, 0x30(%rsp)
testq %rcx, %rcx
je 0x13f67f
movq 0x10(%rbx), %rax
leaq -0x1(%rcx), %rdx
movq %rdx, (%rbx)
movl -0x4(%rax,%rcx,4), %eax
movq 0x10(%rdi), %r12
movq %rax, 0x28(%rsp)
imulq $0x28, %rax, %rax
cmpl $-0x9, (%r12,%rax)
movq %rdx, %rcx
ja 0x13f442
addq %rax, %r12
xorl %r11d, %r11d
cmpl $0x4, %r11d
je 0x13f677
movl 0x18(%r12), %ebx
movl $0x0, 0x8(%rsp)
pushq $-0x1
popq %rax
movl %eax, %ebp
movl %eax, (%rsp)
movl $0x0, 0x4(%rsp)
movl %eax, 0x10(%rsp)
movl %eax, 0x14(%rsp)
movl %r11d, 0xc(%rsp)
movl %ebx, %eax
cmpq %rax, 0x8(%r12)
jbe 0x13f5ed
movq 0x20(%r12), %rcx
movl (%rcx,%rax,8), %r15d
andq %r14, %r15
cmpq %r14, %r15
je 0x13f5e6
movq 0x10(%rdi), %r13
imulq $0x28, %r15, %rdx
movl (%r13,%rdx), %esi
andl $0x3, %esi
cmpl %r11d, %esi
jne 0x13f5e6
cmpl 0x18(%rdi), %r15d
je 0x13f5e6
cmpl 0x1c(%rdi), %r15d
je 0x13f5e6
addq %rdx, %r13
movq 0x18(%r13), %r14
xorl %edx, %edx
xorl %esi, %esi
movl %edx, %r9d
cmpq %r9, %r14
jbe 0x13f52e
movq 0x20(%r13), %r8
movl (%r8,%r9,8), %r8d
notl %r8d
testl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
je 0x13f52a
movl %edx, %ebp
testl %esi, %esi
movl %r10d, %esi
jne 0x13f59e
incl %edx
jmp 0x13f505
cmpl $0x1, %esi
jne 0x13f5e0
movq 0x20(%r13), %rdx
movl %ebp, %esi
movl (%rdx,%rsi,8), %r8d
movl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
andl %r9d, %r8d
cmpl 0x28(%rsp), %r8d
jne 0x13f68e
cmpl $0x0, 0x8(%rsp)
je 0x13f5c8
movl 0x4(%rdx,%rsi,8), %eax
movl %eax, 0x24(%rsp)
movl %r14d, %r14d
cmpq %r14, 0x8(%r13)
jbe 0x13f5a2
movq 0x20(%r13), %rax
movl (%rax,%r14,8), %r8d
movl %r8d, %esi
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %esi
cmpl %ecx, %esi
je 0x13f599
movl 0x4(%rax,%r14,8), %ecx
shrl $0x1f, %r8d
movl (%rsp), %edx
callq 0x14f1ee
movq 0x18(%rsp), %rdi
incl %r14d
jmp 0x13f564
movl %edx, %ebp
jmp 0x13f5e0
movl 0x24(%rsp), %eax
addl %eax, 0x4(%rsp)
movl %r15d, %esi
callq 0x13f229
movl 0xc(%rsp), %r11d
pushq $0x1
popq %r10
movq 0x18(%rsp), %rdi
movl (%rsp), %eax
movl %eax, %r15d
jmp 0x13f5d8
movl 0x4(%rcx,%rax,8), %eax
movl %eax, 0x4(%rsp)
movl %ebx, 0x14(%rsp)
movl %ebp, 0x10(%rsp)
incl 0x8(%rsp)
movl %r15d, (%rsp)
movl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
incl %ebx
jmp 0x13f4ab
cmpl $0x0, 0x8(%rsp)
movq 0x30(%rsp), %rbx
je 0x13f66f
movq 0x10(%rdi), %rax
movl (%rsp), %ecx
imulq $0x28, %rcx, %rcx
movq 0x20(%rax,%rcx), %rax
movl 0x10(%rsp), %ecx
movl 0x4(%rsp), %edx
movl %edx, 0x4(%rax,%rcx,8)
movq 0x20(%r12), %rax
movl 0x14(%rsp), %ecx
movl %edx, 0x4(%rax,%rcx,8)
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rcx
jne 0x13f662
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movl 0xc(%rsp), %r11d
pushq $0x1
popq %r10
movq 0x18(%rsp), %rdi
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbx)
movl (%rsp), %edx
movl %edx, (%rax,%rcx,4)
incl %r11d
jmp 0x13f477
movq (%rbx), %rcx
jmp 0x13f442
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb0a0f(%rip), %rdi     # 0x1f00a4
leaq 0xb085f(%rip), %rsi     # 0x1efefb
leaq 0xb0a17(%rip), %rcx     # 0x1f00ba
movl $0x52c, %edx            # imm = 0x52C
callq 0x2110