// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/hic.cpp
// Function: print_bubbles(ma_ug_t*, bubble_type*, kvec_pe_hit*, hc_links*, ha_ug_index*)
void print_bubbles(ma_ug_t* ug, bubble_type* bub, kvec_pe_hit* hits, hc_links* link, ha_ug_index* idx)
{
    uint64_t tLen, t_utg, i, k;
    uint32_t beg, sink, n, *a;
    for (i = 0, tLen = 0; i < bub->ug->u.n; i++) tLen += bub->ug->u.a[i].len;
    fprintf(stderr, "[M::%s] # unitigs: %lu, # bases: %lu\n",  __func__, bub->ug->u.n, tLen);
    for (i = 0, tLen = 0, t_utg = 0; i < bub->f_bub; i++)
    {
        get_bubbles(bub, i, &beg, &sink, &a, &n, NULL);
        t_utg += n;
        for (k = 0; k < n; k++)
        {
            tLen +=bub->ug->u.a[(a[k]>>1)].len;
        }
    }
    fprintf(stderr, "[M::%s] # bubbles: %lu, # unitigs: %lu, # bases: %lu\n",  __func__, 
    Get_bub_num(*bub), t_utg, tLen);


    for (i = 0, tLen = 0, t_utg = 0; i < ug->g->n_seq; i++)
    {
        if(IF_BUB(i, *bub))
        {
            t_utg++;
            tLen +=bub->ug->u.a[i].len;
        }
    }
    fprintf(stderr, "[M::%s] # bubbles: %lu, # unitigs: %lu, # bases: %lu\n",  __func__, 
    Get_bub_num(*bub), t_utg, tLen);

    for (i = 0, tLen = 0, t_utg = 0; i < ug->g->n_seq; i++)
    {
        if(IF_HET(i, *bub))
        {
            t_utg++;
            tLen +=bub->ug->u.a[i].len;
        }
    }
    fprintf(stderr, "[M::%s] # het unitigs: %lu, # het bases: %lu\n",  __func__, t_utg, tLen);

    uint8_t* flag; CALLOC(flag, ug->g->n_seq);
    uint64_t s_uid, e_uid, shif = 64 - idx->uID_bits;
    if(hits)
    {
        for (k = 0; k < hits->a.n; ++k) 
        {
            s_uid = ((hits->a.a[k].s<<1)>>shif);
            e_uid = ((hits->a.a[k].e<<1)>>shif);
            if(bub->index[s_uid] == (uint32_t)-1 || bub->index[e_uid] == (uint32_t)-1) continue;
            if(IF_BUB(s_uid, *bub) && IF_BUB(e_uid, *bub))
            {
                flag[s_uid] |= 1;
                flag[e_uid] |= 1;
                continue;
            }
            if(IF_HET(s_uid, *bub) && IF_HET(e_uid, *bub))
            {
                flag[s_uid] |= 4;
                flag[e_uid] |= 4;
                continue;
            }
            if(IF_BUB(s_uid, *bub)) flag[s_uid] |= 2, flag[e_uid] |= 2;
            if(IF_BUB(e_uid, *bub)) flag[e_uid] |= 2, flag[s_uid] |= 2;
        }
    }
    else if(link)
    {
        for (i = 0; i < link->a.n; i++)
        {
            for (k = 0; k < link->a.a[i].e.n; ++k) 
            {
                if(link->a.a[i].e.a[k].del) continue;
                s_uid = i;
                e_uid = link->a.a[i].e.a[k].uID;
                if(bub->index[s_uid] == (uint32_t)-1 || bub->index[e_uid] == (uint32_t)-1) continue;
                if(IF_BUB(s_uid, *bub) && IF_BUB(e_uid, *bub))
                {
                    flag[s_uid] |= 1;
                    flag[e_uid] |= 1;
                    continue;
                }
                if(IF_HET(s_uid, *bub) && IF_HET(e_uid, *bub))
                {
                    flag[s_uid] |= 4;
                    flag[e_uid] |= 4;
                    continue;
                }
                if(IF_BUB(s_uid, *bub)) flag[s_uid] |= 2, flag[e_uid] |= 2;
                if(IF_BUB(e_uid, *bub)) flag[e_uid] |= 2, flag[s_uid] |= 2;
            }
        }
    }
    



    for (i = 0, tLen = 0, t_utg = 0; i < ug->g->n_seq; i++)
    {
        if(flag[i] & (uint32_t)1)
        {
            t_utg++;
            tLen +=bub->ug->u.a[i].len;
        } 
    }
    fprintf(stderr, "[M::%s] # bubble-chained unitigs: %lu, # bubble-chained bases: %lu\n",  
                    __func__, t_utg, tLen);

    for (i = 0, tLen = 0, t_utg = 0; i < ug->g->n_seq; i++)
    {
        if((flag[i] & (uint32_t)1) || (flag[i] & (uint32_t)2))
        {
            t_utg++;
            tLen +=bub->ug->u.a[i].len;
        } 
    }
    fprintf(stderr, "[M::%s] # (bubble && het)-chained unitigs: %lu, # (bubble && het)-chained bases: %lu\n",  
                    __func__, t_utg, tLen);


    for (i = 0, tLen = 0, t_utg = 0; i < ug->g->n_seq; i++)
    {
        if((flag[i] & (uint32_t)1) || (flag[i] & (uint32_t)2) || (flag[i] & (uint32_t)4))
        {
            t_utg++;
            tLen +=bub->ug->u.a[i].len;
        } 
    }
    fprintf(stderr, "[M::%s] # (bubble || het)-chained unitigs: %lu, # (bubble || het)-chained bases: %lu\n",  
                    __func__, t_utg, tLen);
    free(flag);


    fprintf(stderr, "************bubble utgs************\n");
    uint64_t pathLen;
    for (i = 0, tLen = 0, t_utg = 0; i < bub->f_bub; i++)
    {
        get_bubbles(bub, i, &beg, &sink, &a, &n, &pathLen);
        t_utg += n;
        fprintf(stderr, "(full-%lu)\tbeg:utg%.6u\tsink:utg%.6u\tpathLen:%lu\t%s\n", 
        i, (beg>>1)+1, (sink>>1)+1, pathLen, i < bub->s_bub? "s-bub":(i<bub->f_bub?"f-bub":"b-bub"));
        for (k = 0; k < n; k++)
        {
            tLen +=bub->ug->u.a[(a[k]>>1)].len;
            fprintf(stderr, "utg%.6u,", (a[k]>>1)+1);
        }
        fprintf(stderr, "\n");
        ///if(i < bub->s_bub && (n != 4 && n != 2 && n != 1)) fprintf(stderr, "weird\n");
    }

    for (i = bub->f_bub, tLen = 0, t_utg = 0; i < bub->f_bub + bub->b_bub; i++)
    {
        get_bubbles(bub, i, &beg, &sink, &a, &n, &pathLen);
        t_utg += n;
        fprintf(stderr, "(broken-%lu)\tbeg:utg%.6u\tsink:utg%.6u\tpathLen:%lu\t%s\n", 
        i, (beg>>1)+1, (sink>>1)+1, pathLen, i < bub->s_bub? "s-bub":(i<bub->f_bub?"f-bub":"b-bub"));
        for (k = 0; k < n; k++)
        {
            tLen +=bub->ug->u.a[(a[k]>>1)].len;
            fprintf(stderr, "utg%.6u,", (a[k]>>1)+1);
        }
        fprintf(stderr, "\n");
    }

    // fprintf(stderr, "************het utgs************\n");
    // for (i = 0; i < ug->g->n_seq; i++)
    // {
    //     if(IF_HET(i, *bub)) fprintf(stderr, "utg%.6lu\n", i+1);
    // }
    // fprintf(stderr, "************het utgs************\n");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %rbp
movq 0x10(%rsi), %rax
movq (%rax), %rcx
testq %rcx, %rcx
jne 0x15219
xorl %r8d, %r8d
jmp 0x15237
movq 0x10(%rax), %rax
xorl %r8d, %r8d
movq %rcx, %rdx
movl (%rax), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
addq %rsi, %r8
addq $0x28, %rax
decq %rdx
jne 0x15223
movq 0x27fda2(%rip), %r13    # 0x294fe0
movq (%r13), %rdi
leaq 0x22628c(%rip), %rsi    # 0x23b4d5
leaq 0x2262ab(%rip), %rdx    # 0x23b4fb
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x22b0
movq 0x80(%rbx), %rax
testq %rax, %rax
jne 0x1526b
xorl %r9d, %r9d
jmp 0x152ca
movq 0x28(%rbx), %rcx
movq 0x40(%rbx), %rdx
addq $0x8, %rcx
xorl %r9d, %r9d
xorl %r15d, %r15d
xorl %esi, %esi
movl (%rdx,%rsi,4), %r8d
movl 0x4(%rdx,%rsi,4), %edi
subl %r8d, %edi
addl $-0x2, %edi
je 0x152bf
leaq (%rcx,%r8,4), %r8
movq 0x10(%rbx), %r10
movq 0x10(%r10), %r10
xorl %r11d, %r11d
movl (%r8,%r11,4), %r14d
shrl %r14d
imulq $0x28, %r14, %r14
movl (%r10,%r14), %r14d
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
addq %r14, %r9
incq %r11
cmpq %r11, %rdi
jne 0x1529e
addq %rdi, %r15
incq %rsi
cmpq %rax, %rsi
jne 0x1527f
movq (%r13), %rdi
movq 0x30(%rbx), %rcx
decq %rcx
leaq 0x22622d(%rip), %rsi    # 0x23b509
leaq 0x226218(%rip), %rdx    # 0x23b4fb
xorl %r13d, %r13d
movq %r15, %r8
xorl %eax, %eax
callq 0x22b0
movq 0x18(%rbp), %rax
movl 0x14(%rax), %edx
andq $0x7fffffff, %rdx       # imm = 0x7FFFFFFF
jne 0x15305
xorl %r9d, %r9d
jmp 0x15349
movq (%rbx), %rax
movq 0x80(%rbx), %rcx
incq %rcx
imulq $0xa, %rdx, %rdx
xorl %esi, %esi
xorl %r9d, %r9d
xorl %r13d, %r13d
movl (%rax), %edi
cmpq %rdi, %rcx
jbe 0x1533c
incq %r13
movq 0x10(%rbx), %rdi
movq 0x10(%rdi), %rdi
movl (%rdi,%rsi,4), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
addq %rdi, %r9
addq $0xa, %rsi
addq $0x4, %rax
cmpq %rsi, %rdx
jne 0x1531e
movq 0x27fc90(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
movq 0x30(%rbx), %rcx
decq %rcx
leaq 0x2261a8(%rip), %rsi    # 0x23b509
leaq 0x226193(%rip), %rdx    # 0x23b4fb
xorl %r15d, %r15d
movq %r13, %r8
xorl %eax, %eax
callq 0x22b0
movq 0x18(%rbp), %rax
movl 0x14(%rax), %edx
andq $0x7fffffff, %rdx       # imm = 0x7FFFFFFF
jne 0x15391
xorl %r8d, %r8d
movq 0x27fc51(%rip), %r9     # 0x294fe0
jmp 0x153dc
movq (%rbx), %rax
movq 0x80(%rbx), %rcx
incq %rcx
imulq $0xa, %rdx, %rdx
xorl %esi, %esi
xorl %r8d, %r8d
xorl %r15d, %r15d
movq 0x27fc2f(%rip), %r9     # 0x294fe0
movl (%rax), %edi
cmpq %rdi, %rcx
jne 0x153cf
incq %r15
movq 0x10(%rbx), %rdi
movq 0x10(%rdi), %rdi
movl (%rdi,%rsi,4), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
addq %rdi, %r8
addq $0xa, %rsi
addq $0x4, %rax
cmpq %rsi, %rdx
jne 0x153b1
movq (%r9), %rdi
leaq 0x226159(%rip), %rsi    # 0x23b53f
leaq 0x22610e(%rip), %rdx    # 0x23b4fb
movq %r15, %rcx
xorl %eax, %eax
callq 0x22b0
movq 0x18(%rbp), %rax
movl 0x14(%rax), %r13d
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
pushq $0x1
popq %rsi
movq %r13, %rdi
callq 0x2120
movq %rax, %r15
testq %r12, %r12
jne 0x154ef
movq 0x8(%rsp), %rcx
testq %rcx, %rcx
je 0x154fc
movq (%rcx), %rax
testq %rax, %rax
je 0x154fc
movq 0x10(%rcx), %rcx
xorl %edx, %edx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
imulq $0x30, %rdx, %r8
movq (%rcx,%r8), %rdi
testq %rdi, %rdi
je 0x154e1
addq %rcx, %r8
movq 0x10(%r8), %r8
leaq (%r15,%rdx), %r9
addq $0x18, %r8
cmpb $0x0, (%r8)
js 0x154d8
movq (%rbx), %r14
movl (%r14,%rdx,4), %r11d
cmpq %rsi, %r11
je 0x154d8
movl -0x10(%r8), %r10d
movl (%r14,%r10,4), %r14d
cmpq %rsi, %r14
je 0x154d8
movq 0x80(%rbx), %r12
incq %r12
cmpq %r11, %r12
jbe 0x154a1
cmpq %r14, %r12
jbe 0x154a1
orb $0x1, (%r9)
addq %r15, %r10
movb $0x1, %r11b
jmp 0x154d5
cmpq %r11, %r12
jne 0x154b7
cmpq %r14, %r12
jne 0x154b7
orb $0x4, (%r9)
addq %r15, %r10
movb $0x4, %r11b
jmp 0x154d5
cmpq %r11, %r12
jbe 0x154c5
orb $0x2, (%r9)
orb $0x2, (%r15,%r10)
cmpq %r14, %r12
jbe 0x154d8
orb $0x2, (%r15,%r10)
movb $0x2, %r11b
movq %r9, %r10
orb %r11b, (%r10)
addq $0x28, %r8
decq %rdi
jne 0x15462
incq %rdx
cmpq %rax, %rdx
jne 0x15442
jmp 0x154fc
movq (%r12), %rax
testq %rax, %rax
jne 0x15821
testl %r13d, %r13d
jne 0x1550f
xorl %ecx, %ecx
xorl %r8d, %r8d
movq 0x27fad3(%rip), %r14    # 0x294fe0
jmp 0x1554c
imulq $0x28, %r13, %rax
xorl %edx, %edx
movq %r15, %rsi
xorl %r8d, %r8d
xorl %ecx, %ecx
movq 0x27fabc(%rip), %r14    # 0x294fe0
testb $0x1, (%rsi)
je 0x15540
incq %rcx
movq 0x10(%rbx), %rdi
movq 0x10(%rdi), %rdi
movl (%rdi,%rdx), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
addq %rdi, %r8
addq $0x28, %rdx
incq %rsi
cmpq %rdx, %rax
jne 0x15524
movq (%r14), %rdi
leaq 0x226017(%rip), %rsi    # 0x23b56d
leaq 0x225f9e(%rip), %rdx    # 0x23b4fb
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x22b0
movq 0x18(%rbp), %rax
movl 0x14(%rax), %eax
andq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
jne 0x1557b
xorl %r8d, %r8d
jmp 0x155b2
imulq $0x28, %rax, %rax
xorl %ecx, %ecx
movq %r15, %rdx
xorl %r8d, %r8d
xorl %r12d, %r12d
testb $0x3, (%rdx)
je 0x155a6
incq %r12
movq 0x10(%rbx), %rsi
movq 0x10(%rsi), %rsi
movl (%rsi,%rcx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
addq %rsi, %r8
addq $0x28, %rcx
incq %rdx
cmpq %rcx, %rax
jne 0x1558a
movq (%r14), %rdi
leaq 0x225ff5(%rip), %rsi    # 0x23b5b1
leaq 0x225f38(%rip), %rdx    # 0x23b4fb
xorl %r13d, %r13d
movq %r12, %rcx
xorl %eax, %eax
callq 0x22b0
movq 0x18(%rbp), %rax
movl 0x14(%rax), %eax
andq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
jne 0x155e4
xorl %r8d, %r8d
jmp 0x1561b
imulq $0x28, %rax, %rax
xorl %ecx, %ecx
movq %r15, %rdx
xorl %r8d, %r8d
xorl %r13d, %r13d
testb $0x7, (%rdx)
je 0x1560f
incq %r13
movq 0x10(%rbx), %rsi
movq 0x10(%rsi), %rsi
movl (%rsi,%rcx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
addq %rsi, %r8
addq $0x28, %rcx
incq %rdx
cmpq %rcx, %rax
jne 0x155f3
movq 0x27f9be(%rip), %rbp    # 0x294fe0
movq (%rbp), %rdi
leaq 0x225fda(%rip), %rsi    # 0x23b607
leaq 0x225ec7(%rip), %rdx    # 0x23b4fb
xorl %r14d, %r14d
movq %r13, %rcx
xorl %eax, %eax
callq 0x22b0
movq %r15, %rdi
callq 0x2220
movq (%rbp), %rcx
leaq 0x226009(%rip), %rdi    # 0x23b65d
pushq $0x24
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
cmpq $0x0, 0x80(%rbx)
je 0x15727
xorl %r12d, %r12d
movq %rbp, %r15
movq 0x28(%rbx), %r13
movq 0x40(%rbx), %rax
movl (%rax,%r12,4), %ebp
movl 0x4(%rax,%r12,4), %r14d
subl %ebp, %r14d
addl $-0x2, %r14d
movl (%r13,%rbp,4), %ecx
leal 0x1(%rbp), %eax
movl (%r13,%rax,4), %r8d
movq 0x58(%rbx), %rax
movq (%rax,%r12,8), %r9
shrl %ecx
incl %ecx
shrl %r8d
incl %r8d
cmpq 0x78(%rbx), %r12
movq (%r15), %rdi
leaq 0x226004(%rip), %rax    # 0x23b6bc
leaq 0x225ff7(%rip), %rdx    # 0x23b6b6
cmovbq %rdx, %rax
movq %rax, (%rsp)
leaq 0x225fb4(%rip), %rsi    # 0x23b682
movq %r12, %rdx
xorl %eax, %eax
callq 0x22b0
testl %r14d, %r14d
je 0x15706
leaq (%r13,%rbp,4), %r13
xorl %ebp, %ebp
movl 0x8(%r13,%rbp,4), %edx
shrl %edx
movq (%r15), %rdi
incl %edx
leaq 0x225fd1(%rip), %rsi    # 0x23b6c8
xorl %eax, %eax
callq 0x22b0
incq %rbp
cmpq %rbp, %r14
jne 0x156e4
movq (%r15), %rsi
pushq $0xa
popq %rdi
callq 0x2270
incq %r12
movq 0x80(%rbx), %r14
cmpq %r14, %r12
movq %r15, %rbp
jb 0x15670
movq 0x88(%rbx), %rax
addq %r14, %rax
cmpq %rax, %r14
jae 0x15812
movq %r14, %r12
movq 0x28(%rbx), %rdx
movq 0x40(%rbx), %rax
movl (%rax,%r12,4), %r15d
movl 0x4(%rax,%r12,4), %r13d
subl %r15d, %r13d
addl $-0x2, %r13d
movl (%rdx,%r15,4), %ecx
leal 0x1(%r15), %eax
movq %rdx, 0x8(%rsp)
movl (%rdx,%rax,4), %r8d
movq 0x58(%rbx), %rax
movq (%rax,%r12,8), %r9
movq (%rbp), %rdi
shrl %ecx
incl %ecx
shrl %r8d
incl %r8d
cmpq %r14, %r12
leaq 0x225f3c(%rip), %rax    # 0x23b6c2
leaq 0x225f2f(%rip), %rdx    # 0x23b6bc
cmovbq %rdx, %rax
cmpq 0x78(%rbx), %r12
leaq 0x225f1a(%rip), %rdx    # 0x23b6b6
cmovbq %rdx, %rax
movq %rax, (%rsp)
leaq 0x225f26(%rip), %rsi    # 0x23b6d1
movq %r12, %rdx
xorl %eax, %eax
callq 0x22b0
testl %r13d, %r13d
je 0x157e9
movq 0x8(%rsp), %rax
leaq (%rax,%r15,4), %r14
xorl %r15d, %r15d
movl 0x8(%r14,%r15,4), %edx
shrl %edx
movq (%rbp), %rdi
incl %edx
leaq 0x225eee(%rip), %rsi    # 0x23b6c8
xorl %eax, %eax
callq 0x22b0
incq %r15
cmpq %r15, %r13
jne 0x157c6
movq (%rbp), %rsi
pushq $0xa
popq %rdi
callq 0x2270
incq %r12
movq 0x80(%rbx), %r14
movq 0x88(%rbx), %rax
addq %r14, %rax
cmpq %rax, %r12
jb 0x1573d
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x40
popq %rcx
movq 0x10(%rsp), %rdx
subq 0x18(%rdx), %rcx
movq 0x10(%r12), %rdx
movq (%rbx), %rsi
addq $0x8, %rdx
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movq -0x8(%rdx), %r8
movq (%rdx), %r9
addq %r8, %r8
shrq %cl, %r8
addq %r9, %r9
shrq %cl, %r9
movl (%rsi,%r8,4), %r11d
cmpq %rdi, %r11
je 0x15895
movl (%rsi,%r9,4), %r10d
cmpq %rdi, %r10
je 0x15895
movq 0x80(%rbx), %r14
incq %r14
cmpq %r11, %r14
jbe 0x1587a
movb $0x1, %r12b
cmpq %r10, %r14
ja 0x15887
cmpq %r11, %r14
jne 0x158a3
movb $0x4, %r12b
cmpq %r10, %r14
jne 0x158a3
movq %r8, %r11
movq %r9, %r8
orb %r12b, (%r15,%r11)
orb %r12b, (%r15,%r8)
addq $0x20, %rdx
decq %rax
jne 0x1583e
jmp 0x154fc
cmpq %r11, %r14
jbe 0x158b2
orb $0x2, (%r15,%r8)
orb $0x2, (%r15,%r9)
movb $0x2, %r12b
movq %r9, %r11
cmpq %r10, %r14
ja 0x1588d
jmp 0x15895