// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movq 0x38(%rdi), %rax
movabsq $-0x400000000000000, %rcx # imm = 0xFC00000000000000
andq %rcx, (%rax)
movq 0x38(%rdi), %rdi
andq $0x0, 0x8(%rdi)
movl 0x18(%r14), %esi
callq 0x13fb20
movl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movq 0x38(%r14), %rdi
callq 0x13fc6d
testq %rax, %rax
je 0x13fb11
movl (%rax), %r15d
movq 0x10(%r14), %rax
imulq $0x28, %r15, %r13
cmpl $-0x9, (%rax,%r13)
ja 0x13f9db
movq %r14, %rdi
movl %r15d, %esi
movq %rbx, %rdx
callq 0x13f3de
movq %r14, %rdi
movl %r15d, %esi
movq %rbx, %rdx
callq 0x13f6ad
addq 0x10(%r14), %r13
xorl %ecx, %ecx
movl %ecx, %ecx
movq 0x18(%r13), %rax
cmpq %rcx, %rax
jbe 0x13fa9f
movq 0x20(%r13), %rax
movl (%rax,%rcx,8), %edx
movq %rdx, %rax
andq %r12, %rax
cmpq %r12, %rax
sete %sil
testl %edx, %edx
setns %dl
orb %sil, %dl
jne 0x13fa9b
movq 0x10(%r14), %rdx
imulq $0x28, %rax, %rax
addq %rdx, %rax
addq $0x8, %rax
movl 0x10(%rax), %r9d
movq (%rax), %rdx
movl %r9d, %esi
cmpq %rsi, %rdx
jbe 0x13fa9b
movq 0x18(%rax), %rdi
movl (%rdi,%rsi,8), %r8d
movl %r8d, %r9d
andl %ebp, %r9d
cmpl %r15d, %r9d
setne %r10b
cmpl %ebp, %r9d
sete %r11b
orb %r10b, %r11b
leal 0x1(%rsi), %r9d
testb %r11b, %r11b
jne 0x13fa60
orl $0x80000000, %r8d       # imm = 0x80000000
movl %r8d, (%rdi,%rsi,8)
incl %ecx
jmp 0x13fa21
orb $0x4, (%r13)
xorl %r15d, %r15d
movl %r15d, %r15d
cmpq %r15, %rax
jbe 0x13f9db
movq 0x20(%r13), %rcx
movl (%rcx,%r15,8), %esi
andq %r12, %rsi
cmpq %r12, %rsi
je 0x13fb0c
movq 0x10(%r14), %rcx
imulq $0x28, %rsi, %rdx
addq %rcx, %rdx
addq $0x8, %rdx
movl 0x10(%rdx), %edi
movq (%rdx), %r8
movl %edi, %edi
cmpq %rdi, %r8
jbe 0x13faff
movq 0x18(%rdx), %r9
movl (%r9,%rdi,8), %r9d
cmpq $0x7ffffffe, %r9        # imm = 0x7FFFFFFE
ja 0x13fafb
imulq $0x28, %r9, %r9
testb $0x4, (%rcx,%r9)
je 0x13fb0c
incl %edi
jmp 0x13fad8
movq 0x38(%r14), %rdi
callq 0x13fb20
movq 0x18(%r13), %rax
incl %r15d
jmp 0x13faa7
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq