// File: /workspace/github_cpp_makefile_star2_O2/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 %edx, %r15d
movq 0xa8(%rsi), %r13
andq $0x0, 0xa0(%r13)
cmpl %ecx, %edx
sete %al
cmpl %r8d, %edx
sete %dl
orb %al, %dl
je 0xa492c
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsi, %r14
movq %rdi, %rbx
movq 0x10(%rsi), %r12
leal (%r15,%r15), %ebp
cmpq $0x0, 0xa8(%r13)
movl %r8d, 0x10(%rsp)
movl %ecx, 0xc(%rsp)
je 0xa4958
movq 0xb0(%r13), %rax
xorl %edx, %edx
jmp 0xa4989
movq $0x2, 0xa8(%r13)
movq 0xb0(%r13), %rdi
pushq $0x8
popq %rsi
callq 0x2370
movl 0xc(%rsp), %ecx
movl 0x10(%rsp), %r8d
movq %rax, 0xb0(%r13)
movq 0xa0(%r13), %rdx
leaq 0x1(%rdx), %rdi
movq %rdi, 0xa0(%r13)
movl %ebp, (%rax,%rdx,4)
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
movq %r14, 0x20(%rsp)
movq %rbx, 0x18(%rsp)
decq %rdi
cmpq $-0x1, %rdi
je 0xa4ab3
movq %rdi, 0xa0(%r13)
movl (%rax,%rdi,4), %edx
movl %edx, %esi
shrl %esi
cmpq $0x0, (%r12,%rsi,8)
jne 0xa49d2
decq %rdi
cmpl %r15d, %esi
jne 0xa49ab
movl %ebp, 0x14(%rsp)
andq $0x0, (%r12,%rsi,8)
movq 0x8(%rbx), %rdi
movq 0x28(%rbx), %rsi
movq (%rsi,%rdx,8), %rdx
movl %edx, %esi
shrq $0x20, %rdx
imulq $0x18, %rsi, %rbx
imulq $0x18, %rdx, %rdx
leaq (%rdi,%rdx), %rbp
addq $0x8, %rbp
xorl %r14d, %r14d
cmpq %r14, %rbx
je 0xa4a99
cmpl $0x0, 0x4(%rbp,%r14)
js 0xa4a90
movl (%rbp,%r14), %r9d
movl %r9d, %edx
shrl %edx
cmpl %ecx, %edx
sete %sil
cmpl %r8d, %edx
sete %dil
orb %sil, %dil
jne 0xa4a90
cmpq $0x0, (%r12,%rdx,8)
je 0xa4a90
movq 0xa0(%r13), %rdx
cmpq 0xa8(%r13), %rdx
jne 0xa4a81
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0xa8(%r13)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movl 0xc(%rsp), %ecx
movl 0x10(%rsp), %r8d
movq %rax, 0xb0(%r13)
movl (%rbp,%r14), %r9d
movq 0xa0(%r13), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0xa0(%r13)
movl %r9d, (%rax,%rdx,4)
addq $0x18, %r14
jmp 0xa4a00
movq 0xa0(%r13), %rdi
movq 0x20(%rsp), %r14
movq 0x18(%rsp), %rbx
movl 0x14(%rsp), %ebp
jmp 0xa49a8
orl $0x1, %ebp
cmpq $0x0, 0xa8(%r13)
je 0xa4ac4
xorl %edi, %edi
jmp 0xa4af1
movq $0x2, 0xa8(%r13)
pushq $0x8
popq %rsi
movq %rax, %rdi
callq 0x2370
movl 0xc(%rsp), %ecx
movl 0x10(%rsp), %r8d
movq %rax, 0xb0(%r13)
movq 0xa0(%r13), %rdi
movl %ebp, (%rax,%rdi,4)
incq %rdi
decq %rdi
cmpq $-0x1, %rdi
je 0xa4bfa
movq %rdi, 0xa0(%r13)
movl (%rax,%rdi,4), %edx
movl %edx, %esi
shrl %esi
cmpq $0x0, (%r12,%rsi,8)
jne 0xa4b21
decq %rdi
cmpl %r15d, %esi
jne 0xa4afa
andq $0x0, (%r12,%rsi,8)
movq 0x8(%rbx), %rdi
movq 0x28(%rbx), %rsi
movq (%rsi,%rdx,8), %rdx
movl %edx, %esi
shrq $0x20, %rdx
imulq $0x18, %rsi, %rbx
imulq $0x18, %rdx, %rdx
leaq (%rdi,%rdx), %rbp
addq $0x8, %rbp
xorl %r14d, %r14d
cmpq %r14, %rbx
je 0xa4be4
cmpl $0x0, 0x4(%rbp,%r14)
js 0xa4bdb
movl (%rbp,%r14), %r9d
movl %r9d, %edx
shrl %edx
cmpl %ecx, %edx
sete %sil
cmpl %r8d, %edx
sete %dil
orb %sil, %dil
jne 0xa4bdb
cmpq $0x0, (%r12,%rdx,8)
je 0xa4bdb
movq 0xa0(%r13), %rdx
cmpq 0xa8(%r13), %rdx
jne 0xa4bcc
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0xa8(%r13)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movl 0xc(%rsp), %ecx
movl 0x10(%rsp), %r8d
movq %rax, 0xb0(%r13)
movl (%rbp,%r14), %r9d
movq 0xa0(%r13), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0xa0(%r13)
movl %r9d, (%rax,%rdx,4)
addq $0x18, %r14
jmp 0xa4b4b
movq 0xa0(%r13), %rdi
movq 0x20(%rsp), %r14
movq 0x18(%rsp), %rbx
jmp 0xa4af7
andq $0x0, 0xa0(%r13)
movq 0xa8(%r14), %rcx
xorl %ebx, %ebx
pushq $0x2
popq %r15
movl %ebx, %ebx
cmpq %rbx, 0x50(%rcx)
jbe 0xa491d
movq 0x60(%rcx), %rdx
movl (%rdx,%rbx,4), %edx
shrl %edx
cmpq $0x0, (%r12,%rdx,8)
je 0xa4c85
movq 0xa0(%r13), %rdx
cmpq 0xa8(%r13), %rdx
jne 0xa4c6e
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
cmoveq %r15, %rsi
movq %rsi, 0xa8(%r13)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0xb0(%r13)
movq 0xa8(%r14), %rcx
movq 0xa0(%r13), %rdx
movq 0x60(%rcx), %rsi
movl (%rsi,%rbx,4), %esi
leaq 0x1(%rdx), %rdi
movq %rdi, 0xa0(%r13)
movl %esi, (%rax,%rdx,4)
jmp 0xa4c8a
orq $-0x1, (%r12,%rdx,8)
incl %ebx
jmp 0xa4c0f