// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: print_bubble_filling_status(ma_ug_t*, asg_t*, R_to_U*, bubble_type*, unsigned int, unsigned int, asg_arc_t*, unsigned int)
void print_bubble_filling_status(ma_ug_t *copy_ug, asg_t *r_g, R_to_U* ruIndex, bubble_type* bub, 
uint32_t beg_idx, uint32_t occ, asg_arc_t* new_edges, uint32_t new_edges_len)
{
    ma_utg_t* nsu = NULL;
    ma_ug_t* ug = copy_ug;
    uint32_t i, k_i, k_v, v, k, beg_utg, sink_utg, *a = NULL, n, uId, endRid, is_broken, is_tangle;
    uint32_t tangle_occ = 0, broken_occ = 0, recover_occ = 0, is_Unitig, contain_uId;
    asg_t* nsg = ug->g;
    for (i = beg_idx; i < beg_idx + occ; i++)
    {
        get_bubbles(bub, i, &beg_utg, &sink_utg, &a, &n, NULL);
        if(beg_utg == (uint32_t)-1 || sink_utg == (uint32_t)-1) continue;
        for (k_i = 0, is_broken = 1, is_tangle = 1; k_i < n; k_i++)
        {
            uId = a[k_i]>>1;
            nsu = &(ug->u.a[uId]);
            if(nsu->m == 0) continue;
            for (k_v = 0; k_v < 2; k_v++)
            {
                v = (uId<<1) + k_v;
                if(get_real_length(nsg, v, NULL) != 0) continue;

                ///tig
                is_tangle = 0;
                if(v&1)
                {
                    endRid = nsu->start^1;
                }
                else
                {
                    endRid = nsu->end^1;
                }

                if(r_g->seq[endRid>>1].del)
                {
                    is_broken = 0;
                    continue;
                }

                if(get_real_length(r_g, endRid, NULL) == 0)
                {
                    is_broken = 1;
                    goto tig_end;
                }
                else
                {
                    is_broken = 0;
                }
            }
        }

        tig_end:
        if(is_tangle)
        {
            tangle_occ++;
            fprintf(stderr, "tangle: beg-utg%.6ul, end-utg%.6ul\n", (beg_utg>>1)+1, (sink_utg>>1)+1);
        }
        else if(is_broken)
        {
            broken_occ++;
            fprintf(stderr, "broken: beg-utg%.6ul, end-utg%.6ul\n", (beg_utg>>1)+1, (sink_utg>>1)+1);
        }
        else
        {   
            recover_occ++;
            fprintf(stderr, "recover: beg-utg%.6ul, end-utg%.6ul\n", (beg_utg>>1)+1, (sink_utg>>1)+1);
        }
    }

    fprintf(stderr, "###########tangle_occ: %u, broken_occ: %u, recover_occ: %u\n", tangle_occ, broken_occ, recover_occ);
    nsg = ug->g;
    for (v = 0; v < nsg->n_seq; v++)
    {
        uId = v;
        nsu = &(ug->u.a[uId]);
        if(nsu->m == 0) continue;
        if(nsg->seq[v].del) continue;
        for (k = 0; k < nsu->n; k++) 
        {
            set_R_to_U(ruIndex, nsu->a[k]>>33, uId, 1, &(r_g->seq[nsu->a[k]>>33].c));
        }
    }
    #define check_debug_edge(g, t) (((g).seq[(t).ul>>33].del == 1) && ((g).seq[(t).v>>1].del == 0))



    for (k = 0; k < new_edges_len; k++)
    {
        v = new_edges[k].ul>>32;
        
        if(check_debug_edge(*r_g, new_edges[k]))
        {
            for (i = broken_occ = 0; i < new_edges_len; i++)
            {
                if((new_edges[i].ul>>32) == v) broken_occ++;
            }

            if(broken_occ > 1)
            {
                fprintf(stderr, "*************tig_to_occ: %u\n", broken_occ);
                for (i = 0; i < new_edges_len; i++)
                {
                    if((new_edges[i].ul>>32) == v)
                    {
                        get_R_to_U(ruIndex, new_edges[i].v>>1, &contain_uId, &is_Unitig);
                        if(is_Unitig == 1)
                        {
                            nsu = &(ug->u.a[contain_uId]);
                            for (k_i = 0; k_i < nsu->n; k_i++)
                            {
                                if((nsu->a[k_i]>>33) == (new_edges[i].v>>1)) break;
                            }
                            
                            fprintf(stderr, "to-utg%.6ul, idx_of_u: %u, u_n: %u\n", 
                                                                    contain_uId+1, k_i, nsu->n);
                        }
                        
                    }
                }
            }            
        }
    }



    for (v = 0; v < ruIndex->len; v++)
    {
        get_R_to_U(ruIndex, v, &uId, &is_Unitig);
        if(is_Unitig == 1) ruIndex->index[v] = (uint32_t)-1;
    }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movl %r9d, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x60(%rbp)
movl $0x0, -0x78(%rbp)
movl $0x0, -0x7c(%rbp)
movl $0x0, -0x80(%rbp)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x90(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl -0x24(%rbp), %ecx
addl -0x28(%rbp), %ecx
cmpl %ecx, %eax
jae 0x15503e
movq -0x20(%rbp), %rdi
movl -0x3c(%rbp), %eax
movl %eax, %esi
leaq -0x50(%rbp), %rdx
leaq -0x54(%rbp), %rcx
leaq -0x60(%rbp), %r8
leaq -0x64(%rbp), %r9
xorl %eax, %eax
movq $0x0, (%rsp)
callq 0x1c4b20
cmpl $-0x1, -0x50(%rbp)
je 0x154e61
cmpl $-0x1, -0x54(%rbp)
jne 0x154e66
jmp 0x155030
movl $0x0, -0x40(%rbp)
movl $0x1, -0x70(%rbp)
movl $0x1, -0x74(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x64(%rbp), %eax
jae 0x154f87
movq -0x60(%rbp), %rax
movl -0x40(%rbp), %ecx
movl (%rax,%rcx,4), %eax
shrl %eax
movl %eax, -0x68(%rbp)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x68(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x154ebb
jmp 0x154f79
movl $0x0, -0x44(%rbp)
cmpl $0x2, -0x44(%rbp)
jae 0x154f77
movl -0x68(%rbp), %eax
shll %eax
addl -0x44(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x90(%rbp), %rdi
movl -0x48(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x166b50
cmpl $0x0, %eax
je 0x154ef1
jmp 0x154f69
movl $0x0, -0x74(%rbp)
movl -0x48(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x154f12
movq -0x30(%rbp), %rax
movl 0x4(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x154f1f
movq -0x30(%rbp), %rax
movl 0x8(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x6c(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x6c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x154f42
movl $0x0, -0x70(%rbp)
jmp 0x154f69
movq -0x10(%rbp), %rdi
movl -0x6c(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x166b50
cmpl $0x0, %eax
jne 0x154f60
movl $0x1, -0x70(%rbp)
jmp 0x154f89
movl $0x0, -0x70(%rbp)
jmp 0x154f69
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x154ec2
jmp 0x154f79
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x154e7b
jmp 0x154f89
cmpl $0x0, -0x74(%rbp)
je 0x154fc2
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
movq 0x26f041(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x50(%rbp), %edx
shrl %edx
addl $0x1, %edx
movl -0x54(%rbp), %ecx
shrl %ecx
addl $0x1, %ecx
leaq 0x2349cd(%rip), %rsi    # 0x389986
movb $0x0, %al
callq 0x22a0
jmp 0x15502e
cmpl $0x0, -0x70(%rbp)
je 0x154ffb
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
movq 0x26f008(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x50(%rbp), %edx
shrl %edx
addl $0x1, %edx
movl -0x54(%rbp), %ecx
shrl %ecx
addl $0x1, %ecx
leaq 0x2349b8(%rip), %rsi    # 0x3899aa
movb $0x0, %al
callq 0x22a0
jmp 0x15502c
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
movq 0x26efd5(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x50(%rbp), %edx
shrl %edx
addl $0x1, %edx
movl -0x54(%rbp), %ecx
shrl %ecx
addl $0x1, %ecx
leaq 0x2349a9(%rip), %rsi    # 0x3899ce
movb $0x0, %al
callq 0x22a0
jmp 0x15502e
jmp 0x155030
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x154e1c
movq 0x26ef9b(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x78(%rbp), %edx
movl -0x7c(%rbp), %ecx
movl -0x80(%rbp), %r8d
leaq 0x23499a(%rip), %rsi    # 0x3899f3
movb $0x0, %al
callq 0x22a0
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x90(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
movq -0x90(%rbp), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0x155151
movl -0x48(%rbp), %eax
movl %eax, -0x68(%rbp)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x68(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x1550bc
jmp 0x155143
movq -0x90(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x48(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x1550d7
jmp 0x155143
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x155141
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x4c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movl %eax, %esi
movl -0x68(%rbp), %edx
movq -0x10(%rbp), %rax
movq 0x20(%rax), %r8
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x4c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
shlq $0x3, %rax
addq %rax, %r8
addq $0x4, %r8
movl $0x1, %ecx
callq 0xd0e20
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x1550de
jmp 0x155143
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x155076
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl 0x18(%rbp), %eax
jae 0x155367
movq 0x10(%rbp), %rax
movl -0x4c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x10(%rbp), %rcx
movl -0x4c(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
shrq $0x21, %rcx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x1, %eax
jne 0x155357
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x10(%rbp), %rcx
movl -0x4c(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x155357
movl $0x0, -0x7c(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl 0x18(%rbp), %eax
jae 0x15521d
movq 0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
movl -0x48(%rbp), %ecx
cmpq %rcx, %rax
jne 0x155210
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x155212
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1551e2
cmpl $0x1, -0x7c(%rbp)
jbe 0x155355
movq 0x26edb2(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x7c(%rbp), %edx
leaq 0x2347f4(%rip), %rsi    # 0x389a2f
movb $0x0, %al
callq 0x22a0
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl 0x18(%rbp), %eax
jae 0x155353
movq 0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
movl -0x48(%rbp), %ecx
cmpq %rcx, %rax
jne 0x155343
movq -0x18(%rbp), %rdi
movq 0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %esi
shrl %esi
leaq -0x88(%rbp), %rdx
leaq -0x84(%rbp), %rcx
callq 0xd3d50
cmpl $0x1, -0x84(%rbp)
jne 0x155341
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x88(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x155315
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x40(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movq 0x10(%rbp), %rcx
movl -0x3c(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jne 0x155308
jmp 0x155315
jmp 0x15530a
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x1552cd
movq 0x26ecc4(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x88(%rbp), %edx
addl $0x1, %edx
movl -0x40(%rbp), %ecx
movq -0x30(%rbp), %rax
movl 0x10(%rax), %r8d
leaq 0x234712(%rip), %rsi    # 0x389a4c
movb $0x0, %al
callq 0x22a0
jmp 0x155343
jmp 0x155345
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x155249
jmp 0x155355
jmp 0x155357
jmp 0x155359
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x155158
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1553b9
movq -0x18(%rbp), %rdi
movl -0x48(%rbp), %esi
leaq -0x68(%rbp), %rdx
leaq -0x84(%rbp), %rcx
callq 0xd3d50
cmpl $0x1, -0x84(%rbp)
jne 0x1553ac
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x48(%rbp), %ecx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
jmp 0x1553ae
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x15536e
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)