// File: /workspace/github_cpp_makefile_star2_O3/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, 0x20(%rsp)
movq %rsi, 0x10(%rsp)
movq 0xa8(%rsi), %r13
movq $0x0, 0xa0(%r13)
cmpl %ecx, %edx
sete %al
cmpl %r8d, %edx
sete %cl
orb %al, %cl
jne 0xe1ddf
movl %r8d, %ebp
movq 0x10(%rsp), %rax
movq 0x10(%rax), %r8
movq %rdx, 0x8(%rsp)
leal (%rdx,%rdx), %ecx
cmpq $0x0, 0xa8(%r13)
movq %r8, (%rsp)
movl %ecx, 0x18(%rsp)
je 0xe1a57
movq 0xb0(%r13), %rax
movl %ecx, (%rax)
movl $0x1, %ecx
jmp 0xe1a9d
movq $0x2, 0xa8(%r13)
movq 0xb0(%r13), %rdi
movl $0x8, %esi
movl %ecx, %ebx
callq 0x2370
movq (%rsp), %r8
movq %rax, 0xb0(%r13)
movq 0xa0(%r13), %rdx
movq %rdx, %rcx
incq %rcx
movq %rcx, 0xa0(%r13)
movl %ebx, (%rax,%rdx,4)
je 0xe1bb6
movq 0x8(%rsp), %rdx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl %edx, 0x1c(%rsp)
leaq -0x1(%rcx), %rdx
movq %rdx, 0xa0(%r13)
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 0xe1ba6
movq $0x0, (%r8,%rdx,8)
movq 0x20(%rsp), %rsi
movq 0x28(%rsi), %rdx
movq (%rdx,%rcx,8), %rcx
testl %ecx, %ecx
je 0xe1ba6
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 %ebx, %ebx
cmpl $0x0, 0x4(%r12,%rbx)
js 0xe1b99
movl (%r12,%rbx), %ecx
movl %ecx, %edx
shrl %edx
cmpl %r14d, %edx
sete %sil
cmpl %ebp, %edx
sete %dil
orb %sil, %dil
jne 0xe1b99
cmpq $0x0, (%r8,%rdx,8)
je 0xe1b99
movq 0xa0(%r13), %rdx
cmpq 0xa8(%r13), %rdx
jne 0xe1b8b
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0xa8(%r13)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq (%rsp), %r8
movq %rax, 0xb0(%r13)
movl (%r12,%rbx), %ecx
movq 0xa0(%r13), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0xa0(%r13)
movl %ecx, (%rax,%rdx,4)
addq $0x18, %rbx
cmpq %rbx, %r15
jne 0xe1b19
movq 0xa0(%r13), %rcx
testq %rcx, %rcx
jne 0xe1aac
movl 0x18(%rsp), %ecx
orl $0x1, %ecx
cmpq $0x0, 0xa8(%r13)
je 0xe1bd0
movl %ecx, (%rax)
movl $0x1, %ecx
jmp 0xe1c08
movq $0x2, 0xa8(%r13)
movl $0x8, %esi
movq %rax, %rdi
movl %ecx, %ebx
callq 0x2370
movq (%rsp), %r8
movq %rax, 0xb0(%r13)
movq 0xa0(%r13), %rcx
movl %ebx, (%rax,%rcx,4)
incq %rcx
je 0xe1d22
movq 0x8(%rsp), %rdx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq %rdx, 0x8(%rsp)
leaq -0x1(%rcx), %rdx
movq %rdx, 0xa0(%r13)
movl -0x4(%rax,%rcx,4), %ecx
movl %ecx, %edx
shrl %edx
cmpq $0x0, (%r8,%rdx,8)
sete %sil
cmpl 0x8(%rsp), %edx
setne %dil
testb %dil, %sil
jne 0xe1d12
movq $0x0, (%r8,%rdx,8)
movq 0x20(%rsp), %rsi
movq 0x28(%rsi), %rdx
movq (%rdx,%rcx,8), %rcx
testl %ecx, %ecx
je 0xe1d12
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 %ebx, %ebx
cmpl $0x0, 0x4(%r12,%rbx)
js 0xe1d05
movl (%r12,%rbx), %ecx
movl %ecx, %edx
shrl %edx
cmpl %r14d, %edx
sete %sil
cmpl %ebp, %edx
sete %dil
orb %sil, %dil
jne 0xe1d05
cmpq $0x0, (%r8,%rdx,8)
je 0xe1d05
movq 0xa0(%r13), %rdx
cmpq 0xa8(%r13), %rdx
jne 0xe1cf7
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0xa8(%r13)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq (%rsp), %r8
movq %rax, 0xb0(%r13)
movl (%r12,%rbx), %ecx
movq 0xa0(%r13), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0xa0(%r13)
movl %ecx, (%rax,%rdx,4)
addq $0x18, %rbx
cmpq %rbx, %r15
jne 0xe1c85
movq 0xa0(%r13), %rcx
testq %rcx, %rcx
jne 0xe1c18
movq $0x0, 0xa0(%r13)
movq 0x10(%rsp), %rcx
movq 0xa8(%rcx), %rcx
cmpq $0x0, 0x50(%rcx)
je 0xe1ddf
movl $0x1, %ebp
xorl %r14d, %r14d
movl $0x2, %ebx
movq 0x60(%rcx), %rdx
movl (%rdx,%r14,4), %edx
movl %edx, %esi
shrl %esi
cmpq $0x0, (%r8,%rsi,8)
je 0xe1dc8
movq 0xa0(%r13), %rdi
cmpq 0xa8(%r13), %rdi
jne 0xe1db8
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
cmoveq %rbx, %rsi
movq %rsi, 0xa8(%r13)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq (%rsp), %r8
movq %rax, 0xb0(%r13)
movq 0x10(%rsp), %rcx
movq 0xa8(%rcx), %rcx
movq 0x60(%rcx), %rdx
movl (%rdx,%r14,4), %edx
movq 0xa0(%r13), %rdi
leaq 0x1(%rdi), %rsi
movq %rsi, 0xa0(%r13)
movl %edx, (%rax,%rdi,4)
jmp 0xe1dd0
movq $-0x1, (%r8,%rsi,8)
movl %ebp, %r14d
incl %ebp
cmpq %r14, 0x50(%rcx)
ja 0xe1d51
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq