// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: clean_primary_untig_graph(ma_ug_t*, asg_t*, ma_hit_t_alloc*, ma_hit_t_alloc*, ma_sub_t*, long long, float, long long, R_to_U*, buf_t*, unsigned char*, float, unsigned int, unsigned int, float, int, int, float, hap_cov_t*)
void clean_primary_untig_graph(ma_ug_t *ug, asg_t *read_g, ma_hit_t_alloc* sources, 
ma_hit_t_alloc* reverse_sources, ma_sub_t* coverage_cut, long long tipsLen, float tip_drop_ratio, 
long long stops_threshold, R_to_U* ruIndex, buf_t* b_0, uint8_t* visit, float density, 
uint32_t miniHapLen, uint32_t miniBiGraph, float chimeric_rate, int is_final_clean, 
int just_bubble_pop, float drop_ratio, hap_cov_t *cov)
{
    #define T_ROUND 2
    asg_t *g = ug->g;
    int round = T_ROUND;

    redo:
    ///print_graph_statistic(g, "beg");
    ///print_debug_gfa(read_g, ug, coverage_cut, "debug_trans_ovlp_hg002", sources, ruIndex, asm_opt.max_hang_Len, asm_opt.min_overlap_Len);
    asg_pop_bubble_primary_trio(ug, NULL, (uint32_t)-1, DROP, cov, NULL, 1, NULL);
    if(just_bubble_pop == 0)
    {
        cut_trio_tip_primary(g, ug, tipsLen, (uint32_t)-1, 0, read_g, reverse_sources, ruIndex, cov->is_r_het, 2);
    }
    // print_debug_gfa(read_g, ug, coverage_cut, "debug_init", sources, ruIndex, asm_opt.max_hang_Len, asm_opt.min_overlap_Len);
    long long pre_cons = get_graph_statistic(g);
    long long cur_cons = 0;
    while(pre_cons != cur_cons)
    {   
        pre_cons = get_graph_statistic(g);
        asg_pop_bubble_primary_trio(ug, NULL, (uint32_t)-1, DROP, cov, NULL, 1, NULL);
        if(just_bubble_pop == 0)
        {
            ///need consider tangles  
            asg_arc_cut_trio_long_tip_primary(g, ug, read_g, reverse_sources, ruIndex, 2, tip_drop_ratio, (uint32_t)-1, cov, NULL); 
            asg_arc_cut_trio_long_equal_tips_assembly(g, ug, read_g, reverse_sources, 2, ruIndex, (uint32_t)-1, cov, NULL);   
            asg_arc_cut_trio_long_tip_primary_complex(g, ug, read_g, reverse_sources, ruIndex, 2, tip_drop_ratio, stops_threshold, cov, NULL, (uint32_t)-1);   
            asg_arc_cut_trio_long_equal_tips_assembly_complex(g, ug, read_g, reverse_sources, 2, ruIndex, stops_threshold, cov, NULL, (uint32_t)-1);
            detect_chimeric_by_topo(g, ug, read_g, reverse_sources, 2, stops_threshold, chimeric_rate, ruIndex, NULL, cov->is_r_het);    
            if(round != T_ROUND)
            {
                unitig_arc_del_short_diploid_by_length_topo(g, ug, drop_ratio, asm_opt.max_short_tip, 
                reverse_sources, 0, 1);
            }
        }
        cur_cons = get_graph_statistic(g);
    }
    if(just_bubble_pop == 0)
    {   
        cut_trio_tip_primary(g, ug, tipsLen, (uint32_t)-1, 0, read_g, reverse_sources, ruIndex, cov->is_r_het, 2);
    }
    resolve_tangles(ug, read_g, reverse_sources, 20, 100, 0.05, 0.2, ruIndex, cov->is_r_het, (uint32_t)-1, drop_ratio); 
    drop_semi_circle(ug, g, read_g, reverse_sources, ruIndex, cov->is_r_het); 
    // print_debug_gfa(read_g, ug, coverage_cut, "debug_clean_end", sources, ruIndex, asm_opt.max_hang_Len, asm_opt.min_overlap_Len);
    unitig_arc_del_short_diploid_by_length_topo(g, ug, drop_ratio, asm_opt.max_short_tip, reverse_sources, 0, 1);    
    ///print_graph_statistic(g, "end");
    if(round > 0)
    {
        if(round != T_ROUND)
        {
            unitig_arc_del_short_diploid_by_length(ug->g, drop_ratio);        
        }
        round--;
        goto redo;
    }    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movss %xmm3, 0x4(%rsp)
movss %xmm2, 0x2c(%rsp)
movss %xmm0, 0x14(%rsp)
movq %r9, 0x30(%rsp)
movq %rcx, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, %r14
movq 0x18(%rdi), %rbx
movl $0x2, %ebp
movq %rdi, 0x8(%rsp)
movl %ebp, 0x10(%rsp)
movq %r14, %rdi
xorl %esi, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x5, %ecx
movq 0xb0(%rsp), %r8
xorl %r9d, %r9d
pushq $0x0
pushq $0x1
callq 0xd3845
addq $0x10, %rsp
cmpl $0x0, 0xa8(%rsp)
jne 0xd4cd8
movq %rbx, %rdi
movq %r14, %rsi
movq 0x30(%rsp), %rdx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
movq 0x18(%rsp), %r9
pushq $0x2
movq 0xb8(%rsp), %rax
pushq 0xa0(%rax)
pushq 0x88(%rsp)
pushq 0x38(%rsp)
callq 0xcde83
addq $0x20, %rsp
movq %rbx, %rdi
callq 0xcdba4
testq %rax, %rax
je 0xd4e89
movq %rbx, %rdi
callq 0xcdba4
movq %rax, %rbp
movq %r14, %rdi
xorl %esi, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x5, %ecx
movq 0xb0(%rsp), %r8
xorl %r9d, %r9d
pushq $0x0
pushq $0x1
callq 0xd3845
addq $0x10, %rsp
cmpl $0x0, 0xa8(%rsp)
jne 0xd4e78
subq $0x8, %rsp
movq %rbx, %rdi
movq %r14, %rsi
movq 0x20(%rsp), %r12
movq %r12, %rdx
movq 0x28(%rsp), %r15
movq %r15, %rcx
movq 0x80(%rsp), %r13
movq %r13, %r8
movl $0x2, %r9d
movss 0x1c(%rsp), %xmm0
xorl %eax, %eax
pushq %rax
movq 0xc0(%rsp), %r14
pushq %r14
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
pushq %rax
callq 0xce4b6
addq $0x18, %rsp
movl $0x2, %r8d
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r13, %r9
xorl %r13d, %r13d
pushq %r13
pushq %r14
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
pushq %rax
callq 0xcf74c
addq $0x20, %rsp
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movq %r12, %rdx
movq %r15, %rcx
movq 0x78(%rsp), %r8
movl $0x2, %r9d
movss 0x14(%rsp), %xmm0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
pushq %rax
pushq %r13
pushq %r14
movl 0x88(%rsp), %r13d
pushq %r13
callq 0xcec2a
addq $0x20, %rsp
movl $0x2, %r8d
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movq %r12, %rdx
movq %r15, %rcx
movq 0x78(%rsp), %r9
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
pushq %rax
xorl %eax, %eax
pushq %rax
pushq %r14
pushq %r13
callq 0xd06a0
addq $0x18, %rsp
movl $0x2, %r8d
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
movq %r12, %rdx
movq %r15, %rcx
movl %r13d, %r9d
movss 0x34(%rsp), %xmm0
pushq 0xa0(%r14)
movq 0x18(%rsp), %r14
xorl %eax, %eax
pushq %rax
pushq 0x90(%rsp)
callq 0xd0f5e
addq $0x20, %rsp
cmpl $0x2, 0x10(%rsp)
je 0xd4e78
leaq 0x1c0900(%rip), %rax    # 0x295758
movl 0x11c(%rax), %edx
movq %rbx, %rdi
movq %r14, %rsi
movss 0x4(%rsp), %xmm0
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0xac04c
movq %rbx, %rdi
callq 0xcdba4
cmpq %rax, %rbp
jne 0xd4ce9
cmpl $0x0, 0xa8(%rsp)
jne 0xd4ecf
movq %rbx, %rdi
movq %r14, %rsi
movq 0x30(%rsp), %rdx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
movq 0x18(%rsp), %r9
pushq $0x2
movq 0xb8(%rsp), %rax
pushq 0xa0(%rax)
pushq 0x88(%rsp)
pushq 0x38(%rsp)
callq 0xcde83
addq $0x20, %rsp
movl $0x14, %ecx
movl $0x64, %r8d
movq %r14, %rdi
movq 0x18(%rsp), %r12
movq %r12, %rsi
movq 0x20(%rsp), %r15
movq %r15, %rdx
movss 0x160ec7(%rip), %xmm0   # 0x235dbc
movss 0x160ec3(%rip), %xmm1   # 0x235dc0
movq 0x78(%rsp), %r13
movq %r13, %r9
movss 0x4(%rsp), %xmm2
pushq $-0x1
movq 0xb8(%rsp), %r14
pushq 0xa0(%r14)
callq 0xd3be6
addq $0x10, %rsp
movq 0xa0(%r14), %r9
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r13, %r8
callq 0xd4320
leaq 0x1c080c(%rip), %rax    # 0x295758
movl 0x11c(%rax), %edx
movq %rbx, %rdi
movq %r14, %rsi
movss 0x4(%rsp), %xmm0
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0xac04c
movl 0x10(%rsp), %ebp
cmpl $0x2, %ebp
je 0xd4f88
testl %ebp, %ebp
je 0xd4f8f
movq 0x18(%r14), %rdi
movss 0x4(%rsp), %xmm0
callq 0xac5b4
decl %ebp
jmp 0xd4c67
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq