// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: clean_graph(int, ma_hit_t_alloc*, ma_hit_t_alloc*, long long, unsigned long*, long long, long long, long long, long long, float, float, char*, long long, int, R_to_U*, asg_t**, ma_sub_t**, unsigned char*, int)
void clean_graph(
int min_dp, ma_hit_t_alloc* sources, ma_hit_t_alloc* reverse_sources, 
long long n_read, uint64_t* readLen, long long mini_overlap_length, 
long long max_hang_length, long long clean_round, long long gap_fuzz,
float min_ovlp_drop_ratio, float max_ovlp_drop_ratio, char* output_file_name, 
long long bubble_dist, int read_graph, R_to_U* ruIndex, asg_t **sg_ptr, 
ma_sub_t **coverage_cut_ptr, uint8_t *cmk, int debug_g)
{
    char *o_file = get_outfile_name(output_file_name);
	ma_sub_t *coverage_cut = *coverage_cut_ptr;
	asg_t *sg = *sg_ptr;
    bub_label_t b_mask_t;
    ug_opt_t uopt; 
    telo_end_t *te = NULL;

    if(asm_opt.telo_motif) te = gen_telo_end_t(&R_INF, asm_opt.telo_motif, asm_opt.telo_mic_sc, asm_opt.telo_pen, asm_opt.telo_drop, asm_opt.thread_num);

    if(debug_g) 
    {
        init_bub_label_t(&b_mask_t, MIN(10, asm_opt.thread_num), n_read);
        goto debug_gfa;
    }
    ///just for debug
    if(!cmk) renew_graph_init(sources, reverse_sources, sg, coverage_cut, ruIndex, n_read);
    // if(asm_opt.is_ont) handle_chemical_arc(asm_opt.thread_num, R_INF.total_reads);
    // if(asm_opt.is_ont) handle_chemical_r(asm_opt.thread_num, R_INF.total_reads);
    
    ///it's hard to say which function is better       
    ///normalize_ma_hit_t_single_side(sources, n_read);

    normalize_ma_hit_t_single_side_advance(sources, n_read, asm_opt.is_ont, cmk);
    // normalize_ma_hit_t_single_side_advance_mult(sources, n_read, asm_opt.thread_num);
    normalize_ma_hit_t_single_side_advance(reverse_sources, n_read, 0, cmk);
    // normalize_ma_hit_t_single_side_advance_mult(reverse_sources, n_read, asm_opt.thread_num);

    if (ha_opt_triobin(&asm_opt))
    {
        drop_edges_by_trio(sources, n_read);
    }
    else
    {
        memset(R_INF.trio_flag, AMBIGU, R_INF.total_reads*sizeof(uint8_t));
    }
    if(asm_opt.ar) init_all_ul_t(&UL_INF, &R_INF);
    // if (asm_opt.flag & HA_F_VERBOSE_GFA) {
    //     write_debug_graph(NULL, sources, coverage_cut, output_file_name, reverse_sources, ruIndex, &UL_INF);
    //     debug_gfa:;
    // }
    ///should recover edges from sources by using UL alignments
    // prt_specific_overlap(sources, 22233, 22235, "0-a");
    // prt_specific_overlap(sources, 22235, 22233, "0-a");
    if(asm_opt.ar) {
        create_ul_info(sources, reverse_sources, max_hang_length, mini_overlap_length, gap_fuzz, min_dp, readLen, coverage_cut, ruIndex, 
        (asm_opt.max_short_tip*2), 0.15, 3, 0.05, 0.9, &b_mask_t, te);
    } 
    // prt_specific_overlap(sources, 22233, 22235, "0-b");
    // prt_specific_overlap(sources, 22235, 22233, "0-b");
    // prt_dbg_rid_ovlp(sources, 27087, NULL, "0-a");
    if(!(asm_opt.is_ont)) clean_weak_ma_hit_t(sources, reverse_sources, n_read, asm_opt.ar?UL_COV_THRES:(uint32_t)-1);
    // prt_dbg_rid_ovlp(sources, 27087, NULL, "0-b");
    // prt_specific_overlap(sources, 22233, 22235, "0-c");
    // prt_specific_overlap(sources, 22235, 22233, "0-c");
    sg = gen_init_sg(min_dp, n_read, mini_overlap_length, max_hang_length, gap_fuzz, sources, readLen, ruIndex, 
    &b_mask_t, &coverage_cut, asm_opt.ar?&UL_INF:NULL, te);
    // if(asm_opt.ar) exit(1);
    /**
    ///print_binned_reads(sources, n_read, coverage_cut);
    
    ///ma_hit_sub is just use to init coverage_cut,
    ///it seems we do not need ma_hit_cut & ma_hit_flt
    ma_hit_sub(min_dp, sources, n_read, readLen, mini_overlap_length, &coverage_cut);
    detect_chimeric_reads(sources, n_read, readLen, coverage_cut, asm_opt.max_ov_diff_final * 2.0, asm_opt.ar?&UL_INF:NULL);
    ma_hit_cut(sources, n_read, readLen, mini_overlap_length, &coverage_cut);
    ///print_binned_reads(sources, n_read, coverage_cut);
    ma_hit_flt(sources, n_read, coverage_cut, max_hang_length, mini_overlap_length);
    ///fix_binned_reads(sources, n_read, coverage_cut);
    ///just need to deal with trio here
    ma_hit_contained_advance(sources, n_read, coverage_cut, ruIndex, max_hang_length, mini_overlap_length);
    sg = ma_sg_gen(sources, n_read, coverage_cut, max_hang_length, mini_overlap_length);
    ///debug_info_of_specfic_node((char*)"m64043_200504_050026/93784180/ccs", sg, ruIndex, (char*)"sbsbsb");
    init_bub_label_t(&b_mask_t, MIN(10, asm_opt.thread_num), sg->n_seq);
    asg_arc_del_trans(sg, gap_fuzz);
    asm_opt.coverage = get_coverage(sources, coverage_cut, n_read);
    **/
    if(VERBOSE >= 1)
    {
        char* unlean_name = (char*)malloc(strlen(output_file_name)+25);
        sprintf(unlean_name, "%s.unclean", output_file_name);
        output_read_graph(sg, coverage_cut, unlean_name, n_read);
        free(unlean_name);
    }


    // if (asm_opt.flag & HA_F_VERBOSE_GFA) {
    //     write_debug_graph(sg, sources, coverage_cut, output_file_name, reverse_sources, ruIndex, &UL_INF);
    //     debug_gfa:;
    // }
    
    gen_ug_opt_t(&uopt, sources, reverse_sources, max_hang_length, mini_overlap_length, gap_fuzz, min_dp, readLen, coverage_cut, ruIndex, 
            (asm_opt.max_short_tip*2), 0.15, 3, 0.05, 0.9, &b_mask_t, te);
    ul_clean_gfa(&uopt, sg, sources, reverse_sources, ruIndex, clean_round, min_ovlp_drop_ratio, max_ovlp_drop_ratio, 
    0.6, asm_opt.max_short_tip, gap_fuzz, &b_mask_t, !!asm_opt.ar, ha_opt_triobin(&asm_opt), UL_COV_THRES, cmk, o_file);
    ///@brief debug
    if (asm_opt.flag & HA_F_VERBOSE_GFA) {
        write_debug_graph(sg, sources, coverage_cut, output_file_name, reverse_sources, ruIndex, &UL_INF);
        debug_gfa:;
        gen_ug_opt_t(&uopt, sources, reverse_sources, max_hang_length, mini_overlap_length, gap_fuzz, min_dp, readLen, coverage_cut, ruIndex, 
                (asm_opt.max_short_tip*2), 0.15, 3, 0.05, 0.9, &b_mask_t, te);
        // set_hom_global_coverage(&asm_opt, sg, coverage_cut, sources, reverse_sources, ruIndex, max_hang_length, mini_overlap_length);
    }

    if(asm_opt.ar) {
        gradually_renew_g(&sources, &reverse_sources, &n_read, &readLen, &coverage_cut, ruIndex, 
        &sg, mini_overlap_length, max_hang_length, &uopt, clean_round, min_ovlp_drop_ratio, 
        max_ovlp_drop_ratio, asm_opt.max_short_tip, gap_fuzz, min_dp, &b_mask_t, 
        ha_opt_triobin(&asm_opt), asm_opt.ul_clean_round, o_file, "re", te);
    } else {
        ug_ext_gfa(&uopt, sg, ug_ext_len);
        if(!ha_opt_triobin(&asm_opt)) {
            // output_unitig_graph(sg, coverage_cut, "pre_clean", sources, ruIndex, max_hang_length, mini_overlap_length);
            hic_clean_adv(sg, &uopt);
        }
    }

    /**
    if(asm_opt.ar) {
        renew_g(&sources, &reverse_sources, &n_read, &readLen, &coverage_cut, ruIndex, &sg, mini_overlap_length, max_hang_length,
        &uopt, clean_round, min_ovlp_drop_ratio, max_ovlp_drop_ratio, asm_opt.max_short_tip, &b_mask_t, 
        ha_opt_triobin(&asm_opt), o_file);
        ///make sure uopt has been updated; not necessary
        gen_ug_opt_t(&uopt, sources, reverse_sources, max_hang_length, mini_overlap_length, gap_fuzz, min_dp, readLen, coverage_cut, ruIndex, 
            (asm_opt.max_short_tip*2), 0.15, 3, 0.05, 0.9, &b_mask_t);
    }
    **/
    // print_debug_gfa(sg, NULL, coverage_cut, "UL.debug", sources, ruIndex, max_hang_length, mini_overlap_length, 0, 0, 0);
    /**
    asg_cut_tip(sg, asm_opt.max_short_tip);
    ///debug_info_of_specfic_node("m64043_200505_112554/8849050/ccs", sg, "inner_1");
    ///drop_inexact_edegs_at_bubbles(sg, bubble_dist);
    
    if(clean_round > 0)
    {
        double cut_step;
        if(clean_round == 1)
        {
            cut_step = max_ovlp_drop_ratio;
        }
        else
        {
            cut_step = (max_ovlp_drop_ratio - min_ovlp_drop_ratio) / (clean_round - 1);
        }
        double drop_ratio = min_ovlp_drop_ratio;
        int i = 0;
        for (i = 0; i < clean_round; i++, drop_ratio += cut_step)
        {
            if(drop_ratio > max_ovlp_drop_ratio)
            {
                drop_ratio = max_ovlp_drop_ratio;
            }

            if(VERBOSE >= 1)
            {
                fprintf(stderr, "\n\n**********%d-th round drop: drop_ratio = %f**********\n", 
                i, drop_ratio);
            }

            ///just topological clean
            pre_clean(sources, coverage_cut, sg, 1);
            ///asg_arc_del_orthology(sg, reverse_sources, drop_ratio, asm_opt.max_short_tip);
            // asg_arc_del_orthology_multiple_way(sg, reverse_sources, drop_ratio, asm_opt.max_short_tip);
            // asg_cut_tip(sg, asm_opt.max_short_tip);

            asg_arc_identify_simple_bubbles_multi(sg, &b_mask_t, 1);
            //reomve edge between two chromesomes
            //this node must be a single read
            asg_arc_del_false_node(sg, sources, asm_opt.max_short_tip);
            asg_cut_tip(sg, asm_opt.max_short_tip);

            ///asg_arc_identify_simple_bubbles_multi(sg, 1);
            asg_arc_identify_simple_bubbles_multi(sg, &b_mask_t, 0);
            ///asg_arc_del_short_diploid_unclean_exact(sg, drop_ratio, sources);
            if (ha_opt_triobin(&asm_opt))
            {
                asg_arc_del_short_diploid_by_exact_trio(sg, asm_opt.max_short_tip, sources);
            }
            else
            {
                asg_arc_del_short_diploid_by_exact(sg, asm_opt.max_short_tip, sources);
            }
            asg_cut_tip(sg, asm_opt.max_short_tip);

            asg_arc_identify_simple_bubbles_multi(sg, &b_mask_t, 1);
            if (ha_opt_triobin(&asm_opt))
            {
                asg_arc_del_short_diploid_by_length_trio(sg, drop_ratio, asm_opt.max_short_tip, reverse_sources, 
                asm_opt.max_short_tip, 1, 1, 0, 0, ruIndex);
            }
            else
            {
                asg_arc_del_short_diploid_by_length(sg, drop_ratio, asm_opt.max_short_tip, reverse_sources, 
                asm_opt.max_short_tip, 1, 1, 0, 0, ruIndex);
            }
            asg_cut_tip(sg, asm_opt.max_short_tip);

            asg_arc_identify_simple_bubbles_multi(sg, &b_mask_t, 1);
            asg_arc_del_short_false_link(sg, 0.6, 0.85, bubble_dist, reverse_sources, asm_opt.max_short_tip, ruIndex);     
    
            asg_arc_identify_simple_bubbles_multi(sg, &b_mask_t, 1);
            asg_arc_del_complex_false_link(sg, 0.6, 0.85, bubble_dist, reverse_sources, asm_opt.max_short_tip);

            asg_cut_tip(sg, asm_opt.max_short_tip);
        }
    }
    if(VERBOSE >= 1)
    {
        fprintf(stderr, "\n\n**********final clean**********\n");
    }


    pre_clean(sources, coverage_cut, sg, 1);


    asg_arc_del_short_diploi_by_suspect_edge(sg, asm_opt.max_short_tip);
    asg_cut_tip(sg, asm_opt.max_short_tip);
    asg_arc_del_triangular_directly(sg, asm_opt.max_short_tip, reverse_sources, ruIndex);


    asg_arc_identify_simple_bubbles_multi(sg, &b_mask_t, 0);
    asg_arc_del_orthology_multiple_way(sg, reverse_sources, 0.4, asm_opt.max_short_tip, ruIndex);
    asg_cut_tip(sg, asm_opt.max_short_tip);




    asg_arc_identify_simple_bubbles_multi(sg, &b_mask_t, 0);
    asg_arc_del_too_short_overlaps(sg, 2000, min_ovlp_drop_ratio, reverse_sources, asm_opt.max_short_tip, ruIndex);
    asg_cut_tip(sg, asm_opt.max_short_tip);

    asg_arc_del_simple_circle_untig(sources, coverage_cut, sg, 100, 0);
    
    ///note: don't apply asg_arc_del_too_short_overlaps() after this function!!!!
    rescue_contained_reads_aggressive(NULL, sg, sources, coverage_cut, ruIndex, max_hang_length, 
    mini_overlap_length, 10, 1, 0, NULL, NULL, &b_mask_t);
    rescue_missing_overlaps_aggressive(NULL, sg, sources, coverage_cut, ruIndex, max_hang_length,
    mini_overlap_length, 1, 0, NULL, &b_mask_t);
    rescue_missing_overlaps_backward(NULL, sg, sources, coverage_cut, ruIndex, max_hang_length, 
    mini_overlap_length, 10, 1, 0, &b_mask_t);
    // rescue_wrong_overlaps_to_unitigs(NULL, sg, sources, reverse_sources, coverage_cut, ruIndex, 
    // max_hang_length, mini_overlap_length, bubble_dist, NULL);
    // rescue_no_coverage_aggressive(sg, sources, reverse_sources, &coverage_cut, ruIndex, max_hang_length, 
    // mini_overlap_length, bubble_dist, 10);

    
    set_hom_global_coverage(&asm_opt, sg, coverage_cut, sources, reverse_sources, ruIndex, 
    max_hang_length, mini_overlap_length);

    rescue_bubble_by_chain(sg, coverage_cut, sources, reverse_sources, (asm_opt.max_short_tip*2), 0.15, 3, 
    ruIndex, 0.05, 0.9, max_hang_length, mini_overlap_length, 10, gap_fuzz, &b_mask_t);
    

    output_unitig_graph(sg, coverage_cut, o_file, sources, ruIndex, max_hang_length, mini_overlap_length);
    // flat_bubbles(sg, ruIndex->is_het); free(ruIndex->is_het); ruIndex->is_het = NULL;
    flat_soma_v(sg, sources, ruIndex);
    **/

    output_contig_graph_primary_pre(sg, coverage_cut, o_file, sources, reverse_sources, 
        asm_opt.small_pop_bubble_size, asm_opt.max_short_tip, ruIndex, max_hang_length, mini_overlap_length, &uopt);
    
    // if(asm_opt.ar) {
    //     char *op_file = get_outfile_name(o_file);
    //     ul_clean_gfa(&uopt, sg, sources, reverse_sources, ruIndex, clean_round, min_ovlp_drop_ratio, max_ovlp_drop_ratio, 
    //     0.6, asm_opt.max_short_tip, gap_fuzz, &b_mask_t, 0/**!!asm_opt.ar**/, ha_opt_triobin(&asm_opt), UL_COV_THRES, op_file);
    //     output_contig_graph_primary_pre(sg, coverage_cut, op_file, sources, reverse_sources, 
    //     asm_opt.small_pop_bubble_size, asm_opt.max_short_tip, ruIndex, max_hang_length, mini_overlap_length, &uopt);
    //     free(op_file);
    // }
    /**
    if (asm_opt.flag & HA_F_VERBOSE_GFA)
    {
        write_debug_graph(sg, sources, coverage_cut, output_file_name, n_read, reverse_sources, ruIndex);
        debug_gfa:;
    }**/

    if(asm_opt.fn_bin_poy)
    {
        if(asm_opt.flag & HA_F_PARTITION) asm_opt.flag -= HA_F_PARTITION;
        output_poly_trio(sg, coverage_cut, o_file, sources, reverse_sources, (asm_opt.max_short_tip*2), 0.15, 3, ruIndex, 
        0.05, 0.9, max_hang_length, mini_overlap_length, gap_fuzz, 0, &b_mask_t, asm_opt.polyploidy);
    }
    else if (ha_opt_triobin(&asm_opt) && ha_opt_hic(&asm_opt))
    {
        if(asm_opt.flag & HA_F_PARTITION) asm_opt.flag -= HA_F_PARTITION;
        benchmark_hic_graph(sg, coverage_cut, o_file, sources, reverse_sources, (asm_opt.max_short_tip*2), 0.15, 3, 
        ruIndex, 0.05, 0.9, max_hang_length, mini_overlap_length, gap_fuzz, &b_mask_t);
    }
    else if (ha_opt_triobin(&asm_opt))
    {   
        if(asm_opt.flag & HA_F_PARTITION) asm_opt.flag -= HA_F_PARTITION;
        // output_trio_graph(sg, coverage_cut, o_file, sources, reverse_sources, (asm_opt.max_short_tip*2), 
        // 0.15, 3, ruIndex, 0.05, 0.9, max_hang_length, mini_overlap_length, 0, gap_fuzz, &uopt, &b_mask_t);
        if(asm_opt.trio_cov_het_ovlp > 0) {
            output_bp_trio_graph(sg, coverage_cut, o_file, sources, reverse_sources, (asm_opt.max_short_tip*2), 
            0.15, 3, ruIndex, 0.05, 0.9, max_hang_length, mini_overlap_length, &b_mask_t, gap_fuzz, &uopt);
        } else {
            output_trio_graph_joint(sg, coverage_cut, o_file, sources, reverse_sources, (asm_opt.max_short_tip*2), 
            0.15, 3, ruIndex, 0.05, 0.9, max_hang_length, mini_overlap_length, gap_fuzz, &b_mask_t, NULL, NULL, &uopt);
        }
    }
    else if(ha_opt_hic(&asm_opt))
    {
        if(asm_opt.flag & HA_F_PARTITION) asm_opt.flag -= HA_F_PARTITION;
        if(asm_opt.polyploidy <= 2) {
            output_hic_graph(sg, coverage_cut, o_file, sources, reverse_sources, (asm_opt.max_short_tip*2), 
            0.15, 3, ruIndex, 0.05, 0.9, max_hang_length, mini_overlap_length, gap_fuzz, &b_mask_t, &uopt);
        } else {
            output_hic_graph_mmhap(sg, coverage_cut, o_file, sources, reverse_sources, (asm_opt.max_short_tip*2), 
            0.15, 3, ruIndex, 0.05, 0.9, max_hang_length, mini_overlap_length, gap_fuzz, &b_mask_t, &uopt);
        }
        
        // output_hic_graph_polyploid(sg, coverage_cut, o_file, sources, reverse_sources, (asm_opt.max_short_tip*2), 
        // 0.15, 3, ruIndex, 0.05, 0.9, max_hang_length, mini_overlap_length, gap_fuzz, &b_mask_t);
    }
    else if((asm_opt.flag & HA_F_PARTITION) && (asm_opt.purge_level_primary > 0))
    {
        output_bp_graph(sg, coverage_cut, o_file, sources, reverse_sources, (asm_opt.max_short_tip*2), 
        0.15, 3, ruIndex, 0.05, 0.9, max_hang_length, mini_overlap_length, &b_mask_t, gap_fuzz, &uopt);
    }
    else
    {
        if(asm_opt.flag & HA_F_PARTITION) asm_opt.flag -= HA_F_PARTITION;
        output_contig_graph_primary(sg, coverage_cut, o_file, sources, reverse_sources, 
        (asm_opt.max_short_tip*2), 0.15, 3, ruIndex, 0.05, 0.9, max_hang_length, mini_overlap_length, &b_mask_t);

        output_contig_graph_alternative(sg, coverage_cut, o_file, sources, ruIndex, max_hang_length, mini_overlap_length);
    }

	*coverage_cut_ptr = coverage_cut;
	*sg_ptr = sg;
    destory_bub_label_t(&b_mask_t); 
    if(te) {
        destory_telo_end_t(te); free(te); te = NULL;
    }
    free(o_file); ///if(asm_opt.ar) destory_all_ul_t(&UL_INF); 
    fprintf(stderr, "Inconsistency threshold for low-quality regions in BED files: %u%%\n", asm_opt.bed_inconsist_rate);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movss %xmm1, 0x3c(%rsp)
movss %xmm0, 0x38(%rsp)
movq %r9, 0x48(%rsp)
movq %rcx, %r12
movq %rdx, %r15
movq %rsi, %rbx
movl %edi, 0x2c(%rsp)
movq 0x180(%rsp), %r13
movq 0x178(%rsp), %r14
movq 0x158(%rsp), %rdi
movq %rsi, 0x18(%rsp)
movq %rdx, 0x20(%rsp)
movq %rcx, 0x58(%rsp)
movq %r8, 0x100(%rsp)
movq %r8, 0x50(%rsp)
callq 0x104233
movq %rax, 0x40(%rsp)
movq (%r13), %r13
movq %r13, 0x10(%rsp)
movq (%r14), %rbp
movq %rbp, 0x8(%rsp)
leaq 0x2863d1(%rip), %rax    # 0x295758
movq 0x288(%rax), %rsi
testq %rsi, %rsi
jne 0xf3a1
movq %rax, %r14
movq $0x0, 0x30(%rsp)
jmp 0xf3ce
movq 0x2a0(%rax), %rdx
movq 0x290(%rax), %rcx
movq 0x298(%rax), %r8
movq %rax, %r14
movslq 0x7c(%rax), %r9
leaq 0x286e6c(%rip), %rdi    # 0x296230
callq 0x9f290
movq %rax, 0x30(%rsp)
cmpl $0x0, 0x190(%rsp)
jne 0xf428
movq 0x188(%rsp), %rax
testq %rax, %rax
jne 0xf46c
movq %rbx, %rdi
movq %r15, %rsi
movq %rbp, %rdx
movq %r13, %rcx
movq 0x170(%rsp), %r8
movq %r12, %r9
callq 0xf40f4
movq %r14, %rbp
movl 0x2a8(%r14), %edx
movq %rbx, %rdi
movq %r12, %rsi
xorl %ecx, %ecx
callq 0xa0d55
movq %r15, %rdi
movq %r12, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
jmp 0xf492
movslq 0x2c(%rsp), %rbx
movq %r14, %rbp
movl 0x7c(%r14), %eax
cmpl $0xa, %eax
pushq $0xa
popq %rsi
cmovll %eax, %esi
leaq 0xd8(%rsp), %rdi
movl %r12d, %edx
callq 0xa0272
movq 0x30(%rsp), %r8
movq 0x48(%rsp), %r14
movq 0x170(%rsp), %r15
movq 0x140(%rsp), %r13
jmp 0xf802
movq %r14, %rbp
movl 0x2a8(%r14), %edx
movq %rbx, %rdi
movq %r12, %rsi
movq %rax, %r14
movq %rax, %rcx
callq 0xa0d55
movq %r15, %rdi
movq %r12, %rsi
xorl %edx, %edx
movq %r14, %rcx
callq 0xa0d55
cmpq $0x0, 0x20(%rbp)
je 0xf4a5
cmpq $0x0, 0x28(%rbp)
jne 0xf4b3
cmpq $0x0, 0x30(%rbp)
je 0xf4c0
cmpq $0x0, 0x38(%rbp)
je 0xf4c0
movq %rbx, %rdi
movq %r12, %rsi
callq 0xa1a16
jmp 0xf4d6
leaq 0x286d69(%rip), %rax    # 0x296230
movq 0x28(%rax), %rdi
movq 0x50(%rax), %rdx
xorl %esi, %esi
callq 0x20e0
cmpq $0x0, 0x68(%rbp)
je 0xf4f7
leaq 0x286e34(%rip), %rdi    # 0x296318
leaq 0x286d45(%rip), %rsi    # 0x296230
callq 0x33e0d
cmpq $0x0, 0x68(%rbp)
jne 0xf4fe
xorl %eax, %eax
jmp 0xf5af
movslq 0x2c(%rsp), %rax
movslq 0x11c(%rbp), %rcx
addq %rcx, %rcx
xorps %xmm0, %xmm0
leaq 0x60(%rsp), %rdi
movups %xmm0, 0x40(%rdi)
movups %xmm0, 0x30(%rdi)
movups %xmm0, 0x20(%rdi)
movq %rbx, 0x8(%rdi)
movq %r15, 0x10(%rdi)
movq 0x140(%rsp), %rdx
movl %edx, 0x40(%rdi)
movq 0x48(%rsp), %rdx
movl %edx, 0x44(%rdi)
movq 0x150(%rsp), %rdx
movq %rdx, 0x50(%rdi)
movq %rax, 0x58(%rdi)
movq 0x100(%rsp), %rax
movq %rax, 0x68(%rdi)
movq %r13, (%rdi)
movq 0x170(%rsp), %rax
movq %rax, 0x30(%rdi)
movq %rcx, 0x18(%rdi)
movl $0x3e19999a, 0x20(%rdi) # imm = 0x3E19999A
movq $0x3, 0x28(%rdi)
movsd 0x2267ae(%rip), %xmm0   # 0x235d30
movsd %xmm0, 0x38(%rdi)
leaq 0xd8(%rsp), %rax
movq %rax, 0x60(%rdi)
movq 0x30(%rsp), %r13
movq %r13, 0x70(%rdi)
callq 0x275ce
movq 0x58(%rsp), %r12
movq 0x18(%rsp), %rbx
movq 0x68(%rbp), %rax
cmpq $0x0, 0x2a8(%rbp)
jne 0xf5e2
movq 0x20(%rsp), %rsi
xorl %ecx, %ecx
cmpq $0x1, %rax
sbbl %ecx, %ecx
orl $0x2, %ecx
movq %rbx, %rdi
movq %r12, %rdx
callq 0xb86b6
movq 0x58(%rsp), %r12
movq 0x18(%rsp), %rbx
movq 0x68(%rbp), %rax
movq 0x140(%rsp), %rcx
movq 0x50(%rsp), %r10
testq %rax, %rax
je 0xf5fb
leaq 0x286d1d(%rip), %rax    # 0x296318
leaq 0x10(%rsp), %r15
leaq 0xd8(%rsp), %r11
movl 0x2c(%rsp), %r14d
movl %r14d, %edi
movq %r12, %rsi
movq 0x48(%rsp), %r12
movq %r12, %rdx
movq 0x150(%rsp), %r8
movq %rbx, %r9
movq 0x30(%rsp), %rbx
pushq %rbx
pushq %rax
pushq %r15
pushq %r11
movq %rcx, %r15
movq 0x190(%rsp), %r13
pushq %r13
pushq %r10
callq 0x104535
addq $0x30, %rsp
movq %rax, 0x8(%rsp)
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rcx
movslq %r14d, %r8
movq 0x50(%rsp), %rsi
leaq 0x10(%rsp), %rdi
movq (%rdi), %rdi
xorps %xmm0, %xmm0
movups %xmm0, 0xa0(%rsp)
movups %xmm0, 0x90(%rsp)
movups %xmm0, 0x80(%rsp)
movq %rdx, 0x68(%rsp)
movq %rcx, 0x70(%rsp)
movl %r15d, 0xa0(%rsp)
movl %r12d, 0xa4(%rsp)
leaq 0xd8(%rsp), %r12
movq 0x150(%rsp), %r9
movq %r9, 0xb0(%rsp)
movq %r8, %r15
movq %r8, 0xb8(%rsp)
movq %rsi, 0xc8(%rsp)
movslq 0x11c(%rbp), %r10
movq %rdi, 0x60(%rsp)
leaq (%r10,%r10), %rsi
movq %r13, 0x90(%rsp)
movq %rsi, 0x78(%rsp)
movl $0x3e19999a, 0x80(%rsp) # imm = 0x3E19999A
movq $0x3, 0x88(%rsp)
movsd 0x22662c(%rip), %xmm0   # 0x235d30
movsd %xmm0, 0x98(%rsp)
movq %r12, 0xc0(%rsp)
movq %rbx, 0xd0(%rsp)
cvtss2sd 0x38(%rsp), %xmm0
xorl %r11d, %r11d
cmpq $0x0, 0x68(%rbp)
cvtss2sd 0x3c(%rsp), %xmm1
setne %r11b
cmpq $0x0, 0x20(%rbp)
je 0xf74e
cmpq $0x0, 0x28(%rbp)
je 0xf74e
pushq $0x1
popq %r14
movq 0x40(%rsp), %rbx
jmp 0xf769
xorl %r14d, %r14d
cmpq $0x0, 0x30(%rbp)
movq 0x40(%rsp), %rbx
je 0xf769
xorl %r14d, %r14d
cmpq $0x0, 0x38(%rbp)
setne %r14b
leaq 0x60(%rsp), %rdi
movsd 0x221e12(%rip), %xmm2   # 0x231588
movq %rax, %rsi
movq 0x170(%rsp), %r8
movq 0x148(%rsp), %r9
pushq %rbx
pushq 0x190(%rsp)
pushq $0x2
pushq %r14
pushq %r11
pushq %r12
movq %r8, %r12
pushq 0x180(%rsp)
pushq %r10
callq 0x1fa38d
addq $0x40, %rsp
testb $0x4, (%rbp)
movq 0x48(%rsp), %r14
movq 0x140(%rsp), %r13
je 0xf8cf
movq %r15, %rbx
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x20(%rsp), %r8
subq $0x8, %rsp
leaq 0x286b31(%rip), %rax    # 0x296318
movq 0x160(%rsp), %rcx
movq %r12, %r15
movq %r12, %r9
pushq %rax
callq 0xd685
popq %rcx
popq %rdx
movq 0x30(%rsp), %r8
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rcx
movq 0x50(%rsp), %rdx
movq 0x10(%rsp), %rsi
movslq 0x11c(%rbp), %rdi
addq %rdi, %rdi
xorps %xmm0, %xmm0
movups %xmm0, 0xa0(%rsp)
movups %xmm0, 0x90(%rsp)
movups %xmm0, 0x80(%rsp)
movq %rax, 0x68(%rsp)
movq %rcx, 0x70(%rsp)
movl %r13d, 0xa0(%rsp)
movl %r14d, 0xa4(%rsp)
movq 0x150(%rsp), %rax
movq %rax, 0xb0(%rsp)
movq %rbx, 0xb8(%rsp)
movq %rdx, 0xc8(%rsp)
movq %rsi, 0x60(%rsp)
movq %r15, %r12
movq %r15, 0x90(%rsp)
movq %rdi, 0x78(%rsp)
movl $0x3e19999a, 0x80(%rsp) # imm = 0x3E19999A
movq $0x3, 0x88(%rsp)
movsd 0x226487(%rip), %xmm0   # 0x235d30
movsd %xmm0, 0x98(%rsp)
leaq 0xd8(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq %r8, 0x30(%rsp)
movq %r8, 0xd0(%rsp)
cmpq $0x0, 0x68(%rbp)
jne 0xf92c
movq 0x8(%rsp), %rsi
leaq 0x60(%rsp), %rdi
movl $0x124f8, %edx          # imm = 0x124F8
callq 0x1faec1
cmpq $0x0, 0x20(%rbp)
movq 0x30(%rsp), %r15
movq 0x40(%rsp), %rbx
je 0xf906
cmpq $0x0, 0x28(%rbp)
jne 0xf9f1
cmpq $0x0, 0x30(%rbp)
je 0xf918
cmpq $0x0, 0x38(%rbp)
jne 0xf9f1
movq 0x8(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0xc1328
jmp 0xf9f1
cvtss2sd 0x38(%rsp), %xmm0
cvtss2sd 0x3c(%rsp), %xmm1
movslq 0x2c(%rsp), %rax
movl 0x250(%rbp), %ecx
subq $0x70, %rsp
movq 0xa0(%rsp), %r15
movq %r15, 0x68(%rsp)
leaq 0x2336c2(%rip), %rdx    # 0x24301d
movq %rdx, 0x60(%rsp)
movq 0xb0(%rsp), %rbx
movq %rbx, 0x58(%rsp)
movl %ecx, 0x50(%rsp)
leaq 0x148(%rsp), %rcx
movq %rcx, 0x40(%rsp)
movq %rax, 0x38(%rsp)
movq 0x1c0(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x1b8(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0xd0(%rsp), %rax
movq %rax, 0x18(%rsp)
movq %r13, 0x10(%rsp)
movq %r14, 0x8(%rsp)
leaq 0x78(%rsp), %rax
movq %rax, (%rsp)
leaq 0x88(%rsp), %rdi
leaq 0x90(%rsp), %rsi
leaq 0xc8(%rsp), %rdx
leaq 0xc0(%rsp), %rcx
leaq 0x80(%rsp), %r8
movq %r12, %r9
callq 0x104901
addq $0x70, %rsp
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rcx
movq 0x180(%rbp), %r9
subq $0x30, %rsp
movl %r14d, 0x18(%rsp)
movl %r13d, 0x10(%rsp)
movq %r12, 0x8(%rsp)
movq %rbx, %rdx
callq 0xd93c
addq $0x30, %rsp
cmpq $0x0, 0x40(%rbp)
jne 0xfb1c
cmpq $0x0, 0x20(%rbp)
sete %cl
cmpq $0x0, 0x28(%rbp)
sete %al
orb %cl, %al
cmpb $0x1, %al
jne 0xfb96
cmpq $0x0, 0x30(%rbp)
je 0xfa85
cmpq $0x0, 0x38(%rbp)
je 0xfa85
cmpq $0x0, 0x50(%rbp)
je 0xfa6b
cmpq $0x0, 0x58(%rbp)
jne 0xfba4
testb %al, %al
je 0xfc14
cmpq $0x0, 0x30(%rbp)
je 0xfa85
cmpq $0x0, 0x38(%rbp)
jne 0xfc14
cmpq $0x0, 0x50(%rbp)
movl (%rbp), %eax
je 0xfd08
cmpq $0x0, 0x58(%rbp)
je 0xfd08
btl $0xb, %eax
jae 0xfaac
addl $0xfffff800, %eax       # imm = 0xFFFFF800
movl %eax, (%rbp)
movslq 0x11c(%rbp), %r9
addq %r9, %r9
cmpl $0x2, 0x1bc(%rbp)
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r8
jg 0xfe82
subq $0x8, %rsp
leaq 0x68(%rsp), %rax
leaq 0xe0(%rsp), %r10
movss 0x2262c8(%rip), %xmm0   # 0x235db8
movss 0x2262c4(%rip), %xmm1   # 0x235dbc
movss 0x2262b4(%rip), %xmm2   # 0x235db4
movq %rbx, %rdx
pushq %rax
pushq %r10
pushq 0x168(%rsp)
pushq %r14
pushq %r13
pushq %r12
pushq $0x3
callq 0xc8852
jmp 0xfb8d
movl (%rbp), %eax
btl $0xb, %eax
jae 0xfb2d
addl $0xfffff800, %eax       # imm = 0xFFFFF800
movl %eax, (%rbp)
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r8
movslq 0x11c(%rbp), %r9
addq %r9, %r9
movl 0x1bc(%rbp), %eax
leaq 0xd8(%rsp), %r10
movss 0x226257(%rip), %xmm0   # 0x235db8
movss 0x226253(%rip), %xmm1   # 0x235dbc
movss 0x226243(%rip), %xmm2   # 0x235db4
movq %rbx, %rdx
pushq %rax
pushq %r10
pushq $0x0
pushq 0x168(%rsp)
pushq %r14
pushq %r13
pushq %r12
pushq $0x3
callq 0xc2ed2
addq $0x40, %rsp
jmp 0xfe07
cmpq $0x0, 0x50(%rbp)
je 0xfc14
cmpq $0x0, 0x58(%rbp)
je 0xfc14
movl (%rbp), %eax
btl $0xb, %eax
jae 0xfbb5
addl $0xfffff800, %eax       # imm = 0xFFFFF800
movl %eax, (%rbp)
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r8
movslq 0x11c(%rbp), %r9
addq %r9, %r9
leaq 0xd8(%rsp), %rax
movss 0x2261d5(%rip), %xmm0   # 0x235db8
movss 0x2261d1(%rip), %xmm1   # 0x235dbc
movss 0x2261c1(%rip), %xmm2   # 0x235db4
movq %rbx, %rdx
pushq %rax
pushq 0x158(%rsp)
pushq %r14
pushq %r13
pushq %r12
pushq $0x3
callq 0xa213
addq $0x30, %rsp
jmp 0xfe07
movl (%rbp), %eax
btl $0xb, %eax
jae 0xfc25
addl $0xfffff800, %eax       # imm = 0xFFFFF800
movl %eax, (%rbp)
movslq 0x11c(%rbp), %r9
addq %r9, %r9
cmpq $0x0, 0x220(%rbp)
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r8
jle 0xfc95
subq $0x8, %rsp
leaq 0x68(%rsp), %rax
leaq 0xe0(%rsp), %r10
movss 0x226152(%rip), %xmm0   # 0x235db8
movss 0x22614e(%rip), %xmm1   # 0x235dbc
movss 0x22613e(%rip), %xmm2   # 0x235db4
movq %rbx, %rdx
pushq %rax
pushq 0x160(%rsp)
pushq %r10
pushq %r14
pushq %r13
pushq %r12
pushq $0x3
callq 0x9fa2
jmp 0xfb8d
subq $0x50, %rsp
leaq 0xb0(%rsp), %rax
movq %rax, 0x40(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rsp)
leaq 0x128(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x1a0(%rsp), %rax
movq %rax, 0x20(%rsp)
movl %r14d, 0x18(%rsp)
movl %r13d, 0x10(%rsp)
movq %r12, 0x8(%rsp)
movq $0x3, (%rsp)
movss 0x2260d1(%rip), %xmm0   # 0x235db8
movss 0x2260cd(%rip), %xmm1   # 0x235dbc
movss 0x2260bd(%rip), %xmm2   # 0x235db4
movq %rbx, %rdx
callq 0x8a60
addq $0x50, %rsp
jmp 0xfe07
btl $0xb, %eax
jae 0xfd7d
cmpl $0x0, 0x130(%rbp)
jle 0xfd7d
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r8
movslq 0x11c(%rbp), %r9
addq %r9, %r9
subq $0x8, %rsp
leaq 0x68(%rsp), %rax
leaq 0xe0(%rsp), %r10
movss 0x22606a(%rip), %xmm0   # 0x235db8
movss 0x226066(%rip), %xmm1   # 0x235dbc
movss 0x226056(%rip), %xmm2   # 0x235db4
movq %rbx, %rdx
pushq %rax
pushq 0x160(%rsp)
pushq %r10
pushq %r14
pushq %r13
pushq %r12
pushq $0x3
callq 0x9d5a
jmp 0xfb8d
btl $0xb, %eax
jae 0xfd8b
addl $0xfffff800, %eax       # imm = 0xFFFFF800
movl %eax, (%rbp)
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r8
movslq 0x11c(%rbp), %r9
addq %r9, %r9
subq $0x8, %rsp
leaq 0xe0(%rsp), %rax
movss 0x225ffb(%rip), %xmm0   # 0x235db8
movss 0x225ff7(%rip), %xmm1   # 0x235dbc
movss 0x225fe7(%rip), %xmm2   # 0x235db4
movq %rbx, %rdx
pushq %rax
pushq %r14
pushq %r13
pushq %r12
pushq $0x3
callq 0xdc1d
addq $0x30, %rsp
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rcx
subq $0x8, %rsp
movq %rbx, %rdx
movq %r12, %r8
movl %r13d, %r9d
pushq %r14
callq 0x8832
popq %rax
popq %rcx
movq 0x10(%rsp), %rax
movq 0x180(%rsp), %rcx
movq %rax, (%rcx)
movq 0x8(%rsp), %rax
movq 0x178(%rsp), %rcx
movq %rax, (%rcx)
leaq 0xd8(%rsp), %rdi
callq 0xa039f
testq %r15, %r15
je 0xfe4a
movq 0x10(%r15), %rdi
callq 0x2220
movq %r15, %rdi
callq 0x2220
movq %rbx, %rdi
callq 0x2220
movq 0x285187(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
movl 0x150(%rbp), %edx
leaq 0x229216(%rip), %rsi    # 0x23907f
xorl %eax, %eax
callq 0x22b0
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
subq $0x8, %rsp
leaq 0x68(%rsp), %rax
leaq 0xe0(%rsp), %r10
movss 0x225f1d(%rip), %xmm0   # 0x235db8
movss 0x225f19(%rip), %xmm1   # 0x235dbc
movss 0x225f09(%rip), %xmm2   # 0x235db4
movq %rbx, %rdx
pushq %rax
pushq %r10
pushq 0x168(%rsp)
pushq %r14
pushq %r13
pushq %r12
pushq $0x3
callq 0xc9fa8
jmp 0xfb8d