// File: /workspace/github_cpp_makefile_star2_O1/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 $0xa8, %rsp
movq %rcx, %r14
movq %rdx, %rbp
movq %rsi, %r12
callq 0xc815c
movq %rax, %rbx
leaq 0x40(%rsp), %r15
movq $0x0, (%r15)
movq 0x18(%rax), %rax
movl 0x14(%rax), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andq %rcx, %rax
movq %rax, 0x48(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq %r15, %rcx
xorl %r8d, %r8d
callq 0x1f04d1
movq %rax, %r13
movq (%r15), %rdi
callq 0x2220
movsd 0xc874c(%rip), %xmm0    # 0x225498
movq %rbp, 0x58(%rsp)
movq %rbp, %rdi
movq %rbx, %rsi
movq %r12, 0xa0(%rsp)
movq %r12, %rdx
xorl %ecx, %ecx
callq 0xc476d
movq 0x18(%rbx), %rdi
movl 0x14(%rdi), %esi
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andq %rax, %rsi
movq %rbx, %r12
movl $0x1, %ebp
movq %rsi, 0x68(%rsp)
movl $0x1, %edx
xorl %ecx, %ecx
callq 0xa0115
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0x15cdc6
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, 0x10(%r12)
movabsq $-0xffffffff, %r14      # imm = 0xFFFFFFFF00000001
movq (%r12), %rax
movq 0x10(%r12), %rbx
leaq 0x1(%rax), %rcx
movq %rcx, (%r12)
leaq (%rax,%rax,4), %r15
xorpd %xmm0, %xmm0
movupd %xmm0, (%rbx,%r15,8)
movupd %xmm0, 0x10(%rbx,%r15,8)
movq $0x0, 0x20(%rbx,%r15,8)
movq $-0x1, 0x4(%rbx,%r15,8)
movl %ebp, 0xc(%rbx,%r15,8)
movl %ebp, 0x10(%rbx,%r15,8)
movl $0x80000001, (%rbx,%r15,8) # imm = 0x80000001
movl $0x8, %edi
callq 0x2280
movq %rax, 0x18(%rbx,%r15,8)
movq %r14, (%rax)
movq 0x18(%r12), %rdi
movl 0x14(%rdi), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movq %rsi, 0x70(%rsp)
movl $0x2, %edx
xorl %ecx, %ecx
callq 0xa0115
movq 0x8(%r12), %rax
cmpq %rax, (%r12)
jne 0x15ce82
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, 0x10(%r12)
movq (%r12), %rax
movq 0x10(%r12), %rbx
leaq 0x1(%rax), %rcx
movq %rcx, (%r12)
leaq (%rax,%rax,4), %r15
xorpd %xmm0, %xmm0
movupd %xmm0, (%rbx,%r15,8)
movupd %xmm0, 0x10(%rbx,%r15,8)
movq %r12, 0x8(%rsp)
xorl %r12d, %r12d
movq %r12, 0x20(%rbx,%r15,8)
movq $-0x1, 0x4(%rbx,%r15,8)
movl $0x1, %eax
movl %eax, 0xc(%rbx,%r15,8)
movl %eax, 0x10(%rbx,%r15,8)
movl $0x80000002, (%rbx,%r15,8) # imm = 0x80000002
movl $0x8, %edi
callq 0x2280
movq %rax, 0x18(%rbx,%r15,8)
incq %r14
movq %r14, (%rax)
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x28(%rax), %rdi
callq 0x2220
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movq %r12, 0x28(%rax)
movq 0x8(%rsp), %r14
andb $0x7f, 0x7(%rax)
movq 0x18(%r14), %rdi
callq 0xa02fa
movq (%r13), %rdi
movq 0x18(%r14), %rax
movl 0x14(%rax), %esi
movl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
andq %rbx, %rsi
shlq $0x2, %rsi
callq 0x2370
movq %rax, (%r13)
movq 0x18(%r14), %rcx
movl 0x14(%rcx), %edx
andq %rbx, %rdx
movq 0x48(%rsp), %rbx
cmpl %edx, %ebx
jae 0x15cf6e
movl 0x80(%r13), %esi
incl %esi
movq %rbx, %rdi
movl %esi, (%rax,%rdi,4)
incq %rdi
movl 0x14(%rcx), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
cmpq %rdx, %rdi
jb 0x15cf5a
movq %rdx, 0x60(%r13)
movl 0x14(%rcx), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, 0x68(%r13)
jae 0x15cfd1
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(%r13)
movq 0x70(%r13), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, 0x70(%r13)
cmpq %rbx, 0x68(%r13)
jbe 0x15cfef
movq 0x70(%r13), %rax
movq %rbx, %rcx
movq $-0x1, (%rax,%rcx,8)
incq %rcx
cmpq 0x68(%r13), %rcx
jb 0x15cfde
movq 0x18(%r14), %rax
movl 0x14(%rax), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movl $0x1, %esi
callq 0x2120
movq %rax, 0x40(%rsp)
testl %ebx, %ebx
je 0x15d104
xorl %eax, %eax
leaq 0x12e214(%rip), %rcx    # 0x28b230
xorl %r11d, %r11d
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x18(%r14), %rdx
movq 0x20(%rdx), %rdx
cmpl $0x0, (%rdx,%rax,8)
js 0x15d0f6
movq 0x10(%r14), %rdx
leaq (%rax,%rax,4), %rsi
movl 0x10(%rdx,%rsi,8), %edi
addq %rdi, %r11
testq %rdi, %rdi
je 0x15d0f6
leaq (%rdx,%rsi,8), %rdx
cmpl $0x0, 0xc(%rdx)
je 0x15d0f6
cmpl $0x0, 0x10(%rdx)
je 0x15d0cf
xorl %esi, %esi
xorl %r8d, %r8d
xorl %edi, %edi
movq 0x28(%rcx), %r9
movq 0x18(%rdx), %r10
movq (%r10,%rdi,8), %r10
shrq $0x21, %r10
movzbl (%r9,%r10), %r9d
cmpl $0x2, %r9d
je 0x15d096
cmpl $0x1, %r9d
jne 0x15d09e
incq %r15
movl $0x1, %r8d
jmp 0x15d09e
incq %r15
movl $0x1, %esi
decb %r9b
cmpb $0x1, %r9b
ja 0x15d0b4
incq %r15
movq 0x40(%rsp), %r9
movb $0x1, (%r9,%rax)
incq %rdi
movl 0x10(%rdx), %r9d
cmpq %r9, %rdi
jb 0x15d06a
testq %r8, %r8
setg %dil
testq %rsi, %rsi
setg %dl
jmp 0x15d0d3
xorl %edi, %edi
xorl %edx, %edx
testb %dil, %dil
je 0x15d0e5
movq 0x40(%rsp), %rsi
movb $0x1, (%rsi,%rax)
addq $0x2, %r12
testb %dl, %dl
je 0x15d0f6
movq 0x40(%rsp), %rdx
movb $0x1, (%rdx,%rax)
addq $0x2, %r12
incq %rax
cmpq %rbx, %rax
jne 0x15d025
jmp 0x15d10f
xorl %r12d, %r12d
xorl %r15d, %r15d
xorl %r11d, %r11d
xorl %eax, %eax
movq %r11, (%rsp)
movq 0x18(%r14), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rcx, %rax
jae 0x15d133
movq 0x40(%rsp), %rcx
movb $0x1, (%rcx,%rax)
incq %rax
jmp 0x15d113
movq %r12, 0x60(%rsp)
movq %r13, 0x50(%rsp)
movq 0x58(%rsp), %rbx
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0x15d174
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmovneq %rcx, %rax
movq %rax, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x4, %rax
leaq (%rax,%rax,2), %rsi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbx)
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, %r12 # imm = 0x7FDFFFFFFFFFFFFF
movq %r12, 0x20(%rax,%rcx)
movq 0x48(%rsp), %rdi
movl %edi, 0x8(%rax,%rcx)
movl %edi, %edx
leaq 0x1(%rdx), %r14
leal 0x1(%rdi), %ebp
movl %ebp, 0x14(%rax,%rcx)
movb $0x2, 0x28(%rax,%rcx)
xorl %r8d, %r8d
movl %r8d, (%rax,%rcx)
movq 0x8(%rsp), %rsi
movq 0x18(%rsi), %rsi
movq 0x20(%rsi), %rsi
movl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
movl (%rsi,%rdi,8), %edi
andl %r13d, %edi
movl %edi, 0x4(%rax,%rcx)
movl %r8d, 0xc(%rax,%rcx)
movl 0x8(%rsi,%rdx,8), %edx
andl %r13d, %edx
movl %edx, 0x10(%rax,%rcx)
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0x15d233
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmovneq %rcx, %rax
movq %rax, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x4, %rax
leaq (%rax,%rax,2), %rsi
callq 0x2370
xorpd %xmm0, %xmm0
movq %rax, 0x10(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
movupd %xmm0, 0x20(%rcx,%rax)
movupd %xmm0, (%rcx,%rax)
movupd %xmm0, 0x10(%rcx,%rax)
movq %r12, 0x20(%rcx,%rax)
movl %ebp, 0x8(%rcx,%rax)
movq 0x48(%rsp), %r8
movl %r8d, 0x14(%rcx,%rax)
movb $0x2, 0x28(%rcx,%rax)
xorl %r12d, %r12d
movl %r12d, (%rcx,%rax)
movq 0x8(%rsp), %rdx
movq 0x18(%rdx), %rdx
movq 0x20(%rdx), %rsi
movl (%rsi,%r14,8), %edi
andl %r13d, %edi
movl %edi, 0x4(%rcx,%rax)
movl %r12d, 0xc(%rcx,%rax)
movl (%rsi,%r8,8), %esi
andl %r13d, %esi
movl %esi, 0x10(%rcx,%rax)
andl 0x14(%rdx), %r13d
movq %rbx, %rdi
movl %r13d, %esi
callq 0xc405a
movq (%rbx), %rax
testq %rax, %rax
movq %rbx, %r13
je 0x15d305
movq 0x10(%r13), %rcx
addq $0x28, %rcx
xorl %r12d, %r12d
movq 0x50(%rsp), %rbx
movq 0x60(%rsp), %r8
cmpb $0x0, (%rcx)
js 0x15d2fa
movq (%rbx), %rsi
movq 0x80(%rbx), %rdx
movl -0x20(%rcx), %edi
movl (%rsi,%rdi,4), %edi
incq %rdx
cmpq %rdi, %rdx
jb 0x15d2fa
movl -0x14(%rcx), %edi
movl (%rsi,%rdi,4), %esi
cmpq %rsi, %rdx
sbbq $-0x1, %r12
addq $0x30, %rcx
decq %rax
jne 0x15d2d0
jmp 0x15d30f
movq 0x50(%rsp), %rbx
movq 0x60(%rsp), %r8
addq %r8, %r12
cmpq %r12, 0x18(%rsp)
jae 0x15d36e
leaq -0x1(%r12), %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
incq %rcx
movq %rcx, 0x18(%rsp)
movq 0x20(%rsp), %rdi
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq %rax, 0x20(%rsp)
movq %r12, 0x60(%rsp)
movq $0x0, 0x10(%rsp)
cmpq $0x0, (%r13)
movq (%rsp), %rdi
je 0x15d5a7
addq %r15, %rdi
xorl %r15d, %r15d
xorl %r12d, %r12d
movq %rdi, (%rsp)
movq 0x10(%r13), %rax
cmpb $0x0, 0x28(%rax,%r15)
js 0x15d596
movq (%rbx), %rdx
movq 0x80(%rbx), %rcx
movl 0x8(%rax,%r15), %esi
movl (%rdx,%rsi,4), %esi
incq %rcx
cmpq %rsi, %rcx
jb 0x15d596
movl 0x14(%rax,%r15), %eax
movl (%rdx,%rax,4), %eax
cmpq %rax, %rcx
jb 0x15d596
movq 0x18(%rsp), %rax
cmpq %rax, 0x10(%rsp)
jne 0x15d413
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x18(%rsp)
movq 0x20(%rsp), %rdi
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq (%rsp), %rdi
movq %rax, 0x20(%rsp)
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rbp
leaq 0x1(%rax), %rcx
movq %rcx, 0x10(%rsp)
leaq (%rax,%rax,2), %r14
shlq $0x4, %r14
xorpd %xmm0, %xmm0
movupd %xmm0, 0x20(%rbp,%r14)
movupd %xmm0, 0x10(%rbp,%r14)
movupd %xmm0, (%rbp,%r14)
movq 0x10(%r13), %rbx
movl 0x8(%rbx,%r15), %eax
movq %r13, %rcx
movq %rdi, %r13
cmpl 0x48(%rsp), %eax
jae 0x15d548
movl 0x14(%rbx,%r15), %edx
movq %rdi, %r13
cmpl 0x48(%rsp), %edx
jae 0x15d548
movl (%rbx,%r15), %edi
movq %rdi, 0x90(%rsp)
movl 0x4(%rbx,%r15), %esi
movq %rsi, 0x88(%rsp)
movq %rdx, 0x78(%rsp)
movq 0x8(%rsp), %rdx
movq 0x10(%rdx), %r13
leaq (%rax,%rax,4), %rax
leaq (,%rax,8), %rdx
addq %r13, %rdx
movq %rdx, 0x80(%rsp)
callq 0x15cc61
movq %rax, 0x98(%rsp)
movl 0xc(%rbx,%r15), %edi
movl 0x10(%rbx,%r15), %esi
movq 0x78(%rsp), %rax
leaq (%rax,%rax,4), %rax
leaq (,%rax,8), %rdx
addq %r13, %rdx
callq 0x15cc61
movq %rax, %r13
movq 0x90(%rsp), %rdi
movq 0x88(%rsp), %rsi
movq 0x80(%rsp), %rdx
callq 0x1f2d50
movq %rax, %rbx
movq 0x58(%rsp), %rax
movq 0x10(%rax), %rax
movl 0xc(%rax,%r15), %edi
movl 0x10(%rax,%r15), %esi
movl 0x14(%rax,%r15), %eax
leaq (%rax,%rax,4), %rdx
shlq $0x3, %rdx
movq 0x8(%rsp), %rax
addq 0x10(%rax), %rdx
callq 0x1f2d50
movq 0x58(%rsp), %rcx
movq (%rsp), %rdi
addq 0x98(%rsp), %r13
addq %rbx, %r13
addq %rax, %r13
addq %r14, %rbp
movq 0x10(%rcx), %rax
movups (%rax,%r15), %xmm0
movupd 0x10(%rax,%r15), %xmm1
movups 0x20(%rax,%r15), %xmm2
movups %xmm2, 0x20(%rbp)
movupd %xmm1, 0x10(%rbp)
movups %xmm0, (%rbp)
cmpq $0x2, %r13
jae 0x15d57c
movl $0x1, %r13d
jmp 0x15d57f
shrq %r13
xorps %xmm0, %xmm0
cvtsi2sd %r13, %xmm0
movsd %xmm0, 0x20(%rbp)
movq 0x50(%rsp), %rbx
movq 0x58(%rsp), %r13
incq %r12
addq $0x30, %r15
cmpq (%r13), %r12
jb 0x15d398
movq 0x48(%rsp), %r12
testl %r12d, %r12d
movq 0x8(%rsp), %rbx
je 0x15d987
xorl %r9d, %r9d
xorpd %xmm0, %xmm0
movl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
xorl %ebp, %ebp
movq 0x40(%rsp), %rax
cmpb $0x0, (%rax,%rbp)
je 0x15d97b
movq 0x10(%rbx), %rcx
leaq (,%rbp,4), %rdx
addq %rbp, %rdx
movl 0x10(%rcx,%rdx,8), %eax
testq %rax, %rax
je 0x15d97b
leaq (%rcx,%rdx,8), %rdx
cmpl $0x0, 0xc(%rdx)
je 0x15d97b
leaq 0x12dc27(%rip), %rcx    # 0x28b230
movq 0x28(%rcx), %rcx
movq 0x18(%rdx), %rdx
xorl %r15d, %r15d
xorl %r14d, %r14d
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, %r14
xorl %r8d, %r8d
cmpb $0x2, %dil
sete %r8b
subq %r8, %r15
incq %rsi
cmpq %rsi, %rax
jne 0x15d619
testq %r14, %r14
je 0x15d7e3
movq 0x18(%rsp), %rax
cmpq %rax, 0x10(%rsp)
jne 0x15d691
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x18(%rsp)
movq 0x20(%rsp), %rdi
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
xorpd %xmm0, %xmm0
xorl %r9d, %r9d
movq %rax, 0x20(%rsp)
movq 0x10(%rsp), %rcx
movq 0x20(%rsp), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, 0x10(%rsp)
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
movupd %xmm0, 0x20(%rax,%rcx)
movupd %xmm0, (%rax,%rcx)
cvtsi2sd %r14, %xmm1
movupd %xmm0, 0x10(%rax,%rcx)
movsd %xmm1, 0x20(%rax,%rcx)
movq 0x68(%rsp), %r8
movl %r8d, 0x8(%rax,%rcx)
movl %ebp, 0x14(%rax,%rcx)
movb $0x2, 0x28(%rax,%rcx)
movl %r9d, (%rax,%rcx)
movq 0x18(%rbx), %rdx
movq 0x20(%rdx), %rdx
movl (%rdx,%r8,8), %esi
andl %r13d, %esi
movl (%rdx,%rbp,8), %edi
andl %r13d, %edi
cmpl %edi, %esi
cmovbl %esi, %edi
movl %edi, 0x4(%rax,%rcx)
movl %r9d, 0xc(%rax,%rcx)
movl (%rdx,%r8,8), %esi
andl %r13d, %esi
movl (%rdx,%rbp,8), %edx
andl %r13d, %edx
cmpl %edx, %esi
cmovbl %esi, %edx
movl %edx, 0x10(%rax,%rcx)
movq 0x18(%rsp), %rax
cmpq %rax, 0x10(%rsp)
jne 0x15d761
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x18(%rsp)
movq 0x20(%rsp), %rdi
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
movsd %xmm1, (%rsp)
callq 0x2370
movsd (%rsp), %xmm1
xorpd %xmm0, %xmm0
xorl %r9d, %r9d
movq %rax, 0x20(%rsp)
movq 0x10(%rsp), %rcx
movq 0x20(%rsp), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, 0x10(%rsp)
leaq (%rcx,%rcx,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 %ebp, 0x8(%rax,%rcx)
movq 0x68(%rsp), %r8
movl %r8d, 0x14(%rax,%rcx)
movb $0x2, 0x28(%rax,%rcx)
movl %r9d, (%rax,%rcx)
movq 0x18(%rbx), %rdx
movq 0x20(%rdx), %rdx
movl (%rdx,%rbp,8), %esi
andl %r13d, %esi
movl (%rdx,%r8,8), %edi
andl %r13d, %edi
cmpl %edi, %esi
cmovbl %esi, %edi
movl %edi, 0x4(%rax,%rcx)
movl %r9d, 0xc(%rax,%rcx)
movl (%rdx,%rbp,8), %esi
andl %r13d, %esi
movl (%rdx,%r8,8), %edx
andl %r13d, %edx
cmpl %edx, %esi
cmovbl %esi, %edx
movl %edx, 0x10(%rax,%rcx)
testq %r15, %r15
je 0x15d97b
movq 0x18(%rsp), %rax
cmpq %rax, 0x10(%rsp)
jne 0x15d82b
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x18(%rsp)
movq 0x20(%rsp), %rdi
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
xorpd %xmm0, %xmm0
xorl %r9d, %r9d
movq %rax, 0x20(%rsp)
movq 0x10(%rsp), %rcx
movq 0x20(%rsp), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, 0x10(%rsp)
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
movupd %xmm0, 0x20(%rax,%rcx)
movupd %xmm0, (%rax,%rcx)
xorps %xmm1, %xmm1
cvtsi2sd %r15, %xmm1
movupd %xmm0, 0x10(%rax,%rcx)
movsd %xmm1, 0x20(%rax,%rcx)
movq 0x70(%rsp), %r14
movl %r14d, 0x8(%rax,%rcx)
movl %ebp, 0x14(%rax,%rcx)
movb $0x2, 0x28(%rax,%rcx)
movl %r9d, (%rax,%rcx)
movq 0x18(%rbx), %rdx
movq 0x20(%rdx), %rdx
movl (%rdx,%r14,8), %esi
andl %r13d, %esi
movl (%rdx,%rbp,8), %edi
andl %r13d, %edi
cmpl %edi, %esi
cmovbl %esi, %edi
movl %edi, 0x4(%rax,%rcx)
movl %r9d, 0xc(%rax,%rcx)
movl (%rdx,%r14,8), %esi
andl %r13d, %esi
movl (%rdx,%rbp,8), %edx
andl %r13d, %edx
cmpl %edx, %esi
cmovbl %esi, %edx
movl %edx, 0x10(%rax,%rcx)
movq 0x18(%rsp), %rax
cmpq %rax, 0x10(%rsp)
jne 0x15d8fe
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x18(%rsp)
movq 0x20(%rsp), %rdi
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
movsd %xmm1, (%rsp)
callq 0x2370
movsd (%rsp), %xmm1
xorpd %xmm0, %xmm0
xorl %r9d, %r9d
movq %rax, 0x20(%rsp)
movq 0x10(%rsp), %rcx
movq 0x20(%rsp), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, 0x10(%rsp)
leaq (%rcx,%rcx,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 %ebp, 0x8(%rax,%rcx)
movl %r14d, 0x14(%rax,%rcx)
movb $0x2, 0x28(%rax,%rcx)
movl %r9d, (%rax,%rcx)
movq 0x18(%rbx), %rdx
movq 0x20(%rdx), %rdx
movl (%rdx,%rbp,8), %esi
andl %r13d, %esi
movl (%rdx,%r14,8), %edi
andl %r13d, %edi
cmpl %edi, %esi
cmovbl %esi, %edi
movl %edi, 0x4(%rax,%rcx)
movl %r9d, 0xc(%rax,%rcx)
movl (%rdx,%rbp,8), %esi
andl %r13d, %esi
movl (%rdx,%r14,8), %edx
andl %r13d, %edx
cmpl %edx, %esi
cmovbl %esi, %edx
movl %edx, 0x10(%rax,%rcx)
incq %rbp
cmpq %r12, %rbp
jne 0x15d5c9
movq 0x40(%rsp), %rdi
callq 0x2220
movq 0x60(%rsp), %rax
cmpq %rax, 0x10(%rsp)
jne 0x15db18
movq 0x18(%rbx), %rax
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl 0x14(%rax), %esi
leaq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0xc405a
movq 0x18(%rbx), %rax
movl 0x14(%rax), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movl $0x1, %esi
callq 0x2120
movq %rax, %r13
movq 0x68(%rsp), %r14
movb $0x1, (%rax,%r14)
movq 0x70(%rsp), %rbp
movb $-0x1, (%rax,%rbp)
subq $0x8, %rsp
xorl %eax, %eax
movsd 0xc7abb(%rip), %xmm0    # 0x2254b0
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %rbx, %rcx
movq 0xa8(%rsp), %r8
xorl %r9d, %r9d
pushq %rax
pushq %rax
pushq 0x70(%rsp)
pushq 0x70(%rsp)
pushq $0x1
pushq %r13
pushq %rax
callq 0x1edea
addq $0x40, %rsp
movb (%r13,%r14), %al
testb %al, %al
je 0x15dacd
movb (%r13,%rbp), %cl
testb %cl, %cl
je 0x15dacd
cmpb %cl, %al
je 0x15dacd
leaq 0x12d7e5(%rip), %r14    # 0x28b230
movq 0x28(%r14), %rdi
movq 0x50(%r14), %rdx
xorl %esi, %esi
callq 0x20e0
testl %r12d, %r12d
je 0x15dacd
xorl %eax, %eax
movq 0x18(%rbx), %rcx
movq 0x20(%rcx), %rcx
cmpl $0x0, (%rcx,%rax,8)
js 0x15dac5
movb (%r13,%rax), %dl
testb %dl, %dl
je 0x15dac5
movq 0x10(%rbx), %rcx
leaq (%rax,%rax,4), %rsi
cmpl $0x0, 0xc(%rcx,%rsi,8)
je 0x15dac5
leaq (%rcx,%rsi,8), %rcx
cmpl $0x0, 0x10(%rcx)
je 0x15dac5
movq 0x68(%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 0x15daa6
incq %rax
cmpq %r12, %rax
jne 0x15da61
movq 0x50(%rsp), %r14
movq %r14, %rdi
callq 0x1380d4
movq %r14, %rdi
callq 0x2220
movq %rbx, %rdi
callq 0xa0004
movq %r13, %rdi
callq 0x2220
movq 0x20(%rsp), %rdi
callq 0x2220
movq 0x38(%rsp), %rdi
callq 0x2220
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd2e4b(%rip), %rdi     # 0x23096a
leaq 0xd2d5a(%rip), %rsi     # 0x230880
leaq 0xd2e55(%rip), %rcx     # 0x230982
movl $0x45dd, %edx           # imm = 0x45DD
callq 0x2110