// File: /workspace/github_cpp_makefile_star2_O1/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, %r14
movl %esi, %ebp
movq $0x0, (%rdx)
cmpq $0x0, 0x8(%rdx)
movq %rdi, 0x18(%rsp)
jne 0x17c011
movq $0x2, 0x8(%r14)
movq 0x10(%r14), %rdi
movl $0x8, %esi
callq 0x2370
movq 0x18(%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 0x17c2be
movl $0x7fffffff, %r9d       # 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 0x17c2b2
leaq (%rax,%rcx,8), %rbx
xorl %r10d, %r10d
movl 0x18(%rbx), %ebp
cmpq %rbp, 0x8(%rbx)
jbe 0x17c217
xorl %r11d, %r11d
movl $0xffffffff, 0x10(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
xorl %r8d, %r8d
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movq 0x20(%rbx), %rax
movl (%rax,%rbp,8), %r15d
andq %r9, %r15
cmpq %r9, %r15
je 0x17c1f6
movq 0x10(%rdi), %rcx
leaq (%r15,%r15,4), %rdx
movl (%rcx,%rdx,8), %esi
andl $0x3, %esi
cmpl %r10d, %esi
jne 0x17c1f6
cmpl 0x18(%rdi), %r15d
je 0x17c1f6
cmpl 0x1c(%rdi), %r15d
je 0x17c1f6
leaq (%rcx,%rdx,8), %r13
movq 0x18(%r13), %r14
xorl %ecx, %ecx
testq %r14, %r14
je 0x17c130
movl %r11d, 0x8(%rsp)
movl %r8d, %r11d
movq 0x20(%r13), %rdx
xorl %r8d, %r8d
xorl %esi, %esi
movl (%rdx,%r8,8), %r8d
notl %r8d
testl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
je 0x17c10e
movl %esi, %r12d
testl %ecx, %ecx
movl $0x1, %ecx
jne 0x17c11a
incl %esi
movq %rsi, %r8
cmpq %rsi, %r14
ja 0x17c0f2
jmp 0x17c122
movl $0x2, %ecx
movl %esi, %r12d
cmpl $0x1, %ecx
sete %cl
movl %r11d, %r8d
movl 0x8(%rsp), %r11d
testb %cl, %cl
je 0x17c1f6
movl %r8d, 0x14(%rsp)
movq 0x20(%r13), %rcx
movl %r12d, %edx
movl (%rcx,%rdx,8), %esi
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andl %r8d, %esi
cmpl 0x30(%rsp), %esi
jne 0x17c2cd
movl 0x14(%rsp), %r8d
testl %r8d, %r8d
je 0x17c16b
addl 0x4(%rcx,%rdx,8), %r11d
jmp 0x17c17e
movl 0x4(%rax,%rbp,8), %r11d
movl %r15d, 0x4(%rsp)
movl %r12d, 0xc(%rsp)
movl %ebp, 0x10(%rsp)
testl %r8d, %r8d
je 0x17c1f3
movl %r11d, 0x8(%rsp)
movl %r10d, 0x24(%rsp)
movl %r14d, %eax
cmpq %rax, 0x8(%r13)
jbe 0x17c1d1
incl %r14d
movq 0x20(%r13), %rcx
movl (%rcx,%rax,8), %r8d
movl %r8d, %esi
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %esi
cmpl %edx, %esi
je 0x17c1c5
movl 0x4(%rcx,%rax,8), %ecx
shrl $0x1f, %r8d
movl 0x4(%rsp), %edx
callq 0x18d628
movq 0x18(%rsp), %rdi
movl %r14d, %eax
incl %r14d
cmpq %rax, 0x8(%r13)
ja 0x17c199
movl %r15d, %esi
callq 0x17bde8
movq 0x18(%rsp), %rdi
movl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
movl 0x24(%rsp), %r10d
movl 0x8(%rsp), %r11d
movl 0x14(%rsp), %r8d
incl %r8d
incl %ebp
cmpq %rbp, 0x8(%rbx)
ja 0x17c093
testl %r8d, %r8d
sete %dl
movl 0xc(%rsp), %eax
movl 0x10(%rsp), %ecx
movq 0x28(%rsp), %r14
jmp 0x17c22e
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
movb $0x1, %dl
xorl %r11d, %r11d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testb %dl, %dl
jne 0x17c2a5
movq 0x10(%rdi), %rdx
movl 0x4(%rsp), %esi
leaq (%rsi,%rsi,4), %rsi
movq 0x20(%rdx,%rsi,8), %rdx
movl %r11d, 0x4(%rdx,%rax,8)
movq 0x20(%rbx), %rax
movl %r11d, 0x4(%rax,%rcx,8)
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0x17c290
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
shlq $0x2, %rsi
movl %r10d, %ebp
callq 0x2370
movl %ebp, %r10d
movl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
movq 0x18(%rsp), %rdi
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r14)
movl 0x4(%rsp), %edx
movl %edx, (%rcx,%rax,4)
incl %r10d
cmpl $0x4, %r10d
jne 0x17c062
movq (%r14), %rax
testq %rax, %rax
jne 0x17c035
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb5cc0(%rip), %rdi     # 0x231f94
leaq 0xb5b10(%rip), %rsi     # 0x231deb
leaq 0xb5cc8(%rip), %rcx     # 0x231faa
movl $0x52c, %edx            # imm = 0x52C
callq 0x2110