// File: /workspace/github_cpp_makefile_star2_O3/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, %r13
movl %esi, %ebp
movq $0x0, (%rdx)
cmpq $0x0, 0x8(%rdx)
movq %rdi, 0x20(%rsp)
je 0x182ce0
movq 0x10(%r13), %rax
movl %ebp, (%rax)
movl $0x1, %ecx
jmp 0x182d16
movq $0x2, 0x8(%r13)
movq 0x10(%r13), %rdi
movl $0x8, %esi
callq 0x2370
movq 0x20(%rsp), %rdi
movq %rax, 0x10(%r13)
movq (%r13), %rdx
movq %rdx, %rcx
incq %rcx
movq %rcx, (%r13)
movl %ebp, (%rax,%rdx,4)
je 0x182faa
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
movq %r13, 0x28(%rsp)
movq 0x10(%r13), %rax
leaq -0x1(%rcx), %rsi
movq %rsi, (%r13)
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 0x182fa1
leaq (%rax,%rdx,8), %rbx
xorl %r11d, %r11d
movl 0x18(%rbx), %ebp
movq 0x8(%rbx), %rax
cmpq %rbp, %rax
jbe 0x182f90
movl $0x0, 0xc(%rsp)
movl $0xffffffff, 0x1c(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x18(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x10(%rsp) # imm = 0xFFFFFFFF
movl $0x0, 0x14(%rsp)
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl %r11d, 0x8(%rsp)
movq 0x20(%rbx), %rsi
movl (%rsi,%rbp,8), %r15d
andq %r10, %r15
cmpq %r10, %r15
je 0x182e1f
movq 0x10(%rdi), %rcx
leaq (%r15,%r15,4), %r9
movl (%rcx,%r9,8), %r8d
andl $0x3, %r8d
cmpl %r11d, %r8d
jne 0x182e1f
cmpl 0x18(%rdi), %r15d
je 0x182e1f
cmpl 0x1c(%rdi), %r15d
je 0x182e1f
leaq (%rcx,%r9,8), %r12
movq 0x18(%r12), %rcx
testq %rcx, %rcx
je 0x182e1f
movq 0x20(%r12), %r11
xorl %r10d, %r10d
movb $0x1, %r8b
xorl %r9d, %r9d
movl %r10d, %r14d
movl (%r11,%r10,8), %r10d
notl %r10d
testl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
jne 0x182e01
incl %r14d
movq %r14, %r10
cmpq %r14, %rcx
ja 0x182de4
jmp 0x182e35
testb $0x1, %r8b
je 0x182efb
leal 0x1(%r14), %r10d
movb $0x1, %r9b
xorl %r8d, %r8d
movl %r14d, %edx
cmpq %r10, %rcx
ja 0x182de1
jmp 0x182e42
movl %edx, %r14d
incl %ebp
movl %r14d, %edx
cmpq %rbp, %rax
ja 0x182d94
jmp 0x182f0b
movl %edx, %r14d
testb $0x1, %r9b
je 0x182edc
movq 0x20(%r12), %rdx
movl %r14d, %r9d
movl (%rdx,%r9,8), %r8d
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
andl %r10d, %r8d
cmpl 0x30(%rsp), %r8d
jne 0x182fb9
cmpl $0x0, 0x14(%rsp)
je 0x182ee1
movl 0xc(%rsp), %eax
addl 0x4(%rdx,%r9,8), %eax
movl %eax, 0xc(%rsp)
movq 0x8(%r12), %rax
cmpq %rcx, %rax
jbe 0x182ec4
leal 0x1(%rcx), %r13d
movq 0x20(%r12), %rdx
movl (%rdx,%rcx,8), %r8d
movl %r8d, %esi
movl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
andl %r9d, %esi
cmpl %r9d, %esi
je 0x182eb9
movl 0x4(%rdx,%rcx,8), %ecx
shrl $0x1f, %r8d
movl 0x10(%rsp), %edx
callq 0x196448
movq 0x20(%rsp), %rdi
movq 0x8(%r12), %rax
movl %r13d, %ecx
incl %r13d
cmpq %rcx, %rax
ja 0x182e84
movl %r15d, %esi
callq 0x182ac0
movq 0x20(%rsp), %rdi
movq 0x8(%rbx), %rax
movq 0x28(%rsp), %r13
jmp 0x182ef7
movl %edx, %r14d
jmp 0x182efb
movl 0x4(%rsi,%rbp,8), %ecx
movl %ecx, 0xc(%rsp)
movl %ebp, 0x1c(%rsp)
movl %r14d, 0x18(%rsp)
movl %r15d, 0x10(%rsp)
incl 0x14(%rsp)
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
movl 0x8(%rsp), %r11d
jmp 0x182e22
cmpl $0x0, 0x14(%rsp)
je 0x182f90
movl 0x1c(%rsp), %eax
movl 0x18(%rsp), %ecx
movq 0x10(%rdi), %rdx
movl 0x10(%rsp), %esi
leaq (%rsi,%rsi,4), %rsi
movq 0x20(%rdx,%rsi,8), %rdx
movl 0xc(%rsp), %esi
movl %esi, 0x4(%rdx,%rcx,8)
movq 0x20(%rbx), %rcx
movl %esi, 0x4(%rcx,%rax,8)
movq (%r13), %rcx
movq 0x10(%r13), %rax
cmpq 0x8(%r13), %rcx
jne 0x182f81
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r13)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movl 0x8(%rsp), %r11d
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
movq 0x20(%rsp), %rdi
movq %rax, 0x10(%r13)
movq (%r13), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r13)
movl 0x10(%rsp), %edx
movl %edx, (%rax,%rcx,4)
incl %r11d
cmpl $0x4, %r11d
jne 0x182d52
movq (%r13), %rcx
testq %rcx, %rcx
jne 0x182d21
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xbb224(%rip), %rdi     # 0x23e1e4
leaq 0xbb074(%rip), %rsi     # 0x23e03b
leaq 0xbb22c(%rip), %rcx     # 0x23e1fa
movl $0x52c, %edx            # imm = 0x52C
callq 0x2110