// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/tovlp.cpp
// Function: dfs_trans_chain(asg_t*, utg_trans_t*, unsigned int, unsigned int, unsigned int)
void dfs_trans_chain(asg_t *g, utg_trans_t *o, uint32_t v, uint32_t beg, uint32_t sink)
{
    buf_t *b = &(o->b0);
    b->b.n = 0;
    if(v == beg || v == sink) return;
    uint64_t *flag = o->pos_idx;
    asg_arc_t *acur = NULL;
    uint32_t cur, ncur, i;
    v = v << 1;
    kv_push(uint32_t, b->b, v);
    while (b->b.n > 0)
    {
        b->b.n--;
        cur = b->b.a[b->b.n];
        if(flag[cur>>1] == 0 && (cur>>1) != (v>>1)) continue;
        flag[cur>>1] = 0;

        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 || (acur[i].v>>1) == sink) continue;
            if(flag[acur[i].v>>1] == 0) continue;
            kv_push(uint32_t, b->b, acur[i].v);
        }
    }

    v = v + 1;
    kv_push(uint32_t, b->b, v);
    while (b->b.n > 0)
    {
        b->b.n--;
        cur = b->b.a[b->b.n];
        if(flag[cur>>1] == 0 && (cur>>1) != (v>>1)) continue;
        flag[cur>>1] = 0;

        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 || (acur[i].v>>1) == sink) continue;
            if(flag[acur[i].v>>1] == 0) continue;
            kv_push(uint32_t, b->b, acur[i].v);
        }
    }

    b->b.n = 0;
    for (i = 0; i < o->topo_res.n; ++i) //has been sorted
    {
        if(flag[o->topo_res.a[i]>>1] == 0)
        {
            flag[o->topo_res.a[i]>>1] = (uint64_t)-1;  
        } 
        else
        {
            kv_push(uint32_t, b->b, o->topo_res.a[i]);
        }
    }


    /*******************************for debug************************************/
    // for (i = 0; i < cov->n; ++i) 
    // {
    //     if(flag[i] != (uint64_t)-1) fprintf(stderr, "ERROR-0\n");
    // }
    /*******************************for debug************************************/
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %ecx, %r14d
movq $0x0, 0x198(%rsi)
cmpl %ecx, %edx
sete %al
cmpl %r8d, %edx
sete %cl
orb %al, %cl
jne 0x198ca3
movl %r8d, %ebp
movq %rsi, %rbx
movq %rdi, 0x20(%rsp)
movq 0xe0(%rsi), %r8
movq %rdx, 0x10(%rsp)
leal (%rdx,%rdx), %ecx
cmpq $0x0, 0x1a0(%rsi)
movq %r8, 0x8(%rsp)
movl %ecx, 0x18(%rsp)
je 0x198921
movq 0x1a8(%rbx), %rax
movl %ecx, (%rax)
movl $0x1, %ecx
jmp 0x19896a
movq $0x2, 0x1a0(%rbx)
movq 0x1a8(%rbx), %rdi
movl $0x8, %esi
movl %ecx, %r15d
callq 0x2370
movq 0x8(%rsp), %r8
movq %rax, 0x1a8(%rbx)
movq 0x198(%rbx), %rdx
movq %rdx, %rcx
incq %rcx
movq %rcx, 0x198(%rbx)
movl %r15d, (%rax,%rdx,4)
je 0x198a85
movq 0x10(%rsp), %rdx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl %edx, 0x1c(%rsp)
leaq -0x1(%rcx), %rdx
movq %rdx, 0x198(%rbx)
movl -0x4(%rax,%rcx,4), %ecx
movl %ecx, %edx
shrl %edx
cmpq $0x0, (%r8,%rdx,8)
sete %sil
cmpl 0x1c(%rsp), %edx
setne %dil
testb %dil, %sil
jne 0x198a75
movq $0x0, (%r8,%rdx,8)
movq 0x20(%rsp), %rsi
movq 0x28(%rsi), %rdx
movq (%rdx,%rcx,8), %rcx
testl %ecx, %ecx
je 0x198a75
movq 0x8(%rsi), %rdx
movq %rcx, %rsi
shrq $0x20, %rsi
movl %ecx, %ecx
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %r12
addq $0x8, %r12
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %r15
xorl %r13d, %r13d
cmpl $0x0, 0x4(%r12,%r13)
js 0x198a68
movl (%r12,%r13), %ecx
movl %ecx, %edx
shrl %edx
cmpl %r14d, %edx
sete %sil
cmpl %ebp, %edx
sete %dil
orb %sil, %dil
jne 0x198a68
cmpq $0x0, (%r8,%rdx,8)
je 0x198a68
movq 0x198(%rbx), %rdx
cmpq 0x1a0(%rbx), %rdx
jne 0x198a5a
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x1a0(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x8(%rsp), %r8
movq %rax, 0x1a8(%rbx)
movl (%r12,%r13), %ecx
movq 0x198(%rbx), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x198(%rbx)
movl %ecx, (%rax,%rdx,4)
addq $0x18, %r13
cmpq %r13, %r15
jne 0x1989e7
movq 0x198(%rbx), %rcx
testq %rcx, %rcx
jne 0x198979
movl 0x18(%rsp), %ecx
orl $0x1, %ecx
cmpq $0x0, 0x1a0(%rbx)
je 0x198a9f
movl %ecx, (%rax)
movl $0x1, %ecx
jmp 0x198ada
movq $0x2, 0x1a0(%rbx)
movl $0x8, %esi
movq %rax, %rdi
movl %ecx, %r15d
callq 0x2370
movq 0x8(%rsp), %r8
movq %rax, 0x1a8(%rbx)
movq 0x198(%rbx), %rcx
movl %r15d, (%rax,%rcx,4)
incq %rcx
je 0x198bf6
movq 0x10(%rsp), %rdx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq %rdx, 0x10(%rsp)
leaq -0x1(%rcx), %rdx
movq %rdx, 0x198(%rbx)
movl -0x4(%rax,%rcx,4), %ecx
movl %ecx, %edx
shrl %edx
cmpq $0x0, (%r8,%rdx,8)
sete %sil
cmpl 0x10(%rsp), %edx
setne %dil
testb %dil, %sil
jne 0x198be6
movq $0x0, (%r8,%rdx,8)
movq 0x20(%rsp), %rsi
movq 0x28(%rsi), %rdx
movq (%rdx,%rcx,8), %rcx
testl %ecx, %ecx
je 0x198be6
movq 0x8(%rsi), %rdx
movq %rcx, %rsi
shrq $0x20, %rsi
movl %ecx, %ecx
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %r12
addq $0x8, %r12
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %r15
xorl %r13d, %r13d
cmpl $0x0, 0x4(%r12,%r13)
js 0x198bd9
movl (%r12,%r13), %ecx
movl %ecx, %edx
shrl %edx
cmpl %r14d, %edx
sete %sil
cmpl %ebp, %edx
sete %dil
orb %sil, %dil
jne 0x198bd9
cmpq $0x0, (%r8,%rdx,8)
je 0x198bd9
movq 0x198(%rbx), %rdx
cmpq 0x1a0(%rbx), %rdx
jne 0x198bcb
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x1a0(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x8(%rsp), %r8
movq %rax, 0x1a8(%rbx)
movl (%r12,%r13), %ecx
movq 0x198(%rbx), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x198(%rbx)
movl %ecx, (%rax,%rdx,4)
addq $0x18, %r13
cmpq %r13, %r15
jne 0x198b58
movq 0x198(%rbx), %rcx
testq %rcx, %rcx
jne 0x198aea
movq $0x0, 0x198(%rbx)
cmpq $0x0, 0xf0(%rbx)
je 0x198ca3
movq 0x100(%rbx), %rcx
movl $0x1, %ebp
xorl %r15d, %r15d
movl $0x2, %r14d
movl (%rcx,%r15,4), %edx
shrl %edx
cmpq $0x0, (%r8,%rdx,8)
je 0x198c8d
movq 0x198(%rbx), %rdx
cmpq 0x1a0(%rbx), %rdx
jne 0x198c79
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
cmoveq %r14, %rsi
movq %rsi, 0x1a0(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x8(%rsp), %r8
movq %rax, 0x1a8(%rbx)
movq 0x100(%rbx), %rcx
movq 0x198(%rbx), %rdx
movl (%rcx,%r15,4), %esi
leaq 0x1(%rdx), %rdi
movq %rdi, 0x198(%rbx)
movl %esi, (%rax,%rdx,4)
jmp 0x198c95
movq $-0x1, (%r8,%rdx,8)
movl %ebp, %r15d
incl %ebp
cmpq %r15, 0xf0(%rbx)
ja 0x198c24
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq