// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movss %xmm1, 0x5c(%rsp)
movss %xmm0, 0x60(%rsp)
movq %r9, 0x40(%rsp)
movq %r8, 0x68(%rsp)
movq %rcx, 0x70(%rsp)
movq %rdx, 0x50(%rsp)
movq %rsi, %r12
andq $0x0, 0x18(%rsp)
movq 0x1a0(%rsp), %rbp
movq %rdi, 0x10(%rsp)
movq 0x18(%rdi), %rax
movq %rax, 0x20(%rsp)
testq %rbp, %rbp
jne 0x1305c
movl 0x14(%r12), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
shlq $0x3, %rdi
callq 0x2280
movq %rax, %r13
jmp 0x13060
movq 0x10(%rbp), %r13
movl 0x14(%r12), %edx
movl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
andq %rbx, %rdx
shlq $0x3, %rdx
movq %r13, %rdi
movl $0xff, %esi
callq 0x20e0
movq 0x20(%rsp), %rax
movl 0x14(%rax), %r15d
andq %rbx, %r15
movl %r15d, 0x30(%rsp)
imulq $0x18, %r15, %r14
movq %r14, %rdi
callq 0x2280
movq %rax, 0x28(%rsp)
testq %r15, %r15
je 0x130b2
movq %rax, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x20e0
movq 0x20(%rsp), %rax
movl 0x14(%rax), %ebx
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
movl %ebx, 0x88(%rsp)
imulq $0x18, %rbx, %r14
movq %r14, %rdi
callq 0x2280
movq %rax, 0x80(%rsp)
testq %rbx, %rbx
movq 0x40(%rsp), %r15
je 0x130f2
movq %rax, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x20e0
leaq 0x27765f(%rip), %rbx    # 0x28a758
movl 0x144(%rbx), %eax
cmpl $-0x1, %eax
jne 0x1314b
movl 0x14(%r12), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq 0x98(%rsp), %r10
leaq 0xa0(%rsp), %r11
movq 0x10(%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %r13, %rcx
movq 0x70(%rsp), %r8
movq 0x50(%rsp), %r9
pushq %r10
pushq %r11
pushq $0x400                  # imm = 0x400
pushq %rax
callq 0x105715
addq $0x20, %rsp
jmp 0x13165
cmpl $0x0, 0x148(%rbx)
cvtsi2sd %eax, %xmm0
je 0x13160
mulsd 0x216a08(%rip), %xmm0   # 0x229b68
cvttsd2si %xmm0, %rax
movq %rax, 0x128(%rsp)
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq 0x20(%rsp), %rax
andl 0x14(%rax), %edx
movq %r12, 0x48(%rsp)
je 0x13263
xorl %esi, %esi
pushq $0x1
popq %rbp
movq %r13, 0x38(%rsp)
movq 0x40(%rsp), %rbx
movl %esi, 0xc(%rsp)
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rdx
movq %rsi, 0x90(%rsp)
imulq $0x28, %rsi, %rax
movq %rdx, 0x78(%rsp)
cmpl $0x0, 0x10(%rdx,%rax)
movq 0x48(%rsp), %rsi
je 0x13228
addq %rax, 0x78(%rsp)
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x78(%rsp), %r14
movq 0x18(%r14), %rax
movq (%rax,%r15,8), %r13
shrq $0x21, %r13
movl 0xc(%rsp), %edx
movq 0x20(%rsi), %rax
leaq (%rax,%r13,8), %r8
addq $0x4, %r8
movq %rbx, %rdi
movl %r13d, %esi
movl %ebp, %ecx
callq 0xa1cd4
movq 0x48(%rsp), %rsi
movq %r12, %rax
shlq $0x20, %rax
addq %r15, %rax
movq 0x38(%rsp), %rdx
movq %rax, (%rdx,%r13,8)
movq 0x38(%rsp), %r13
movq 0x18(%r14), %rax
addl (%rax,%r15,8), %r12d
incq %r15
movl 0x10(%r14), %eax
cmpq %rax, %r15
jb 0x131c9
movq 0x90(%rsp), %rsi
incq %rsi
movq 0x20(%rsp), %rax
movl 0x14(%rax), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
cmpq %rdx, %rsi
jb 0x13194
movq 0x48(%rsp), %r12
movq 0x1a0(%rsp), %rbp
movq 0x40(%rsp), %r15
leaq 0x2774f5(%rip), %rbx    # 0x28a758
movl 0x7c(%rbx), %esi
leaq 0x28(%rsp), %rbx
leaq 0xc0(%rsp), %r14
movss 0x21693d(%rip), %xmm1   # 0x229bb8
movq %r14, %rdi
movq 0x10(%rsp), %rcx
movq %r12, %r8
movq 0x70(%rsp), %r9
movss 0x60(%rsp), %xmm0
pushq %rbp
pushq %rbx
movl 0x198(%rsp), %eax
pushq %rax
movl 0x198(%rsp), %eax
pushq %rax
pushq %r13
pushq 0x78(%rsp)
pushq %r15
pushq 0xa0(%rsp)
callq 0x105ab9
addq $0x40, %rsp
cmpq $0x0, 0x68(%r14)
jns 0x13328
leaq 0x80(%rsp), %rax
movsd 0x21a1fe(%rip), %xmm0   # 0x22d4d0
movq 0x10(%rsp), %rdi
movq %r12, %rsi
movl 0x178(%rsp), %ecx
pushq %rcx
pushq %rax
pushq %rbx
pushq %r14
callq 0x1108a5
addq $0x20, %rsp
xorl %ecx, %ecx
testl %eax, %eax
leaq 0xa0(%rsp), %rax
leaq 0x98(%rsp), %rdx
cmoveq %rax, %rdx
cvtsi2sdq (%rdx), %xmm0
sete %cl
leaq 0x21a17a(%rip), %rax    # 0x22d490
mulsd (%rax,%rcx,8), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, 0x128(%rsp)
leaq 0x277429(%rip), %r12    # 0x28a758
cmpl $-0x1, 0x144(%r12)
jne 0x13349
movl 0x128(%rsp), %eax
movl %eax, 0x144(%r12)
movl 0x198(%rsp), %ebx
movslq 0x14c(%r12), %rax
cmpq $-0x1, %rax
je 0x13366
movq %rax, 0x128(%rsp)
movq 0x276c73(%rip), %r15    # 0x289fe0
movq (%r15), %rdi
cmpl $0x0, 0x148(%r12)
movl 0x144(%r12), %eax
cvtsi2sd %eax, %xmm0
divsd 0x2167db(%rip), %xmm0   # 0x229b68
cvttsd2si %xmm0, %ecx
cmovnel %eax, %ecx
leaq 0x21a602(%rip), %rsi    # 0x22d99d
leaq 0x21a62b(%rip), %r14    # 0x22d9cd
movq %r14, %rdx
xorl %eax, %eax
callq 0x22b0
movq (%r15), %rdi
movq 0x128(%rsp), %rcx
leaq 0x21a61a(%rip), %rsi    # 0x22d9d8
movq %r14, %rdx
xorl %eax, %eax
callq 0x22b0
testl %ebx, %ebx
jne 0x137d3
movq %r13, 0x38(%rsp)
movl 0x1b0(%rsp), %r15d
movl 0x1a8(%rsp), %r13d
movl 0x7c(%r12), %edi
movq 0x20(%rsp), %rax
movl 0x14(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq 0xfd634(%rip), %rsi     # 0x110a33
leaq 0xc0(%rsp), %rdx
callq 0x1047b4
leaq 0x28(%rsp), %r14
movq %r14, %rdi
movl 0x178(%rsp), %esi
callq 0x10cd21
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
movq 0x48(%rsp), %r12
movq %r12, %rdx
callq 0x111f86
movq %rax, 0x18(%rsp)
subq $0x8, %rsp
leaq 0x88(%rsp), %rsi
movsd 0x212062(%rip), %xmm0   # 0x2254b0
movq %r14, %rdi
pushq %rax
callq 0x10c731
popq %rax
popq %rcx
testl %r13d, %r13d
sete %al
testl %r15d, %r15d
setne %cl
orb %al, %cl
jne 0x13480
leaq 0x28(%rsp), %rsi
movq 0x10(%rsp), %rdi
movq %rbp, %rdx
movq 0x38(%rsp), %rcx
callq 0x112688
leaq 0x2772d1(%rip), %rax    # 0x28a758
cmpl $0x2, 0x1bc(%rax)
jg 0x134e9
movq 0xa8(%rbp), %rsi
leaq 0x277d92(%rip), %rax    # 0x28b230
movq 0x28(%rax), %r9
subq $0x40, %rsp
pushq $0x1
popq %rax
movl %eax, 0x28(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x18(%rsp)
movl %eax, 0x10(%rsp)
movl %eax, (%rsp)
andl $0x0, 0x30(%rsp)
andq $0x0, 0x8(%rsp)
leaq 0x68(%rsp), %rdi
movsd 0x211fda(%rip), %xmm0   # 0x2254b0
xorl %edx, %edx
movq 0x50(%rsp), %rcx
movq %r12, %r8
callq 0x1edea
addq $0x40, %rsp
movl 0x190(%rsp), %ebx
testl %r13d, %r13d
sete %al
cmpl $0x1, %r15d
setne %cl
orb %al, %cl
movq 0x38(%rsp), %r13
jne 0x1351b
leaq 0x28(%rsp), %rsi
movq 0x10(%rsp), %rdi
movq %rbp, %rdx
movq %r13, %rcx
callq 0x112688
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rcx
leaq 0x28(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq %rbp, %r8
callq 0x111e10
testl %ebx, %ebx
jne 0x1378e
cmpl $0x0, 0x30(%rsp)
je 0x136f3
xorl %r8d, %r8d
movl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
movl %r8d, 0xc(%rsp)
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x20(%rax), %rax
cmpl $0x0, (%rax,%r8,8)
js 0x136e3
cmpb $0x1, 0x4(%rax,%r8,8)
je 0x136e3
movq 0x28(%rsp), %rcx
movl 0xc(%rsp), %eax
imulq $0x18, %rax, %rax
cmpq $0x0, (%rcx,%rax)
je 0x136e3
addq %rax, %rcx
pushq $0x1
popq %r14
xorl %eax, %eax
movq 0x10(%rcx), %rdi
shlq $0x6, %rax
cmpb $0x2, 0x2(%rdi,%rax)
je 0x136c2
addq %rax, %rdi
movq 0x18(%rsp), %rax
movq 0x28(%rax), %r13
movq 0x20(%r13), %rcx
movl 0x24(%rdi), %eax
cmpb $0x1, 0x4(%rcx,%rax,8)
je 0x136c2
cmpl $0x0, (%rcx,%rax,8)
js 0x136c2
movl 0x28(%rdi), %edx
cmpb $0x1, 0x4(%rcx,%rdx,8)
je 0x136c2
cmpl $0x0, (%rcx,%rdx,8)
js 0x136c2
movq 0x10(%rsp), %rcx
movq 0x10(%rcx), %rcx
imulq $0x28, %rax, %rax
movl (%rcx,%rax), %esi
movl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
andl %r9d, %esi
imulq $0x28, %rdx, %rax
movl (%rcx,%rax), %edx
andl %r9d, %edx
leaq 0x27713a(%rip), %rax    # 0x28a758
movss 0x158(%rax), %xmm0
movl 0x180(%rsp), %ecx
movq %r8, %rbx
movl 0x188(%rsp), %r8d
leaq 0xa8(%rsp), %r9
callq 0x10da16
movq %rbx, %r8
testl %eax, %eax
js 0x136c2
movl 0x4(%r13), %ecx
andl %r15d, %ecx
movl (%r13), %eax
cmpl %eax, %ecx
jne 0x1367e
leal (%rax,%rax), %ecx
testl %eax, %eax
pushq $0x10
popq %rax
cmovel %eax, %ecx
movl %ecx, (%r13)
movq 0x8(%r13), %rdi
imulq $0x18, %rcx, %rsi
callq 0x2370
movq %rbx, %r8
movq %rax, 0x8(%r13)
movq 0x8(%r13), %rax
movl 0x4(%r13), %ecx
movl %ecx, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
leal 0x1(%rcx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %esi, %ecx
movl %ecx, 0x4(%r13)
imulq $0x18, %rdx, %rcx
movq 0xb8(%rsp), %rdx
movq %rdx, 0x10(%rax,%rcx)
movupd 0xa8(%rsp), %xmm0
movupd %xmm0, (%rax,%rcx)
movl %r14d, %eax
movq 0x28(%rsp), %rdx
movl 0xc(%rsp), %ecx
imulq $0x18, %rcx, %rsi
leaq (%rdx,%rsi), %rcx
incl %r14d
cmpq %rax, (%rdx,%rsi)
ja 0x135a1
incq %r8
movl 0x30(%rsp), %eax
cmpq %rax, %r8
jb 0x13557
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rdi
callq 0xa02fa
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rdi
callq 0xa047e
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rdi
pushq $0x1
popq %rsi
movss 0x5c(%rsp), %xmm0
callq 0x10e10c
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rdi
movq 0xc0(%rsp), %rax
leaq 0x30(%rax), %r10
leaq 0x50(%rax), %r11
leaq 0x28(%rsp), %rdx
movq 0x10(%rsp), %rsi
movq 0x40(%rsp), %rcx
movq 0x68(%rsp), %r8
movq 0x50(%rsp), %r9
pushq %rbp
pushq 0x8(%rax)
addq $0x70, %rax
pushq 0x180(%rsp)
movl 0x1a0(%rsp), %ebx
pushq %rbx
movl 0x1a0(%rsp), %ebx
pushq %rbx
pushq %rax
pushq %r11
pushq %r10
movq 0x78(%rsp), %r13
pushq %r13
pushq %r12
callq 0x10fef1
addq $0x50, %rsp
movl 0x30(%rsp), %ecx
testq %rcx, %rcx
je 0x137cb
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x20(%rax), %rdx
xorl %eax, %eax
cmpb $0x1, 0x4(%rdx,%rax,8)
jne 0x137bf
movq 0x10(%rsp), %rsi
movq 0x18(%rsi), %rsi
movq 0x20(%rsi), %rsi
movb $0x1, 0x4(%rsi,%rax,8)
incq %rax
cmpq %rax, %rcx
jne 0x137a6
decl %eax
jmp 0x137cf
movl 0xc(%rsp), %eax
movl %eax, 0xc(%rsp)
movq 0x40(%rsp), %rbx
cmpq $0x0, (%rbx)
movq 0x48(%rsp), %r15
je 0x13819
xorl %r14d, %r14d
leaq 0xc(%rsp), %r12
leaq 0x64(%rsp), %rbp
movq %rbx, %rdi
movl %r14d, %esi
movq %r12, %rdx
movq %rbp, %rcx
callq 0xa306f
cmpl $0x1, 0x64(%rsp)
jne 0x13811
movq 0x8(%rbx), %rax
orl $-0x1, (%rax,%r14,4)
incl %r14d
cmpq %r14, (%rbx)
ja 0x137f0
movq 0x20(%rsp), %rdi
callq 0xa02fa
leaq 0x28(%rsp), %rdi
callq 0x105ca4
leaq 0x80(%rsp), %rdi
callq 0x105ca4
cmpq $0x0, 0x1a0(%rsp)
je 0x13862
movl 0x14(%r15), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
shlq $0x3, %rdx
movq %r13, %rdi
movl $0xff, %esi
callq 0x20e0
jmp 0x1386a
movq %r13, %rdi
callq 0x2220
leaq 0xc0(%rsp), %rdi
callq 0x105c10
leaq 0x18(%rsp), %rdi
callq 0x1122a3
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq