// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/hic.cpp
// Function: get_bub_graph(ma_ug_t*, bubble_type*)
void get_bub_graph(ma_ug_t* ug, bubble_type* bub)
{
    asg_t *sg = ug->g;
    asg_arc_t t, *p = NULL;
    pdq pq;
    init_pdq(&pq, sg->n_seq<<1);
    uint32_t n_vtx = sg->n_seq<<1, v, k;
    uint32_t *pre = NULL; MALLOC(pre, n_vtx);
    uint32_t pre_id, adjecent, bub_occ;
    asg_t *bub_g = asg_init();
    for (v = 0; v < bub->f_bub; v++)///all bubbles
    {
        uint64_t pathbase;
        uint32_t beg, sink;
        get_bubbles(bub, v, &beg, &sink, NULL, NULL, &pathbase);
        asg_seq_set(bub_g, v, pathbase, (bub->check_het && IF_HET(beg>>1, *bub) && IF_HET(sink>>1, *bub))?1:0);
        bub_g->seq[v].c = PRIMARY_LABLE;
    }

    //check all unitigs, instead of bubble nodes
    for (v = 0; v < n_vtx; ++v)
    {
        if(sg->seq[v>>1].del) continue;
        if(bub->b_s_idx.a[v>>1] == (uint64_t)-1) continue; ///if (v>>1) is not a beg or sink of bubbles
        ///one node might be the beg/sink node of at most two bubbles
        bub_occ = connect_bub_occ(bub, v>>1, bub->check_het);
        if(bub_occ == 0) continue;
        if(bub_occ == 2)
        {
            if(ma_2_bub_arc(bub, v, NULL, v^1, NULL, &t, bub->check_het))
            {
                t.ol = sg->seq[v>>1].len;
                p = asg_arc_pushp(bub_g);
                *p = t;
            }
            continue;
        }
        if(ma_2_bub_arc(bub, v, NULL, (uint32_t)-1, NULL, &t, bub->check_het) == 0) continue;

        ///v is the beg/sink node of only one bubble
        get_shortest_path(v, &pq, sg, pre);
        for (k = 0; k < pq.dis.n; k++)
        {
            if(pq.dis.a[k] == (uint64_t)-1) continue;
            if(bub->b_s_idx.a[k>>1] == (uint64_t)-1) continue;
            if(connect_bub_occ(bub, k>>1, bub->check_het) == 0) continue;
            if((k>>1) == (v>>1)) continue;
            pre_id = pre[k];
            adjecent = 0;
            while (pre_id != v)
            {
                if(connect_bub_occ(bub, pre_id>>1, bub->check_het) > 0)///some bubbles between v and k
                {
                    adjecent = 1;
                    break;
                } 
                pre_id = pre[pre_id];
            }

            if(adjecent == 0)
            {
                if(ma_2_bub_arc(bub, v, NULL, k^1, NULL, &t, bub->check_het))///edges spanning tangles
                {
                    t.el = 0; t.ol = pq.dis.a[k] + sg->seq[k>>1].len;
                    p = asg_arc_pushp(bub_g);
                    *p = t;
                }
            }
        }
    }

    free(pre);
    destory_pdq(&pq);

    asg_cleanup(bub_g);
    bub_g->r_seq = bub_g->n_seq;
    bub->b_g = bub_g;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rsi, %rbx
movq 0x18(%rdi), %r14
movl 0x14(%r14), %eax
addl %eax, %eax
movslq %eax, %rsi
leaq 0x70(%rsp), %rdi
callq 0x14198e
movq %r14, 0x20(%rsp)
movl 0x14(%r14), %eax
addl %eax, %eax
movq %rax, 0x58(%rsp)
leaq (,%rax,4), %rdi
callq 0x2280
movq %rax, 0x30(%rsp)
callq 0xa0485
movq %rax, %r14
movq 0x80(%rbx), %rax
testq %rax, %rax
je 0x14b824
xorl %r15d, %r15d
cmpl $0x0, 0xb0(%rbx)
movl $0x0, %ecx
je 0x14b7f8
movq 0x28(%rbx), %rsi
movq 0x40(%rbx), %rcx
movl (%rcx,%r15,4), %r8d
movl (%rsi,%r8,4), %ecx
movq (%rbx), %rdx
shrl %ecx
movl (%rdx,%rcx,4), %edi
incq %rax
movl $0x0, %ecx
cmpq %rdi, %rax
jne 0x14b7f8
incl %r8d
movl (%rsi,%r8,4), %eax
shrl %eax
xorl %ecx, %ecx
cmpl (%rdx,%rax,4), %edi
sete %cl
movq 0x58(%rbx), %rax
movl (%rax,%r15,8), %edx
movq %r14, %rdi
movl %r15d, %esi
callq 0xa0887
movq 0x20(%r14), %rax
movb $0x0, 0x4(%rax,%r15,8)
incl %r15d
movq 0x80(%rbx), %rax
cmpq %r15, %rax
ja 0x14b7b4
movq %r14, 0x38(%rsp)
cmpl $0x0, 0x58(%rsp)
je 0x14bb8a
xorl %r13d, %r13d
movq 0x20(%rsp), %rax
movq 0x20(%rax), %rax
movl %r13d, %ecx
shrl %ecx
movq %rcx, 0x28(%rsp)
cmpl $0x0, (%rax,%rcx,8)
js 0x14bb7c
movq 0x70(%rbx), %rax
movq 0x28(%rsp), %rcx
cmpq $-0x1, (%rax,%rcx,8)
je 0x14bb7c
movl 0xb0(%rbx), %r15d
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
leaq 0x18(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movl %r15d, %r8d
callq 0x14ac07
xorl %eax, %eax
cmpq $-0x1, 0x18(%rsp)
sete %al
xorl %ecx, %ecx
cmpq $-0x1, 0x10(%rsp)
sete %cl
addl %eax, %ecx
movl $0x2, %eax
subl %ecx, %eax
je 0x14bb7c
cmpl $0x2, %eax
jne 0x14b953
movl %r13d, %ecx
xorl $0x1, %ecx
movl %r15d, (%rsp)
movq %rbx, %rdi
movl %r13d, %esi
xorl %edx, %edx
xorl %r8d, %r8d
leaq 0x40(%rsp), %r9
callq 0x14adb4
testl %eax, %eax
je 0x14bb7c
movq 0x20(%rsp), %rax
movq 0x20(%rax), %rax
movq 0x28(%rsp), %rcx
movl (%rax,%rcx,8), %eax
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl %esi, %eax
movl 0x4c(%rsp), %ecx
movl $0x80000000, %edx       # imm = 0x80000000
andl %edx, %ecx
orl %eax, %ecx
movl %ecx, 0x4c(%rsp)
movq 0x38(%rsp), %r14
movl 0x4(%r14), %edx
movl %edx, %ecx
andl %esi, %ecx
cmpl (%r14), %ecx
jne 0x14bb4a
leal (%rcx,%rcx), %eax
testl %ecx, %ecx
movl $0x10, %ecx
cmovel %ecx, %eax
movl %eax, (%r14)
movq 0x8(%r14), %rdi
shlq $0x3, %rax
leaq (%rax,%rax,2), %rsi
callq 0x2370
movq %rax, 0x8(%r14)
movl 0x4(%r14), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
jmp 0x14bb4e
movl %r15d, (%rsp)
movq %rbx, %rdi
movl %r13d, %esi
xorl %edx, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
leaq 0x40(%rsp), %r9
callq 0x14adb4
testl %eax, %eax
je 0x14bb7c
movl %r13d, %edi
leaq 0x70(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq 0x30(%rsp), %rcx
callq 0x141c64
movq 0xa0(%rsp), %rax
movq %rax, 0x68(%rsp)
testq %rax, %rax
je 0x14bb7c
xorl %r15d, %r15d
movq 0xb0(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rax
cmpq $-0x1, (%rax,%r15,8)
je 0x14bb3a
movq 0x70(%rbx), %rax
movl %r15d, %r14d
shrl %r14d
cmpq $-0x1, (%rax,%r14,8)
je 0x14bb3a
movl 0xb0(%rbx), %r12d
movq %rbx, %rdi
movl %r14d, %esi
leaq 0x18(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movl %r12d, %r8d
callq 0x14ac07
movq 0x10(%rsp), %rax
andq 0x18(%rsp), %rax
cmpq $-0x1, %rax
sete %al
cmpl 0x28(%rsp), %r14d
je 0x14bb3a
testb %al, %al
jne 0x14bb3a
movq 0x30(%rsp), %rax
movl (%rax,%r15,4), %ebp
cmpl %r13d, %ebp
je 0x14ba69
movl %ebp, %esi
shrl %esi
movq %rbx, %rdi
leaq 0x18(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movl %r12d, %r8d
callq 0x14ac07
cmpq $-0x1, 0x18(%rsp)
jne 0x14bb3a
cmpq $-0x1, 0x10(%rsp)
jne 0x14bb3a
movl %ebp, %eax
movq 0x30(%rsp), %rcx
movl (%rcx,%rax,4), %ebp
jmp 0x14ba27
movl %r15d, %ecx
xorl $0x1, %ecx
movl %r12d, (%rsp)
movq %rbx, %rdi
movl %r13d, %esi
xorl %edx, %edx
xorl %r8d, %r8d
leaq 0x40(%rsp), %r9
callq 0x14adb4
testl %eax, %eax
je 0x14bb3a
movb $0x0, 0x52(%rsp)
movq 0x20(%rsp), %rax
movq 0x20(%rax), %rax
movl (%rax,%r14,8), %eax
movq 0x60(%rsp), %rcx
addl (%rcx,%r15,8), %eax
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl %esi, %eax
movl 0x4c(%rsp), %ecx
movl $0x80000000, %edx       # imm = 0x80000000
andl %edx, %ecx
orl %eax, %ecx
movl %ecx, 0x4c(%rsp)
movq 0x38(%rsp), %r14
movl 0x4(%r14), %edx
movl %edx, %ecx
andl %esi, %ecx
cmpl (%r14), %ecx
jne 0x14bb08
leal (%rcx,%rcx), %eax
testl %ecx, %ecx
movl $0x10, %ecx
cmovel %ecx, %eax
movl %eax, (%r14)
movq 0x8(%r14), %rdi
shlq $0x3, %rax
leaq (%rax,%rax,2), %rsi
callq 0x2370
movq %rax, 0x8(%r14)
movl 0x4(%r14), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
jmp 0x14bb0c
movq 0x8(%r14), %rax
leal 0x1(%rdx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %edx       # imm = 0x80000000
orl %esi, %edx
movl %edx, 0x4(%r14)
movl %ecx, %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x50(%rsp), %rdx
movq %rdx, 0x10(%rax,%rcx,8)
movups 0x40(%rsp), %xmm0
movups %xmm0, (%rax,%rcx,8)
incl %r15d
cmpq %r15, 0x68(%rsp)
ja 0x14b9b6
jmp 0x14bb7c
movq 0x8(%r14), %rax
leal 0x1(%rdx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %edx       # imm = 0x80000000
orl %esi, %edx
movl %edx, 0x4(%r14)
movl %ecx, %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x50(%rsp), %rdx
movq %rdx, 0x10(%rax,%rcx,8)
movups 0x40(%rsp), %xmm0
movups %xmm0, (%rax,%rcx,8)
incl %r13d
cmpl 0x58(%rsp), %r13d
jne 0x14b837
movq 0x30(%rsp), %rdi
callq 0x2220
movq 0x98(%rsp), %rdi
callq 0x2220
movq 0xb0(%rsp), %rdi
callq 0x2220
movq 0x80(%rsp), %rdi
callq 0x2220
movq 0x38(%rsp), %r14
movq %r14, %rdi
callq 0xa0a7d
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl 0x14(%r14), %eax
movl %eax, 0x18(%r14)
movq %r14, 0xb8(%rbx)
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq