// File: /workspace/github_cpp_makefile_star2_O1/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 %rdi, 0x18(%rsp)
movq $0x0, 0x198(%rsi)
cmpl %ecx, %edx
sete %al
cmpl %r8d, %edx
sete %cl
orb %al, %cl
jne 0x18feaf
movl %r8d, %ebp
movq %rsi, %rbx
movq 0xe0(%rsi), %rdi
movq %rdx, 0x10(%rsp)
leal (%rdx,%rdx), %r15d
cmpq $0x0, 0x1a0(%rsi)
movq %rdi, 0x8(%rsp)
jne 0x18fb10
movq $0x2, 0x1a0(%rbx)
movq 0x1a8(%rbx), %rdi
movl $0x8, %esi
callq 0x2370
movq 0x8(%rsp), %rdi
movq %rax, 0x1a8(%rbx)
movq 0x198(%rbx), %rcx
movq 0x1a8(%rbx), %rdx
movq %rcx, %rax
incq %rax
movq %rax, 0x198(%rbx)
movl %r15d, 0x20(%rsp)
movl %r15d, (%rdx,%rcx,4)
je 0x18fc66
movq 0x10(%rsp), %rcx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, 0x24(%rsp)
leaq -0x1(%rax), %rcx
movq %rcx, 0x198(%rbx)
movq 0x1a8(%rbx), %rcx
movl -0x4(%rcx,%rax,4), %eax
movl %eax, %ecx
shrl %ecx
cmpq $0x0, (%rdi,%rcx,8)
setne %dl
cmpl 0x24(%rsp), %ecx
sete %sil
orb %dl, %sil
je 0x18fc56
movq $0x0, (%rdi,%rcx,8)
movq 0x18(%rsp), %rcx
movq 0x28(%rcx), %rcx
movq (%rcx,%rax,8), %rax
testl %eax, %eax
je 0x18fc56
movq 0x18(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %eax
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %r12
addq $0x8, %r12
shlq $0x3, %rax
leaq (%rax,%rax,2), %r15
xorl %r13d, %r13d
cmpl $0x0, 0x4(%r12,%r13)
js 0x18fc49
movl (%r12,%r13), %eax
shrl %eax
cmpl %r14d, %eax
sete %cl
cmpl %ebp, %eax
sete %dl
orb %cl, %dl
jne 0x18fc49
cmpq $0x0, (%rdi,%rax,8)
je 0x18fc49
movq 0x1a0(%rbx), %rax
cmpq %rax, 0x198(%rbx)
jne 0x18fc29
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x1a0(%rbx)
movq 0x1a8(%rbx), %rdi
shlq $0x2, %rsi
callq 0x2370
movq 0x8(%rsp), %rdi
movq %rax, 0x1a8(%rbx)
movl (%r12,%r13), %eax
movq 0x198(%rbx), %rcx
movq 0x1a8(%rbx), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x198(%rbx)
movl %eax, (%rdx,%rcx,4)
addq $0x18, %r13
cmpq %r13, %r15
jne 0x18fbc2
movq 0x198(%rbx), %rax
testq %rax, %rax
jne 0x18fb49
movl 0x20(%rsp), %r15d
orl $0x1, %r15d
cmpq $0x0, 0x1a0(%rbx)
jne 0x18fca1
movq $0x2, 0x1a0(%rbx)
movq 0x1a8(%rbx), %rdi
movl $0x8, %esi
callq 0x2370
movq 0x8(%rsp), %rdi
movq %rax, 0x1a8(%rbx)
movq 0x198(%rbx), %rcx
movq 0x1a8(%rbx), %rdx
movq %rcx, %rax
incq %rax
movq %rax, 0x198(%rbx)
movl %r15d, (%rdx,%rcx,4)
je 0x18fdf3
movq 0x10(%rsp), %rcx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq %rcx, 0x10(%rsp)
leaq -0x1(%rax), %rcx
movq %rcx, 0x198(%rbx)
movq 0x1a8(%rbx), %rcx
movl -0x4(%rcx,%rax,4), %eax
movl %eax, %ecx
shrl %ecx
cmpq $0x0, (%rdi,%rcx,8)
setne %dl
cmpl 0x10(%rsp), %ecx
sete %sil
orb %dl, %sil
je 0x18fde3
movq $0x0, (%rdi,%rcx,8)
movq 0x18(%rsp), %rcx
movq 0x28(%rcx), %rcx
movq (%rcx,%rax,8), %rax
testl %eax, %eax
je 0x18fde3
movq 0x18(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %eax
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %r12
addq $0x8, %r12
shlq $0x3, %rax
leaq (%rax,%rax,2), %r15
xorl %r13d, %r13d
cmpl $0x0, 0x4(%r12,%r13)
js 0x18fdd6
movl (%r12,%r13), %eax
shrl %eax
cmpl %r14d, %eax
sete %cl
cmpl %ebp, %eax
sete %dl
orb %cl, %dl
jne 0x18fdd6
cmpq $0x0, (%rdi,%rax,8)
je 0x18fdd6
movq 0x1a0(%rbx), %rax
cmpq %rax, 0x198(%rbx)
jne 0x18fdb6
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x1a0(%rbx)
movq 0x1a8(%rbx), %rdi
shlq $0x2, %rsi
callq 0x2370
movq 0x8(%rsp), %rdi
movq %rax, 0x1a8(%rbx)
movl (%r12,%r13), %eax
movq 0x198(%rbx), %rcx
movq 0x1a8(%rbx), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x198(%rbx)
movl %eax, (%rdx,%rcx,4)
addq $0x18, %r13
cmpq %r13, %r15
jne 0x18fd4f
movq 0x198(%rbx), %rax
testq %rax, %rax
jne 0x18fcd6
movq $0x0, 0x198(%rbx)
cmpq $0x0, 0xf0(%rbx)
je 0x18feaf
movl $0x1, %ebp
xorl %r15d, %r15d
movl $0x2, %r14d
movq 0x100(%rbx), %rax
movl (%rax,%r15,4), %eax
shrl %eax
cmpq $0x0, (%rdi,%rax,8)
je 0x18fe95
movq 0x1a0(%rbx), %rax
cmpq %rax, 0x198(%rbx)
jne 0x18fe6c
leaq (%rax,%rax), %rsi
testq %rax, %rax
cmoveq %r14, %rsi
movq %rsi, 0x1a0(%rbx)
movq 0x1a8(%rbx), %rdi
shlq $0x2, %rsi
callq 0x2370
movq 0x8(%rsp), %rdi
movq %rax, 0x1a8(%rbx)
movq 0x100(%rbx), %rax
movq 0x198(%rbx), %rcx
movl (%rax,%r15,4), %eax
movq 0x1a8(%rbx), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x198(%rbx)
movl %eax, (%rdx,%rcx,4)
jmp 0x18fe9d
movq $-0x1, (%rdi,%rax,8)
movl %ebp, %r15d
incl %ebp
cmpq %r15, 0xf0(%rbx)
ja 0x18fe1a
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq