// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: debug_bubble_chain(asg_t*, ma_ug_t*, bubble_type*, unsigned int, kvec_t_u32_warp*, unsigned char*)
void debug_bubble_chain(asg_t *sg, ma_ug_t *ug, bubble_type* bub, uint32_t bid, kvec_t_u32_warp* stack, uint8_t* vis_flag)
{
    if(bid >= bub->f_bub) return;
    uint32_t beg_utg, sink_utg, *a = NULL, n, begRid, sinkRid;
    get_bubbles(bub, bid, &beg_utg, &sink_utg, &a, &n, NULL);
    if(beg_utg == (uint32_t)-1 || sink_utg == (uint32_t)-1) return;
    if(beg_utg&1)
    {
        begRid = ug->u.a[beg_utg>>1].start^1;
    }
    else
    {
        begRid = ug->u.a[beg_utg>>1].end^1;
    }

    if(sink_utg&1)
    {
        sinkRid = ug->u.a[sink_utg>>1].start;
    }
    else
    {
        sinkRid = ug->u.a[sink_utg>>1].end;
    }

    asg_arc_t *acur = NULL;
    uint32_t cur, ncur, i, n_vx = sg->n_seq<<1;
    stack->a.n = 0; 
    memset(vis_flag, 0, n_vx);

    kv_push(uint32_t, stack->a, begRid);
    while (stack->a.n > 0)
    {
        stack->a.n--;
        cur = stack->a.a[stack->a.n];
        ncur = asg_arc_n(sg, cur);
        acur = asg_arc_a(sg, cur);
        vis_flag[cur] = 1;
        for (i = 0; i < ncur; i++)
        {
            if(acur[i].del) continue;
            if(vis_flag[acur[i].v]) continue;
            if(acur[i].v == sinkRid) continue;
            kv_push(uint32_t, stack->a, acur[i].v);
        }
    }
    vis_flag[sinkRid] = 1;


    /*******************************for debug************************************/
    uint32_t utg_occ = 0, rtg_occ = 0;
    for (i = 0; i < n; i++)
    {
        utg_occ += ug->u.a[a[i]>>1].n;
    }

    for (i = 0; i < n_vx; i++)
    {
        if(vis_flag[i]) rtg_occ++;
    }
    
    fprintf(stderr, "bid: %u, rtg_occ: %u, utg_occ: %u\n", bid, rtg_occ, utg_occ);
    if(rtg_occ != utg_occ + 2) fprintf(stderr, "ERROR\n");
    /*******************************for debug************************************/
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rax
movq %rdi, 0x18(%rsp)
movl %ecx, %esi
cmpq %rsi, 0x80(%rdx)
jbe 0xbbade
movq %r9, %r14
movq %r8, %r12
movq %rax, 0x10(%rsp)
movl %ecx, 0x8(%rsp)
leaq 0x28(%rsp), %r8
andq $0x0, (%r8)
andq $0x0, (%rsp)
leaq 0x34(%rsp), %rbp
leaq 0x30(%rsp), %rbx
leaq 0xc(%rsp), %r9
movq %rdx, %rdi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0xf6ab5
movl (%rbp), %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %rcx
sete %dl
movl (%rbx), %eax
cmpl $-0x1, %eax
sete %sil
orb %dl, %sil
je 0xbbaed
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %eax
xorl %edx, %edx
testb $0x1, %cl
sete %dl
movq 0x10(%rsp), %rsi
movq 0x10(%rsi), %rsi
shrl %ecx
imulq $0x28, %rcx, %rcx
addq %rsi, %rcx
movl 0x4(%rcx,%rdx,4), %ebp
xorl $0x1, %ebp
movl %eax, %ecx
shrl %ecx
imulq $0x28, %rcx, %rcx
movl %eax, %edx
shrl %edx
imulq $0x28, %rdx, %rdx
testb $0x1, %al
leaq 0x4(%rsi,%rcx), %rax
leaq 0x8(%rsi,%rdx), %rcx
cmovneq %rax, %rcx
movl (%rcx), %ebx
movq 0x18(%rsp), %rax
movl 0x14(%rax), %edx
addl %edx, %edx
andq $0x0, (%r12)
movq %r14, %rdi
xorl %esi, %esi
movq %rdx, 0x20(%rsp)
callq 0x20e0
movq (%r12), %rcx
pushq $0x2
popq %rax
cmpq 0x8(%r12), %rcx
jne 0xbbb87
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
cmoveq %rax, %rsi
movq %rsi, 0x8(%r12)
movq 0x10(%r12), %rdi
shlq $0x2, %rsi
callq 0x2370
movq %rax, 0x10(%r12)
movq (%r12), %rcx
jmp 0xbbb8c
movq 0x10(%r12), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, (%r12)
movl %ebp, (%rax,%rcx,4)
testq %rdx, %rdx
je 0xbbc54
leaq -0x1(%rdx), %rax
movq %rax, (%r12)
movq 0x10(%r12), %rax
movl -0x4(%rax,%rdx,4), %eax
movq 0x18(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq 0x28(%rdx), %rdx
movq (%rdx,%rax,8), %rdx
movl %edx, %esi
shrq $0x20, %rdx
movb $0x1, (%r14,%rax)
imulq $0x18, %rsi, %rbp
imulq $0x18, %rdx, %rax
leaq (%rcx,%rax), %r13
addq $0x8, %r13
xorl %r15d, %r15d
cmpq %r15, %rbp
je 0xbbc4b
cmpl $0x0, 0x4(%r13,%r15)
js 0xbbc45
movl (%r13,%r15), %ecx
cmpb $0x0, (%r14,%rcx)
jne 0xbbc45
cmpl %ebx, %ecx
je 0xbbc45
movq (%r12), %rdx
movq 0x10(%r12), %rax
cmpq 0x8(%r12), %rdx
jne 0xbbc3a
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r12)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r12)
movl (%r13,%r15), %ecx
movq (%r12), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, (%r12)
movl %ecx, (%rax,%rdx,4)
addq $0x18, %r15
jmp 0xbbbe0
movq (%r12), %rdx
jmp 0xbbb97
movb $0x1, (%r14,%rbx)
movl 0xc(%rsp), %eax
movq 0x28(%rsp), %rcx
xorl %edx, %edx
xorl %r12d, %r12d
movq 0x10(%rsp), %r8
cmpq %rdx, %rax
je 0xbbc88
movq 0x10(%r8), %rsi
movl (%rcx,%rdx,4), %edi
shrl %edi
imulq $0x28, %rdi, %rdi
addl 0x10(%rsi,%rdi), %r12d
incq %rdx
jmp 0xbbc6c
xorl %eax, %eax
xorl %r15d, %r15d
movl 0x8(%rsp), %edx
movq 0x20(%rsp), %rcx
cmpq %rax, %rcx
je 0xbbca9
cmpb $0x1, (%r14,%rax)
sbbl $-0x1, %r15d
incq %rax
jmp 0xbbc96
movq 0x197330(%rip), %rbx    # 0x252fe0
movq (%rbx), %rdi
leaq 0x12f08b(%rip), %rsi    # 0x1ead45
movl %r15d, %ecx
movl %r12d, %r8d
xorl %eax, %eax
callq 0x22b0
addl $0x2, %r12d
cmpl %r12d, %r15d
je 0xbbade
movq (%rbx), %rcx
leaq 0x12f0a6(%rip), %rdi    # 0x1ead84
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
jmp 0xbbade