// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: gen_bubble_chain(asg_t*, ma_ug_t*, ug_opt_t*, unsigned char**, unsigned char)
bubble_type *gen_bubble_chain(asg_t *sg, ma_ug_t *ug, ug_opt_t *uopt, uint8_t **ir_het, uint8_t avoid_het)
{
    kvec_asg_arc_t_warp new_rtg_edges;
    kv_init(new_rtg_edges.a);
    hap_cov_t *cov = NULL; 
    bubble_type *bub = NULL; 

    asg_t *copy_sg = copy_read_graph(sg);
    ma_ug_t *copy_ug = copy_untig_graph(ug);   
    // fprintf(stderr, "0[M::%s]\n", __func__);
    adjust_utg_by_primary(&copy_ug, copy_sg, TRIO_THRES, uopt->sources, uopt->reverse_sources, uopt->coverage_cut, 
    uopt->tipsLen, uopt->tip_drop_ratio, uopt->stops_threshold, uopt->ruIndex, uopt->chimeric_rate, uopt->drop_ratio,
    uopt->max_hang, uopt->min_ovlp, &new_rtg_edges, &cov, uopt->b_mask_t, 0, 0);
    ma_ug_destroy(copy_ug); copy_ug = NULL;
    asg_destroy(copy_sg); copy_sg = NULL; 
    // fprintf(stderr, "1[M::%s]\n", __func__);
    CALLOC(bub, 1); (*ir_het) = cov->t_ch->ir_het; 
    cov->t_ch->ir_het = NULL; cov->is_r_het = NULL;
    if(!avoid_het) {
        identify_bubbles(ug, bub, (*ir_het), NULL);
    } else {
        uint8_t *pr_het; CALLOC(pr_het, sg->n_seq);
        identify_bubbles_recal_poy(sg, ug, bub, pr_het, uopt->sources, uopt->ruIndex, NULL);
        free(pr_het);
    }
    
    // fprintf(stderr, "2[M::%s]\n", __func__);
    kv_destroy(new_rtg_edges.a); destory_hap_cov_t(&cov);
    if(asm_opt.purge_level_primary == 0) {///all nodes are het
        uint32_t k; 
        for (k = 0; k < ug->g->n_seq; k++) {
            if(IF_HOM(k, *bub)) bub->index[k] = bub->f_bub+1;
        }
    }
    // fprintf(stderr, "3[M::%s]\n", __func__);
    return bub;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl %r8d, 0x4c(%rsp)
movq %rcx, 0x58(%rsp)
movq %rdx, %r12
movq %rsi, %rbx
xorps %xmm0, %xmm0
leaq 0x70(%rsp), %r13
movaps %xmm0, (%r13)
andq $0x0, 0x10(%r13)
leaq 0x60(%rsp), %r15
andq $0x0, (%r15)
movq %rdi, 0x50(%rsp)
callq 0x8c8a9
movq %rax, %r14
movq %rbx, %rdi
callq 0x8c99a
leaq 0x68(%rsp), %rbp
movq %rax, (%rbp)
movq (%r12), %r8
movq 0x8(%r12), %rdx
movq 0x10(%r12), %rcx
movq 0x18(%r12), %r9
movss 0x20(%r12), %xmm1
movups 0x28(%r12), %xmm0
movss 0x38(%r12), %xmm2
movss 0x3c(%r12), %xmm3
movl 0x40(%r12), %eax
movl 0x44(%r12), %esi
movq 0x60(%r12), %rdi
movq %rdi, 0x30(%rsp)
movq %r15, 0x28(%rsp)
movq %r13, 0x20(%rsp)
movl %esi, 0x18(%rsp)
movl %eax, 0x10(%rsp)
movups %xmm0, (%rsp)
andl $0x0, 0x40(%rsp)
andl $0x0, 0x38(%rsp)
movss 0x37dcb(%rip), %xmm0    # 0x1e7cb4
movq %rbp, %rdi
movq %r14, %rsi
callq 0x8cb4c
movq (%rbp), %rdi
callq 0x6921d
andq $0x0, (%rbp)
movq %r14, %rdi
callq 0x68f68
pushq $0x1
popq %rdi
movl $0x110, %esi            # imm = 0x110
callq 0x2120
movq 0x58(%rsp), %rdx
movq %rax, %r14
movq (%r15), %rax
movq 0xa8(%rax), %rcx
movq 0x10(%rcx), %rcx
movq %rcx, (%rdx)
movq 0xa8(%rax), %rcx
andq $0x0, 0x10(%rcx)
andq $0x0, 0xa0(%rax)
cmpl $0x0, 0x4c(%rsp)
je 0x1aff8f
movq 0x50(%rsp), %r15
movl 0x14(%r15), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
pushq $0x1
popq %rsi
callq 0x2120
movq %rax, %r13
movq 0x8(%r12), %r8
movq 0x30(%r12), %r9
andq $0x0, (%rsp)
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq %rax, %rcx
callq 0xf90db
movq %r13, %rdi
callq 0x2220
jmp 0x1aff9f
movq (%rdx), %rdx
movq %rbx, %rdi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0xf7387
movq 0x80(%rsp), %rdi
callq 0x2220
leaq 0x60(%rsp), %rdi
callq 0x8d243
leaq 0xa379b(%rip), %rax     # 0x253758
cmpl $0x0, 0x130(%rax)
je 0x1affdb
movq %r14, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rbx), %rax
xorl %ecx, %ecx
movl 0x14(%rax), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
cmpq %rdx, %rcx
jae 0x1affc6
movq (%r14), %rdx
movq 0x80(%r14), %rsi
movl (%rdx,%rcx,4), %edi
incq %rsi
cmpq %rdi, %rsi
jae 0x1b0007
movl %esi, (%rdx,%rcx,4)
incq %rcx
jmp 0x1affe1