// File: /workspace/github_cpp_makefile_star2_O3/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
subq $0x18, %rsp
movq %rsi, 0x8(%rsp)
movq %rdi, %rbp
movabsq $-0x400000000000000, %rcx # imm = 0xFC00000000000000
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movq 0x38(%rdi), %rax
andq %rcx, (%rax)
movq 0x38(%rdi), %rax
movl 0x18(%rdi), %ecx
movq (%rax), %rdx
movq 0x18(%rax), %rsi
movq $0x1, 0x8(%rax)
andq 0x10(%rax), %rdx
andq %r10, %rdx
movl %ecx, (%rsi,%rdx,4)
movl $0x1, %ecx
movq %rdi, 0x10(%rsp)
movq (%rax), %rdx
movq 0x18(%rax), %rsi
leaq 0x1(%rdx), %rdi
andq %r10, %rdi
movq %rdx, %r8
movabsq $-0x400000000000000, %r9 # imm = 0xFC00000000000000
andq %r9, %r8
andq 0x10(%rax), %rdi
orq %r8, %rdi
movq %rdi, (%rax)
decq %rcx
movq %rcx, 0x8(%rax)
testq %rsi, %rsi
je 0x1836be
andq %r10, %rdx
movl (%rsi,%rdx,4), %r15d
movq 0x10(%rbp), %rax
leaq (%r15,%r15,4), %rbx
cmpl $-0x8, (%rax,%rbx,8)
jae 0x1836ad
movq %rbp, %rdi
movl %r15d, %esi
movq 0x8(%rsp), %r14
movq %r14, %rdx
callq 0x182cad
movq %rbp, %rdi
movl %r15d, %esi
movq %r14, %rdx
callq 0x182fd8
movq 0x10(%rbp), %rax
leaq (%rax,%rbx,8), %rbx
movq 0x18(%rbx), %rdx
testq %rdx, %rdx
je 0x1836a0
xorl %eax, %eax
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
movl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
movq 0x20(%rbx), %rcx
movl (%rcx,%rax,8), %esi
movq %rsi, %rcx
andq %r9, %rcx
cmpq %r9, %rcx
sete %dil
testl %esi, %esi
setns %sil
orb %dil, %sil
jne 0x1834a9
movq 0x10(%rbp), %rdi
leaq (%rcx,%rcx,4), %r8
movl 0x18(%rdi,%r8,8), %ecx
movq 0x8(%rdi,%r8,8), %rsi
cmpq %rcx, %rsi
jbe 0x1834a9
leaq (%rdi,%r8,8), %rdi
addq $0x8, %rdi
movq 0x18(%rdi), %rdi
leal 0x1(%rcx), %r8d
movl (%rdi,%rcx,8), %r9d
movl %r9d, %r10d
andl %r14d, %r10d
cmpl %r15d, %r10d
setne %r11b
cmpl %r14d, %r10d
sete %r10b
orb %r11b, %r10b
je 0x18348a
movl %r8d, %ecx
incl %r8d
cmpq %rcx, %rsi
ja 0x183460
jmp 0x183499
orl $0x80000000, %r9d       # imm = 0x80000000
movl %r9d, (%rdi,%rcx,8)
movq 0x18(%rbx), %rdx
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
incl %eax
cmpq %rax, %rdx
ja 0x18341a
orb $0x4, (%rbx)
testq %rdx, %rdx
je 0x1836ad
xorl %r13d, %r13d
movq %rbx, (%rsp)
movq 0x20(%rbx), %rax
movl (%rax,%r13,8), %r14d
andq %r9, %r14
cmpq %r9, %r14
je 0x18368a
movq 0x10(%rbp), %rax
leaq (%r14,%r14,4), %rsi
movl 0x18(%rax,%rsi,8), %edi
movq 0x8(%rax,%rsi,8), %rcx
cmpq %rdi, %rcx
jbe 0x183526
leaq (%rax,%rsi,8), %rsi
addq $0x8, %rsi
movq 0x18(%rsi), %rsi
leal 0x1(%rdi), %r8d
movl (%rsi,%rdi,8), %edi
cmpq $0x7ffffffe, %rdi       # imm = 0x7FFFFFFE
ja 0x18351b
leaq (%rdi,%rdi,4), %rdi
testb $0x4, (%rax,%rdi,8)
je 0x18368a
movl %r8d, %edi
incl %r8d
cmpq %rdi, %rcx
ja 0x183501
movq 0x38(%rbp), %rbp
movq (%rbp), %rsi
movq 0x8(%rbp), %rbx
movq %rsi, %rax
shrq $0x3a, %rax
movl $0x1, %edi
movl %eax, %ecx
shlq %cl, %rdi
cmpq %rdi, %rbx
jne 0x183667
leal 0x1(%rax), %r15d
movl $0x1, %r12d
movl %r15d, %ecx
shlq %cl, %r12
cmpq %rbx, %r12
jae 0x18359d
movq $-0x1, %r15
incq %r15
movq %rbx, %rdi
movl %r15d, %ecx
shrq %cl, %rdi
cmpq $0x3f, %r15
ja 0x18357f
testq %rdi, %rdi
jne 0x183568
cmpq %r15, %rax
je 0x183667
movl $0x1, %r12d
movl %r15d, %ecx
shlq %cl, %r12
cmpq %rax, %r15
jbe 0x183698
movq 0x18(%rbp), %rdi
movl $0x4, %esi
movl %r15d, %ecx
shlq %cl, %rsi
callq 0x2370
movq %rax, 0x18(%rbp)
movq (%rbp), %rsi
movq 0x8(%rbp), %rdx
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movq %rsi, %rax
andq %r10, %rax
addq %rax, %rdx
cmpq %rbx, %rdx
jbe 0x18360c
movq 0x18(%rbp), %rcx
movq %rbx, %rdx
subq %rax, %rdx
movq %r12, %rsi
subq %rdx, %rsi
leaq (%rcx,%rsi,4), %rdi
leaq (%rcx,%rax,4), %rsi
shlq $0x2, %rdx
callq 0x2360
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
subq %rbx, %r12
addq (%rbp), %r12
movq %r12, %rsi
jmp 0x183630
subq %r12, %rdx
jbe 0x183630
movq 0x18(%rbp), %rdi
leaq (%rdi,%r12,4), %rsi
shlq $0x2, %rdx
callq 0x2360
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movq (%rbp), %rsi
movq %r15, %rax
shlq $0x3a, %rax
andq %r10, %rsi
orq %rax, %rsi
movq %rsi, (%rbp)
movq $-0x1, %rax
movl %r15d, %ecx
shlq %cl, %rax
notq %rax
movq %rax, 0x10(%rbp)
movq 0x8(%rbp), %rbx
movq (%rsp), %rax
movq 0x18(%rax), %rdx
movl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
movq 0x18(%rbp), %rax
leaq 0x1(%rbx), %rcx
movq %rcx, 0x8(%rbp)
andq %r10, %rsi
addq %rbx, %rsi
andq 0x10(%rbp), %rsi
movl %r14d, (%rax,%rsi,4)
movq 0x10(%rsp), %rbp
movq (%rsp), %rbx
incl %r13d
cmpq %r13, %rdx
ja 0x1834c7
jmp 0x1836ad
movq %rbx, %rdx
jmp 0x1835c7
orb $0x4, (%rbx)
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movq 0x38(%rbp), %rax
movq 0x8(%rax), %rcx
testq %rcx, %rcx
jne 0x18337b
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq