// File: /workspace/github_cpp_makefile_star2_O2/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 $0x68, %rsp
movl %r9d, %ebp
movl %r8d, %r14d
movq %rcx, %r12
movq %rdx, %r13
movq %rsi, %r15
leaq 0x58(%rsp), %rax
andq $0x0, (%rax)
movq %rdi, 0x40(%rsp)
movq 0x18(%rdi), %rbx
addl %r8d, %ebp
movl $0x0, 0x38(%rsp)
movl $0x0, 0x3c(%rsp)
movl $0x0, 0x34(%rsp)
movq %rdx, 0x18(%rsp)
movq %rsi, 0x20(%rsp)
movl %ebp, 0x2c(%rsp)
movq %rcx, 0x48(%rsp)
cmpl %ebp, %r14d
jae 0xb7be0
movl %r14d, %esi
andq $0x0, (%rsp)
movq %r12, %rdi
leaq 0x14(%rsp), %rdx
leaq 0x10(%rsp), %rcx
leaq 0x58(%rsp), %r8
leaq 0x54(%rsp), %r9
callq 0xf6ab5
cmpl $-0x1, 0x14(%rsp)
je 0xb7a3a
cmpl $-0x1, 0x10(%rsp)
jne 0xb7a3f
incl %r14d
jmp 0xb79ff
movl %r14d, 0x30(%rsp)
xorl %edx, %edx
pushq $0x1
popq %r12
movl %r12d, %r13d
movl 0x54(%rsp), %eax
cmpq %rax, %rdx
jae 0xb7b3a
movq 0x58(%rsp), %rax
movl (%rax,%rdx,4), %r15d
movl %r15d, %eax
shrl %eax
movq 0x40(%rsp), %rcx
movq 0x10(%rcx), %r14
imulq $0x28, %rax, %rax
cmpl $0x0, 0xc(%r14,%rax)
je 0xb7ae9
movq %rdx, 0x60(%rsp)
addq %rax, %r14
andl $-0x2, %r15d
xorl %ebp, %ebp
cmpl $0x2, %ebp
je 0xb7ae4
leal (%r15,%rbp), %esi
movq %rbx, %rdi
xorl %edx, %edx
callq 0xc2e7a
testl %eax, %eax
jne 0xb7ae0
xorl %eax, %eax
testl %ebp, %ebp
sete %al
movl 0x4(%r14,%rax,4), %esi
movq 0x20(%rsp), %rdi
movq 0x20(%rdi), %rax
movl %esi, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0xb7ada
xorl $0x1, %esi
xorl %r13d, %r13d
xorl %edx, %edx
callq 0xc2e7a
movl $0x0, %r12d
testl %eax, %eax
jne 0xb7ae0
jmp 0xb7af1
xorl %r13d, %r13d
xorl %r12d, %r12d
incl %ebp
jmp 0xb7a8b
movq 0x60(%rsp), %rdx
incq %rdx
jmp 0xb7a4d
movl 0x14(%rsp), %edx
movl 0x10(%rsp), %ecx
movq 0x18(%rsp), %r13
movq 0x20(%rsp), %r15
movl 0x2c(%rsp), %ebp
movl 0x30(%rsp), %r14d
movq 0x48(%rsp), %r12
incl 0x3c(%rsp)
movq 0x19b4c4(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
shrl %edx
incl %edx
shrl %ecx
incl %ecx
leaq 0x133151(%rip), %rsi    # 0x1eac7f
xorl %eax, %eax
callq 0x22b0
jmp 0xb7a3a
testl %r12d, %r12d
jne 0xb7b8d
movl 0x14(%rsp), %edx
movl 0x10(%rsp), %ecx
testl %r13d, %r13d
movq 0x20(%rsp), %r15
movl 0x2c(%rsp), %ebp
movl 0x30(%rsp), %r14d
movq 0x48(%rsp), %r12
jne 0xb7bd6
incl 0x34(%rsp)
movq 0x19b476(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
shrl %edx
incl %edx
shrl %ecx
incl %ecx
leaq 0x133127(%rip), %rsi    # 0x1eaca3
xorl %eax, %eax
callq 0x22b0
movq 0x18(%rsp), %r13
jmp 0xb7a3a
incl 0x38(%rsp)
movq 0x19b448(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
movl 0x14(%rsp), %edx
shrl %edx
incl %edx
movl 0x10(%rsp), %ecx
shrl %ecx
incl %ecx
leaq 0x1330a9(%rip), %rsi    # 0x1eac5b
xorl %eax, %eax
callq 0x22b0
movq 0x18(%rsp), %r13
movq 0x20(%rsp), %r15
movl 0x2c(%rsp), %ebp
movl 0x30(%rsp), %r14d
movq 0x48(%rsp), %r12
jmp 0xb7a3a
movq 0x18(%rsp), %r13
jmp 0xb7b11
movq 0x19b3f9(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
leaq 0x1330d7(%rip), %rsi    # 0x1eacc8
xorl %ebx, %ebx
movl 0x38(%rsp), %edx
movl 0x3c(%rsp), %ecx
movl 0x34(%rsp), %r8d
xorl %eax, %eax
callq 0x22b0
movq 0x40(%rsp), %rax
movq 0x18(%rax), %r14
pushq $0x1
popq %rbp
movl 0x14(%r14), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, %rbx
jae 0xb7c87
movq 0x40(%rsp), %rax
movq 0x10(%rax), %r15
imulq $0x28, %rbx, %rax
cmpl $0x0, 0xc(%r15,%rax)
je 0xb7c7d
movq 0x20(%r14), %rcx
cmpl $0x0, (%rcx,%rbx,8)
js 0xb7c7d
addq %rax, %r15
xorl %r12d, %r12d
movl 0x10(%r15), %eax
cmpq %rax, %r12
jae 0xb7c7d
movq 0x18(%r15), %rax
movq (%rax,%r12,8), %rsi
shrq $0x21, %rsi
movq 0x20(%rsp), %rax
movq 0x20(%rax), %rax
leaq (%rax,%rsi,8), %r8
addq $0x4, %r8
movq %r13, %rdi
movl %ebx, %edx
movl %ebp, %ecx
callq 0x6ab56
incq %r12
jmp 0xb7c46
incq %rbx
movq 0x20(%rsp), %r15
jmp 0xb7c13
movl 0xa8(%rsp), %edi
imulq $0x18, %rdi, %rbp
leaq 0x13306b(%rip), %rsi    # 0x1ead04
leaq 0x133081(%rip), %r9     # 0x1ead21
xorl %ebx, %ebx
cmpq %rdi, %rbx
je 0xb7ddf
imulq $0x18, %rbx, %rcx
movq 0xa0(%rsp), %r14
movq (%r14,%rcx), %r12
movq 0x20(%r15), %rax
movq %r12, %rdx
shrq $0x21, %rdx
cmpl $0x0, (%rax,%rdx,8)
jns 0xb7cfe
addq %r14, %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0xb7cfe
shrq $0x20, %r12
xorl %eax, %eax
xorl %edx, %edx
cmpq %rax, %rbp
je 0xb7cf9
xorl %ecx, %ecx
cmpl %r12d, 0x4(%r14,%rax)
sete %cl
addl %ecx, %edx
addq $0x18, %rax
jmp 0xb7ce2
cmpl $0x2, %edx
jae 0xb7d0d
incq %rbx
movq 0x18(%rsp), %r13
movq 0x20(%rsp), %r15
jmp 0xb7ca2
movq 0x19b2cc(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
xorl %eax, %eax
movq %r9, %r15
callq 0x22b0
movq %r15, %r9
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
leaq 0x132fd4(%rip), %rsi    # 0x1ead04
movl 0xa8(%rsp), %edi
xorl %r13d, %r13d
cmpq %rdi, %r13
je 0xb7cfe
imulq $0x18, %r13, %rax
cmpl %r12d, 0x4(%r14,%rax)
jne 0xb7d71
addq %r14, %rax
movl 0x8(%rax), %edx
shrl %edx
movq 0x18(%rsp), %rax
cmpq %rdx, (%rax)
jbe 0xb7d71
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
movl (%rax,%rdx,4), %eax
cmpq %rcx, %rax
je 0xb7d71
testl %eax, %eax
js 0xb7d76
incq %r13
jmp 0xb7d3a
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x40(%rsp), %rcx
movq 0x10(%rcx), %rcx
imulq $0x28, %rax, %rdi
leaq (%rcx,%rdi), %rsi
movl 0x10(%rcx,%rdi), %r8d
xorl %ecx, %ecx
cmpq %rcx, %r8
je 0xb7dad
movq 0x18(%rsi), %rdi
movq (%rdi,%rcx,8), %rdi
shrq $0x21, %rdi
cmpl %edx, %edi
je 0xb7db0
incq %rcx
jmp 0xb7d93
movl %r8d, %ecx
movq 0x19b229(%rip), %rdx    # 0x252fe0
movq (%rdx), %rdi
leal 0x1(%rax), %edx
movq %r9, %rsi
xorl %eax, %eax
callq 0x22b0
movq %r15, %r9
movl 0xa8(%rsp), %edi
leaq 0x132f2c(%rip), %rsi    # 0x1ead04
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
jmp 0xb7d71
movq (%r13), %rax
xorl %ecx, %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jbe 0xb7dfe
movq 0x8(%r13), %rdx
cmpl $-0x2, (%rdx,%rcx,4)
jg 0xb7dfa
orl $-0x1, (%rdx,%rcx,4)
incl %ecx
jmp 0xb7de5
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq