// File: /workspace/github_cpp_makefile_star2_O1/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 0xf9fa1
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 0x13812e
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 0xf9fb0
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
xorl %eax, %eax
testb $0x1, %cl
sete %al
shrl %ecx
leaq (%rcx,%rcx,4), %rcx
leaq (%rsi,%rcx,8), %rcx
movl 0x4(%rcx,%rax,4), %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 0x8(%r12), %rax
cmpq %rax, (%r12)
jne 0xfa03d
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0x8(%r12)
movq 0x10(%r12), %rdi
shlq $0x2, %rsi
callq 0x2370
movq %rax, 0x10(%r12)
movq %r13, 0x18(%rsp)
movq (%r12), %rcx
movq 0x10(%r12), %rdx
movq %rcx, %rax
incq %rax
movq %rax, (%r12)
movl %ebx, (%rdx,%rcx,4)
je 0xfa122
leaq -0x1(%rax), %rcx
movq %rcx, (%r12)
movq 0x10(%r12), %rcx
movl -0x4(%rcx,%rax,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 0xfa115
movq %rcx, %rdx
shrq $0x20, %rdx
movl %ecx, %ecx
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %rbx
addq $0x8, %rbx
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %r13
xorl %ebp, %ebp
cmpl $0x0, 0x4(%rbx,%rbp)
js 0xfa10c
movl (%rbx,%rbp), %eax
cmpb $0x0, (%r14,%rax)
jne 0xfa10c
cmpl %r15d, %eax
je 0xfa10c
movq 0x8(%r12), %rax
cmpq %rax, (%r12)
jne 0xfa0f5
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r12)
movq 0x10(%r12), %rdi
shlq $0x2, %rsi
callq 0x2370
movq %rax, 0x10(%r12)
movl (%rbx,%rbp), %eax
movq (%r12), %rcx
movq 0x10(%r12), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r12)
movl %eax, (%rdx,%rcx,4)
addq $0x18, %rbp
cmpq %rbp, %r13
jne 0xfa0ac
movq (%r12), %rax
testq %rax, %rax
jne 0xfa05e
movb $0x1, (%r14,%r15)
movl 0xc(%rsp), %eax
xorl %r12d, %r12d
movl $0x0, %r13d
testq %rax, %rax
je 0xfa162
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 0xfa14c
movq 0x20(%rsp), %rax
testl %eax, %eax
movl 0x8(%rsp), %edx
je 0xfa187
movl %eax, %eax
xorl %ecx, %ecx
xorl %r12d, %r12d
cmpb $0x1, (%r14,%rcx)
sbbl $-0x1, %r12d
incq %rcx
cmpq %rcx, %rax
jne 0xfa176
movq 0x18fe52(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
leaq 0x132abd(%rip), %rsi    # 0x22cc55
movl %r12d, %ecx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x22b0
addl $0x2, %r13d
cmpl %r13d, %r12d
je 0xf9fa1
callq 0x11dee
jmp 0xf9fa1