// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: debug_topo_sorting(asg_t*, hap_cov_t*, unsigned int, unsigned int)
void debug_topo_sorting(asg_t *g, hap_cov_t *cov, uint32_t beg, uint32_t sink)
{
    buf_t *b = &(cov->t_ch->b_buf_0);
    uint64_t *flag = cov->pos_idx;
    asg_arc_t *acur = NULL;
    uint32_t cur, ncur, i, k, k_i, v;

    for (k = 0; k < cov->t_ch->topo_res.n; k++)
    {
        v = cov->t_ch->topo_res.a[k];

        b->b.n = 0;
        kv_push(uint32_t, b->b, v);
        while (b->b.n > 0)
        {
            b->b.n--;
            cur = b->b.a[b->b.n];

            ncur = asg_arc_n(g, cur);
            acur = asg_arc_a(g, cur);
            for (i = 0; i < ncur; i++)
            {
                if(acur[i].del) continue;
                if((acur[i].v>>1) == (beg>>1) || (acur[i].v>>1) == (sink>>1)) continue;
                kv_push(uint32_t, b->b, acur[i].v);
                if(flag[acur[i].v>>1] == 0)
                {
                    fprintf(stderr, "\nERROR-1\n");
                    fprintf(stderr, "beg>>1: %u, sink>>1: %u, topo_res.n: %u, v>>1: %u, w>>1: %u\n", 
                                            beg>>1, sink>>1, (uint32_t)cov->t_ch->topo_res.n, v>>1, acur[i].v>>1);
                    for (k_i = 0; k_i < cov->t_ch->topo_res.n; k_i++)
                    {
                        fprintf(stderr, "k_i: %u, topo_res>>1: %u\n", k_i, cov->t_ch->topo_res.a[k_i]>>1);
                    }
                } 
                
            }
        }

        flag[cov->t_ch->topo_res.a[k]>>1] = 0;
    }

    for (k = 0; k < cov->t_ch->topo_res.n; k++)
    {
        flag[cov->t_ch->topo_res.a[k]>>1] = (uint64_t)-1;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %ecx, %r8d
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, 0x28(%rsp)
movq 0x10(%rsi), %rax
movq %rax, 0x18(%rsp)
movq 0xa8(%rsi), %r15
shrl %ebp
shrl %r8d
movq %r15, %rax
xorl %ecx, %ecx
movl %r8d, 0xc(%rsp)
movq %rsi, 0x10(%rsp)
movl %ebp, 0x24(%rsp)
movl %ecx, %r14d
movq 0x50(%rax), %rcx
cmpq %r14, %rcx
jbe 0xa4f0f
movq 0x60(%rax), %rax
movl (%rax,%r14,4), %r12d
andq $0x0, 0xa0(%r15)
cmpq $0x0, 0xa8(%r15)
movq 0xb0(%r15), %rax
je 0xa4d06
xorl %edx, %edx
jmp 0xa4d2f
movq $0x2, 0xa8(%r15)
movq %rax, %rdi
pushq $0x8
popq %rsi
callq 0x2370
movl 0xc(%rsp), %r8d
movq %rax, 0xb0(%r15)
movq 0xa0(%r15), %rdx
leaq 0x1(%rdx), %rcx
movq %rcx, 0xa0(%r15)
movl %r12d, (%rax,%rdx,4)
shrl %r12d
movl %r12d, 0x20(%rsp)
movq %r14, 0x30(%rsp)
testq %rcx, %rcx
je 0xa4eeb
leaq -0x1(%rcx), %rax
movq %rax, 0xa0(%r15)
movq 0xb0(%r15), %rax
movl -0x4(%rax,%rcx,4), %eax
movq 0x28(%rsp), %rdx
movq 0x28(%rdx), %rcx
movq (%rcx,%rax,8), %rax
movl %eax, %r14d
shrq $0x20, %rax
imulq $0x18, %rax, %r12
addq 0x8(%rdx), %r12
xorl %ebx, %ebx
cmpq %r14, %rbx
je 0xa4ed5
imulq $0x18, %rbx, %r13
cmpl $0x0, 0xc(%r12,%r13)
js 0xa4e2a
addq %r12, %r13
movl 0x8(%r13), %ecx
movl %ecx, %eax
shrl %eax
cmpl %ebp, %eax
sete %dl
cmpl %r8d, %eax
sete %al
orb %dl, %al
jne 0xa4e2a
movq 0xa0(%r15), %rdx
movq 0xb0(%r15), %rax
cmpq 0xa8(%r15), %rdx
jne 0xa4e0a
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0xa8(%r15)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movl 0xc(%rsp), %r8d
movq %rax, 0xb0(%r15)
movl 0x8(%r13), %ecx
movq 0xa0(%r15), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0xa0(%r15)
movl %ecx, (%rax,%rdx,4)
movl 0x8(%r13), %eax
shrl %eax
movq 0x18(%rsp), %rcx
cmpq $0x0, (%rcx,%rax,8)
je 0xa4e32
incq %rbx
jmp 0xa4d88
movq 0x1ae1a7(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x144f23(%rip), %rdi    # 0x1e9d66
pushq $0x9
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq 0x1ae18b(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
movl %ebp, %edx
movq 0x10(%rsp), %rbp
movq 0xa8(%rbp), %rax
movl 0x50(%rax), %r8d
movl 0x8(%r13), %eax
shrl %eax
movl %eax, (%rsp)
xorl %r13d, %r13d
leaq 0x144ef3(%rip), %rsi    # 0x1e9d70
movl 0xc(%rsp), %ecx
movl 0x20(%rsp), %r9d
xorl %eax, %eax
callq 0x22b0
movl %r13d, %r13d
movq 0xa8(%rbp), %rax
cmpq %r13, 0x50(%rax)
movl 0xc(%rsp), %r8d
movl 0x24(%rsp), %ebp
jbe 0xa4e2a
movq 0x1ae133(%rip), %rcx    # 0x252fe0
movq (%rcx), %rdi
movq 0x60(%rax), %rax
movl (%rax,%r13,4), %ecx
shrl %ecx
leaq 0x144eec(%rip), %rsi    # 0x1e9dad
movl %r13d, %edx
xorl %eax, %eax
callq 0x22b0
incl %r13d
movq 0x10(%rsp), %rbp
jmp 0xa4e8d
movq 0xa0(%r15), %rcx
movq 0x10(%rsp), %rbx
movq 0x30(%rsp), %r14
jmp 0xa4d4b
movq 0xa8(%rbx), %rax
movq 0x60(%rax), %rcx
movl (%rcx,%r14,4), %ecx
shrl %ecx
movq 0x18(%rsp), %rdx
andq $0x0, (%rdx,%rcx,8)
leal 0x1(%r14), %ecx
jmp 0xa4cd1
xorl %edx, %edx
movq 0x18(%rsp), %rsi
movl %edx, %edx
cmpq %rdx, %rcx
jbe 0xa4f33
movq 0x60(%rax), %rcx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
orq $-0x1, (%rsi,%rcx,8)
incl %edx
movq 0x50(%rax), %rcx
jmp 0xa4f16
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq