// File: /workspace/github_cpp_makefile_star2_O2/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 $0x18, %rsp
movl %edx, %r15d
andq $0x0, 0x198(%rsi)
cmpl %ecx, %edx
sete %al
cmpl %r8d, %edx
sete %dl
orb %al, %dl
je 0x1515af
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsi, %rbx
movq %rdi, %r14
movq 0xe0(%rsi), %r13
leal (%r15,%r15), %ebp
cmpq $0x0, 0x1a0(%rsi)
movl %r8d, 0x8(%rsp)
movl %ecx, 0x4(%rsp)
je 0x1515de
movq 0x1a8(%rbx), %rax
xorl %edx, %edx
jmp 0x15160f
movq $0x2, 0x1a0(%rbx)
movq 0x1a8(%rbx), %rdi
pushq $0x8
popq %rsi
callq 0x2370
movl 0x4(%rsp), %ecx
movl 0x8(%rsp), %r8d
movq %rax, 0x1a8(%rbx)
movq 0x198(%rbx), %rdx
leaq 0x1(%rdx), %rdi
movq %rdi, 0x198(%rbx)
movl %ebp, (%rax,%rdx,4)
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
movq %r14, 0x10(%rsp)
decq %rdi
cmpq $-0x1, %rdi
je 0x151736
movq %rdi, 0x198(%rbx)
movl (%rax,%rdi,4), %edx
movl %edx, %esi
shrl %esi
cmpq $0x0, (%r13,%rsi,8)
jne 0x151654
decq %rdi
cmpl %r15d, %esi
jne 0x15162c
movl %ebp, 0xc(%rsp)
andq $0x0, (%r13,%rsi,8)
movq 0x8(%r14), %rdi
movq 0x28(%r14), %rsi
movq (%rsi,%rdx,8), %rdx
movl %edx, %esi
shrq $0x20, %rdx
imulq $0x18, %rsi, %r12
imulq $0x18, %rdx, %rdx
leaq (%rdi,%rdx), %rbp
addq $0x8, %rbp
xorl %r14d, %r14d
cmpq %r14, %r12
je 0x151721
cmpl $0x0, 0x4(%rbp,%r14)
js 0x151718
movl (%rbp,%r14), %r9d
movl %r9d, %edx
shrl %edx
cmpl %ecx, %edx
sete %sil
cmpl %r8d, %edx
sete %dil
orb %sil, %dil
jne 0x151718
cmpq $0x0, (%r13,%rdx,8)
je 0x151718
movq 0x198(%rbx), %rdx
cmpq 0x1a0(%rbx), %rdx
jne 0x151709
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x1a0(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movl 0x4(%rsp), %ecx
movl 0x8(%rsp), %r8d
movq %rax, 0x1a8(%rbx)
movl (%rbp,%r14), %r9d
movq 0x198(%rbx), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x198(%rbx)
movl %r9d, (%rax,%rdx,4)
addq $0x18, %r14
jmp 0x151683
movq 0x198(%rbx), %rdi
movq 0x10(%rsp), %r14
movl 0xc(%rsp), %ebp
jmp 0x151629
orl $0x1, %ebp
cmpq $0x0, 0x1a0(%rbx)
je 0x151747
xorl %edi, %edi
jmp 0x151774
movq $0x2, 0x1a0(%rbx)
pushq $0x8
popq %rsi
movq %rax, %rdi
callq 0x2370
movl 0x4(%rsp), %ecx
movl 0x8(%rsp), %r8d
movq %rax, 0x1a8(%rbx)
movq 0x198(%rbx), %rdi
movl %ebp, (%rax,%rdi,4)
incq %rdi
decq %rdi
cmpq $-0x1, %rdi
je 0x15187f
movq %rdi, 0x198(%rbx)
movl (%rax,%rdi,4), %edx
movl %edx, %esi
shrl %esi
cmpq $0x0, (%r13,%rsi,8)
jne 0x1517a5
decq %rdi
cmpl %r15d, %esi
jne 0x15177d
andq $0x0, (%r13,%rsi,8)
movq 0x8(%r14), %rdi
movq 0x28(%r14), %rsi
movq (%rsi,%rdx,8), %rdx
movl %edx, %esi
shrq $0x20, %rdx
imulq $0x18, %rsi, %r12
imulq $0x18, %rdx, %rdx
leaq (%rdi,%rdx), %rbp
addq $0x8, %rbp
xorl %r14d, %r14d
cmpq %r14, %r12
je 0x15186e
cmpl $0x0, 0x4(%rbp,%r14)
js 0x151865
movl (%rbp,%r14), %r9d
movl %r9d, %edx
shrl %edx
cmpl %ecx, %edx
sete %sil
cmpl %r8d, %edx
sete %dil
orb %sil, %dil
jne 0x151865
cmpq $0x0, (%r13,%rdx,8)
je 0x151865
movq 0x198(%rbx), %rdx
cmpq 0x1a0(%rbx), %rdx
jne 0x151856
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x1a0(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movl 0x4(%rsp), %ecx
movl 0x8(%rsp), %r8d
movq %rax, 0x1a8(%rbx)
movl (%rbp,%r14), %r9d
movq 0x198(%rbx), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x198(%rbx)
movl %r9d, (%rax,%rdx,4)
addq $0x18, %r14
jmp 0x1517d0
movq 0x198(%rbx), %rdi
movq 0x10(%rsp), %r14
jmp 0x15177a
andq $0x0, 0x198(%rbx)
xorl %r14d, %r14d
pushq $0x2
popq %r15
movl %r14d, %r14d
cmpq %r14, 0xf0(%rbx)
jbe 0x1515a0
movq 0x100(%rbx), %rcx
movl (%rcx,%r14,4), %ecx
movl %ecx, %edx
shrl %edx
cmpq $0x0, (%r13,%rdx,8)
je 0x15190c
movq 0x198(%rbx), %rdx
cmpq 0x1a0(%rbx), %rdx
jne 0x1518fc
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
cmoveq %r15, %rsi
movq %rsi, 0x1a0(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x1a8(%rbx)
movq 0x100(%rbx), %rcx
movq 0x198(%rbx), %rdx
movl (%rcx,%r14,4), %ecx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x198(%rbx)
movl %ecx, (%rax,%rdx,4)
jmp 0x151912
orq $-0x1, (%r13,%rdx,8)
incl %r14d
jmp 0x15188e