// File: chhylp123[P]hifiasm/Purge_Dups.cpp
// Function: purge_dups(ma_ug_t*, asg_t*, ma_sub_t*, ma_hit_t_alloc*, ma_hit_t_alloc*, R_to_U*, kvec_asg_arc_t_warp*, float, unsigned int, int, int, float, unsigned int, unsigned int, hap_cov_t*, unsigned int, unsigned int)
void purge_dups(ma_ug_t *ug, asg_t *read_g, ma_sub_t* coverage_cut, ma_hit_t_alloc* sources, 
ma_hit_t_alloc* reverse_sources, R_to_U* ruIndex, kvec_asg_arc_t_warp* edge, float density, 
uint32_t purege_minLen, int max_hang, int min_ovlp, float drop_ratio, uint32_t just_contain, 
uint32_t just_coverage, hap_cov_t *cov, uint32_t collect_p_trans, uint32_t collect_p_trans_f)
{
    p_g_t *pg = NULL;
    asg_t* nsg = ug->g;
    uint32_t v, rId, uId, i, offset;
    ma_utg_t* reads = NULL;
    uint64_t* position_index = NULL;
    if(cov) position_index = cov->pos_idx;
    else position_index = (uint64_t*)malloc(sizeof(uint64_t)*read_g->n_seq);
    memset(position_index, -1, sizeof(uint64_t)*read_g->n_seq);
    
    hap_overlaps_list all_ovlp;
    init_hap_overlaps_list(&all_ovlp, nsg->n_seq);
    hap_overlaps_list back_all_ovlp;
    init_hap_overlaps_list(&back_all_ovlp, nsg->n_seq);
    asg_arc_t t, *p = NULL;
    int r;
    hap_alignment_struct_pip hap_buf;
    long long k_mer_only, coverage_only;

    if(asm_opt.hom_global_coverage != -1)
    {
        hap_buf.cov_threshold = (asm_opt.hom_global_coverage_set?
                (((double)asm_opt.hom_global_coverage)*((double)HOM_PEAK_RATE)):(asm_opt.hom_global_coverage));
    }
    else
    {
        hap_buf.cov_threshold = get_read_coverage_thres(ug, read_g, ruIndex, position_index, 
        sources, coverage_cut, read_g->n_seq, COV_COUNT, &k_mer_only, &coverage_only);
    }
    
    
    for (v = 0; v < nsg->n_seq; v++)
    {
        uId = v;
        reads = &(ug->u.a[uId]);
        for (i = 0, offset = 0; i < reads->n; i++)
        {
            rId = reads->a[i]>>33;
            set_R_to_U(ruIndex, rId, uId, 1, &(read_g->seq[rId].c));

            position_index[rId] = offset;
            position_index[rId] = position_index[rId] << 32;
            position_index[rId] = position_index[rId] | (uint64_t)i;

            offset += (uint32_t)reads->a[i];
        }
    }

    // if(just_coverage == 0)
    // {
    //     ma_ug_seq(ug, read_g, coverage_cut, sources, edge, max_hang, min_ovlp, 0, 0);
    // }
    // init_ug_idx(ug, asm_opt.k_mer_length, asm_opt.polyploidy, 2, !just_coverage);
    
    init_hap_alignment_struct_pip(&hap_buf, asm_opt.thread_num, nsg->n_seq, ug, read_g,  
    sources, reverse_sources, ruIndex, coverage_cut, position_index, density, max_hang, min_ovlp, 
    0.1, &all_ovlp, cov);
    
    if(hap_buf.cov_threshold < 0)
    {
        if(if_ploid_sample(ug, read_g, ruIndex, sources, reverse_sources, coverage_cut, 
        &hap_buf, &all_ovlp, &back_all_ovlp, purege_minLen, 0.333))
        {
            ///if peak is het, coverage peak is more reliable 
            hap_buf.cov_threshold = coverage_only * HET_PEAK_RATE;
        }
        else
        {
            ///if peak is homo, k-mer peak is more reliable 
            hap_buf.cov_threshold = k_mer_only * HOM_PEAK_RATE;
        }
    }
    if(asm_opt.hom_global_coverage == -1) asm_opt.hom_global_coverage = hap_buf.cov_threshold;
    if(asm_opt.pur_global_coverage != -1) hap_buf.cov_threshold = asm_opt.pur_global_coverage;
    fprintf(stderr, "[M::%s] homozygous read coverage threshold: %d\n", __func__, asm_opt.hom_global_coverage_set?
                            asm_opt.hom_global_coverage:(int)(((double)asm_opt.hom_global_coverage)/((double)HOM_PEAK_RATE)));
    fprintf(stderr, "[M::%s] purge duplication coverage threshold: %lld\n", __func__, hap_buf.cov_threshold);
    if(just_coverage) goto end_coverage;

    kt_for(asm_opt.thread_num, hap_alignment_advance_worker, &hap_buf, nsg->n_seq);
    
    ///if(debug_enable) print_all_purge_ovlp(ug, &all_ovlp);
    filter_hap_overlaps_by_length(&all_ovlp, purege_minLen);

    // normalize_hap_overlaps_advance(&all_ovlp, &back_all_ovlp, ug, read_g, reverse_sources, ruIndex);
    pg = init_p_g_t(ug, cov, read_g);
    normalize_hap_overlaps_advance_by_p_g_t(&all_ovlp, &back_all_ovlp, ug, read_g, reverse_sources, ruIndex, pg, cov, 0.8);

    if(collect_p_trans && collect_p_trans_f == 0)
    {
        collect_purge_trans_cov(ug, &all_ovlp, cov, position_index);
    } 
    
    if(asm_opt.polyploidy <= 2)
    {
        mc_solve(&all_ovlp, cov->t_ch, NULL, ug, read_g, 0.8, R_INF.trio_flag, 1, NULL, 1, NULL, NULL, 1, 0);
    } 
    
    if(collect_p_trans && collect_p_trans_f == 1)
    {
        collect_purge_trans_cov(ug, &all_ovlp, cov, position_index);
    } 

    ///normalize_hap_overlaps_advance(&all_ovlp, &back_all_ovlp, ug, read_g, reverse_sources, ruIndex);
    ///debug_hap_overlaps(&all_ovlp, &back_all_ovlp);

    remove_contained_haplotig(&all_ovlp, ug, nsg, pg->pg_h_lev, cov);
    
    if(just_contain == 0)
    {
        for (v = 0; v < all_ovlp.num; v++)
        {
            uId = v;
            if(pg->pg_h_lev->seq[uId].del || pg->pg_h_lev->seq[uId].c == ALTER_LABLE) continue;
            for (i = 0; i < all_ovlp.x[uId].a.n; i++)
            {
                if(all_ovlp.x[uId].a.a[i].status == DELETE) continue;
                if(pg->pg_h_lev->seq[all_ovlp.x[uId].a.a[i].xUid].c == ALTER_LABLE||
                   pg->pg_h_lev->seq[all_ovlp.x[uId].a.a[i].xUid].del||
                   pg->pg_h_lev->seq[all_ovlp.x[uId].a.a[i].yUid].c == ALTER_LABLE||
                   pg->pg_h_lev->seq[all_ovlp.x[uId].a.a[i].yUid].del)
                {
                    continue;
                }

                
                ///print_hap_paf(ug, &(all_ovlp.x[uId].a.a[i]));
                
                r = get_hap_arch(&(all_ovlp.x[uId].a.a[i]), ug->u.a[all_ovlp.x[uId].a.a[i].xUid].len, 
                ug->u.a[all_ovlp.x[uId].a.a[i].yUid].len, max_hang, asm_opt.max_hang_rate, min_ovlp, &t);
                
                if(r < 0) continue;
                p = asg_arc_pushp(pg->pg_h_lev);
                *p = t;
            }
        }

        asg_cleanup(pg->pg_h_lev);
		asg_symm(pg->pg_h_lev);
        ///may need to do transitive reduction
        clean_purge_graph(pg->pg_h_lev, drop_ratio, 1);

        // if(debug_enable) print_purge_gfa(ug, purge_g);
        // if(debug_enable) print_all_purge_ovlp(ug, &all_ovlp);
        /*******************************for debug************************************/
        // print_het_ovlp(pg, ug, &all_ovlp, 0.8);
        /*******************************for debug************************************/

        link_unitigs(pg->pg_h_lev, ug, &all_ovlp, ruIndex, reverse_sources, coverage_cut, read_g, position_index, 
        &(hap_buf.buf[0].u_buffer), &(hap_buf.buf[0].u_buffer_tailIndex), &(hap_buf.buf[0].u_buffer_prevIndex),
        max_hang, min_ovlp, edge, hap_buf.buf[0].visit, cov);
    }

    for (v = 0; v < all_ovlp.num; v++)
    {
        uId = v;
        if(pg->pg_h_lev->seq[uId].c == ALTER_LABLE)
        {
            ug->g->seq[uId].c = ALTER_LABLE;
        }
    }

    end_coverage:
    uint32_t is_Unitig;
    for (v = 0; v < ruIndex->len; v++)
    {
        get_R_to_U(ruIndex, v, &uId, &is_Unitig);
        if(is_Unitig == 1) ruIndex->index[v] = (uint32_t)-1;
    }
    asg_cleanup(nsg);
    destory_hap_overlaps_list(&all_ovlp);
    destory_hap_overlaps_list(&back_all_ovlp);
    if(cov) memset(position_index, -1, sizeof(uint64_t)*read_g->n_seq);
    else free(position_index);
    destory_hap_alignment_struct_pip(&hap_buf);
    destory_p_g_t(&pg);
    // if(just_coverage == 0)
    // {
    //     des_ug_idx();
    //     for (i = 0; i < ug->u.n; i++)
    //     {
    //         free(ug->u.a[i].s);
    //         ug->u.a[i].s = NULL;
    //     }
    // }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
movl 0x50(%rbp), %eax
movl 0x48(%rbp), %eax
movq 0x40(%rbp), %rax
movl 0x38(%rbp), %eax
movl 0x30(%rbp), %eax
movl 0x28(%rbp), %eax
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movq %rdi, -0x30(%rbp)
movq %rsi, -0x38(%rbp)
movq %rdx, -0x40(%rbp)
movq %rcx, -0x48(%rbp)
movq %r8, -0x50(%rbp)
movq %r9, -0x58(%rbp)
movss %xmm0, -0x5c(%rbp)
movss %xmm1, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x70(%rbp)
movq $0x0, -0x90(%rbp)
movq $0x0, -0x98(%rbp)
cmpq $0x0, 0x40(%rbp)
je 0x184b55
movq 0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x98(%rbp)
jmp 0x184b75
movq -0x38(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edi
shlq $0x3, %rdi
callq 0x2270
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edx
shlq $0x3, %rdx
movl $0xff, %esi
callq 0x2100
movq -0x70(%rbp), %rax
movl 0x14(%rax), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
leaq -0xa8(%rbp), %rdi
callq 0x16ff70
movq -0x70(%rbp), %rax
movl 0x14(%rax), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
leaq -0xb8(%rbp), %rdi
callq 0x16ff70
movq $0x0, -0xd8(%rbp)
leaq 0x23fc1a(%rip), %rax    # 0x3c47f8
cmpl $-0x1, 0x144(%rax)
je 0x184c49
leaq 0x23fc0a(%rip), %rax    # 0x3c47f8
cmpl $0x0, 0x148(%rax)
je 0x184c1c
leaq 0x23fbfa(%rip), %rax    # 0x3c47f8
cvtsi2sdl 0x144(%rax), %xmm0
movsd 0x201c32(%rip), %xmm1   # 0x386840
mulsd %xmm1, %xmm0
movsd %xmm0, -0x178(%rbp)
jmp 0x184c33
leaq 0x23fbd5(%rip), %rax    # 0x3c47f8
cvtsi2sdl 0x144(%rax), %xmm0
movsd %xmm0, -0x178(%rbp)
movsd -0x178(%rbp), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0xf0(%rbp)
jmp 0x184ca6
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0x98(%rbp), %rcx
movq -0x48(%rbp), %r8
movq -0x40(%rbp), %r9
movq -0x38(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %r11d
leaq -0x160(%rbp), %r10
leaq -0x168(%rbp), %rax
movq %r11, (%rsp)
movq $0x400, 0x8(%rsp)       # imm = 0x400
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x16f6a0
movq %rax, -0xf0(%rbp)
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
movq -0x70(%rbp), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0x184ddf
movl -0x74(%rbp), %eax
movl %eax, -0x7c(%rbp)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x7c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movl $0x0, -0x80(%rbp)
movl $0x0, -0x84(%rbp)
movl -0x80(%rbp), %eax
movq -0x90(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x184dcf
movq -0x90(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x80(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movl %eax, -0x78(%rbp)
movq -0x58(%rbp), %rdi
movl -0x78(%rbp), %esi
movl -0x7c(%rbp), %edx
movq -0x38(%rbp), %rax
movq 0x20(%rax), %r8
movl -0x78(%rbp), %eax
shlq $0x3, %rax
addq %rax, %r8
addq $0x4, %r8
movl $0x1, %ecx
callq 0xd0e20
movl -0x84(%rbp), %eax
movl %eax, %edx
movq -0x98(%rbp), %rax
movl -0x78(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x98(%rbp), %rax
movl -0x78(%rbp), %ecx
movq (%rax,%rcx,8), %rdx
shlq $0x20, %rdx
movq -0x98(%rbp), %rax
movl -0x78(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x98(%rbp), %rax
movl -0x78(%rbp), %ecx
movq (%rax,%rcx,8), %rdx
movl -0x80(%rbp), %eax
orq %rax, %rdx
movq -0x98(%rbp), %rax
movl -0x78(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x90(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x80(%rbp), %ecx
movq (%rax,%rcx,8), %rax
addl -0x84(%rbp), %eax
movl %eax, -0x84(%rbp)
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x184cf5
jmp 0x184dd1
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x184cad
leaq 0x23fa12(%rip), %rax    # 0x3c47f8
movl 0x7c(%rax), %esi
movq -0x70(%rbp), %rax
movl 0x14(%rax), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %r8
movq -0x48(%rbp), %r9
movq -0x50(%rbp), %r13
movq -0x58(%rbp), %r12
movq -0x40(%rbp), %r15
movq -0x98(%rbp), %r14
movss -0x5c(%rbp), %xmm0
movl 0x20(%rbp), %ebx
movl 0x28(%rbp), %r11d
movq 0x40(%rbp), %rax
leaq -0x158(%rbp), %rdi
movss 0x201a64(%rip), %xmm1   # 0x386898
leaq -0xa8(%rbp), %r10
movq %r13, (%rsp)
movq %r12, 0x8(%rsp)
movq %r15, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movl %ebx, 0x20(%rsp)
movl %r11d, 0x28(%rsp)
movq %r10, 0x30(%rsp)
movq %rax, 0x38(%rsp)
callq 0x16fd00
cmpq $0x0, -0xf0(%rbp)
jge 0x184f0e
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x50(%rbp), %r8
movq -0x40(%rbp), %r9
movl 0x18(%rbp), %eax
leaq -0x158(%rbp), %rbx
leaq -0xa8(%rbp), %r11
leaq -0xb8(%rbp), %r10
movsd 0x20540c(%rip), %xmm0   # 0x38a2b8
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movl %eax, 0x18(%rsp)
callq 0x1812f0
cmpl $0x0, %eax
je 0x184eeb
cvtsi2sdq -0x168(%rbp), %xmm0
movsd 0x201997(%rip), %xmm1   # 0x386870
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0xf0(%rbp)
jmp 0x184f0c
cvtsi2sdq -0x160(%rbp), %xmm0
movsd 0x201944(%rip), %xmm1   # 0x386840
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0xf0(%rbp)
jmp 0x184f0e
leaq 0x23f8e3(%rip), %rax    # 0x3c47f8
cmpl $-0x1, 0x144(%rax)
jne 0x184f34
movq -0xf0(%rbp), %rax
movl %eax, %ecx
leaq 0x23f8ca(%rip), %rax    # 0x3c47f8
movl %ecx, 0x144(%rax)
leaq 0x23f8bd(%rip), %rax    # 0x3c47f8
cmpl $-0x1, 0x14c(%rax)
je 0x184f59
leaq 0x23f8ad(%rip), %rax    # 0x3c47f8
movslq 0x14c(%rax), %rax
movq %rax, -0xf0(%rbp)
movq 0x23f080(%rip), %rax    # 0x3c3fe0
movq (%rax), %rax
movq %rax, -0x180(%rbp)
leaq 0x23f887(%rip), %rax    # 0x3c47f8
cmpl $0x0, 0x148(%rax)
je 0x184f8f
leaq 0x23f877(%rip), %rax    # 0x3c47f8
movl 0x144(%rax), %eax
movl %eax, -0x184(%rbp)
jmp 0x184fb4
leaq 0x23f862(%rip), %rax    # 0x3c47f8
cvtsi2sdl 0x144(%rax), %xmm0
movsd 0x20189a(%rip), %xmm1   # 0x386840
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x184(%rbp)
movq -0x180(%rbp), %rdi
movl -0x184(%rbp), %ecx
leaq 0x20579d(%rip), %rsi    # 0x38a765
leaq 0x2057c6(%rip), %rdx    # 0x38a795
movb $0x0, %al
callq 0x22a0
movq 0x23f003(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0xf0(%rbp), %rcx
leaq 0x2057b2(%rip), %rsi    # 0x38a7a0
leaq 0x2057a0(%rip), %rdx    # 0x38a795
movb $0x0, %al
callq 0x22a0
cmpl $0x0, 0x38(%rbp)
je 0x185007
jmp 0x185576
leaq 0x23f7ea(%rip), %rax    # 0x3c47f8
movl 0x7c(%rax), %edi
movq -0x70(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
leaq -0x3ab8(%rip), %rsi     # 0x181570
leaq -0x158(%rbp), %rdx
callq 0x16d710
movl 0x18(%rbp), %esi
leaq -0xa8(%rbp), %rdi
callq 0x17ba50
movq -0x30(%rbp), %rdi
movq 0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x1836d0
movq %rax, -0x68(%rbp)
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x50(%rbp), %r8
movq -0x58(%rbp), %r9
movq -0x68(%rbp), %r10
movq 0x40(%rbp), %rax
leaq -0xa8(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
movsd 0x1fd1aa(%rip), %xmm0   # 0x382230
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x17adb0
cmpl $0x0, 0x48(%rbp)
je 0x1850bb
cmpl $0x0, 0x50(%rbp)
jne 0x1850bb
movq -0x30(%rbp), %rdi
movq 0x40(%rbp), %rdx
movq -0x98(%rbp), %rcx
leaq -0xa8(%rbp), %rsi
callq 0x1842d0
leaq 0x23f736(%rip), %rax    # 0x3c47f8
cmpl $0x2, 0x1bc(%rax)
jg 0x18513d
movq 0x40(%rbp), %rax
movq 0xa8(%rax), %rsi
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %r8
leaq 0x2401eb(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %r9
leaq -0xa8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
movsd 0x1fd134(%rip), %xmm0   # 0x382230
xorl %eax, %eax
movl $0x1, (%rsp)
movq $0x0, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
movl $0x1, 0x28(%rsp)
movl $0x0, 0x30(%rsp)
callq 0x227770
cmpl $0x0, 0x48(%rbp)
je 0x185164
cmpl $0x1, 0x50(%rbp)
jne 0x185164
movq -0x30(%rbp), %rdi
movq 0x40(%rbp), %rdx
movq -0x98(%rbp), %rcx
leaq -0xa8(%rbp), %rsi
callq 0x1842d0
movq -0x30(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq -0x68(%rbp), %rax
movq 0x28(%rax), %rcx
movq 0x40(%rbp), %r8
leaq -0xa8(%rbp), %rdi
callq 0x182fe0
cmpl $0x0, 0x30(%rbp)
jne 0x185522
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
cmpl -0xa0(%rbp), %eax
jae 0x18543b
movl -0x74(%rbp), %eax
movl %eax, -0x7c(%rbp)
movq -0x68(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x20(%rax), %rax
movl -0x7c(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x1851dd
movq -0x68(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x20(%rax), %rax
movl -0x7c(%rbp), %ecx
movzbl 0x4(%rax,%rcx,8), %eax
cmpl $0x1, %eax
jne 0x1851e2
jmp 0x18542d
movl $0x0, -0x80(%rbp)
movl -0x80(%rbp), %eax
movq -0xa8(%rbp), %rcx
movl -0x7c(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jae 0x18542b
movq -0xa8(%rbp), %rax
movl -0x7c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl -0x80(%rbp), %ecx
shlq $0x6, %rcx
addq %rcx, %rax
movzbl 0x2(%rax), %eax
cmpl $0x2, %eax
jne 0x185233
jmp 0x18541d
movq -0x68(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x20(%rax), %rax
movq -0xa8(%rbp), %rcx
movl -0x7c(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq 0x10(%rcx), %rcx
movl -0x80(%rbp), %edx
shlq $0x6, %rdx
addq %rdx, %rcx
movl 0x24(%rcx), %ecx
movzbl 0x4(%rax,%rcx,8), %eax
cmpl $0x1, %eax
je 0x185319
movq -0x68(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x20(%rax), %rax
movq -0xa8(%rbp), %rcx
movl -0x7c(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq 0x10(%rcx), %rcx
movl -0x80(%rbp), %edx
shlq $0x6, %rdx
addq %rdx, %rcx
movl 0x24(%rcx), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x185319
movq -0x68(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x20(%rax), %rax
movq -0xa8(%rbp), %rcx
movl -0x7c(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq 0x10(%rcx), %rcx
movl -0x80(%rbp), %edx
shlq $0x6, %rdx
addq %rdx, %rcx
movl 0x28(%rcx), %ecx
movzbl 0x4(%rax,%rcx,8), %eax
cmpl $0x1, %eax
je 0x185319
movq -0x68(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x20(%rax), %rax
movq -0xa8(%rbp), %rcx
movl -0x7c(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq 0x10(%rcx), %rcx
movl -0x80(%rbp), %edx
shlq $0x6, %rdx
addq %rdx, %rcx
movl 0x28(%rcx), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x18531e
jmp 0x18541d
movq -0xa8(%rbp), %rax
movl -0x7c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rdi
movl -0x80(%rbp), %eax
shlq $0x6, %rax
addq %rax, %rdi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0xa8(%rbp), %rcx
movl -0x7c(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq 0x10(%rcx), %rcx
movl -0x80(%rbp), %edx
shlq $0x6, %rdx
addq %rdx, %rcx
movl 0x24(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0xa8(%rbp), %rcx
movl -0x7c(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq 0x10(%rcx), %rcx
movl -0x80(%rbp), %edx
shlq $0x6, %rdx
addq %rdx, %rcx
movl 0x28(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl 0x20(%rbp), %ecx
leaq 0x23f43f(%rip), %rax    # 0x3c47f8
movss 0x158(%rax), %xmm0
movl 0x28(%rbp), %r8d
leaq -0xd0(%rbp), %r9
callq 0x17ce40
movl %eax, -0xdc(%rbp)
cmpl $0x0, -0xdc(%rbp)
jge 0x1853e2
jmp 0x18541d
movq -0x68(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x185650
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movq -0xd0(%rbp), %rcx
movq %rcx, (%rax)
movq -0xc8(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0xc0(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x1851e9
jmp 0x18542d
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x185195
movq -0x68(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0xcdd10
movq -0x68(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0xce020
movq -0x68(%rbp), %rax
movq 0x28(%rax), %rdi
movss -0x60(%rbp), %xmm0
movl $0x1, %esi
callq 0x17d9a0
movq -0x68(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x30(%rbp), %rsi
movq -0x58(%rbp), %rcx
movq -0x50(%rbp), %r8
movq -0x40(%rbp), %r9
movq -0x38(%rbp), %rax
movq -0x98(%rbp), %rdx
movq %rdx, -0x198(%rbp)
movq -0x158(%rbp), %r13
addq $0x30, %r13
movq -0x158(%rbp), %r12
addq $0x50, %r12
movq -0x158(%rbp), %r15
addq $0x70, %r15
movl 0x20(%rbp), %r14d
movl 0x28(%rbp), %ebx
movq 0x10(%rbp), %r11
movq -0x158(%rbp), %rdx
movq 0x8(%rdx), %r10
movq 0x40(%rbp), %rdx
movq %rdx, -0x190(%rbp)
leaq -0xa8(%rbp), %rdx
movq %rax, (%rsp)
movq -0x198(%rbp), %rax
movq %rax, 0x8(%rsp)
movq -0x190(%rbp), %rax
movq %r13, 0x10(%rsp)
movq %r12, 0x18(%rsp)
movq %r15, 0x20(%rsp)
movl %r14d, 0x28(%rsp)
movl %ebx, 0x30(%rsp)
movq %r11, 0x38(%rsp)
movq %r10, 0x40(%rsp)
movq %rax, 0x48(%rsp)
callq 0x180af0
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
cmpl -0xa0(%rbp), %eax
jae 0x185574
movl -0x74(%rbp), %eax
movl %eax, -0x7c(%rbp)
movq -0x68(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x20(%rax), %rax
movl -0x7c(%rbp), %ecx
movzbl 0x4(%rax,%rcx,8), %eax
cmpl $0x1, %eax
jne 0x185567
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl -0x7c(%rbp), %ecx
movb $0x1, 0x4(%rax,%rcx,8)
jmp 0x185569
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x185529
jmp 0x185576
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
movq -0x58(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1855c8
movq -0x58(%rbp), %rdi
movl -0x74(%rbp), %esi
leaq -0x7c(%rbp), %rdx
leaq -0x16c(%rbp), %rcx
callq 0xd3d50
cmpl $0x1, -0x16c(%rbp)
jne 0x1855bb
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x74(%rbp), %ecx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
jmp 0x1855bd
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x18557d
movq -0x70(%rbp), %rdi
callq 0xcdd10
leaq -0xa8(%rbp), %rdi
callq 0x170040
leaq -0xb8(%rbp), %rdi
callq 0x170040
cmpq $0x0, 0x40(%rbp)
je 0x185617
movq -0x98(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edx
shlq $0x3, %rdx
movl $0xff, %esi
callq 0x2100
jmp 0x185623
movq -0x98(%rbp), %rdi
callq 0x2210
leaq -0x158(%rbp), %rdi
callq 0x16ff00
leaq -0x68(%rbp), %rdi
callq 0x183b90
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopw (%rax,%rax)