// File: 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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movb %r8b, %al
movq %rdi, -0x30(%rbp)
movq %rsi, -0x38(%rbp)
movq %rdx, -0x40(%rbp)
movq %rcx, -0x48(%rbp)
movb %al, -0x49(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
movq -0x30(%rbp), %rdi
callq 0x10b830
movq %rax, -0x88(%rbp)
movq -0x38(%rbp), %rdi
callq 0x10ba70
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rsi
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x40(%rbp), %rax
movq (%rax), %r8
movq -0x40(%rbp), %rax
movq 0x18(%rax), %r9
movq -0x40(%rbp), %rax
movss 0x20(%rax), %xmm1
movq -0x40(%rbp), %rax
movq 0x28(%rax), %r12
movq -0x40(%rbp), %rax
movq 0x30(%rax), %r15
movq -0x40(%rbp), %rax
movss 0x38(%rax), %xmm2
movq -0x40(%rbp), %rax
movss 0x3c(%rax), %xmm3
movq -0x40(%rbp), %rax
movl 0x40(%rax), %r14d
movq -0x40(%rbp), %rax
movl 0x44(%rax), %ebx
movq -0x40(%rbp), %rax
movq 0x60(%rax), %rax
leaq -0x90(%rbp), %rdi
movss 0x64043(%rip), %xmm0    # 0x38689c
leaq -0x70(%rbp), %r11
leaq -0x78(%rbp), %r10
xorl %r13d, %r13d
movq %r12, (%rsp)
movq %r15, 0x8(%rsp)
movl %r14d, 0x10(%rsp)
movl %ebx, 0x18(%rsp)
movq %r11, 0x20(%rsp)
movq %r10, 0x28(%rsp)
movq %rax, 0x30(%rsp)
movl $0x0, 0x38(%rsp)
movl $0x0, 0x40(%rsp)
callq 0x10bde0
movq -0x90(%rbp), %rdi
callq 0xcd6f0
movq $0x0, -0x90(%rbp)
movq -0x88(%rbp), %rdi
callq 0xcd170
movq $0x0, -0x88(%rbp)
movl $0x1, %edi
movl $0x110, %esi            # imm = 0x110
callq 0x2140
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rax
movq 0xa8(%rax), %rax
movq 0x10(%rax), %rcx
movq -0x48(%rbp), %rax
movq %rcx, (%rax)
movq -0x78(%rbp), %rax
movq 0xa8(%rax), %rax
movq $0x0, 0x10(%rax)
movq -0x78(%rbp), %rax
movq $0x0, 0xa0(%rax)
cmpb $0x0, -0x49(%rbp)
jne 0x322933
movq -0x38(%rbp), %rdi
movq -0x80(%rbp), %rsi
movq -0x48(%rbp), %rax
movq (%rax), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x1c5bb0
jmp 0x322992
movq -0x30(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edi
movl $0x1, %esi
callq 0x2140
movq %rax, -0x98(%rbp)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x80(%rbp), %rdx
movq -0x98(%rbp), %rcx
movq -0x40(%rbp), %rax
movq 0x8(%rax), %r8
movq -0x40(%rbp), %rax
movq 0x30(%rax), %r9
xorl %eax, %eax
movq $0x0, (%rsp)
callq 0x1c9190
movq -0x98(%rbp), %rdi
callq 0x2210
movq -0x60(%rbp), %rdi
callq 0x2210
leaq -0x78(%rbp), %rdi
callq 0x10c960
leaq 0xa1e4d(%rip), %rax     # 0x3c47f8
cmpl $0x0, 0x130(%rax)
jne 0x322a33
movl $0x0, -0x9c(%rbp)
movl -0x9c(%rbp), %eax
movq -0x38(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0x322a31
movq -0x80(%rbp), %rax
movq (%rax), %rax
movl -0x9c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq -0x80(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jbe 0x322a1e
movq -0x80(%rbp), %rax
movq 0x80(%rax), %rax
addq $0x1, %rax
movl %eax, %edx
movq -0x80(%rbp), %rax
movq (%rax), %rax
movl -0x9c(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
jmp 0x322a20
movl -0x9c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
jmp 0x3229be
jmp 0x322a33
movq -0x80(%rbp), %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)