// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/hic.cpp
// Function: trio_phasing_refine(ma_ug_t*, asg_t*, kv_u_trans_t*, ug_opt_t*)
void trio_phasing_refine(ma_ug_t *iug, asg_t* sg, kv_u_trans_t *ref, ug_opt_t *opt)
{
    ma_ug_t *ug = copy_untig_graph(iug); uint8_t *bf = NULL; 
    uint64_t ug_n0 = ug->g->n_seq, k, i, ul, cis_n, trans_n, w_n, tot_hap, tot_r, frid, mrid, flag; 
    kv_u_trans_t in; memset(&in, 0, sizeof(in)); ma_utg_t *p; u_trans_t *z; int64_t fh, mh;
    bubble_type *bub = gen_bubble_chain(sg, ug, opt, &bf, 0); free(bf);
    clean_u_trans_t_idx_filter_adv(ref, ug, sg, 0.95, 0);
    
    ///update ug itself
    ul = FATHER; frid = ug->g->n_seq; asg_seq_set(ug->g, frid, ul, 0); 
    kv_pushp(ma_utg_t, ug->u, &p); memset(p, 0, sizeof((*p)));
    p->s = 0; p->start = UINT32_MAX; p->end = UINT32_MAX; p->len = ul, p->n = p->m = 1; p->circ = 1;
    kv_roundup32(p->m); p->a = (uint64_t*)malloc(8 * p->m); 
    p->a[0] = UINT32_MAX; p->a[0] <<= 32; p->a[0] |= ul;
    
    ul = MOTHER; mrid = ug->g->n_seq; asg_seq_set(ug->g, mrid, ul, 0); 
    kv_pushp(ma_utg_t, ug->u, &p); memset(p, 0, sizeof((*p)));
    p->s = 0; p->start = UINT32_MAX; p->end = UINT32_MAX; p->len = ul, p->n = p->m = 1; p->circ = 1;
    kv_roundup32(p->m); p->a = (uint64_t*)malloc(8 * p->m); 
    p->a[0] = UINT32_MAX; p->a[0] <<= 32; p->a[0] |= ul;

    free(ug->g->idx); ug->g->idx = 0; ug->g->is_srt = 0; asg_cleanup(ug->g);

    ///update bubble
    REALLOC(bub->index, ug->g->n_seq);
    for (k = ug_n0; k < ug->g->n_seq; k++) bub->index[k] = bub->f_bub+1;
    
    bub->b_s_idx.n = ug->g->n_seq; kv_resize(uint64_t, bub->b_s_idx, ug->g->n_seq);
    for (k = ug_n0; k < bub->b_s_idx.m; k++) bub->b_s_idx.a[k] = (uint64_t)-1;

    ///check if a node has haplotype markers
    CALLOC(bf, ug->g->n_seq);
    for (k = cis_n = tot_hap = tot_r = 0; k < ug_n0; k++) {
        if(ug->g->seq[k].del) continue;
        p = &(ug->u.a[k]); tot_r += p->n;
        if(p->n == 0 || p->m == 0) continue;
        for (i = fh = mh = 0; i < p->n; i++) {
            if(R_INF.trio_flag[p->a[i]>>33] == FATHER) {
                tot_hap++; fh = 1;
            } else if(R_INF.trio_flag[p->a[i]>>33] == MOTHER) {
                tot_hap++; mh = 1;
            }
            if((R_INF.trio_flag[p->a[i]>>33] == FATHER) || (R_INF.trio_flag[p->a[i]>>33] == MOTHER)) {
                tot_hap++; bf[k] = 1; 
            }
        }
        if(fh > 0) {
            bf[k] = 1; cis_n+=2;
        }
        if(mh > 0) {
            bf[k] = 1; cis_n+=2;
        }
    }
    for (; k < ug->g->n_seq; k++) bf[k] = 1;///for father/mother nodes
    

    ///update trans overlaps
    kv_pushp(u_trans_t, *ref, &z); memset(z, 0, sizeof((*z)));
    z->f = RC_2; z->nw = (DBL_MAX/2); z->rev = 0;
    z->qn = ug_n0; z->tn = ug_n0+1; z->del = 0;
    z->qs = 0; z->qe = ug->g->seq[z->qn].len;
    z->ts = 0; z->te = ug->g->seq[z->tn].len;

    kv_pushp(u_trans_t, *ref, &z); memset(z, 0, sizeof((*z)));
    z->f = RC_2; z->nw = (DBL_MAX/2); z->rev = 0;
    z->qn = ug_n0+1; z->tn = ug_n0; z->del = 0;
    z->qs = 0; z->qe = ug->g->seq[z->qn].len;
    z->ts = 0; z->te = ug->g->seq[z->tn].len;

    kt_u_trans_t_idx(ref, ug->g->n_seq);
    // clean_u_trans_t_idx_adv(ref, ug, sg);
    // clean_u_trans_t_idx_filter_adv(ref, ug, sg);

    ///gen all links
    for (k = trans_n = 0; k < ref->n; k++) {
        if(ref->a[k].del) continue;
        if((IF_HOM(ref->a[k].qn, (*bub))) || (IF_HOM(ref->a[k].tn, (*bub)))) continue;
        ///disable bf
        // if((!bf[ref->a[k].qn]) || (!bf[ref->a[k].tn])) continue;
        trans_n++;
    }
    kv_resize(u_trans_t, in, (trans_n+cis_n)); 

    for (k = in.n = 0; k < ref->n; k++) {
        if(ref->a[k].del) continue;
        if((IF_HOM(ref->a[k].qn, (*bub))) || (IF_HOM(ref->a[k].tn, (*bub)))) continue;
        ///disable bf
        // if((!bf[ref->a[k].qn]) || (!bf[ref->a[k].tn])) continue;

        kv_pushp(u_trans_t, in, &z); memset(z, 0, sizeof((*z))); w_n = 0;
        if((ref->a[k].qn < ug_n0) && (ref->a[k].tn < ug_n0)) {
            w_n += ug_occ_hap_w(ref->a[k].qs, ref->a[k].qe, &(ug->u.a[ref->a[k].qn])) + 
            ug_occ_hap_w(ref->a[k].ts, ref->a[k].te, &(ug->u.a[ref->a[k].tn]));
            w_n += ug_occ_w(ref->a[k].qs, ref->a[k].qe, &(ug->u.a[ref->a[k].qn])) + 
            ug_occ_w(ref->a[k].ts, ref->a[k].te, &(ug->u.a[ref->a[k].tn]));
        } else {
            w_n += tot_hap + tot_r;
        }
        w_n >>= 1;///wn/4
        (*z) = ref->a[k]; z->nw = ((w_n)?(w_n):(1));
    }

    for (k = 0; k < ug_n0; k++) {
        if(!bf[k]) continue;
        p = &(ug->u.a[k]);
        if(p->n == 0 || p->m == 0) continue;
        fh = mh = 0;
        for (i = 0; i < p->n; i++) {
            if(R_INF.trio_flag[p->a[i]>>33] == FATHER) fh--;
            if(R_INF.trio_flag[p->a[i]>>33] == MOTHER) mh--;
        }
        if(fh != 0) {
            w_n = frid;

            kv_pushp(u_trans_t, in, &z); memset(z, 0, sizeof((*z)));
            z->f = RC_2; z->nw = fh; z->rev = 0;
            z->qn = w_n; z->tn = k; z->del = 0;
            z->qs = 0; z->qe = MIN(ug->g->seq[z->qn].len, ug->g->seq[z->tn].len);
            z->ts = 0; z->te = MIN(ug->g->seq[z->qn].len, ug->g->seq[z->tn].len);

            kv_pushp(u_trans_t, in, &z); memset(z, 0, sizeof((*z)));
            z->f = RC_2; z->nw = fh; z->rev = 0;
            z->qn = k; z->tn = w_n; z->del = 0;
            z->qs = 0; z->qe = MIN(ug->g->seq[z->qn].len, ug->g->seq[z->tn].len);
            z->ts = 0; z->te = MIN(ug->g->seq[z->qn].len, ug->g->seq[z->tn].len);
        }

        if(mh != 0) {
            w_n = mrid;

            kv_pushp(u_trans_t, in, &z); memset(z, 0, sizeof((*z)));
            z->f = RC_2; z->nw = mh; z->rev = 0;
            z->qn = w_n; z->tn = k; z->del = 0;
            z->qs = 0; z->qe = MIN(ug->g->seq[z->qn].len, ug->g->seq[z->tn].len);
            z->ts = 0; z->te = MIN(ug->g->seq[z->qn].len, ug->g->seq[z->tn].len);

            kv_pushp(u_trans_t, in, &z); memset(z, 0, sizeof((*z)));
            z->f = RC_2; z->nw = mh; z->rev = 0;
            z->qn = k; z->tn = w_n; z->del = 0;
            z->qs = 0; z->qe = MIN(ug->g->seq[z->qn].len, ug->g->seq[z->tn].len);
            z->ts = 0; z->te = MIN(ug->g->seq[z->qn].len, ug->g->seq[z->tn].len);
        }
    }
    free(bf);
    assert(in.n == (trans_n+cis_n));
    kt_u_trans_t_idx(&in, ug->g->n_seq);
    // clean_u_trans_t_idx_adv(&in, ug, sg);

    ps_t *s = init_ps_t(11, ug->g->n_seq); s->s[frid] = 1; s->s[mrid] = -1; 
    mc_solve(NULL, NULL, &in, ug, sg, 0.8, NULL, 0, s->s, 1, bub, ref, 0, 0);
    // fprintf(stderr, "[M::%s::] s[frid]::%d, s->s[mrid]::%d\n", __func__, s->s[frid], s->s[mrid]);
    if((s->s[frid] != 0) && (s->s[mrid] != 0) && (s->s[frid] != s->s[mrid])) {
        memset(R_INF.trio_flag, AMBIGU, R_INF.total_reads * sizeof(uint8_t));
        for (i = 0; i < ug_n0; i++) {
            if(ug->g->seq[i].del) continue;
            flag = AMBIGU;
            if(s->s[i] == 0) continue;
            flag = (s->s[i] == s->s[frid]? FATHER:MOTHER);
            p = &ug->u.a[i];
            if(p->m == 0) continue;
            for (k = 0; k < p->n; k++) R_INF.trio_flag[p->a[k]>>33] = flag;
        }
    }

    destory_bubbles(bub); free(bub); ma_ug_destroy(ug);
    destory_ps_t(&s); kv_destroy(in); kv_destroy(in.idx);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rcx, %r14
movq %rdx, %rbp
movq %rsi, %r13
callq 0xc8eab
movq %rax, %r12
leaq 0x18(%rsp), %r15
movq $0x0, (%r15)
movq 0x18(%rax), %rax
movl 0x14(%rax), %eax
movl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
andq %rbx, %rax
movq %rax, (%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq %r15, %rcx
xorl %r8d, %r8d
callq 0x1fba56
movq %rax, 0x28(%rsp)
movq (%r15), %rdi
callq 0x2220
movsd 0xcdda4(%rip), %xmm0    # 0x231598
movq %rbp, 0x20(%rsp)
movq %rbp, %rdi
movq %r12, %rsi
movq %r13, 0xb0(%rsp)
movq %r13, %rdx
xorl %ecx, %ecx
callq 0xc559a
movq 0x18(%r12), %rdi
movl 0x14(%rdi), %esi
andq %rbx, %rsi
movq %rsi, 0x38(%rsp)
movl $0x1, %edx
xorl %ecx, %ecx
callq 0xa0887
movq (%r12), %rax
cmpq 0x8(%r12), %rax
jne 0x16386d
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmovneq %rcx, %rax
movq %rax, 0x8(%r12)
movq 0x10(%r12), %rdi
shlq $0x3, %rax
leaq (%rax,%rax,4), %rsi
callq 0x2370
movq %rax, %r15
movq %rax, 0x10(%r12)
movq (%r12), %rax
jmp 0x163872
movq 0x10(%r12), %r15
movabsq $-0xffffffff, %r14      # imm = 0xFFFFFFFF00000001
leaq 0x1(%rax), %rcx
movq %rcx, (%r12)
movq %r12, 0x8(%rsp)
leaq (%rax,%rax,4), %rbx
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r15,%rbx,8)
movq $0x0, 0x20(%r15,%rbx,8)
movl $0x1, 0x10(%r15,%rbx,8)
movaps 0xd7951(%rip), %xmm0    # 0x23b200
movups %xmm0, (%r15,%rbx,8)
movl $0x8, %edi
callq 0x2280
movq %rax, 0x18(%r15,%rbx,8)
movq 0x8(%rsp), %rbx
movq %r14, (%rax)
movq 0x18(%rbx), %rdi
movl 0x14(%rdi), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movq %rsi, 0x70(%rsp)
movl $0x2, %edx
xorl %ecx, %ecx
callq 0xa0887
movq (%rbx), %rax
movq 0x10(%rbx), %r15
cmpq 0x8(%rbx), %rax
jne 0x163924
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmovneq %rcx, %rax
movq %rax, 0x8(%rbx)
shlq $0x3, %rax
leaq (%rax,%rax,4), %rsi
movq %r15, %rdi
callq 0x2370
movq %rax, %r15
movq %rax, 0x10(%rbx)
movq (%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, (%rbx)
movq %rbx, %r13
leaq (%rax,%rax,4), %rbx
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r15,%rbx,8)
xorl %r12d, %r12d
movq %r12, 0x20(%r15,%rbx,8)
movl $0x1, 0x10(%r15,%rbx,8)
movapd 0xd78bc(%rip), %xmm0    # 0x23b210
movupd %xmm0, (%r15,%rbx,8)
movl $0x8, %edi
callq 0x2280
movq %rax, 0x18(%r15,%rbx,8)
incq %r14
movq %r14, (%rax)
movq 0x18(%r13), %rax
movq 0x28(%rax), %rdi
callq 0x2220
movq 0x18(%r13), %rax
movq %r12, 0x28(%rax)
andb $0x7f, 0x7(%rax)
movq 0x18(%r13), %rdi
callq 0xa0a7d
movq 0x28(%rsp), %r14
movq (%r14), %rdi
movq 0x18(%r13), %rax
movl 0x14(%rax), %esi
movl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
andq %rbx, %rsi
shlq $0x2, %rsi
callq 0x2370
movq %rax, (%r14)
movq 0x18(%r13), %rcx
movl 0x14(%rcx), %edx
andq %rbx, %rdx
movq (%rsp), %r8
cmpl %edx, %r8d
jae 0x1639e7
movl 0x80(%r14), %esi
incl %esi
movq %r8, %rdi
movl %esi, (%rax,%rdi,4)
incq %rdi
movl 0x14(%rcx), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
cmpq %rdx, %rdi
jb 0x1639d3
movq %rdx, 0x60(%r14)
movq 0x68(%r14), %rdx
movl 0x14(%rcx), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, %rdx
jae 0x163a55
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x68(%r14)
movq 0x70(%r14), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq (%rsp), %r8
movq %rax, 0x70(%r14)
movq 0x68(%r14), %rdx
cmpq %r8, %rdx
movq 0x8(%rsp), %rbx
jbe 0x163a77
movq 0x70(%r14), %rax
movq %r8, %rcx
movq $-0x1, (%rax,%rcx,8)
incq %rcx
cmpq 0x68(%r14), %rcx
jb 0x163a66
movq 0x18(%rbx), %rax
movl 0x14(%rax), %r15d
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
movl $0x1, %esi
movq %r15, %rdi
callq 0x2120
movq (%rsp), %r8
movq %rax, 0x18(%rsp)
testl %r8d, %r8d
je 0x163b87
xorl %eax, %eax
leaq 0x132782(%rip), %rcx    # 0x296230
xorl %r14d, %r14d
xorl %r12d, %r12d
xorl %r15d, %r15d
movq 0x18(%rbx), %rdx
movq 0x20(%rdx), %rdx
cmpl $0x0, (%rdx,%rax,8)
js 0x163b65
movq 0x10(%rbx), %rdx
leaq (%rax,%rax,4), %rsi
movl 0x10(%rdx,%rsi,8), %edi
addq %rdi, %r14
testq %rdi, %rdi
je 0x163b65
leaq (%rdx,%rsi,8), %rsi
cmpl $0x0, 0xc(%rsi)
je 0x163b65
movq 0x28(%rcx), %r10
xorl %edx, %edx
xorl %r8d, %r8d
xorl %r9d, %r9d
movq 0x18(%rsi), %r11
movq (%r11,%r9,8), %r11
shrq $0x21, %r11
movzbl (%r10,%r11), %r11d
cmpl $0x1, %r11d
je 0x163b1b
cmpl $0x2, %r11d
jne 0x163b32
movl $0x1, %edx
jmp 0x163b1e
movq %r11, %r8
addq $0x2, %r12
movq 0x18(%rsp), %rdi
movb $0x1, (%rdi,%rax)
movq 0x28(%rcx), %r10
movl 0x10(%rsi), %edi
incq %r9
movl %edi, %r11d
cmpq %r11, %r9
jb 0x163af7
testq %r8, %r8
jle 0x163b4f
movq 0x18(%rsp), %rsi
movb $0x1, (%rsi,%rax)
addq $0x2, %r15
movq (%rsp), %r8
testq %rdx, %rdx
jle 0x163b65
movq 0x18(%rsp), %rdx
movb $0x1, (%rdx,%rax)
addq $0x2, %r15
incq %rax
cmpq %r8, %rax
jne 0x163ab7
movq %r15, 0x30(%rsp)
movq 0x18(%rbx), %rax
movl 0x14(%rax), %r15d
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
jmp 0x163b96
movq $0x0, 0x30(%rsp)
xorl %r12d, %r12d
xorl %r14d, %r14d
cmpl %r8d, %r15d
jbe 0x163bbc
movq %r8, %rax
movq 0x18(%rsp), %rcx
movb $0x1, (%rcx,%rax)
incq %rax
movq 0x18(%rbx), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rcx, %rax
jb 0x163b9e
movq 0x20(%rsp), %rbp
movq (%rbp), %rcx
cmpq 0x8(%rbp), %rcx
movq %r14, 0x10(%rsp)
jne 0x163c03
leaq (%rcx,%rcx), %rax
testq %rcx, %rcx
movl $0x2, %ecx
cmovneq %rax, %rcx
movq %rcx, 0x8(%rbp)
movq 0x10(%rbp), %rdi
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq (%rsp), %r8
movq %rax, 0x10(%rbp)
movq (%rbp), %rcx
jmp 0x163c07
movq 0x10(%rbp), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbp)
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
xorpd %xmm0, %xmm0
movupd %xmm0, 0x20(%rax,%rcx)
movupd %xmm0, (%rax,%rcx)
movupd %xmm0, 0x10(%rax,%rcx)
movabsq $0x7fdfffffffffffff, %rdi # imm = 0x7FDFFFFFFFFFFFFF
movq %rdi, 0x20(%rax,%rcx)
movl %r8d, 0x8(%rax,%rcx)
movl %r8d, %r14d
leal 0x1(%r8), %r15d
movl %r15d, 0x14(%rax,%rcx)
movb $0x2, 0x28(%rax,%rcx)
movq 0x18(%rbx), %rdx
movq 0x20(%rdx), %rdx
movl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
movl (%rdx,%r8,8), %esi
andl %r13d, %esi
movl %esi, 0x4(%rax,%rcx)
movl $0x0, 0xc(%rax,%rcx)
movl 0x8(%rdx,%r14,8), %edx
andl %r13d, %edx
incq %r14
movl %edx, 0x10(%rax,%rcx)
movq (%rbp), %rcx
movq 0x10(%rbp), %rax
cmpq 0x8(%rbp), %rcx
jne 0x163ccd
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmovneq %rdx, %rcx
movq %rcx, 0x8(%rbp)
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
movq %rax, %rdi
callq 0x2370
movabsq $0x7fdfffffffffffff, %rdi # imm = 0x7FDFFFFFFFFFFFFF
xorpd %xmm0, %xmm0
movq (%rsp), %r8
movq %rax, 0x10(%rbp)
movq (%rbp), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbp)
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
movupd %xmm0, 0x20(%rax,%rcx)
movupd %xmm0, (%rax,%rcx)
movupd %xmm0, 0x10(%rax,%rcx)
movq %rdi, 0x20(%rax,%rcx)
movl %r15d, 0x8(%rax,%rcx)
movl %r8d, 0x14(%rax,%rcx)
movb $0x2, 0x28(%rax,%rcx)
movq 0x18(%rbx), %rdx
movq 0x20(%rdx), %rsi
movl (%rsi,%r14,8), %edi
andl %r13d, %edi
movl %edi, 0x4(%rax,%rcx)
movl $0x0, 0xc(%rax,%rcx)
movl (%rsi,%r8,8), %esi
andl %r13d, %esi
movl %esi, 0x10(%rax,%rcx)
andl 0x14(%rdx), %r13d
movq %rbp, %rdi
movl %r13d, %esi
callq 0xc4edd
movq (%rbp), %r15
testq %r15, %r15
movq %rbp, %r8
je 0x163d8c
movq 0x10(%r8), %rax
addq $0x28, %rax
xorl %r9d, %r9d
movq %r15, %rcx
movq 0x28(%rsp), %r13
cmpb $0x0, (%rax)
js 0x163d81
movq (%r13), %rsi
movq 0x80(%r13), %rdx
movl -0x20(%rax), %edi
movl (%rsi,%rdi,4), %edi
incq %rdx
cmpq %rdi, %rdx
jb 0x163d81
movl -0x14(%rax), %edi
movl (%rsi,%rdi,4), %esi
cmpq %rsi, %rdx
sbbq $-0x1, %r9
addq $0x30, %rax
decq %rcx
jne 0x163d56
jmp 0x163d94
xorl %r9d, %r9d
movq 0x28(%rsp), %r13
addq 0x30(%rsp), %r9
movq %r9, 0x30(%rsp)
je 0x163dfc
leaq -0x1(%r9), %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rbp
shrq $0x10, %rbp
orq %rax, %rbp
incq %rbp
movq %rbp, 0x48(%rsp)
movq %rbp, %rax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rdi
callq 0x2280
movq 0x20(%rsp), %r8
movq %rax, %r11
movq %rax, 0x50(%rsp)
jmp 0x163e01
xorl %r11d, %r11d
xorl %ebp, %ebp
movq (%rsp), %r9
movq $0x0, 0x40(%rsp)
testq %r15, %r15
je 0x16404b
addq %r12, 0x10(%rsp)
xorl %r12d, %r12d
xorl %r10d, %r10d
xorl %r14d, %r14d
movq 0x10(%r8), %rax
cmpb $0x0, 0x28(%rax,%r12)
js 0x16403b
movq (%r13), %rdx
movq 0x80(%r13), %rcx
movl 0x8(%rax,%r12), %esi
movl (%rdx,%rsi,4), %esi
incq %rcx
cmpq %rsi, %rcx
jb 0x16403b
movl 0x14(%rax,%r12), %eax
movl (%rdx,%rax,4), %eax
cmpq %rax, %rcx
jb 0x16403b
cmpq %rbp, %r10
jne 0x163eaf
leaq (,%rbp,2), %rbx
testq %rbp, %rbp
movl $0x2, %eax
cmoveq %rax, %rbx
movq %rbx, 0x48(%rsp)
movq %rbx, %rax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rsi
movq %r11, %rdi
callq 0x2370
movq 0x20(%rsp), %r8
movq (%rsp), %r9
movq %rax, %r11
movq %rax, 0x50(%rsp)
movq 0x40(%rsp), %r10
movq %rbx, %rbp
leaq (%r10,%r10,2), %r13
incq %r10
movq %r10, 0x40(%rsp)
shlq $0x4, %r13
xorpd %xmm0, %xmm0
movupd %xmm0, 0x20(%r11,%r13)
movupd %xmm0, 0x10(%r11,%r13)
movupd %xmm0, (%r11,%r13)
movq 0x10(%r8), %rbx
movl 0x8(%rbx,%r12), %eax
cmpl %r9d, %eax
jae 0x163fe5
movl 0x14(%rbx,%r12), %r15d
cmpl %r9d, %r15d
jae 0x163fe5
movl (%rbx,%r12), %edi
movq %rdi, 0x88(%rsp)
movl 0x4(%rbx,%r12), %esi
movq %rsi, 0x80(%rsp)
movq 0x8(%rsp), %rcx
movq 0x10(%rcx), %rcx
movq %rcx, 0x78(%rsp)
leaq (%rax,%rax,4), %rax
leaq (%rcx,%rax,8), %rdx
movq %rdx, 0x90(%rsp)
movq %r11, 0xa8(%rsp)
movq %r10, 0xa0(%rsp)
callq 0x163708
movq %rax, 0x98(%rsp)
movl 0xc(%rbx,%r12), %edi
movl 0x10(%rbx,%r12), %esi
leaq (%r15,%r15,4), %rax
movq 0x78(%rsp), %rcx
leaq (%rcx,%rax,8), %rdx
callq 0x163708
movq %rax, %r15
movq 0x88(%rsp), %rdi
movq 0x80(%rsp), %rsi
movq 0x90(%rsp), %rdx
callq 0x1fe266
movq %rax, %rbx
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movl 0xc(%rax,%r12), %edi
movl 0x10(%rax,%r12), %esi
movl 0x14(%rax,%r12), %eax
leaq (%rax,%rax,4), %rdx
shlq $0x3, %rdx
movq 0x8(%rsp), %rax
addq 0x10(%rax), %rdx
callq 0x1fe266
movq 0xa0(%rsp), %r10
movq 0xa8(%rsp), %r11
movq 0x20(%rsp), %r8
movq (%rsp), %r9
addq 0x98(%rsp), %r15
addq %rbx, %r15
addq %rax, %r15
movq 0x10(%r8), %rbx
jmp 0x163fea
movq 0x10(%rsp), %r15
addq %r11, %r13
movups (%rbx,%r12), %xmm0
movupd 0x10(%rbx,%r12), %xmm1
movups 0x20(%rbx,%r12), %xmm2
movups %xmm2, 0x20(%r13)
movupd %xmm1, 0x10(%r13)
movups %xmm0, (%r13)
cmpq $0x2, %r15
jae 0x16401d
movl $0x1, %r15d
jmp 0x164020
shrq %r15
movq 0x8(%rsp), %rbx
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
movsd %xmm0, 0x20(%r13)
movq (%r8), %r15
movq 0x28(%rsp), %r13
incq %r14
addq $0x30, %r12
cmpq %r15, %r14
jb 0x163e25
testl %r9d, %r9d
movq 0x70(%rsp), %r12
je 0x164446
xorl %r15d, %r15d
xorpd %xmm0, %xmm0
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
movq 0x18(%rsp), %rax
cmpb $0x0, (%rax,%r15)
je 0x16443a
movq 0x10(%rbx), %rcx
leaq (%r15,%r15,4), %rdx
movl 0x10(%rcx,%rdx,8), %eax
testq %rax, %rax
je 0x16443a
leaq (%rcx,%rdx,8), %rdx
cmpl $0x0, 0xc(%rdx)
je 0x16443a
leaq 0x132190(%rip), %rcx    # 0x296230
movq 0x28(%rcx), %rcx
movq 0x18(%rdx), %rdx
xorl %r14d, %r14d
xorl %r12d, %r12d
xorl %esi, %esi
movq (%rdx,%rsi,8), %rdi
shrq $0x21, %rdi
movb (%rcx,%rdi), %dil
xorl %r8d, %r8d
cmpb $0x1, %dil
sete %r8b
subq %r8, %r12
xorl %r8d, %r8d
cmpb $0x2, %dil
sete %r8b
subq %r8, %r14
incq %rsi
cmpq %rsi, %rax
jne 0x1640b0
testq %r12, %r12
je 0x16428e
movq 0x40(%rsp), %r13
movq 0x50(%rsp), %rax
cmpq %rbp, %r13
jne 0x16413b
leaq (,%rbp,2), %rbx
testq %rbp, %rbp
movl $0x2, %ecx
cmoveq %rcx, %rbx
movq %rbx, 0x48(%rsp)
movq %rbx, %rcx
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
movq %rax, %rdi
callq 0x2370
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
xorpd %xmm0, %xmm0
movq %rax, 0x50(%rsp)
movq %rbx, %rbp
movq 0x8(%rsp), %rbx
leaq (,%r13,2), %rcx
addq %r13, %rcx
shlq $0x4, %rcx
movupd %xmm0, 0x20(%rax,%rcx)
movupd %xmm0, (%rax,%rcx)
movupd %xmm0, 0x10(%rax,%rcx)
cvtsi2sd %r12, %xmm1
movsd %xmm1, 0x20(%rax,%rcx)
movq 0x38(%rsp), %r8
movl %r8d, 0x8(%rax,%rcx)
movl %r15d, 0x14(%rax,%rcx)
movb $0x2, 0x28(%rax,%rcx)
movq 0x18(%rbx), %rdx
movq 0x20(%rdx), %rdx
movl (%rdx,%r8,8), %esi
andl %r10d, %esi
movl (%rdx,%r15,8), %edi
andl %r10d, %edi
cmpl %edi, %esi
cmovbl %esi, %edi
leaq 0x1(%r13), %r12
movl %edi, 0x4(%rax,%rcx)
movl $0x0, 0xc(%rax,%rcx)
movl (%rdx,%r8,8), %esi
andl %r10d, %esi
movl (%rdx,%r15,8), %edx
andl %r10d, %edx
cmpl %edx, %esi
cmovbl %esi, %edx
movl %edx, 0x10(%rax,%rcx)
cmpq %rbp, %r12
jne 0x164210
leaq (,%rbp,2), %rbx
testq %rbp, %rbp
movl $0x2, %ecx
cmoveq %rcx, %rbx
movq %rbx, 0x48(%rsp)
movq %rbx, %rcx
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
movq %rax, %rdi
movsd %xmm1, 0x10(%rsp)
callq 0x2370
movsd 0x10(%rsp), %xmm1
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
xorpd %xmm0, %xmm0
movq %rax, 0x50(%rsp)
movq %rbx, %rbp
movq 0x8(%rsp), %rbx
movq (%rsp), %r9
addq $0x2, %r13
movq %r13, 0x40(%rsp)
leaq (%r12,%r12,2), %rcx
shlq $0x4, %rcx
movupd %xmm0, 0x20(%rax,%rcx)
movupd %xmm0, (%rax,%rcx)
movupd %xmm0, 0x10(%rax,%rcx)
movsd %xmm1, 0x20(%rax,%rcx)
movl %r15d, 0x8(%rax,%rcx)
movq 0x38(%rsp), %r8
movl %r8d, 0x14(%rax,%rcx)
movb $0x2, 0x28(%rax,%rcx)
movq 0x18(%rbx), %rdx
movq 0x20(%rdx), %rdx
movl (%rdx,%r15,8), %esi
andl %r10d, %esi
movl (%rdx,%r8,8), %edi
andl %r10d, %edi
cmpl %edi, %esi
cmovbl %esi, %edi
movl %edi, 0x4(%rax,%rcx)
movl $0x0, 0xc(%rax,%rcx)
movl (%rdx,%r15,8), %esi
andl %r10d, %esi
movl (%rdx,%r8,8), %edx
andl %r10d, %edx
cmpl %edx, %esi
cmovbl %esi, %edx
movl %edx, 0x10(%rax,%rcx)
testq %r14, %r14
movq 0x70(%rsp), %r12
je 0x16443a
movq 0x40(%rsp), %r13
movq 0x50(%rsp), %rax
cmpq %rbp, %r13
jne 0x1642ee
leaq (,%rbp,2), %rbx
testq %rbp, %rbp
movl $0x2, %ecx
cmoveq %rcx, %rbx
movq %rbx, 0x48(%rsp)
movq %rbx, %rcx
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
movq %rax, %rdi
callq 0x2370
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
xorpd %xmm0, %xmm0
movq %rax, 0x50(%rsp)
movq %rbx, %rbp
movq 0x8(%rsp), %rbx
leaq (,%r13,2), %rcx
addq %r13, %rcx
shlq $0x4, %rcx
movupd %xmm0, 0x20(%rax,%rcx)
movupd %xmm0, (%rax,%rcx)
movupd %xmm0, 0x10(%rax,%rcx)
xorps %xmm1, %xmm1
cvtsi2sd %r14, %xmm1
movsd %xmm1, 0x20(%rax,%rcx)
movl %r12d, 0x8(%rax,%rcx)
movl %r15d, 0x14(%rax,%rcx)
movb $0x2, 0x28(%rax,%rcx)
movq 0x18(%rbx), %rdx
movq 0x20(%rdx), %rdx
movl (%rdx,%r12,8), %esi
andl %r10d, %esi
movl (%rdx,%r15,8), %edi
andl %r10d, %edi
cmpl %edi, %esi
cmovbl %esi, %edi
leaq 0x1(%r13), %rbx
movl %edi, 0x4(%rax,%rcx)
movl $0x0, 0xc(%rax,%rcx)
movl (%rdx,%r12,8), %esi
andl %r10d, %esi
movl (%rdx,%r15,8), %edx
andl %r10d, %edx
cmpl %edx, %esi
cmovbl %esi, %edx
movl %edx, 0x10(%rax,%rcx)
cmpq %rbp, %rbx
jne 0x1643bc
leaq (,%rbp,2), %r14
testq %rbp, %rbp
movl $0x2, %ecx
cmoveq %rcx, %r14
movq %r14, 0x48(%rsp)
movq %r14, %rcx
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
movq %rax, %rdi
movsd %xmm1, 0x10(%rsp)
callq 0x2370
movsd 0x10(%rsp), %xmm1
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
xorpd %xmm0, %xmm0
movq %rax, 0x50(%rsp)
movq %r14, %rbp
movq (%rsp), %r9
addq $0x2, %r13
movq %r13, 0x40(%rsp)
leaq (%rbx,%rbx,2), %rcx
shlq $0x4, %rcx
movupd %xmm0, 0x20(%rax,%rcx)
movupd %xmm0, (%rax,%rcx)
movupd %xmm0, 0x10(%rax,%rcx)
movsd %xmm1, 0x20(%rax,%rcx)
movl %r15d, 0x8(%rax,%rcx)
movl %r12d, 0x14(%rax,%rcx)
movb $0x2, 0x28(%rax,%rcx)
movq 0x8(%rsp), %rbx
movq 0x18(%rbx), %rdx
movq 0x20(%rdx), %rdx
movl (%rdx,%r15,8), %esi
andl %r10d, %esi
movl (%rdx,%r12,8), %edi
andl %r10d, %edi
cmpl %edi, %esi
cmovbl %esi, %edi
movl %edi, 0x4(%rax,%rcx)
movl $0x0, 0xc(%rax,%rcx)
movl (%rdx,%r15,8), %esi
andl %r10d, %esi
movl (%rdx,%r12,8), %edx
andl %r10d, %edx
cmpl %edx, %esi
cmovbl %esi, %edx
movl %edx, 0x10(%rax,%rcx)
incq %r15
cmpq %r9, %r15
jne 0x164066
movq 0x18(%rsp), %rdi
callq 0x2220
movq 0x30(%rsp), %rax
cmpq %rax, 0x40(%rsp)
jne 0x1645d7
movq 0x18(%rbx), %rax
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl 0x14(%rax), %esi
leaq 0x40(%rsp), %r15
movq %r15, %rdi
callq 0xc4edd
movq 0x18(%rbx), %rax
movl 0x14(%rax), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movl $0x1, %esi
callq 0x2120
movq %rax, %r13
movq 0x38(%rsp), %r14
movb $0x1, (%rax,%r14)
movb $-0x1, (%rax,%r12)
subq $0x8, %rsp
xorl %eax, %eax
movsd 0xcd100(%rip), %xmm0    # 0x2315b0
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %rbx, %rcx
movq 0xb8(%rsp), %r8
xorl %r9d, %r9d
pushq %rax
pushq %rax
pushq 0x38(%rsp)
pushq 0x48(%rsp)
pushq $0x1
pushq %r13
pushq %rax
callq 0x1e07b
addq $0x40, %rsp
movb (%r13,%r14), %al
testb %al, %al
je 0x16458c
movb (%r13,%r12), %cl
testb %cl, %cl
je 0x16458c
cmpb %cl, %al
je 0x16458c
leaq 0x131d2a(%rip), %r14    # 0x296230
movq 0x28(%r14), %rdi
movq 0x50(%r14), %rdx
xorl %esi, %esi
callq 0x20e0
movq (%rsp), %r9
testl %r9d, %r9d
je 0x16458c
xorl %eax, %eax
movq 0x18(%rbx), %rcx
movq 0x20(%rcx), %rcx
cmpl $0x0, (%rcx,%rax,8)
js 0x164584
movb (%r13,%rax), %dl
testb %dl, %dl
je 0x164584
movq 0x10(%rbx), %rcx
leaq (%rax,%rax,4), %rsi
cmpl $0x0, 0xc(%rcx,%rsi,8)
je 0x164584
leaq (%rcx,%rsi,8), %rcx
cmpl $0x0, 0x10(%rcx)
je 0x164584
movq 0x38(%rsp), %rsi
cmpb (%r13,%rsi), %dl
sete %sil
movb $0x2, %dl
subb %sil, %dl
xorl %esi, %esi
movq 0x28(%r14), %rdi
movq 0x18(%rcx), %r8
movq (%r8,%rsi,8), %r8
shrq $0x21, %r8
movb %dl, (%rdi,%r8)
incq %rsi
movl 0x10(%rcx), %edi
cmpq %rdi, %rsi
jb 0x164565
incq %rax
cmpq %r9, %rax
jne 0x164520
movq 0x28(%rsp), %r14
movq %r14, %rdi
callq 0x13dea7
movq %r14, %rdi
callq 0x2220
movq %rbx, %rdi
callq 0xa0761
movq %r13, %rdi
callq 0x2220
movq 0x50(%rsp), %rdi
callq 0x2220
movq 0x68(%rsp), %rdi
callq 0x2220
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd8598(%rip), %rdi     # 0x23cb76
leaq 0xd84a7(%rip), %rsi     # 0x23ca8c
leaq 0xd85a2(%rip), %rcx     # 0x23cb8e
movl $0x45dd, %edx           # imm = 0x45DD
callq 0x2110