// File: /workspace/github_cpp_makefile_star2_O3/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, %r13
movq %rdi, 0x10(%rsp)
movl %ecx, %esi
cmpq %rsi, 0x80(%rdx)
jbe 0xfd77f
movq %r9, %r14
movq %r8, %r12
movl %ecx, %ebx
xorl %eax, %eax
leaq 0x28(%rsp), %r8
movq %rax, (%r8)
movq %rax, (%rsp)
leaq 0x34(%rsp), %rbp
leaq 0x30(%rsp), %r15
leaq 0xc(%rsp), %r9
movq %rdx, %rdi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x13df01
movl (%rbp), %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, %rax
sete %dl
movl (%r15), %ecx
cmpl $-0x1, %ecx
sete %sil
orb %dl, %sil
je 0xfd78e
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebx, 0x8(%rsp)
movl %ecx, %ecx
xorl %edx, %edx
testb $0x1, %al
sete %dl
movq 0x10(%r13), %rsi
shrl %eax
leaq (%rax,%rax,4), %rax
leaq (%rsi,%rax,8), %rax
movl 0x4(%rax,%rdx,4), %ebx
xorl $0x1, %ebx
movl %ecx, %eax
shrl %eax
movl %ecx, %edx
shrl %edx
testb $0x1, %cl
leaq (%rax,%rax,4), %rax
leaq 0x4(%rsi,%rax,8), %rax
leaq (%rdx,%rdx,4), %rcx
leaq 0x8(%rsi,%rcx,8), %rcx
cmovneq %rax, %rcx
movl (%rcx), %r15d
movq 0x10(%rsp), %rax
movl 0x14(%rax), %edx
addl %edx, %edx
movq $0x0, (%r12)
movq %r14, %rdi
xorl %esi, %esi
movq %rdx, 0x20(%rsp)
callq 0x20e0
movq (%r12), %rcx
cmpq 0x8(%r12), %rcx
jne 0xfd82e
leaq (%rcx,%rcx), %rax
testq %rcx, %rcx
movl $0x2, %esi
cmovneq %rax, %rsi
movq %rsi, 0x8(%r12)
movq 0x10(%r12), %rdi
shlq $0x2, %rsi
callq 0x2370
movq %rax, 0x10(%r12)
movq (%r12), %rcx
jmp 0xfd833
movq 0x10(%r12), %rax
movq %r13, 0x18(%rsp)
movq %rcx, %rdx
incq %rdx
movq %rdx, (%r12)
movl %ebx, (%rax,%rcx,4)
je 0xfd90f
leaq -0x1(%rdx), %rax
movq %rax, (%r12)
movq 0x10(%r12), %rax
movl -0x4(%rax,%rdx,4), %edx
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x28(%rcx), %rcx
movq (%rcx,%rdx,8), %rcx
movb $0x1, (%r14,%rdx)
testl %ecx, %ecx
je 0xfd902
movq %rcx, %rdx
shrq $0x20, %rdx
movl %ecx, %ecx
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %rbp
addq $0x8, %rbp
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %r13
xorl %ebx, %ebx
cmpl $0x0, 0x4(%rbp,%rbx)
js 0xfd8f9
movl (%rbp,%rbx), %ecx
cmpb $0x0, (%r14,%rcx)
jne 0xfd8f9
cmpl %r15d, %ecx
je 0xfd8f9
movq (%r12), %rdx
movq 0x10(%r12), %rax
cmpq 0x8(%r12), %rdx
jne 0xfd8ee
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r12)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r12)
movl (%rbp,%rbx), %ecx
movq (%r12), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, (%r12)
movl %ecx, (%rax,%rdx,4)
addq $0x18, %rbx
cmpq %rbx, %r13
jne 0xfd899
movq (%r12), %rdx
testq %rdx, %rdx
jne 0xfd84b
movb $0x1, (%r14,%r15)
movl 0xc(%rsp), %eax
xorl %r12d, %r12d
movl $0x0, %r13d
testq %rax, %rax
je 0xfd94f
movq 0x18(%rsp), %rcx
movq 0x10(%rcx), %rcx
xorl %edx, %edx
movq 0x28(%rsp), %rsi
xorl %r13d, %r13d
movl (%rsi,%rdx,4), %edi
shrl %edi
leaq (%rdi,%rdi,4), %rdi
addl 0x10(%rcx,%rdi,8), %r13d
incq %rdx
cmpq %rdx, %rax
jne 0xfd939
movq 0x20(%rsp), %rcx
testq %rcx, %rcx
movl 0x8(%rsp), %edx
je 0xfd973
xorl %eax, %eax
xorl %r12d, %r12d
cmpb $0x1, (%r14,%rax)
sbbl $-0x1, %r12d
incq %rax
cmpq %rax, %rcx
jne 0xfd962
movq 0x197666(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
leaq 0x13b4c1(%rip), %rsi    # 0x238e45
movl %r12d, %ecx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x22b0
addl $0x2, %r13d
cmpl %r13d, %r12d
je 0xfd77f
callq 0x11a30
jmp 0xfd77f