// File: 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
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 0x24fc26
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x24fbeb
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x60(%rbp)
jmp 0x24fbf6
movl $0x2, %eax
movq %rax, -0x60(%rbp)
jmp 0x24fbf6
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 0x24fc47
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
je 0x24ffef
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 0x24fc95
jmp 0x24fc47
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 0x24ffea
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
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jae 0x24ff10
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 0x24fd1d
jmp 0x24ff02
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 0x24fd5c
jmp 0x24ff02
movl -0x40(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x18(%rcx), %eax
je 0x24fd74
movl -0x40(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jne 0x24fd79
jmp 0x24ff02
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movl %eax, -0x38(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x38(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x24fdd8
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 0x24fdb4
jmp 0x24fdcd
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x1, -0x44(%rbp)
jbe 0x24fdcb
jmp 0x24fdd8
jmp 0x24fdcd
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x24fd8b
cmpl $0x1, -0x44(%rbp)
je 0x24fde3
jmp 0x24ff02
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 0x24fdfd
jmp 0x24fe1c
leaq 0x13efb0(%rip), %rdi    # 0x38edb4
leaq 0x13ee00(%rip), %rsi    # 0x38ec0b
movl $0x56f, %edx            # imm = 0x56F
leaq 0x13efe7(%rip), %rcx    # 0x38edfe
callq 0x2130
cmpl $0x0, -0x48(%rbp)
jne 0x24fe48
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 0x24fe5d
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 0x24fee7
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jae 0x24fee5
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 0x24fe97
jmp 0x24feda
movq -0x8(%rbp), %rdi
movl -0x4c(%rbp), %esi
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x38(%rbp), %ecx
movl (%rax,%rcx,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
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 0x24fe6e
jmp 0x24fee7
cmpl $0x0, -0x48(%rbp)
jbe 0x24fef9
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 0x24fced
cmpl $0x0, -0x48(%rbp)
je 0x24ffda
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 0x24ffb9
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x24ff7e
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x68(%rbp)
jmp 0x24ff89
movl $0x2, %eax
movq %rax, -0x68(%rbp)
jmp 0x24ff89
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 0x24ffda
jmp 0x24ffdc
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x24fcb2
jmp 0x24fc47
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)