// File: chhylp123[P]hifiasm/ecovlp.cpp
// Function: refine_cns_g(cns_gfa*, asg32_v*)
void refine_cns_g(cns_gfa *cns, asg32_v *b32)
{
    uint32_t v, w, vk, wk, *p = NULL; cns_t *av = NULL, *aw = NULL;
    kdq_clear(cns->q); 
    kdq_push(uint32_t, cns->q, cns->si); ///in-degree == 0

    while (1) {
        p = kdq_shift(uint32_t, cns->q);
        if(!p) break; v = *p;

        if(del_cns_nn((*cns), v)) continue;
        ///merge in
        merge_cns_g_in(cns, v, b32);
        ///merge out
        merge_cns_g_ou(cns, v, b32);

        av = &((*cns).a[v]);
        ///set arcs
        for (vk = 0; vk < av->arc.nou; vk++) {///out-edge of v
            if(del_cns_arc((*av), vk)) continue;
            if(av->arc.a[vk].f == 0) continue;

            av->arc.a[vk].f = 1; w = av->arc.a[vk].v; aw = &((*cns).a[w]);

            for (wk = aw->arc.nou; wk < aw->arc.n; wk++) {///in-edge of w
                if((aw->arc.a[wk].v != v) || (del_cns_arc((*aw), wk))) continue;
                aw->arc.a[wk].f = 1; break;
            }
        }
        ///set node
        av->f = 1;


        for (vk = 0; vk < av->arc.nou; vk++) {///out-edge of v
            if(del_cns_arc((*av), vk)) continue;
            w = av->arc.a[vk].v;

            aw = &((*cns).a[w]);
            for (wk = aw->arc.nou; wk < aw->arc.n; wk++) {///in-edge of w
                if((del_cns_arc((*aw), wk))) continue;
                if(aw->arc.a[wk].f) continue;///test arcs
                if(cns->a[aw->arc.a[wk].v].f) continue;///test node
                break;
            }
            if(wk >= aw->arc.n) {
                kdq_push(uint32_t, cns->q, w); ///in-degree == 0
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movabsq $-0x400000000000000, %rcx # imm = 0xFC00000000000000
andq (%rax), %rcx
orq $0x0, %rcx
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq $0x0, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x18(%rax), %esi
callq 0x250340
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x2503d0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x250085
jmp 0x250338
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x14(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
shrl $0x3, %eax
cmpl $0x1fffffff, %eax       # imm = 0x1FFFFFFF
jne 0x2500ae
jmp 0x250068
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0x10(%rbp), %rdx
callq 0x24f740
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0x10(%rbp), %rdx
callq 0x24fba0
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x14(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jae 0x250205
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x1c(%rbp), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
jne 0x25011b
jmp 0x2501f7
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x1c(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x250136
jmp 0x2501f7
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x1c(%rbp), %ecx
movl (%rax,%rcx,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
orl $0x80000000, %edx       # imm = 0x80000000
movl %edx, (%rax,%rcx,8)
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x1c(%rbp), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x18(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x2501f5
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x20(%rbp), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl -0x14(%rbp), %eax
jne 0x2501c9
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x20(%rbp), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
jne 0x2501cb
jmp 0x2501ea
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x20(%rbp), %ecx
movl (%rax,%rcx,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
orl $0x80000000, %edx       # imm = 0x80000000
movl %edx, (%rax,%rcx,8)
jmp 0x2501f5
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x25018a
jmp 0x2501f7
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x2500eb
movq -0x30(%rbp), %rax
movl (%rax), %ecx
andl $-0x5, %ecx
orl $0x4, %ecx
movl %ecx, (%rax)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jae 0x250333
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x1c(%rbp), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
jne 0x25024a
jmp 0x250325
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x1c(%rbp), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x18(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x250306
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x20(%rbp), %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
jne 0x2502aa
jmp 0x2502f8
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x20(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x2502c2
jmp 0x2502f8
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
movq 0x20(%rcx), %rcx
movl -0x20(%rbp), %edx
movl (%rcx,%rdx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
shrl $0x2, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2502f6
jmp 0x2502f8
jmp 0x250306
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x250281
movl -0x20(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jb 0x250323
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
movl -0x18(%rbp), %esi
callq 0x250340
jmp 0x250325
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x25021a
jmp 0x250068
addq $0x40, %rsp
popq %rbp
retq
nop