// File: /workspace/github_cpp_makefile_star2_O1/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 $0xa8, %rsp
movl %r8d, 0x54(%rsp)
movq %rcx, 0x68(%rsp)
movq %rdx, %r12
movq %rsi, %rbp
xorps %xmm0, %xmm0
leaq 0x80(%rsp), %r13
movaps %xmm0, (%r13)
xorl %ebx, %ebx
movq %rbx, 0x10(%r13)
leaq 0x70(%rsp), %r15
movq %rbx, (%r15)
movq %rdi, 0x60(%rsp)
callq 0xc802c
movq %rax, %r14
movq %rbp, 0x58(%rsp)
movq %rbp, %rdi
callq 0xc815c
leaq 0x78(%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
movl %ebx, 0x40(%rsp)
movl %ebx, 0x38(%rsp)
movq %rdi, 0x30(%rsp)
movq %r15, 0x28(%rsp)
movq %r13, 0x20(%rsp)
movl %esi, 0x18(%rsp)
movl %eax, 0x10(%rsp)
movups %xmm0, (%rsp)
movss 0x39621(%rip), %xmm0    # 0x229bbc
movq %rbp, %rdi
movq %r14, %rsi
callq 0xc8339
movq (%rbp), %rdi
callq 0xa0004
movq %rbx, (%rbp)
movq %r14, %rdi
callq 0x9fcdb
movl $0x1, %edi
movl $0x110, %esi            # imm = 0x110
callq 0x2120
movq 0x68(%rsp), %rdx
movq %rax, %r14
movq (%r15), %rax
movq 0xa8(%rax), %rcx
movq 0x10(%rcx), %rcx
movq %rcx, (%rdx)
movq 0xa8(%rax), %rcx
movq %rbx, 0x10(%rcx)
movq %rbx, 0xa0(%rax)
cmpl $0x0, 0x54(%rsp)
je 0x1f0649
movq 0x60(%rsp), %rbx
movl 0x14(%rbx), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movl $0x1, %esi
callq 0x2120
movq %rax, %r13
movq 0x8(%r12), %r8
movq 0x30(%r12), %r9
movq $0x0, (%rsp)
movq %rbx, %rdi
movq 0x58(%rsp), %r15
movq %r15, %rsi
movq %r14, %rdx
movq %rax, %rcx
callq 0x13abb6
movq %r13, %rdi
callq 0x2220
jmp 0x1f065e
movq (%rdx), %rdx
movq 0x58(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x138ab3
movq 0x90(%rsp), %rdi
callq 0x2220
leaq 0x70(%rsp), %rdi
callq 0xc8943
leaq 0x9a0dc(%rip), %rax     # 0x28a758
cmpl $0x0, 0x130(%rax)
jne 0x1f06bd
movq 0x18(%r15), %rax
testl $0x7fffffff, 0x14(%rax) # imm = 0x7FFFFFFF
je 0x1f06bd
movq (%r14), %rcx
movq 0x80(%r14), %rdx
incq %rdx
xorl %esi, %esi
movl (%rcx,%rsi,4), %edi
cmpq %rdi, %rdx
jae 0x1f06ac
movl %edx, (%rcx,%rsi,4)
incq %rsi
movl 0x14(%rax), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
cmpq %rdi, %rsi
jb 0x1f06a1
movq %r14, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq