// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movq 0x50(%rbp), %rax
movl 0x48(%rbp), %eax
movl 0x40(%rbp), %eax
movl 0x38(%rbp), %eax
movl 0x30(%rbp), %eax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movss %xmm0, -0x34(%rbp)
movss %xmm1, -0x38(%rbp)
movss %xmm2, -0x3c(%rbp)
movss %xmm3, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x48(%rbp)
movl $0x2, -0x4c(%rbp)
movq -0x8(%rbp), %rdi
movq 0x50(%rbp), %r8
xorl %eax, %eax
movl %eax, %r9d
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x5, %ecx
movq %r9, %rsi
movl $0x1, (%rsp)
movq $0x0, 0x8(%rsp)
callq 0x11c760
cmpl $0x0, 0x48(%rbp)
jne 0x11e1b7
movq -0x48(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x30(%rbp), %rax
movl %eax, %edx
movq -0x10(%rbp), %r9
movq -0x20(%rbp), %r11
movq 0x18(%rbp), %r10
movq 0x50(%rbp), %rax
movq 0xa0(%rax), %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movl $0x2, 0x18(%rsp)
callq 0x1168e0
movq -0x48(%rbp), %rdi
callq 0x116380
movq %rax, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x60(%rbp), %rax
je 0x11e3bf
movq -0x48(%rbp), %rdi
callq 0x116380
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq 0x50(%rbp), %r8
xorl %eax, %eax
movl %eax, %r9d
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x5, %ecx
movq %r9, %rsi
movl $0x1, (%rsp)
movq $0x0, 0x8(%rsp)
callq 0x11c760
cmpl $0x0, 0x48(%rbp)
jne 0x11e3ad
movq -0x48(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq 0x18(%rbp), %r8
movss -0x34(%rbp), %xmm0
movq 0x50(%rbp), %rax
movl $0x2, %r9d
xorl %r10d, %r10d
movl $0xffffffff, (%rsp)     # imm = 0xFFFFFFFF
movq %rax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
callq 0x116eb0
movq -0x48(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq 0x18(%rbp), %r9
movq 0x50(%rbp), %rax
movl $0x2, %r8d
xorl %r10d, %r10d
movl $0xffffffff, (%rsp)     # imm = 0xFFFFFFFF
movq %rax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
callq 0x117ee0
movq -0x48(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq 0x18(%rbp), %r8
movss -0x34(%rbp), %xmm0
movq 0x10(%rbp), %rax
movl %eax, %r10d
movq 0x50(%rbp), %rax
movl $0x2, %r9d
xorl %r11d, %r11d
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movl $0xffffffff, 0x18(%rsp) # imm = 0xFFFFFFFF
callq 0x117510
movq -0x48(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq 0x18(%rbp), %r9
movq 0x10(%rbp), %rax
movl %eax, %r10d
movq 0x50(%rbp), %rax
movl $0x2, %r8d
xorl %r11d, %r11d
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movl $0xffffffff, 0x18(%rsp) # imm = 0xFFFFFFFF
callq 0x118f40
movq -0x48(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq 0x10(%rbp), %rax
movl %eax, %r9d
movss -0x3c(%rbp), %xmm0
movq 0x18(%rbp), %r10
movq 0x50(%rbp), %rax
movq 0xa0(%rax), %rax
movl $0x2, %r8d
xorl %r11d, %r11d
movq %r10, (%rsp)
movq $0x0, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x1195b0
cmpl $0x2, -0x4c(%rbp)
je 0x11e3ab
movq -0x48(%rbp), %rdi
movq -0x8(%rbp), %rsi
movss -0x40(%rbp), %xmm0
leaq 0x2a6465(%rip), %rax    # 0x3c47f8
movl 0x11c(%rax), %edx
movq -0x20(%rbp), %rcx
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0xddd20
jmp 0x11e3ad
movq -0x48(%rbp), %rdi
callq 0x116380
movq %rax, -0x60(%rbp)
jmp 0x11e1cc
cmpl $0x0, 0x48(%rbp)
jne 0x11e40d
movq -0x48(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x30(%rbp), %rax
movl %eax, %edx
movq -0x10(%rbp), %r9
movq -0x20(%rbp), %r11
movq 0x18(%rbp), %r10
movq 0x50(%rbp), %rax
movq 0xa0(%rax), %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movl $0x2, 0x18(%rsp)
callq 0x1168e0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq 0x18(%rbp), %r9
movq 0x50(%rbp), %rax
movq 0xa0(%rax), %rax
movss -0x40(%rbp), %xmm2
movl $0x14, %ecx
movl $0x64, %r8d
movss 0x268464(%rip), %xmm0   # 0x3868a4
movss 0x260c24(%rip), %xmm1   # 0x37f06c
movq %rax, (%rsp)
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
callq 0x11cca0
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq 0x18(%rbp), %r8
movq 0x50(%rbp), %rax
movq 0xa0(%rax), %r9
callq 0x11d700
movq -0x48(%rbp), %rdi
movq -0x8(%rbp), %rsi
movss -0x40(%rbp), %xmm0
leaq 0x2a6367(%rip), %rax    # 0x3c47f8
movl 0x11c(%rax), %edx
movq -0x20(%rbp), %rcx
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0xddd20
cmpl $0x0, -0x4c(%rbp)
jle 0x11e4d5
cmpl $0x2, -0x4c(%rbp)
je 0x11e4c7
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movss -0x40(%rbp), %xmm0
callq 0xde540
movl -0x4c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x11e13a
addq $0x80, %rsp
popq %rbp
retq
nop