// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpq 0x80(%rcx), %rax
jb 0x15b3a7
jmp 0x15b793
movq $0x0, -0x40(%rbp)
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
leaq -0x34(%rbp), %rdx
leaq -0x38(%rbp), %rcx
leaq -0x40(%rbp), %r8
leaq -0x44(%rbp), %r9
xorl %eax, %eax
movq $0x0, (%rsp)
callq 0x1c4b20
cmpl $-0x1, -0x34(%rbp)
je 0x15b3e3
cmpl $-0x1, -0x38(%rbp)
jne 0x15b3e8
jmp 0x15b793
movl -0x34(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x15b414
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x15b433
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x48(%rbp)
movl -0x38(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x15b45c
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x38(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x4c(%rbp)
jmp 0x15b478
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x38(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x4c(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movl %eax, -0x68(%rbp)
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movq -0x30(%rbp), %rdi
movl -0x68(%rbp), %eax
movl %eax, %edx
xorl %esi, %esi
callq 0x2100
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x15b514
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x15b4d9
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x78(%rbp)
jmp 0x15b4e4
movl $0x2, %eax
movq %rax, -0x78(%rbp)
jmp 0x15b4e4
movq -0x78(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x48(%rbp), %edx
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movl %edx, (%rax,%rcx,4)
jmp 0x15b535
movq -0x28(%rbp), %rax
cmpq $0x0, (%rax)
jbe 0x15b6c1
movq -0x28(%rbp), %rax
movq (%rax), %rcx
addq $-0x1, %rcx
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x5c(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x5c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x5c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rax
movl -0x5c(%rbp), %ecx
movb $0x1, (%rax,%rcx)
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x60(%rbp), %eax
jae 0x15b6bc
movq -0x58(%rbp), %rax
movl -0x64(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x15b5da
jmp 0x15b6ae
movq -0x30(%rbp), %rax
movq -0x58(%rbp), %rcx
movl -0x64(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
cmpb $0x0, (%rax,%rcx)
je 0x15b5fa
jmp 0x15b6ae
movq -0x58(%rbp), %rax
movl -0x64(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpl -0x4c(%rbp), %eax
jne 0x15b615
jmp 0x15b6ae
jmp 0x15b617
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x15b67f
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x15b644
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x80(%rbp)
jmp 0x15b64f
movl $0x2, %eax
movq %rax, -0x80(%rbp)
jmp 0x15b64f
movq -0x80(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x58(%rbp), %rax
movl -0x64(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %edx
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movl %edx, (%rax,%rcx,4)
jmp 0x15b6ae
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x15b5b0
jmp 0x15b535
movq -0x30(%rbp), %rax
movl -0x4c(%rbp), %ecx
movb $0x1, (%rax,%rcx)
movl $0x0, -0x6c(%rbp)
movl $0x0, -0x70(%rbp)
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x44(%rbp), %eax
jae 0x15b71a
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x40(%rbp), %rcx
movl -0x64(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
addl -0x6c(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x15b6e1
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x68(%rbp), %eax
jae 0x15b74c
movq -0x30(%rbp), %rax
movl -0x64(%rbp), %ecx
cmpb $0x0, (%rax,%rcx)
je 0x15b73f
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x15b741
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x15b721
movq 0x26888d(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x1c(%rbp), %edx
movl -0x70(%rbp), %ecx
movl -0x6c(%rbp), %r8d
leaq 0x22e309(%rip), %rsi    # 0x389a70
movb $0x0, %al
callq 0x22a0
movl -0x70(%rbp), %eax
movl -0x6c(%rbp), %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
je 0x15b793
movq 0x26885e(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x22e323(%rip), %rsi    # 0x389aaf
movb $0x0, %al
callq 0x22a0
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)