// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdx, 0x30(%rsp)
movq %rsi, %r14
movq %rdi, 0x28(%rsp)
andq $0x0, 0x58(%rsp)
addl %r8d, %r9d
movl $0x0, 0x1c(%rsp)
movl $0x0, 0x18(%rsp)
movl $0x0, 0x14(%rsp)
cmpl %r8d, %r9d
jbe 0xe787
movq %rcx, %rbx
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x38(%rsp)
movl %r8d, %esi
movl %r9d, %eax
movq %rax, 0x78(%rsp)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl $0x0, 0x14(%rsp)
movl $0x0, 0x18(%rsp)
movl $0x0, 0x1c(%rsp)
movq %rcx, 0x40(%rsp)
andq $0x0, (%rsp)
movq %rbx, %rdi
movq %rsi, 0x80(%rsp)
leaq 0x54(%rsp), %rdx
leaq 0x50(%rsp), %rcx
leaq 0x58(%rsp), %r8
leaq 0x4c(%rsp), %r9
callq 0x13df01
movl 0x54(%rsp), %edx
cmpl $-0x1, %edx
sete %al
movl 0x50(%rsp), %ecx
cmpl $-0x1, %ecx
sete %sil
orb %al, %sil
je 0xe5d8
movq 0x80(%rsp), %rsi
incq %rsi
cmpq 0x78(%rsp), %rsi
jne 0xe57e
jmp 0xe787
movl 0x4c(%rsp), %eax
movq %rax, 0x70(%rsp)
testq %rax, %rax
jne 0xe5f6
incl 0x1c(%rsp)
leaq 0x22a76a(%rip), %rsi    # 0x238d5b
jmp 0xe769
movl %ecx, 0x20(%rsp)
movl %edx, 0x24(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x28(%rsp), %rax
movq 0x10(%rax), %r8
xorl %ecx, %ecx
pushq $0x1
popq %rax
movl %eax, %edi
movq %r8, 0x60(%rsp)
movq 0x68(%rsp), %rdx
movl (%rdx,%rcx,4), %r9d
movl %r9d, %esi
shrl %esi
imulq $0x28, %rsi, %r10
cmpl $0x0, 0xc(%r8,%r10)
je 0xe718
addq %r8, %r10
andl $-0x2, %r9d
movq 0x38(%rsp), %rdx
movq 0x28(%rdx), %r11
movb $0x1, %sil
pushq $0x8
popq %rbx
xorl %r15d, %r15d
orq %r9, %r15
movq (%r11,%r15,8), %r15
movq %r15, %r8
andq %rbp, %r8
je 0xe69f
movq 0x38(%rsp), %rdx
movq 0x8(%rdx), %r12
shrq $0x20, %r15
imulq $0x18, %r15, %r15
addq %r15, %r12
addq $0xc, %r12
imulq $0x18, %r8, %r15
xorl %r13d, %r13d
xorl %r8d, %r8d
movl (%r12,%r13), %edx
notl %edx
shrl $0x1f, %edx
addl %edx, %r8d
addq $0x18, %r13
cmpq %r13, %r15
jne 0xe685
testl %r8d, %r8d
jne 0xe702
movl (%r10,%rbx), %eax
movq 0x20(%r14), %rdx
movl %eax, %edi
shrl %edi
cmpl $0x0, (%rdx,%rdi,8)
js 0xe6fe
xorq $0x1, %rax
movq 0x28(%r14), %rdx
movq (%rdx,%rax,8), %rax
movq %rax, %rdi
andq %rbp, %rdi
je 0xe751
movq 0x8(%r14), %rdx
shrq $0x20, %rax
imulq $0x18, %rax, %rax
addq %rdx, %rax
addq $0xc, %rax
imulq $0x18, %rdi, %rdi
xorl %ebx, %ebx
xorl %r8d, %r8d
movl (%rax,%rbx), %edx
notl %edx
shrl $0x1f, %edx
addl %edx, %r8d
addq $0x18, %rbx
cmpq %rbx, %rdi
jne 0xe6e5
testl %r8d, %r8d
je 0xe751
xorl %eax, %eax
xorl %edi, %edi
pushq $0x4
popq %rbx
pushq $0x1
popq %r15
testb $0x1, %sil
movl $0x0, %esi
jne 0xe654
incq %rcx
cmpq 0x70(%rsp), %rcx
movq 0x60(%rsp), %r8
jne 0xe61d
testl %edi, %edi
movq 0x40(%rsp), %rbx
movl 0x24(%rsp), %edx
movl 0x20(%rsp), %ecx
jne 0xe5e6
testl %eax, %eax
jne 0xe751
incl 0x14(%rsp)
leaq 0x22a654(%rip), %rsi    # 0x238da3
jmp 0xe75c
incl 0x18(%rsp)
leaq 0x22a623(%rip), %rsi    # 0x238d7f
movq 0x40(%rsp), %rbx
movl 0x24(%rsp), %edx
movl 0x20(%rsp), %ecx
movq 0x286870(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
shrl %edx
incl %edx
shrl %ecx
incl %ecx
xorl %eax, %eax
callq 0x22b0
jmp 0xe5c1
movq 0x286852(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
leaq 0x22a630(%rip), %rsi    # 0x238dc8
movl 0x1c(%rsp), %edx
movl 0x18(%rsp), %ecx
movl 0x14(%rsp), %r8d
xorl %eax, %eax
callq 0x22b0
movq 0x28(%rsp), %rdi
movq 0x18(%rdi), %r12
movl 0x14(%r12), %eax
testl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x30(%rsp), %r9
je 0xe844
xorl %ebx, %ebx
pushq $0x1
popq %rbp
movq 0x10(%rdi), %r13
imulq $0x28, %rbx, %rcx
cmpl $0x0, 0xc(%r13,%rcx)
je 0xe834
movq 0x20(%r12), %rdx
cmpl $0x0, (%rdx,%rbx,8)
js 0xe834
addq %rcx, %r13
cmpl $0x0, 0x10(%r13)
je 0xe834
xorl %r15d, %r15d
movq 0x18(%r13), %rax
movq (%rax,%r15,8), %rsi
shrq $0x21, %rsi
movq 0x20(%r14), %rax
leaq (%rax,%rsi,8), %r8
addq $0x4, %r8
movq 0x30(%rsp), %rdi
movl %ebx, %edx
movl %ebp, %ecx
callq 0xa27e9
movq 0x30(%rsp), %r9
incq %r15
movl 0x10(%r13), %eax
cmpq %rax, %r15
jb 0xe7f3
movl 0x14(%r12), %eax
movq 0x28(%rsp), %rdi
incq %rbx
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rcx, %rbx
jb 0xe7cb
movl 0xc8(%rsp), %eax
testl %eax, %eax
je 0xe99a
movq 0xc0(%rsp), %r13
movl %eax, %r8d
imulq $0x18, %r8, %r15
xorl %ebx, %ebx
leaq 0x22a599(%rip), %rsi    # 0x238e04
imulq $0x18, %rbx, %rcx
movq (%r13,%rcx), %r12
movq 0x20(%r14), %rax
movq %r12, %rdx
shrq $0x21, %rdx
cmpl $0x0, (%rax,%rdx,8)
jns 0xe8b5
addq %r13, %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0xe8b5
shrq $0x20, %r12
xorl %eax, %eax
xorl %edx, %edx
xorl %ecx, %ecx
cmpl %r12d, 0x4(%r13,%rax)
sete %cl
addl %ecx, %edx
addq $0x18, %rax
cmpq %rax, %r15
jne 0xe89b
cmpl $0x2, %edx
jae 0xe8c2
incq %rbx
cmpq %r8, %rbx
jne 0xe86b
jmp 0xe99a
movq 0x286717(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
xorl %eax, %eax
movq %r8, 0x38(%rsp)
callq 0x22b0
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
leaq 0x22a51f(%rip), %rsi    # 0x238e04
movq 0x38(%rsp), %r8
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %r9
xorl %ebp, %ebp
imulq $0x18, %rbp, %rax
cmpl %r12d, 0x4(%r13,%rax)
jne 0xe91e
addq %r13, %rax
movl 0x8(%rax), %eax
shrl %eax
cmpq %rax, (%r9)
jbe 0xe91e
movq 0x8(%r9), %rcx
movl (%rcx,%rax,4), %edx
cmpq %r10, %rdx
je 0xe91e
testl %edx, %edx
js 0xe928
incq %rbp
cmpq %r8, %rbp
jne 0xe8f6
jmp 0xe8b5
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq 0x10(%rdi), %rsi
imulq $0x28, %rdx, %rdi
movl 0x10(%rsi,%rdi), %r8d
xorl %ecx, %ecx
testq %r8, %r8
je 0xe962
addq %rdi, %rsi
movq 0x18(%rsi), %rsi
xorl %ecx, %ecx
movq (%rsi,%rcx,8), %rdi
shrq $0x21, %rdi
cmpl %eax, %edi
je 0xe962
incq %rcx
cmpq %rcx, %r8
jne 0xe94b
movl %r8d, %ecx
movq 0x286677(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
incl %edx
leaq 0x22a4ac(%rip), %rsi    # 0x238e21
xorl %eax, %eax
callq 0x22b0
movq 0x30(%rsp), %r9
movq 0x28(%rsp), %rdi
movq 0x38(%rsp), %r8
leaq 0x22a472(%rip), %rsi    # 0x238e04
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
jmp 0xe91e
movq (%r9), %rax
testq %rax, %rax
je 0xe9bc
movq 0x8(%r9), %rcx
xorl %edx, %edx
cmpl $-0x2, (%rcx,%rdx,4)
jg 0xe9b2
orl $-0x1, (%rcx,%rdx,4)
incq %rdx
movl %edx, %esi
cmpq %rsi, %rax
ja 0xe9a8
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq