// File: /workspace/github_cpp_makefile_star2_O1/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, %r12
movq %rdx, %rbp
movq %rsi, %rbx
movq %rdi, %r14
movq 0x10(%rsi), %rax
movq (%rax), %rcx
testq %rcx, %rcx
jne 0x15ae1
xorl %r8d, %r8d
jmp 0x15aff
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 0x15aeb
movq 0x2744da(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
leaq 0x219775(%rip), %rsi    # 0x22f285
leaq 0x219794(%rip), %rdx    # 0x22f2ab
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x22b0
movq 0x80(%rbx), %rax
testq %rax, %rax
jne 0x15b32
xorl %r9d, %r9d
jmp 0x15b91
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 0x15b86
leaq (%rcx,%r8,4), %r8
movq 0x10(%rbx), %r10
movq 0x10(%r10), %r10
xorl %r11d, %r11d
movl (%r8,%r11,4), %r13d
shrl %r13d
imulq $0x28, %r13, %r13
movl (%r10,%r13), %r13d
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
addq %r13, %r9
incq %r11
cmpq %r11, %rdi
jne 0x15b65
addq %rdi, %r15
incq %rsi
cmpq %rax, %rsi
jne 0x15b46
movq 0x274448(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
movq 0x30(%rbx), %rcx
decq %rcx
leaq 0x219710(%rip), %rsi    # 0x22f2b9
leaq 0x2196fb(%rip), %rdx    # 0x22f2ab
xorl %r13d, %r13d
movq %r15, %r8
xorl %eax, %eax
callq 0x22b0
movq 0x18(%r14), %rax
movl 0x14(%rax), %edx
andq $0x7fffffff, %rdx       # imm = 0x7FFFFFFF
jne 0x15bd2
xorl %r9d, %r9d
jmp 0x15c16
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 0x15c09
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 0x15beb
movq 0x2743c3(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
movq 0x30(%rbx), %rcx
decq %rcx
leaq 0x21968b(%rip), %rsi    # 0x22f2b9
leaq 0x219676(%rip), %rdx    # 0x22f2ab
xorl %r15d, %r15d
movq %r13, %r8
xorl %eax, %eax
callq 0x22b0
movq 0x18(%r14), %rax
movl 0x14(%rax), %edx
andq $0x7fffffff, %rdx       # imm = 0x7FFFFFFF
jne 0x15c57
xorl %r8d, %r8d
jmp 0x15c9b
movq (%rbx), %rax
movq 0x80(%rbx), %rcx
incq %rcx
imulq $0xa, %rdx, %rdx
xorl %esi, %esi
xorl %r8d, %r8d
xorl %r15d, %r15d
movl (%rax), %edi
cmpq %rdi, %rcx
jne 0x15c8e
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 0x15c70
movq 0x27433e(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
leaq 0x219643(%rip), %rsi    # 0x22f2ef
leaq 0x2195f8(%rip), %rdx    # 0x22f2ab
movq %r15, %rcx
xorl %eax, %eax
callq 0x22b0
movq 0x18(%r14), %rax
movl 0x14(%rax), %r13d
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
pushq $0x1
popq %rsi
movq %r13, %rdi
callq 0x2120
movq %rax, %r15
testq %rbp, %rbp
jne 0x15db9
testq %r12, %r12
je 0x15dc6
movq (%r12), %rax
testq %rax, %rax
je 0x15dc6
movq 0x10(%r12), %rcx
xorl %edx, %edx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
imulq $0x30, %rdx, %r8
movq (%rcx,%r8), %rdi
testq %rdi, %rdi
je 0x15dab
addq %rcx, %r8
movq 0x10(%r8), %r8
leaq (%r15,%rdx), %r9
addq $0x18, %r8
cmpb $0x0, (%r8)
js 0x15d9e
movq (%rbx), %r12
movl (%r12,%rdx,4), %r11d
cmpq %rsi, %r11
je 0x15d9e
movl -0x10(%r8), %r10d
movl (%r12,%r10,4), %r12d
cmpq %rsi, %r12
je 0x15d9e
movq 0x80(%rbx), %rbp
incq %rbp
cmpq %r11, %rbp
jbe 0x15d65
cmpq %r12, %rbp
jbe 0x15d65
orb $0x1, (%r15,%rdx)
addq %r15, %r10
movb $0x1, %r11b
jmp 0x15d9b
cmpq %r11, %rbp
jne 0x15d7c
cmpq %r12, %rbp
jne 0x15d7c
orb $0x4, (%r15,%rdx)
addq %r15, %r10
movb $0x4, %r11b
jmp 0x15d9b
cmpq %r11, %rbp
jbe 0x15d8b
orb $0x2, (%r15,%rdx)
orb $0x2, (%r15,%r10)
cmpq %r12, %rbp
jbe 0x15d9e
orb $0x2, (%r15,%r10)
movb $0x2, %r11b
movq %r9, %r10
orb %r11b, (%r10)
addq $0x28, %r8
decq %rdi
jne 0x15d25
incq %rdx
cmpq %rax, %rdx
jne 0x15d05
jmp 0x15dc6
movq (%rbp), %rax
testq %rax, %rax
jne 0x160e3
testl %r13d, %r13d
jne 0x15dd9
xorl %ecx, %ecx
xorl %r8d, %r8d
movq 0x274209(%rip), %rbp    # 0x289fe0
jmp 0x15e16
imulq $0x28, %r13, %rax
xorl %edx, %edx
movq %r15, %rsi
xorl %r8d, %r8d
xorl %ecx, %ecx
movq 0x2741f2(%rip), %rbp    # 0x289fe0
testb $0x1, (%rsi)
je 0x15e0a
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 0x15dee
movq (%rbp), %rdi
leaq 0x2194fc(%rip), %rsi    # 0x22f31d
leaq 0x219483(%rip), %rdx    # 0x22f2ab
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x22b0
movq 0x18(%r14), %rax
movl 0x14(%rax), %eax
andq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
jne 0x15e46
xorl %r8d, %r8d
jmp 0x15e7d
imulq $0x28, %rax, %rax
xorl %ecx, %ecx
movq %r15, %rdx
xorl %r8d, %r8d
xorl %r12d, %r12d
testb $0x3, (%rdx)
je 0x15e71
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 0x15e55
movq (%rbp), %rdi
leaq 0x2194d9(%rip), %rsi    # 0x22f361
leaq 0x21941c(%rip), %rdx    # 0x22f2ab
xorl %r13d, %r13d
movq %r12, %rcx
xorl %eax, %eax
callq 0x22b0
movq 0x18(%r14), %rax
movl 0x14(%rax), %eax
andq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
jne 0x15eb0
xorl %r8d, %r8d
jmp 0x15ee7
imulq $0x28, %rax, %rax
xorl %ecx, %ecx
movq %r15, %rdx
xorl %r8d, %r8d
xorl %r13d, %r13d
testb $0x7, (%rdx)
je 0x15edb
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 0x15ebf
movq (%rbp), %rdi
leaq 0x2194c5(%rip), %rsi    # 0x22f3b7
leaq 0x2193b2(%rip), %rdx    # 0x22f2ab
movq %r13, %rcx
xorl %eax, %eax
callq 0x22b0
movq %r15, %rdi
callq 0x2220
movq (%rbp), %rcx
leaq 0x2194f7(%rip), %rdi    # 0x22f40d
pushq $0x24
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq 0x80(%rbx), %r14
testq %r14, %r14
je 0x15feb
xorl %r13d, %r13d
movq 0x28(%rbx), %r15
movq 0x40(%rbx), %rax
movq %rbp, %r12
movl (%rax,%r13,4), %ebp
movl 0x4(%rax,%r13,4), %r14d
subl %ebp, %r14d
addl $-0x2, %r14d
movl (%r15,%rbp,4), %ecx
leal 0x1(%rbp), %eax
movl (%r15,%rax,4), %r8d
movq 0x58(%rbx), %rax
movq (%rax,%r13,8), %r9
shrl %ecx
incl %ecx
shrl %r8d
incl %r8d
cmpq 0x78(%rbx), %r13
movq (%r12), %rdi
leaq 0x2194f1(%rip), %rax    # 0x22f46c
leaq 0x2194e4(%rip), %rdx    # 0x22f466
cmovbq %rdx, %rax
movq %rax, (%rsp)
leaq 0x2194a1(%rip), %rsi    # 0x22f432
movq %r13, %rdx
xorl %eax, %eax
callq 0x22b0
testl %r14d, %r14d
je 0x15fc9
leaq (%r15,%rbp,4), %r15
xorl %ebp, %ebp
movl 0x8(%r15,%rbp,4), %edx
shrl %edx
movq (%r12), %rdi
incl %edx
leaq 0x2194be(%rip), %rsi    # 0x22f478
xorl %eax, %eax
callq 0x22b0
incq %rbp
cmpq %rbp, %r14
jne 0x15fa6
movq (%r12), %rsi
pushq $0xa
popq %rdi
callq 0x2270
incq %r13
movq 0x80(%rbx), %r14
cmpq %r14, %r13
movq %r12, %rbp
jb 0x15f34
movq 0x80(%rbx), %rax
movq 0x88(%rbx), %rcx
addq %rax, %rcx
cmpq %rcx, %r14
jae 0x160d4
movq 0x28(%rbx), %r15
movq 0x40(%rbx), %rcx
movq %rbp, %r12
movl (%rcx,%r14,4), %ebp
movl 0x4(%rcx,%r14,4), %r13d
subl %ebp, %r13d
addl $-0x2, %r13d
movl (%r15,%rbp,4), %ecx
leal 0x1(%rbp), %edx
movl (%r15,%rdx,4), %r8d
movq 0x58(%rbx), %rdx
movq (%rdx,%r14,8), %r9
movq (%r12), %rdi
shrl %ecx
incl %ecx
shrl %r8d
incl %r8d
cmpq %rax, %r14
leaq 0x219427(%rip), %rax    # 0x22f472
leaq 0x21941a(%rip), %rdx    # 0x22f46c
cmovbq %rdx, %rax
cmpq 0x78(%rbx), %r14
leaq 0x219405(%rip), %rdx    # 0x22f466
cmovbq %rdx, %rax
movq %rax, (%rsp)
leaq 0x219411(%rip), %rsi    # 0x22f481
movq %r14, %rdx
xorl %eax, %eax
callq 0x22b0
testl %r13d, %r13d
je 0x160a8
leaq (%r15,%rbp,4), %r15
xorl %ebp, %ebp
movl 0x8(%r15,%rbp,4), %edx
shrl %edx
movq (%r12), %rdi
incl %edx
leaq 0x2193df(%rip), %rsi    # 0x22f478
xorl %eax, %eax
callq 0x22b0
incq %rbp
cmpq %rbp, %r13
jne 0x16085
movq (%r12), %rsi
pushq $0xa
popq %rdi
callq 0x2270
incq %r14
movq 0x80(%rbx), %rax
movq 0x88(%rbx), %rcx
addq %rax, %rcx
cmpq %rcx, %r14
movq %r12, %rbp
jb 0x16005
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(%rbp), %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 0x16156
movl (%rsi,%r9,4), %r10d
cmpq %rdi, %r10
je 0x16156
movq 0x80(%rbx), %r12
incq %r12
cmpq %r11, %r12
jbe 0x1613b
movb $0x1, %bpl
cmpq %r10, %r12
ja 0x16148
cmpq %r11, %r12
jne 0x16164
movb $0x4, %bpl
cmpq %r10, %r12
jne 0x16164
movq %r8, %r11
movq %r9, %r8
orb %bpl, (%r15,%r11)
orb %bpl, (%r15,%r8)
addq $0x20, %rdx
decq %rax
jne 0x160ff
jmp 0x15dc6
cmpq %r11, %r12
jbe 0x16173
orb $0x2, (%r15,%r8)
orb $0x2, (%r15,%r9)
movb $0x2, %bpl
movq %r9, %r11
cmpq %r10, %r12
ja 0x1614e
jmp 0x16156