// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x24f7c6
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x24f78b
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x60(%rbp)
jmp 0x24f796
movl $0x2, %eax
movq %rax, -0x60(%rbp)
jmp 0x24f796
movq -0x60(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0xc(%rbp), %edx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movl %edx, (%rax,%rcx,4)
jmp 0x24f7e7
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
je 0x24fb93
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rdx
movq (%rdx), %rcx
movq %rcx, %rsi
addq $-0x1, %rsi
movq %rsi, (%rdx)
movl -0x4(%rax,%rcx,4), %eax
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
shrl $0x3, %eax
cmpl $0x1fffffff, %eax       # imm = 0x1FFFFFFF
jne 0x24f835
jmp 0x24f7e7
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movl $0x0, -0x30(%rbp)
cmpl $0x4, -0x30(%rbp)
jae 0x24fb8e
movl $0x0, -0x50(%rbp)
movl $0x0, -0x48(%rbp)
movl $0xffffffff, -0x3c(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x54(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x58(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x4c(%rbp) # imm = 0xFFFFFFFF
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x24fab4
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x34(%rbp), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
jne 0x24f8c1
jmp 0x24faa6
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x34(%rbp), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x40(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %eax
andl $0x3, %eax
cmpl -0x30(%rbp), %eax
je 0x24f900
jmp 0x24faa6
movl -0x40(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x18(%rcx), %eax
je 0x24f918
movl -0x40(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jne 0x24f91d
jmp 0x24faa6
movl $0x0, -0x44(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jae 0x24f978
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x38(%rbp), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
jne 0x24f954
jmp 0x24f96d
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x1, -0x44(%rbp)
jbe 0x24f96b
jmp 0x24f978
jmp 0x24f96d
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x24f92b
cmpl $0x1, -0x44(%rbp)
je 0x24f983
jmp 0x24faa6
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x3c(%rbp), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl -0x2c(%rbp), %eax
jne 0x24f99d
jmp 0x24f9bc
leaq 0x13f410(%rip), %rdi    # 0x38edb4
leaq 0x13f260(%rip), %rsi    # 0x38ec0b
movl $0x52c, %edx            # imm = 0x52C
leaq 0x13f413(%rip), %rcx    # 0x38edca
callq 0x2130
cmpl $0x0, -0x48(%rbp)
jne 0x24f9e8
movl -0x40(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x54(%rbp)
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x34(%rbp), %ecx
movl 0x4(%rax,%rcx,8), %eax
movl %eax, -0x50(%rbp)
jmp 0x24f9fd
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x3c(%rbp), %ecx
movl 0x4(%rax,%rcx,8), %eax
addl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x48(%rbp)
jbe 0x24fa8b
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x24fa89
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x38(%rbp), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
jne 0x24fa3b
jmp 0x24fa7e
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x38(%rbp), %ecx
movl (%rax,%rcx,8), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movl -0x4c(%rbp), %edx
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x38(%rbp), %ecx
movl 0x4(%rax,%rcx,8), %ecx
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x38(%rbp), %r8d
movl (%rax,%r8,8), %r8d
shrl $0x1f, %r8d
callq 0x26cfb0
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x24fa12
jmp 0x24fa8b
cmpl $0x0, -0x48(%rbp)
jbe 0x24fa9d
movq -0x8(%rbp), %rdi
movl -0x40(%rbp), %esi
callq 0x24f410
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x24f891
cmpl $0x0, -0x48(%rbp)
je 0x24fb7e
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movl -0x50(%rbp), %edx
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x54(%rbp), %ecx
movl %edx, 0x4(%rax,%rcx,8)
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x58(%rbp), %ecx
movl %edx, 0x4(%rax,%rcx,8)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x24fb5d
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x24fb22
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x68(%rbp)
jmp 0x24fb2d
movl $0x2, %eax
movq %rax, -0x68(%rbp)
jmp 0x24fb2d
movq -0x68(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x4c(%rbp), %edx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movl %edx, (%rax,%rcx,4)
jmp 0x24fb7e
jmp 0x24fb80
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x24f852
jmp 0x24f7e7
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)