// File: /workspace/github_cpp_makefile_star2_O1/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 $0x78, %rsp
movq %rdx, 0x20(%rsp)
movq %rsi, %r14
movq %rdi, 0x18(%rsp)
andq $0x0, 0x58(%rsp)
addl %r8d, %r9d
xorl %ebp, %ebp
movl $0x0, 0xc(%rsp)
movl $0x0, 0x10(%rsp)
cmpl %r8d, %r9d
jbe 0xe6fc
movq %rcx, %rbx
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x28(%rsp)
movl %r8d, %r15d
movl %r9d, %r12d
movl $0x0, 0x10(%rsp)
movl $0x0, 0xc(%rsp)
xorl %ebp, %ebp
movq %rcx, 0x38(%rsp)
movq %r12, 0x30(%rsp)
andq $0x0, (%rsp)
movq %rbx, %rdi
movq %r15, %rsi
leaq 0x54(%rsp), %rdx
leaq 0x50(%rsp), %rcx
leaq 0x58(%rsp), %r8
leaq 0x4c(%rsp), %r9
callq 0x13812e
movl 0x54(%rsp), %edx
cmpl $-0x1, %edx
sete %al
movl 0x50(%rsp), %ecx
cmpl $-0x1, %ecx
sete %sil
orb %al, %sil
je 0xe521
incq %r15
cmpq %r12, %r15
jne 0xe4d6
jmp 0xe6fc
movl 0x4c(%rsp), %eax
movq %rax, 0x70(%rsp)
testq %rax, %rax
jne 0xe538
xorl %esi, %esi
xorl %eax, %eax
jmp 0xe6a0
movq %r15, 0x40(%rsp)
movl %ebp, 0x14(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rdi
xorl %r8d, %r8d
pushq $0x1
popq %rbx
movl %ebx, %esi
movq %rdi, 0x60(%rsp)
movq 0x68(%rsp), %rax
movl (%rax,%r8,4), %r9d
movl %r9d, %eax
shrl %eax
imulq $0x28, %rax, %r10
cmpl $0x0, 0xc(%rdi,%r10)
je 0xe66b
addq %rdi, %r10
andl $-0x2, %r9d
movq 0x28(%rsp), %rax
movq 0x28(%rax), %r11
xorl %r12d, %r12d
movq %r12, %rax
orq %r9, %rax
movq (%r11,%rax,8), %rax
movq %rax, %rdi
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
andq %r15, %rdi
je 0xe5e7
movq 0x28(%rsp), %r15
movq 0x8(%r15), %r13
shrq $0x20, %rax
imulq $0x18, %rax, %rax
addq %r13, %rax
addq $0xc, %rax
imulq $0x18, %rdi, %rdi
xorl %ebp, %ebp
xorl %r13d, %r13d
movl (%rax,%rbp), %r15d
notl %r15d
shrl $0x1f, %r15d
addl %r15d, %r13d
addq $0x18, %rbp
cmpq %rbp, %rdi
jne 0xe5cb
testl %r13d, %r13d
jne 0xe65a
xorl %eax, %eax
testq %r12, %r12
sete %al
movl 0x4(%r10,%rax,4), %eax
movq 0x20(%r14), %rsi
movl %eax, %edi
shrl %edi
cmpl $0x0, (%rsi,%rdi,8)
js 0xe656
xorq $0x1, %rax
movq 0x28(%r14), %rsi
movq (%rsi,%rax,8), %rdi
xorl %esi, %esi
movq %rdi, %rbx
movb $0x1, %al
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
andq %r15, %rbx
je 0xe68d
movq 0x8(%r14), %r15
shrq $0x20, %rdi
imulq $0x18, %rdi, %rdi
addq %r15, %rdi
addq $0xc, %rdi
imulq $0x18, %rbx, %rbx
xorl %r13d, %r13d
movl (%rdi,%r13), %ebp
notl %ebp
shrl $0x1f, %ebp
addl %ebp, %esi
addq $0x18, %r13
cmpq %r13, %rbx
jne 0xe63a
xorl %ebx, %ebx
testl %esi, %esi
jne 0xe658
jmp 0xe68b
xorl %ebx, %ebx
xorl %esi, %esi
leaq 0x1(%r12), %rax
testq %r12, %r12
movq %rax, %r12
je 0xe592
incq %r8
cmpq 0x70(%rsp), %r8
movq 0x60(%rsp), %rdi
jne 0xe561
testl %esi, %esi
sete %al
testl %ebx, %ebx
sete %sil
jmp 0xe68d
xorl %esi, %esi
movq 0x38(%rsp), %rbx
movl 0x14(%rsp), %ebp
movq 0x40(%rsp), %r15
movq 0x30(%rsp), %r12
testb %al, %al
je 0xe6c8
movq 0x27b935(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
shrl %edx
incl %edx
shrl %ecx
incl %ecx
testb %sil, %sil
je 0xe6e5
incl 0x10(%rsp)
leaq 0x21e4ed(%rip), %rsi    # 0x22cbb3
jmp 0xe6f0
incl %ebp
movq 0x27b90f(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
shrl %edx
incl %edx
shrl %ecx
incl %ecx
leaq 0x21e488(%rip), %rsi    # 0x22cb6b
jmp 0xe6f0
incl 0xc(%rsp)
leaq 0x21e49f(%rip), %rsi    # 0x22cb8f
xorl %eax, %eax
callq 0x22b0
jmp 0xe514
movq 0x27b8dd(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
leaq 0x21e4cb(%rip), %rsi    # 0x22cbd8
movl %ebp, %edx
movl 0xc(%rsp), %ecx
movl 0x10(%rsp), %r8d
xorl %eax, %eax
callq 0x22b0
movq 0x18(%rsp), %rax
movq 0x18(%rax), %r12
testl $0x7fffffff, 0x14(%r12) # imm = 0x7FFFFFFF
movq 0x20(%rsp), %rdi
je 0xe7b3
xorl %ebx, %ebx
pushq $0x1
popq %rbp
movq 0x18(%rsp), %rax
movq 0x10(%rax), %r13
imulq $0x28, %rbx, %rax
cmpl $0x0, 0xc(%r13,%rax)
je 0xe7a1
movq 0x20(%r12), %rcx
cmpl $0x0, (%rcx,%rbx,8)
js 0xe7a1
addq %rax, %r13
cmpl $0x0, 0x10(%r13)
je 0xe7a1
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 0x20(%rsp), %rdi
movl %ebx, %edx
movl %ebp, %ecx
callq 0xa1cd4
movq 0x20(%rsp), %rdi
incq %r15
movl 0x10(%r13), %eax
cmpq %rax, %r15
jb 0xe76a
incq %rbx
movl 0x14(%r12), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, %rbx
jb 0xe73d
movl 0xb8(%rsp), %eax
testl %eax, %eax
je 0xe8ff
movq 0xb0(%rsp), %r13
movl %eax, %esi
imulq $0x18, %rsi, %r15
xorl %ebx, %ebx
imulq $0x18, %rbx, %rcx
movq (%r13,%rcx), %r12
movq 0x20(%r14), %rax
movq %r12, %rdx
shrq $0x21, %rdx
cmpl $0x0, (%rax,%rdx,8)
jns 0xe81c
addq %r13, %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0xe81c
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 0xe802
cmpl $0x2, %edx
jae 0xe829
incq %rbx
cmpq %rsi, %rbx
jne 0xe7d2
jmp 0xe8ff
movq 0x27b7b0(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
movq %rsi, 0x28(%rsp)
leaq 0x21e3d5(%rip), %rsi    # 0x22cc14
xorl %eax, %eax
callq 0x22b0
pushq $-0x1
popq %r8
movq 0x28(%rsp), %rsi
movq 0x20(%rsp), %rdi
xorl %ebp, %ebp
imulq $0x18, %rbp, %rax
cmpl %r12d, 0x4(%r13,%rax)
jne 0xe890
addq %r13, %rax
movl 0x8(%rax), %eax
shrl %eax
cmpq %rax, (%rdi)
jbe 0xe887
movq 0x8(%rdi), %rcx
movl (%rcx,%rax,4), %ecx
cmpl $-0x1, %ecx
je 0xe887
movl %ecx, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
shrl $0x1f, %ecx
jmp 0xe88c
xorl %ecx, %ecx
movl %r8d, %edx
testb %cl, %cl
jne 0xe89a
incq %rbp
cmpq %rsi, %rbp
jne 0xe856
jmp 0xe81c
movq 0x18(%rsp), %rcx
movq 0x10(%rcx), %rsi
movl %edx, %ecx
imulq $0x28, %rcx, %rdi
movl 0x10(%rsi,%rdi), %r8d
xorl %ecx, %ecx
testq %r8, %r8
je 0xe8d5
addq %rdi, %rsi
movq 0x18(%rsi), %rsi
xorl %ecx, %ecx
movq (%rsi,%rcx,8), %rdi
shrq $0x21, %rdi
cmpl %eax, %edi
je 0xe8d5
incq %rcx
cmpl %ecx, %r8d
jne 0xe8be
movl %r8d, %ecx
movq 0x27b704(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
incl %edx
leaq 0x21e349(%rip), %rsi    # 0x22cc31
xorl %eax, %eax
callq 0x22b0
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
pushq $-0x1
popq %r8
jmp 0xe890
movq (%rdi), %rax
testq %rax, %rax
je 0xe925
movq 0x8(%rdi), %rcx
xorl %edx, %edx
cmpl $-0x2, (%rcx,%rdx,4)
jg 0xe91b
movq 0x8(%rdi), %rsi
orl $-0x1, (%rsi,%rdx,4)
incq %rdx
movl %edx, %esi
cmpq %rsi, %rax
ja 0xe90d
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq