// File: /workspace/github_cpp_makefile_star2_O1/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
movabsq $-0x400000000000000, %rcx # imm = 0xFC00000000000000
movq 0x38(%rdi), %rax
andq %rcx, (%rax)
movq 0x38(%rdi), %rdi
movq $0x0, 0x8(%rdi)
movl 0x18(%r14), %esi
callq 0x17c80f
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
movq 0x38(%r14), %rcx
movq 0x8(%rcx), %rdx
testq %rdx, %rdx
je 0x17c6a3
movq (%rcx), %rsi
movq %rsi, %rax
movabsq $0x3ffffffffffffff, %r8 # imm = 0x3FFFFFFFFFFFFFF
andq %r8, %rax
leaq 0x1(%rsi), %rdi
andq %r8, %rdi
movabsq $-0x400000000000000, %r8 # imm = 0xFC00000000000000
andq %r8, %rsi
shlq $0x2, %rax
addq 0x18(%rcx), %rax
andq 0x10(%rcx), %rdi
orq %rsi, %rdi
movq %rdi, (%rcx)
decq %rdx
movq %rdx, 0x8(%rcx)
jmp 0x17c6a5
xorl %eax, %eax
testq %rax, %rax
je 0x17c800
movl (%rax), %r15d
movq 0x10(%r14), %rax
leaq (%r15,%r15,4), %r13
cmpl $-0x9, (%rax,%r13,8)
ja 0x17c654
movq %r14, %rdi
movl %r15d, %esi
movq %rbx, %rdx
callq 0x17bfcc
movq %r14, %rdi
movl %r15d, %esi
movq %rbx, %rdx
callq 0x17c2ec
movq 0x10(%r14), %rax
leaq (%rax,%r13,8), %r13
cmpq $0x0, 0x18(%r13)
je 0x17c76f
xorl %eax, %eax
movq 0x20(%r13), %rcx
movl (%rcx,%rax,8), %edx
movq %rdx, %rcx
andq %rbp, %rcx
cmpq %rbp, %rcx
sete %sil
testl %edx, %edx
setns %dl
orb %sil, %dl
jne 0x17c767
movq 0x10(%r14), %rsi
leaq (%rcx,%rcx,4), %rdi
movl 0x18(%rsi,%rdi,8), %ecx
movq 0x8(%rsi,%rdi,8), %rdx
cmpq %rcx, %rdx
jbe 0x17c767
leaq (%rsi,%rdi,8), %rsi
addq $0x8, %rsi
movq 0x18(%rsi), %rsi
leal 0x1(%rcx), %edi
movl (%rsi,%rcx,8), %r8d
movl %r8d, %r9d
andl %r12d, %r9d
cmpl %r15d, %r9d
setne %r10b
cmpl %r12d, %r9d
sete %r9b
orb %r10b, %r9b
je 0x17c75c
movl %edi, %ecx
incl %edi
cmpq %rcx, %rdx
ja 0x17c734
jmp 0x17c767
orl $0x80000000, %r8d       # imm = 0x80000000
movl %r8d, (%rsi,%rcx,8)
incl %eax
cmpq %rax, 0x18(%r13)
ja 0x17c6f1
orb $0x4, (%r13)
cmpq $0x0, 0x18(%r13)
je 0x17c654
xorl %r15d, %r15d
movq 0x20(%r13), %rax
movl (%rax,%r15,8), %esi
andq %rbp, %rsi
cmpq %rbp, %rsi
je 0x17c7f2
movq 0x10(%r14), %rax
leaq (%rsi,%rsi,4), %rdi
movl 0x18(%rax,%rdi,8), %r8d
movq 0x8(%rax,%rdi,8), %rcx
cmpq %r8, %rcx
seta %dl
jbe 0x17c7e9
leaq (%rax,%rdi,8), %rdi
addq $0x8, %rdi
movq 0x18(%rdi), %rdi
leal 0x1(%r8), %r9d
movl (%rdi,%r8,8), %r8d
cmpq $0x7ffffffe, %r8        # imm = 0x7FFFFFFE
ja 0x17c7d4
leaq (%r8,%r8,4), %r8
testb $0x4, (%rax,%r8,8)
je 0x17c7e4
movl %r9d, %r8d
incl %r9d
cmpq %r8, %rcx
seta %dl
ja 0x17c7bc
jmp 0x17c7e9
testb $0x1, %dl
jne 0x17c7f2
movq 0x38(%r14), %rdi
callq 0x17c80f
incl %r15d
cmpq %r15, 0x18(%r13)
ja 0x17c782
jmp 0x17c654
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq