// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: dfs_trans_chain_bub(asg_t*, hap_cov_t*, unsigned int, unsigned int, unsigned int)
void dfs_trans_chain_bub(asg_t *g, hap_cov_t *cov, uint32_t v, uint32_t beg, uint32_t sink)
{
    buf_t *b = &(cov->t_ch->b_buf_0);
    b->b.n = 0;
    if(v == beg || v == sink) return;
    uint64_t *flag = cov->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 < cov->t_ch->topo_res.n; ++i) //has been sorted
    {
        if(flag[cov->t_ch->topo_res.a[i]>>1] == 0)
        {
            flag[cov->t_ch->topo_res.a[i]>>1] = (uint64_t)-1;  
        } 
        else
        {
            kv_push(uint32_t, b->b, cov->t_ch->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, 0x10(%rsp)
movq 0xa8(%rsi), %r13
movq $0x0, 0xa0(%r13)
cmpl %ecx, %edx
sete %al
cmpl %r8d, %edx
sete %cl
orb %al, %cl
jne 0xe0ab4
movl %r8d, %ebp
movq %rsi, 0x20(%rsp)
movq 0x10(%rsi), %rdi
movq %rdx, 0x8(%rsp)
leal (%rdx,%rdx), %ebx
cmpq $0x0, 0xa8(%r13)
movq %rdi, (%rsp)
jne 0xe0711
movq $0x2, 0xa8(%r13)
movq 0xb0(%r13), %rdi
movl $0x8, %esi
callq 0x2370
movq (%rsp), %rdi
movq %rax, 0xb0(%r13)
movq 0xa0(%r13), %rcx
movq 0xb0(%r13), %rdx
movq %rcx, %rax
incq %rax
movq %rax, 0xa0(%r13)
movl %ebx, 0x18(%rsp)
movl %ebx, (%rdx,%rcx,4)
je 0xe0864
movq 0x8(%rsp), %rcx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, 0x1c(%rsp)
leaq -0x1(%rax), %rcx
movq %rcx, 0xa0(%r13)
movq 0xb0(%r13), %rcx
movl -0x4(%rcx,%rax,4), %eax
movl %eax, %ecx
shrl %ecx
cmpq $0x0, (%rdi,%rcx,8)
setne %dl
cmpl 0x1c(%rsp), %ecx
sete %sil
orb %dl, %sil
je 0xe0854
movq $0x0, (%rdi,%rcx,8)
movq 0x10(%rsp), %rcx
movq 0x28(%rcx), %rcx
movq (%rcx,%rax,8), %rax
testl %eax, %eax
je 0xe0854
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %eax
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %rbx
addq $0x8, %rbx
shlq $0x3, %rax
leaq (%rax,%rax,2), %r12
xorl %r15d, %r15d
cmpl $0x0, 0x4(%rbx,%r15)
js 0xe0847
movl (%rbx,%r15), %eax
shrl %eax
cmpl %r14d, %eax
sete %cl
cmpl %ebp, %eax
sete %dl
orb %cl, %dl
jne 0xe0847
cmpq $0x0, (%rdi,%rax,8)
je 0xe0847
movq 0xa8(%r13), %rax
cmpq %rax, 0xa0(%r13)
jne 0xe0827
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0xa8(%r13)
movq 0xb0(%r13), %rdi
shlq $0x2, %rsi
callq 0x2370
movq (%rsp), %rdi
movq %rax, 0xb0(%r13)
movl (%rbx,%r15), %eax
movq 0xa0(%r13), %rcx
movq 0xb0(%r13), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0xa0(%r13)
movl %eax, (%rdx,%rcx,4)
addq $0x18, %r15
cmpq %r15, %r12
jne 0xe07c1
movq 0xa0(%r13), %rax
testq %rax, %rax
jne 0xe0748
movl 0x18(%rsp), %ebx
orl $0x1, %ebx
cmpq $0x0, 0xa8(%r13)
jne 0xe089c
movq $0x2, 0xa8(%r13)
movq 0xb0(%r13), %rdi
movl $0x8, %esi
callq 0x2370
movq (%rsp), %rdi
movq %rax, 0xb0(%r13)
movq 0xa0(%r13), %rcx
movq 0xb0(%r13), %rdx
movq %rcx, %rax
incq %rax
movq %rax, 0xa0(%r13)
movl %ebx, (%rdx,%rcx,4)
je 0xe09ec
movq 0x8(%rsp), %rcx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq %rcx, 0x8(%rsp)
leaq -0x1(%rax), %rcx
movq %rcx, 0xa0(%r13)
movq 0xb0(%r13), %rcx
movl -0x4(%rcx,%rax,4), %eax
movl %eax, %ecx
shrl %ecx
cmpq $0x0, (%rdi,%rcx,8)
setne %dl
cmpl 0x8(%rsp), %ecx
sete %sil
orb %dl, %sil
je 0xe09dc
movq $0x0, (%rdi,%rcx,8)
movq 0x10(%rsp), %rcx
movq 0x28(%rcx), %rcx
movq (%rcx,%rax,8), %rax
testl %eax, %eax
je 0xe09dc
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %eax
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %rbx
addq $0x8, %rbx
shlq $0x3, %rax
leaq (%rax,%rax,2), %r12
xorl %r15d, %r15d
cmpl $0x0, 0x4(%rbx,%r15)
js 0xe09cf
movl (%rbx,%r15), %eax
shrl %eax
cmpl %r14d, %eax
sete %cl
cmpl %ebp, %eax
sete %dl
orb %cl, %dl
jne 0xe09cf
cmpq $0x0, (%rdi,%rax,8)
je 0xe09cf
movq 0xa8(%r13), %rax
cmpq %rax, 0xa0(%r13)
jne 0xe09af
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0xa8(%r13)
movq 0xb0(%r13), %rdi
shlq $0x2, %rsi
callq 0x2370
movq (%rsp), %rdi
movq %rax, 0xb0(%r13)
movl (%rbx,%r15), %eax
movq 0xa0(%r13), %rcx
movq 0xb0(%r13), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0xa0(%r13)
movl %eax, (%rdx,%rcx,4)
addq $0x18, %r15
cmpq %r15, %r12
jne 0xe0949
movq 0xa0(%r13), %rax
testq %rax, %rax
jne 0xe08d0
movq $0x0, 0xa0(%r13)
movq 0x20(%rsp), %r15
movq 0xa8(%r15), %rax
cmpq $0x0, 0x50(%rax)
je 0xe0ab4
movl $0x1, %ebp
xorl %r14d, %r14d
movl $0x2, %ebx
movq 0x60(%rax), %rax
movl (%rax,%r14,4), %eax
shrl %eax
cmpq $0x0, (%rdi,%rax,8)
je 0xe0a96
movq 0xa8(%r13), %rax
cmpq %rax, 0xa0(%r13)
jne 0xe0a69
leaq (%rax,%rax), %rsi
testq %rax, %rax
cmoveq %rbx, %rsi
movq %rsi, 0xa8(%r13)
movq 0xb0(%r13), %rdi
shlq $0x2, %rsi
callq 0x2370
movq (%rsp), %rdi
movq %rax, 0xb0(%r13)
movq 0xa8(%r15), %rax
movq 0x60(%rax), %rax
movl (%rax,%r14,4), %eax
movq 0xa0(%r13), %rcx
movq 0xb0(%r13), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0xa0(%r13)
movl %eax, (%rdx,%rcx,4)
jmp 0xe0a9e
movq $-0x1, (%rdi,%rax,8)
movl %ebp, %r14d
movq 0xa8(%r15), %rax
incl %ebp
cmpq %r14, 0x50(%rax)
ja 0xe0a1b
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq