// File: chhylp123[P]hifiasm/gfa_ut.cpp
// Function: deep_graph_clean(ug_opt_t*, asg_t*, unsigned char, unsigned char, long, double, double, double, long, long, long)
void deep_graph_clean(ug_opt_t *uopt, asg_t *sg, uint8_t is_ou, uint8_t is_trio, int64_t max_ext, 
double min_ovlp_drop_ratio, double max_ovlp_drop_ratio, double ou_rat, int64_t min_ou, int64_t clean_round, int64_t long_tip)
{
    ug_clean_t *sl; asg64_v b; double step; int64_t i;
    kv_init(b); hic_clean_adv(sg, uopt);
    step = (clean_round==1?max_ovlp_drop_ratio:((max_ovlp_drop_ratio-min_ovlp_drop_ratio)/(clean_round-1)));
    sl = init_ug_clean_t(uopt, sg, is_ou, is_trio, max_ext, min_ovlp_drop_ratio, ou_rat, min_ou);

    // print_debug_gfa(sg, NULL, uopt->coverage_cut, "debug", uopt->sources, uopt->ruIndex, uopt->max_hang, uopt->min_ovlp, 0, 0, 0);
    for (i = 0, sl->len_rat = min_ovlp_drop_ratio; i < clean_round; i++, sl->len_rat += step) {
        if(sl->len_rat > max_ovlp_drop_ratio) sl->len_rat = max_ovlp_drop_ratio;
        update_ug_clean_t(sl);
        kt_for(asm_opt.thread_num, cal_bub_best, sl, sl->ug->g->n_seq);
        cal_bub_best_by_len(sl, &b, max_ext, is_trio, sl->is_ou, sl->len_rat, sl->ou_rat, min_ou, long_tip);
    }

    // if(is_ou) {
    //     uint64_t k; sl->is_ou = 0;
    //     for (k = 0; k < sl->ug->g->n_arc; k++) sl->ug->g->arc[k].ou = 0;
    //     max_ovlp_drop_ratio = 0.6;
    //     if(max_ovlp_drop_ratio > min_ovlp_drop_ratio) {
    //         step = (clean_round==1?max_ovlp_drop_ratio:((max_ovlp_drop_ratio-min_ovlp_drop_ratio)/(clean_round-1)));
    //         for (i = 0, sl->len_rat = min_ovlp_drop_ratio; i < clean_round; i++, sl->len_rat += step) {
    //             if(sl->len_rat > max_ovlp_drop_ratio) sl->len_rat = max_ovlp_drop_ratio;
    //             update_ug_clean_t(sl);
    //             kt_for(asm_opt.thread_num, cal_bub_best, sl, sl->ug->g->n_seq);
    //             cal_bub_best_by_len(sl, &b, max_ext, is_trio, sl->is_ou, sl->len_rat, sl->ou_rat, min_ou);
    //         }
    //     }
    // }

    // update_ug_clean_t(sl);
    // cal_bub_best_by_topo(sl, &b, max_ext, is_trio, sl->is_ou, sl->len_rat, sl->ou_rat, min_ou, long_tip);

    kv_destroy(b); destroy_ug_clean_t(sl); free(sl);
    hic_clean_adv(sg, uopt);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movb %cl, %al
movb %dl, %cl
movq 0x18(%rbp), %rdx
movq 0x10(%rbp), %rdx
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb %cl, -0x11(%rbp)
movb %al, -0x12(%rbp)
movq %r8, -0x20(%rbp)
movsd %xmm0, -0x28(%rbp)
movsd %xmm1, -0x30(%rbp)
movsd %xmm2, -0x38(%rbp)
movq %r9, -0x40(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0xfec60
cmpq $0x1, 0x10(%rbp)
jne 0x3796d4
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
jmp 0x3796f4
movsd -0x30(%rbp), %xmm0
subsd -0x28(%rbp), %xmm0
movq 0x10(%rbp), %rax
subq $0x1, %rax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movb -0x11(%rbp), %cl
movb -0x12(%rbp), %al
movq -0x20(%rbp), %r8
movsd -0x28(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movq -0x40(%rbp), %r9
movzbl %cl, %edx
movzbl %al, %ecx
callq 0x379860
movq %rax, -0x48(%rbp)
movq $0x0, -0x70(%rbp)
movsd -0x28(%rbp), %xmm0
movq -0x48(%rbp), %rax
movsd %xmm0, 0xb0(%rax)
movq -0x70(%rbp), %rax
cmpq 0x10(%rbp), %rax
jge 0x379826
movq -0x48(%rbp), %rax
movsd 0xb0(%rax), %xmm0
ucomisd -0x30(%rbp), %xmm0
jbe 0x379778
movsd -0x30(%rbp), %xmm0
movq -0x48(%rbp), %rax
movsd %xmm0, 0xb0(%rax)
movq -0x48(%rbp), %rdi
callq 0x379b50
leaq 0x4b070(%rip), %rax     # 0x3c47f8
movl 0x7c(%rax), %edi
movq -0x48(%rbp), %rdx
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
leaq 0x1db2(%rip), %rsi      # 0x37b560
callq 0x16d710
movq -0x48(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %edx
movzbl -0x12(%rbp), %ecx
movq -0x48(%rbp), %rax
movzbl 0x98(%rax), %r8d
movq -0x48(%rbp), %rax
movsd 0xb0(%rax), %xmm0
movq -0x48(%rbp), %rax
movsd 0xb8(%rax), %xmm1
movq -0x40(%rbp), %rax
movl %eax, %r9d
movq 0x18(%rbp), %rax
leaq -0x60(%rbp), %rsi
movl %eax, (%rsp)
callq 0x37a680
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
movsd -0x68(%rbp), %xmm0
movq -0x48(%rbp), %rax
addsd 0xb0(%rax), %xmm0
movsd %xmm0, 0xb0(%rax)
jmp 0x379746
movq -0x50(%rbp), %rdi
callq 0x2210
movq -0x48(%rbp), %rdi
callq 0x379ad0
movq -0x48(%rbp), %rdi
callq 0x2210
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0xfec60
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)