// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/inter.cpp
// Function: mg_gchain1_dp(void*, ma_ug_t const*, asg_t const*, int*, mg_lchain_t*, int, int, int, int, int, int, float, float, int, ug_opt_t const*, mg128_t const*, unsigned long**)
int32_t mg_gchain1_dp(void *km, const ma_ug_t *ug, const asg_t *rg, int32_t *n_lc_, mg_lchain_t *lc, int32_t qlen, int32_t max_dist_g, int32_t max_dist_q, int32_t bw, int32_t max_skip,
                      int32_t ref_bonus, float chn_pen_gap, float mask_level, int32_t max_gc_seq_ext, const ug_opt_t *uopt, const mg128_t *an, uint64_t **u_)
{
    int32_t i, j, k, m_dst, n_dst, n_ext, n_u, n_v, n_lc = *n_lc_, rrs, rre;
    int32_t *f, *v, *t, li_qs, li_qe, li_rs, li_re, lj_qs, lj_qe, lj_rs, lj_re;
    int64_t *p;
    uint64_t *u;
    mg_path_dst_t *dst;
    gc_frag_t *a;
    mg_lchain_t *swap;
    // char *qs;
    asg_t *g = ug->g;

    *u_ = 0;
    if (n_lc == 0) return 0;

	// extend_lchain(lc, n_lc, qlen, ug);
    KMALLOC(km, a, n_lc);
    ///n_lc how many linear chains; just filter some linear chains
    for (i = n_ext = 0; i < n_lc; ++i) { // a[] is a view of frag[]; for sorting
        mg_lchain_t *r = &lc[i];
        gc_frag_t *ai = &a[i];
        int32_t is_isolated = 0, min_end_dist_g;
		transfor_coord(r, qlen, ug->u.a[r->v>>1].len, NULL, NULL, &rrs, &rre);
        r->dist_pre = -1;///indicate parent in graph chain
        min_end_dist_g = g->seq[r->v>>1].len - rre;///r->v: ref_id|rev
        if (rrs < min_end_dist_g) min_end_dist_g = rrs;
        if (min_end_dist_g > max_dist_g) is_isolated = 1; // if too far from segment ends
        else if (min_end_dist_g>>3 > r->score) is_isolated = 1; // if the lchain too small relative to distance to the segment ends
        ai->srt = (uint32_t)is_isolated<<31 | r->qe;
        ai->i = i;
        if (!is_isolated) ++n_ext;
    }
    ///if the alignment is too far from segment ends, which means it cannot contribute to graph alignment
    if (n_ext < 2) { // no graph chaining needed; early return
        kfree(km, a);
        KMALLOC(km, u, n_lc);
        for (i = 0; i < n_lc; ++i)
            u[i] = (uint64_t)lc[i].score<<32 | 1;
        *u_ = u;
		// compress_lchain(lc, n_lc, qlen, ug, an);
        return n_lc;
    }
    radix_sort_gc(a, a + n_lc);///sort by: is_isolated(1):qe

    KMALLOC(km, v, n_lc);
    KMALLOC(km, f, n_ext);
    KMALLOC(km, p, n_ext);
    KCALLOC(km, t, n_ext);
    // KMALLOC(km, qs, max_dist_q + 1);//for 

    m_dst = n_dst = 0, dst = 0;
    ///n_ext is number of linear chains that might be included in graph chains
    ///sorted by the positions in query; sorted by qe of each chain
    for (i = 0; i < n_ext; ++i) { // core loop
        gc_frag_t *ai = &a[i];
        mg_lchain_t *li = &lc[ai->i];///linear chain; sorted by qe, i.e. end position in query
		int32_t mm_ovlp = max_ovlp(ug->g, li->v^1);
		transfor_coord(li, qlen, ug->u.a[li->v>>1].len, &li_qs, &li_qe, &li_rs, &li_re);
        ///note segi is query id, instead of ref id; it is not such useful
        /**
         * a[].x: idx_in_minimizer_arr(32)r_pos(32)
         * a[].y: weight(8)query_id(8)flag(8)span(8)q_pos(32)
        **/
        { // collect end points potentially reachable from _i_
            int32_t x = li->qs + bw + mm_ovlp, n_skip = 0;
            if (x > qlen) x = qlen;
            ///collect alignments that can be reachable from the left side
            ///that is, a[x].qe <= x
            x = find_max(i, a, x);
            n_dst = 0;
            for (j = x; j >= 0; --j) { // collect potential destination vertices
                gc_frag_t *aj = &a[j];
                //potential chains that might be overlapped with the left side of li
                mg_lchain_t *lj = &lc[aj->i];
                mg_path_dst_t *q;
                int32_t target_dist, dq/**, so = specific_ovlp(ug, uopt, li->v^1, lj->v^1)**/;
				transfor_coord(lj, qlen, ug->u.a[lj->v>>1].len, &lj_qs, &lj_qe, &lj_rs, &lj_re);
                ///lj->qs >= li->qs && lj->qe <= li->qs, so lj is contained
                if (lj->qs >= li->qs) continue; // lj is contained in li on the query coordinate
				/**
				  * doesn't work for overlap graph
                if (lj_qe > li_qs) { // test overlap on the query
                    int o = lj_qe - li_qs - so;///get_lchain_ovlp(lj, li, ug->g, qlen, ug); 
					///mask_level = 0.5, if overlap is too long
                    ///note here is the overlap in query, so too long overlaps might be wrong
                    if (o > (lj->qe - lj->qs) * mask_level || o > (li->qe - li->qs) * mask_level)
                        continue;
                }
				**/
                dq = li_qs - lj_qe;///dq might be smaller than 0
                if (dq > max_dist_q) break; // if query gap too large, stop
                ///The above filter chains like:
                ///1. lj is contained in li
                ///2. the overlap between li and lj is too large
                ///3. li and lj are too far
                ///above we have checked gap/overlap in query 
                ///then we need to check gap/overlap in reference
                if (li->v != lj->v) { // the two linear chains are on two different refs
                    // minimal graph gap; the real graph gap might be larger
                    int32_t min_dist = li_rs + (g->seq[lj->v>>1].len - lj_re); 
                    if (min_dist > max_dist_g) continue; // graph gap too large
                    //note here min_dist - (lj->qs - li->qe) > bw is important
                    //min_dist is always larger than 0, (lj->qs - li->qe) might be negative 
					/**
				  	  * doesn't work for overlap graph
					min_dist -= so;
					if (min_dist - bw > li->qs - lj->qe) continue; ///note seg* is the query id, instead of ref id
					**/
					target_dist = mg_target_dist(g, lj, li);
                    if (target_dist < 0) continue; // this may happen if the query overlap is far too large
                } else if (lj->rs >= li->rs || lj->re >= li->re) { // not colinear
                    continue;
                } else {///li->v == lj->v and colinear; at the same ref id
                    ///w is indel, w is always positive
                    int32_t dr = li->rs - lj->re, dq = li->qs - lj->qe, w = dr > dq? dr - dq : dq - dr;
                    ///note that l*->v is the ref id, while seg* is the query id
                    if (w > bw) continue; // test bandwidth
                    if (dr > max_dist_g || dr < -max_dist_g) continue;
                    if (lj->re > li->rs) { // test overlap on the graph segment
                        int o = lj->re - li->rs;
                        if (o > (lj->re - lj->rs) * mask_level || o > (li->re - li->rs) * mask_level)
                            continue;
                    }
                    target_dist = mg_target_dist(g, lj, li);
                }
                if (n_dst == m_dst) KEXPAND(km, dst, m_dst); // TODO: watch out the quadratic behavior!
                q = &dst[n_dst++];///q saves information for i->j
                memset(q, 0, sizeof(mg_path_dst_t));
                ///note v is (rid:rev), so two alignment chains might be at the same ref id with different directions
                q->inner = (li->v == lj->v);
                q->v = lj->v^1;///must be v^1 instead of v
                q->meta = j;
                q->qlen = li->qs - lj->qe;///might be negative
				/**
				  * doesn't work for overlap graph
				q->so = 0;
				if(li->v != lj->v && lj->qe > li->qs) {
					lj_qe = lj->qe; li_qs = li->qs + g->seq[lj->v>>1].len - so;
					q->so = lj_qe - li_qs;
					if(q->so < 0) q->so = 0;
				}
				**/
                q->target_dist = target_dist;///cannot understand the target_dist
                q->target_hash = 0;
                q->check_hash = 0;
                if (t[j] == i) {///this pre-cut is weird; attention
                    if (++n_skip > max_skip)
                        break;
                }
                if (p[j] >= 0) t[p[j]] = i;
            }
        }
        ///the above saves all linear chains that might be reached to the left side of chain i
        ///all those chains are saved to dst<n_dst>
        { // confirm reach-ability
            int32_t k;
            // test reach-ability without sequences
            // (g->seg[li->v>>1].len - li->rs) ----> is like the node length in string graph
            mg_shortest_k(km, g, li->v^1, n_dst, dst, max_dist_g + (g->seq[li->v>>1].len - li->rs), MG_MAX_SHORT_K, /**0, 0, 1,**/ 0);
            // remove unreachable destinations
            for (j = k = 0; j < n_dst; ++j) {
                mg_path_dst_t *dj = &dst[j];
                int32_t sc;
                if (dj->n_path == 0) continue; // unreachable
                sc = cal_sc(dj, li, lc, an, a, f, bw, ref_bonus, chn_pen_gap);
                if (sc == INT32_MIN) continue; // out of band
                if (sc + li->score < 0) continue; // negative score and too low
                dst[k] = dst[j];
                dst[k++].srt_key = INT64_MAX/2 - (int64_t)sc; // sort in the descending order
            }
            n_dst = k;
            if (n_dst > 0) {
                radix_sort_dst(dst, dst + n_dst);
                // discard weaker chains if the best score is much larger (assuming base-level heuristic won't lift it to the top chain)
                // dst[0].srt_key has the largest score
                for (j = 1; j < n_dst; ++j) 
                    if ((int64_t)(dst[j].srt_key - dst[0].srt_key) > li->score)//discard chains with too small weight
                        break;
                n_dst = j;
                if (n_dst > max_gc_seq_ext) n_dst = max_gc_seq_ext; // discard weaker chains
            }
        }
		/** //path
        if (n_dst > 0) { // find paths with sequences
            int32_t min_qs = li->qs;
            for (j = 0; j < n_dst; ++j) {
                const mg_lchain_t *lj;
                assert(dst[j].n_path > 0);
                ///a[]->srt = (uint32_t)is_isolated<<31 | r->qe;
                ///a[]->i = i;
                lj = &lc[a[dst[j].meta].i];
                if (lj->qe < min_qs) min_qs = lj->qe;
            }
            ///qs keeps the sequence at the gap between the li and lj in query
            memcpy(qs, &qseq[min_qs], li->qs - min_qs);
            mg_shortest_k(km, g, li->v^1, n_dst, dst, max_dist_g + (g->seg[li->v>>1].len - li->rs), MG_MAX_SHORT_K, li->qs - min_qs, qs, 1, 0);
            if (mg_dbg_flag & MG_DBG_GC1) fprintf(stderr, "[src:%d] q_intv=[%d,%d), src=%c%s[%d], n_dst=%d, max_dist=%d, min_qs=%d, lc_score=%d\n", ai->i, li->qs, li->qe, "><"[(li->v&1)^1], g->seg[li->v>>1].name, li->v^1, n_dst, max_dist_g + (g->seg[li->v>>1].len - li->rs), min_qs, li->score);
        }**/
        { // DP
            int32_t max_f = li->score, max_j = -1, max_d = -1, max_inner = 0;
            uint32_t max_hash = 0;
            for (j = 0; j < n_dst; ++j) {
                mg_path_dst_t *dj = &dst[j];
                int32_t sc;
                sc = cal_sc(dj, li, lc, an, a, f, bw, ref_bonus, chn_pen_gap);
                if (sc == INT32_MIN) continue;
                if (sc > max_f) max_f = sc, max_j = dj->meta, max_d = dj->dist, max_hash = dj->hash, max_inner = dj->inner;
            }
            f[i] = max_f, p[i] = max_j;
            li->dist_pre = max_d;
            li->hash_pre = max_hash;
            li->inner_pre = max_inner;
            v[i] = max_j >= 0 && v[max_j] > max_f? v[max_j] : max_f;
        }
    }
    kfree(km, dst);

	// print_gchain(a, p, lc, n_ext, ug, qlen);

    // kfree(km, qs);
    ///n_ext: number of useful chains
    ///n_lc - n_ext: number of isoated chains
    u = mg_chain_backtrack(km, n_ext, f, p, v, t, 0, 0, n_lc - n_ext, &n_u, &n_v);
    kfree(km, f); kfree(km, p); kfree(km, t);
    ///store the extra isoated chains
    for (i = 0; i < n_lc - n_ext; ++i) {
        u[n_u++] = (uint64_t)lc[a[n_ext + i].i].score << 32 | 1;
        v[n_v++] = n_ext + i;
    }

    ///reorganize lc;
    KMALLOC(km, swap, n_v);
    for (i = 0, k = 0; i < n_u; ++i) {
        int32_t k0 = k, ni = (int32_t)u[i];
        for (j = 0; j < ni; ++j)
            swap[k++] = lc[a[v[k0 + (ni - j - 1)]].i];
    }
    assert(k == n_v);
    memcpy(lc, swap, n_v * sizeof(mg_lchain_t));
    *n_lc_ = n_v;
    *u_ = u;
	// compress_lchain(lc, *n_lc_, qlen, ug, an);

    kfree(km, a);
    kfree(km, swap);
    kfree(km, v);
    return n_u;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %r8, 0x10(%rsp)
movq 0x150(%rsp), %r14
movslq (%rcx), %rbx
movq %rsi, 0x68(%rsp)
movq 0x18(%rsi), %rax
movq %rax, 0x60(%rsp)
movq $0x0, (%r14)
testq %rbx, %rbx
je 0x1a53f9
movl %r9d, %ebp
movq %rdi, %r15
movss %xmm0, 0x58(%rsp)
movss %xmm1, 0x98(%rsp)
movq %rcx, 0xc0(%rsp)
leaq (,%rbx,8), %r12
movq %r12, %rsi
callq 0x1ee115
testl %ebx, %ebx
jle 0x1a53b3
movq %r12, 0x18(%rsp)
movq %r15, 0x30(%rsp)
movq %rbx, 0x38(%rsp)
movslq %ebp, %rcx
movq %rcx, 0x90(%rsp)
movq 0x68(%rsp), %rcx
movq 0x10(%rcx), %r13
movq 0x60(%rsp), %rcx
movq 0x20(%rcx), %rbp
xorl %ebx, %ebx
leaq 0xb4(%rsp), %r15
movq 0x10(%rsp), %r12
movl $0x0, 0x2c(%rsp)
movq %rax, 0x8(%rsp)
movl 0x8(%r12), %r14d
shrl %r14d
leaq (%r14,%r14,4), %rax
movl (%r13,%rax,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
subq $0x8, %rsp
movq %r12, %rdi
movq 0x98(%rsp), %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %r15, %r9
leaq 0xb8(%rsp), %rax
pushq %rax
callq 0x1a4876
addq $0x10, %rsp
movl $0xffffffff, 0x20(%r12) # imm = 0xFFFFFFFF
movl (%rbp,%r14,8), %ecx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %ecx
subl 0xb0(%rsp), %ecx
movl 0xb4(%rsp), %eax
cmpl %ecx, %eax
cmovll %eax, %ecx
cmpl 0x110(%rsp), %ecx
jle 0x1a5356
movl 0x18(%r12), %esi
movl $0x80000000, %eax       # imm = 0x80000000
orl %eax, %esi
jmp 0x1a5375
sarl $0x3, %ecx
xorl %esi, %esi
xorl %edx, %edx
cmpl 0x1c(%r12), %ecx
setg %sil
setle %dl
shll $0x1f, %esi
orl 0x18(%r12), %esi
addl %edx, 0x2c(%rsp)
movq 0x8(%rsp), %rax
movl %esi, (%rax,%rbx,8)
movl %ebx, 0x4(%rax,%rbx,8)
incq %rbx
addq $0x28, %r12
cmpq %rbx, 0x38(%rsp)
jne 0x1a52d7
movl 0x2c(%rsp), %ebp
cmpl $0x1, %ebp
movq 0x38(%rsp), %rbx
movq 0x150(%rsp), %r14
movq 0x30(%rsp), %r15
movq 0x18(%rsp), %r12
jg 0x1a5400
movq %r15, %rdi
movq %rax, %rsi
callq 0x1ee04f
movq %r15, %rdi
movq %r12, %rsi
callq 0x1ee115
testl %ebx, %ebx
movq 0x10(%rsp), %rsi
jle 0x1a53f1
addq $0x1c, %rsi
xorl %ecx, %ecx
movl (%rsi), %edx
shlq $0x20, %rdx
incq %rdx
movq %rdx, (%rax,%rcx,8)
incq %rcx
addq $0x28, %rsi
cmpq %rcx, %rbx
jne 0x1a53d8
movq %rax, (%r14)
jmp 0x1a5fcb
xorl %ebx, %ebx
jmp 0x1a5fcb
leaq (%rax,%rbx,8), %rsi
movq %rax, %rdi
callq 0x1a0c21
shlq $0x2, %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x1ee115
movq %rax, 0x48(%rsp)
movl %ebp, %ebx
leaq (,%rbx,4), %rsi
movq %r15, %rdi
callq 0x1ee115
movq %rax, 0x70(%rsp)
leaq (,%rbx,8), %rsi
movq %r15, %rdi
callq 0x1ee115
movq %rax, 0x88(%rsp)
movl $0x4, %edx
movq %r15, %rdi
movq %rbx, 0x80(%rsp)
movq %rbx, %rsi
callq 0x1edfb4
movq 0x8(%rsp), %r11
movq %rax, 0x78(%rsp)
movl 0x110(%rsp), %eax
negl %eax
movl %eax, 0x9c(%rsp)
xorl %eax, %eax
movl $0x0, 0x54(%rsp)
xorl %ebx, %ebx
movq 0x10(%rsp), %r14
movq %rax, 0x40(%rsp)
movslq 0x4(%r11,%rax,8), %rax
leaq (%rax,%rax,4), %rax
movq 0x68(%rsp), %rcx
movq 0x18(%rcx), %rcx
movl 0x8(%r14,%rax,8), %r15d
movq %r15, %rsi
xorq $0x1, %rsi
movq 0x28(%rcx), %rdx
movq %rsi, 0x20(%rsp)
movq (%rdx,%rsi,8), %rdx
movq %rdx, %rsi
movl $0x0, %r13d
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
andq %rdi, %rsi
je 0x1a5512
movq 0x8(%rcx), %rdi
shrq $0x20, %rdx
shlq $0x3, %rsi
leaq (%rsi,%rsi,2), %rcx
leaq (%rdx,%rdx,2), %rdx
leaq (%rdi,%rdx,8), %rdx
addq $0xc, %rdx
xorl %esi, %esi
xorl %r13d, %r13d
movl (%rdx,%rsi), %edi
cmpl %edi, %r13d
movl %edi, %r8d
cmoval %r13d, %r8d
testl %edi, %edi
cmovnsl %r8d, %r13d
addq $0x18, %rsi
cmpq %rsi, %rcx
jne 0x1a54f6
leaq (%r14,%rax,8), %rbp
movq 0x68(%rsp), %rax
movq 0x10(%rax), %rax
shrl %r15d
leaq (%r15,%r15,4), %rcx
movl (%rax,%rcx,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
subq $0x8, %rsp
movq %rbp, %rdi
movq 0x98(%rsp), %r12
movq %r12, %rsi
leaq 0xb4(%rsp), %rcx
leaq 0xdc(%rsp), %r8
leaq 0xb0(%rsp), %r9
leaq 0xd8(%rsp), %rax
pushq %rax
callq 0x1a4876
addq $0x10, %rsp
addl 0x120(%rsp), %r13d
movq %rbp, 0x18(%rsp)
addl 0x14(%rbp), %r13d
cmpl %r12d, %r13d
cmovgel %r12d, %r13d
movl $0x0, 0x4(%rsp)
movq 0x40(%rsp), %rax
testq %rax, %rax
je 0x1a58e8
movq 0x8(%rsp), %r11
cmpl %r13d, -0x8(%r11,%rax,8)
jae 0x1a55aa
decq %rax
jmp 0x1a55e5
cmpl %r13d, (%r11)
jae 0x1a58e8
xorl %eax, %eax
movq 0x40(%rsp), %rcx
movl %ecx, %esi
subl %eax, %esi
movl %esi, %edx
shrl $0x1f, %edx
addl %esi, %edx
sarl %edx
leal (%rdx,%rax), %esi
movslq %esi, %rdi
cmpl %r13d, (%r11,%rdi,8)
jb 0x1a55d7
movl %esi, %ecx
jmp 0x1a55db
addl %edx, %eax
incl %eax
cmpl %eax, %ecx
jg 0x1a55ba
jne 0x1a5fdf
testl %eax, %eax
js 0x1a58e8
movl %eax, %r15d
movl $0x0, 0x4(%rsp)
movl $0x0, 0x20(%rsp)
movslq 0x4(%r11,%r15,8), %rax
leaq (%rax,%rax,4), %rax
leaq (%r14,%rax,8), %rbp
movq 0x68(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x8(%rbp), %r14d
movl %r14d, %r12d
shrl %r12d
leaq (%r12,%r12,4), %rcx
movl (%rax,%rcx,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
subq $0x8, %rsp
movq %rbp, %rdi
movq 0x98(%rsp), %rsi
leaq 0xd4(%rsp), %rcx
leaq 0xac(%rsp), %r8
leaq 0xd0(%rsp), %r9
leaq 0xa8(%rsp), %rax
pushq %rax
callq 0x1a4876
addq $0x10, %rsp
movq 0x18(%rsp), %rax
movl 0x14(%rax), %r13d
cmpl %r13d, 0x14(%rbp)
jge 0x1a5775
movl 0xac(%rsp), %eax
subl 0xa4(%rsp), %eax
cmpl 0x118(%rsp), %eax
jg 0x1a58ef
movq 0x18(%rsp), %rdx
movl 0x8(%rdx), %ecx
cmpl %r14d, %ecx
movq 0x8(%rsp), %r11
jne 0x1a5781
movl 0xc(%rbp), %edi
movl 0xc(%rdx), %eax
cmpl %eax, %edi
jge 0x1a57ae
movl 0x10(%rbp), %ecx
movl 0x10(%rdx), %esi
cmpl %esi, %ecx
movq 0x10(%rsp), %r14
jge 0x1a57b3
movl %eax, %r8d
subl %ecx, %r8d
movl 0x18(%rbp), %edx
movl %r8d, %r9d
subl %r13d, %r9d
addl %edx, %r9d
movl %r9d, %r10d
negl %r10d
cmovsl %r9d, %r10d
cmpl 0x120(%rsp), %r10d
jg 0x1a57b3
cmpl 0x110(%rsp), %r8d
setg %r9b
cmpl 0x9c(%rsp), %r8d
setl %r8b
orb %r9b, %r8b
jne 0x1a57b3
movl %ecx, %r8d
subl %eax, %r8d
jle 0x1a5752
cvtsi2ss %r8d, %xmm0
movl %ecx, %r8d
subl %edi, %r8d
cvtsi2ss %r8d, %xmm1
movss 0x98(%rsp), %xmm2
mulss %xmm2, %xmm1
ucomiss %xmm1, %xmm0
ja 0x1a57b3
subl %eax, %esi
xorps %xmm1, %xmm1
cvtsi2ss %esi, %xmm1
mulss %xmm2, %xmm1
ucomiss %xmm1, %xmm0
ja 0x1a57b3
movq 0x60(%rsp), %rsi
movq 0x20(%rsi), %rsi
movl (%rsi,%r12,8), %esi
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
andl %edi, %esi
addl %ecx, %r13d
addl %edx, %eax
addl %esi, %eax
subl %eax, %r13d
addl %esi, %r13d
jmp 0x1a57eb
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %r11
jmp 0x1a57b3
movl 0xa8(%rsp), %esi
movq 0x60(%rsp), %rax
movq 0x20(%rax), %rdx
movl (%rdx,%r12,8), %eax
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
andl %edi, %eax
subl 0xa0(%rsp), %esi
addl %eax, %esi
cmpl 0x110(%rsp), %esi
jle 0x1a57c8
movq 0x10(%rsp), %r14
leaq -0x1(%r15), %rax
testq %r15, %r15
movq %rax, %r15
jg 0x1a5600
jmp 0x1a58f4
shrl %ecx
movl (%rdx,%rcx,8), %ecx
andl %edi, %ecx
addl 0x18(%rbp), %eax
addl 0x10(%rbp), %r13d
movq 0x18(%rsp), %rdx
addl 0xc(%rdx), %eax
subl %eax, %r13d
addl %ecx, %r13d
movq 0x10(%rsp), %r14
js 0x1a57b3
movl 0x54(%rsp), %esi
cmpl %esi, 0x4(%rsp)
jne 0x1a5832
movl %esi, %r14d
sarl %r14d
addl %esi, %r14d
cmpl $0x4, %esi
movl $0x10, %eax
cmovll %eax, %r14d
movslq %r14d, %rax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rdx
movq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x1ee21d
movq 0x8(%rsp), %r11
movq %rax, %rbx
movl %r14d, %esi
movq 0x10(%rsp), %r14
movl 0x4(%rsp), %ecx
movslq %ecx, %rax
incl %ecx
movl %ecx, 0x4(%rsp)
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rbx,%rax)
movups %xmm0, 0x10(%rbx,%rax)
movups %xmm0, (%rbx,%rax)
movq 0x18(%rsp), %rdi
movl 0x8(%rdi), %ecx
xorl %edx, %edx
cmpl 0x8(%rbp), %ecx
sete %dl
shll $0x1f, %edx
movl %edx, 0xc(%rbx,%rax)
movl 0x8(%rbp), %ecx
xorl $0x1, %ecx
movl %ecx, (%rbx,%rax)
movl %r15d, %ecx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
orl %edx, %ecx
movl %ecx, 0xc(%rbx,%rax)
movl 0x14(%rdi), %edx
subl 0x18(%rbp), %edx
movl %edx, 0x10(%rbx,%rax)
movl %r13d, 0x4(%rbx,%rax)
movl %ecx, 0xc(%rbx,%rax)
movq 0x78(%rsp), %rax
movl (%rax,%r15,4), %eax
cmpq %rax, 0x40(%rsp)
movl %esi, 0x54(%rsp)
jne 0x1a58c1
movl 0x20(%rsp), %eax
cmpl 0x128(%rsp), %eax
jge 0x1a58f4
incl %eax
movl %eax, 0x20(%rsp)
movq 0x88(%rsp), %rax
movq (%rax,%r15,8), %rax
testq %rax, %rax
js 0x1a57b3
movq 0x78(%rsp), %rcx
movq 0x40(%rsp), %rdx
movl %edx, (%rcx,%rax,4)
jmp 0x1a57b3
movq 0x20(%rsp), %rdx
jmp 0x1a5906
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rax
movl 0x8(%rax), %r15d
movl %r15d, %edx
xorl $0x1, %edx
shrl %r15d
movq 0x60(%rsp), %rsi
movq 0x20(%rsi), %rax
movl (%rax,%r15,8), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
movl 0x110(%rsp), %r9d
movq 0x18(%rsp), %r13
subl 0xc(%r13), %r9d
addl %eax, %r9d
movq 0x30(%rsp), %rdi
movl 0x4(%rsp), %ebp
movl %ebp, %ecx
movq %rbx, %r8
pushq $0x0
pushq $0xf
callq 0x1a32bc
addq $0x10, %rsp
testl %ebp, %ebp
movq 0x8(%rsp), %r11
movss 0x58(%rsp), %xmm4
movsd 0x886b2(%rip), %xmm5    # 0x22e010
movss 0x9a23a(%rip), %xmm6    # 0x23fba0
movss 0x9a236(%rip), %xmm7    # 0x23fba4
movss 0x9a231(%rip), %xmm8    # 0x23fba8
jle 0x1a5d1d
movl %ebp, %eax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rax
xorl %ecx, %ecx
xorl %r15d, %r15d
movl 0x14(%rbx,%rcx), %edx
testl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
je 0x1a5ae7
movl 0x1c(%rbx,%rcx), %esi
subl 0x4(%rbx,%rcx), %esi
movl %esi, %r9d
negl %r9d
cmovsl %esi, %r9d
cmpl 0x120(%rsp), %r9d
jg 0x1a5ae7
movl 0xc(%rbx,%rcx), %esi
andl $0x3fffffff, %esi       # imm = 0x3FFFFFFF
movslq 0x4(%r11,%rsi,8), %rdi
leaq (%rdi,%rdi,4), %rdi
movl 0x18(%r14,%rdi,8), %r8d
movl 0x14(%r13), %edi
cmpl %edi, %r8d
jle 0x1a5a1d
movl 0x18(%r13), %r10d
movl %r10d, %r11d
subl %r8d, %r11d
xorps %xmm0, %xmm0
cvtsi2sd %r11d, %xmm0
movq 0x8(%rsp), %r11
subl %edi, %r10d
xorps %xmm1, %xmm1
cvtsi2sd %r10d, %xmm1
movl 0x1c(%r13), %r8d
divsd %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r8d, %xmm1
mulsd %xmm0, %xmm1
addsd %xmm5, %xmm1
cvttsd2si %xmm1, %edi
jmp 0x1a5a24
movl 0x1c(%r13), %r8d
movl %r8d, %edi
xorps %xmm0, %xmm0
cvtsi2ss %r9d, %xmm0
xorps %xmm1, %xmm1
cmpl $0x2, %r9d
jb 0x1a5a79
movd %xmm0, %r9d
movl %r9d, %r10d
shrl $0x17, %r10d
addl $-0x80, %r10d
xorps %xmm2, %xmm2
cvtsi2ss %r10, %xmm2
andl $0x7fffff, %r9d         # imm = 0x7FFFFF
orl $0x3f800000, %r9d       # imm = 0x3F800000
movd %r9d, %xmm3
movdqa %xmm3, %xmm1
mulss %xmm6, %xmm1
addss %xmm7, %xmm1
mulss %xmm3, %xmm1
addss %xmm8, %xmm1
addss %xmm2, %xmm1
sarl $0x1f, %edx
andl 0x130(%rsp), %edx
addl %edx, %edi
mulss %xmm4, %xmm0
addss %xmm1, %xmm0
cvttss2si %xmm0, %edx
movq 0x70(%rsp), %r9
addl (%r9,%rsi,4), %edi
subl %edx, %edi
movl %edi, %edx
negl %edx
jo 0x1a5ae7
addl %edi, %r8d
js 0x1a5ae7
leaq (%rbx,%rcx), %rdx
movslq %r15d, %r15
leaq (%r15,%r15,2), %rsi
shlq $0x4, %rsi
movq 0x20(%rdx), %r8
movq %r8, 0x20(%rbx,%rsi)
movups (%rdx), %xmm0
movups 0x10(%rdx), %xmm1
movups %xmm1, 0x10(%rbx,%rsi)
movups %xmm0, (%rbx,%rsi)
movslq %edi, %rdx
movabsq $0x3fffffffffffffff, %rdi # imm = 0x3FFFFFFFFFFFFFFF
subq %rdx, %rdi
incl %r15d
movq %rdi, 0x28(%rbx,%rsi)
addq $0x30, %rcx
cmpq %rcx, %rax
jne 0x1a598c
testl %r15d, %r15d
jle 0x1a5d1d
movl %r15d, %r12d
leaq (%r12,%r12,2), %rsi
shlq $0x4, %rsi
addq %rbx, %rsi
movq %rbx, %rdi
callq 0x1a0ef7
movl $0x1, %ecx
cmpl $0x1, %r15d
je 0x1a5b49
movq 0x28(%rbx), %rax
movslq 0x1c(%r13), %rdx
leaq 0x58(%rbx), %rsi
movl $0x1, %ecx
movq (%rsi), %rdi
subq %rax, %rdi
cmpq %rdx, %rdi
jg 0x1a5b49
incq %rcx
addq $0x30, %rsi
cmpq %rcx, %r12
jne 0x1a5b2f
movl %r12d, %ecx
movl 0x138(%rsp), %eax
cmpl %eax, %ecx
cmovgel %eax, %ecx
movl 0x1c(%r13), %eax
testl %ecx, %ecx
movss 0x58(%rsp), %xmm5
movsd 0x884a7(%rip), %xmm6    # 0x22e010
movss 0x9a02f(%rip), %xmm7    # 0x23fba0
movss 0x9a02a(%rip), %xmm8    # 0x23fba4
movss 0x9a025(%rip), %xmm9    # 0x23fba8
jle 0x1a5d9b
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movl %ecx, %ecx
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %r8
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
xorl %r9d, %r9d
movl $0x0, 0x5c(%rsp)
xorl %ecx, %ecx
movl $0xffffffff, 0x20(%rsp) # imm = 0xFFFFFFFF
movl %eax, %r10d
movl 0x14(%rbx,%r9), %ebp
testl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
je 0x1a5cf0
movl 0x1c(%rbx,%r9), %r11d
movl %r11d, %edi
subl 0x4(%rbx,%r9), %edi
movl %edi, %esi
negl %esi
cmovsl %edi, %esi
cmpl 0x120(%rsp), %esi
jg 0x1a5cf0
movl 0xc(%rbx,%r9), %r15d
movl %r15d, %r12d
andl $0x3fffffff, %r12d      # imm = 0x3FFFFFFF
movq 0x8(%rsp), %rdx
movslq 0x4(%rdx,%r12,8), %rdi
leaq (%rdi,%rdi,4), %rdi
movl 0x18(%r14,%rdi,8), %edi
movq 0x18(%rsp), %rdx
movl 0x14(%rdx), %r14d
movl %eax, %r13d
cmpl %r14d, %edi
jle 0x1a5c50
movq 0x18(%rsp), %rdx
movl 0x18(%rdx), %edx
movl %edx, %r13d
subl %edi, %r13d
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
subl %r14d, %edx
xorps %xmm2, %xmm2
cvtsi2sd %edx, %xmm2
divsd %xmm2, %xmm1
mulsd %xmm0, %xmm1
addsd %xmm6, %xmm1
cvttsd2si %xmm1, %r13d
xorps %xmm1, %xmm1
cvtsi2ss %esi, %xmm1
xorps %xmm2, %xmm2
cmpl $0x2, %esi
jb 0x1a5c9d
movd %xmm1, %edx
movl %edx, %esi
shrl $0x17, %esi
addl $-0x80, %esi
xorps %xmm3, %xmm3
cvtsi2ss %rsi, %xmm3
andl $0x7fffff, %edx         # imm = 0x7FFFFF
orl $0x3f800000, %edx       # imm = 0x3F800000
movd %edx, %xmm4
movdqa %xmm4, %xmm2
mulss %xmm7, %xmm2
addss %xmm8, %xmm2
mulss %xmm4, %xmm2
addss %xmm9, %xmm2
addss %xmm3, %xmm2
sarl $0x1f, %ebp
andl 0x130(%rsp), %ebp
addl %ebp, %r13d
mulss %xmm5, %xmm1
addss %xmm2, %xmm1
cvttss2si %xmm1, %edx
movq 0x70(%rsp), %rsi
addl (%rsi,%r12,4), %r13d
subl %edx, %r13d
movl %r13d, %edx
negl %edx
movq 0x10(%rsp), %r14
jo 0x1a5cf0
cmpl %r10d, %r13d
jle 0x1a5cf0
movl 0x24(%rbx,%r9), %ecx
movl %ecx, 0x5c(%rsp)
shrl $0x1f, %r15d
movl %r13d, %r10d
movl %r12d, 0x20(%rsp)
movl %r11d, 0x4(%rsp)
movl %r15d, %ecx
addq $0x30, %r9
cmpq %r9, %r8
jne 0x1a5bba
shll $0x1f, %ecx
movl %r10d, %eax
movq 0x8(%rsp), %r11
movq 0x18(%rsp), %r13
movl 0x4(%rsp), %r8d
movl 0x20(%rsp), %esi
movl 0x5c(%rsp), %r9d
jmp 0x1a5d31
movl 0x1c(%r13), %eax
xorl %ecx, %ecx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
xorl %r9d, %r9d
movq 0x70(%rsp), %rdx
movq 0x40(%rsp), %rdi
movl %eax, (%rdx,%rdi,4)
movslq %esi, %rsi
movq 0x88(%rsp), %rdx
movq %rsi, (%rdx,%rdi,8)
movl %r8d, 0x20(%r13)
movl %r9d, 0x24(%r13)
movl 0x4(%r13), %edx
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
andl %edi, %edx
orl %ecx, %edx
movl %edx, 0x4(%r13)
testl %esi, %esi
js 0x1a5d76
movq 0x48(%rsp), %rcx
movl (%rcx,%rsi,4), %ecx
cmpl %eax, %ecx
jg 0x1a5d78
movl %eax, %ecx
movq 0x48(%rsp), %rax
movq 0x40(%rsp), %rdx
movl %ecx, (%rax,%rdx,4)
movq %rdx, %rax
incq %rax
cmpq 0x80(%rsp), %rax
jne 0x1a5492
jmp 0x1a5db5
xorl %ecx, %ecx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
xorl %r9d, %r9d
movq 0x8(%rsp), %r11
jmp 0x1a5d31
movq 0x30(%rsp), %rbp
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x1ee04f
subq $0x8, %rsp
leaq 0xc0(%rsp), %r10
leaq 0xc4(%rsp), %r11
movq 0x40(%rsp), %rax
subl 0x34(%rsp), %eax
xorl %r13d, %r13d
movq %rbp, %rdi
movq 0x88(%rsp), %rsi
movq 0x78(%rsp), %r15
movq %r15, %rdx
movq 0x90(%rsp), %r14
movq %r14, %rcx
movq 0x50(%rsp), %r8
movq 0x80(%rsp), %r12
movq %r12, %r9
pushq %r10
pushq %r11
pushq %rax
pushq %r13
pushq %r13
callq 0x1a24aa
addq $0x30, %rsp
movq %rax, %rbx
movq %rbp, %rdi
movq %r15, %rsi
callq 0x1ee04f
movq %rbp, %rdi
movq %r14, %rsi
callq 0x1ee04f
movq %rbp, %rdi
movq %r12, %rsi
callq 0x1ee04f
leaq 0xbc(%rsp), %rax
movl (%rax), %eax
leaq 0xb8(%rsp), %rcx
movl (%rcx), %ebp
movq 0x38(%rsp), %r14
subl 0x2c(%rsp), %r14d
jle 0x1a5ecc
movslq %eax, %rsi
movslq %ebp, %rdx
movl %r14d, %ecx
movq 0x48(%rsp), %rdi
leaq (%rdi,%rdx,4), %rdx
leaq (%rbx,%rsi,8), %rsi
movq 0x8(%rsp), %rdi
movq 0x80(%rsp), %r15
leaq (%rdi,%r15,8), %rdi
addq $0x4, %rdi
xorl %r14d, %r14d
movq 0x10(%rsp), %r10
movslq (%rdi,%r14,8), %r8
leaq (%r8,%r8,4), %r8
movl 0x1c(%r10,%r8,8), %r8d
shlq $0x20, %r8
incq %r8
movq %r8, (%rsi,%r14,8)
leal (%r15,%r14), %r8d
movl %r8d, (%rdx,%r14,4)
incq %r14
cmpq %r14, %rcx
jne 0x1a5e9c
addl %r14d, %ebp
addl %eax, %r14d
jmp 0x1a5ecf
movl %eax, %r14d
movq 0x30(%rsp), %rdi
movslq %ebp, %rax
shlq $0x3, %rax
leaq (%rax,%rax,4), %r12
movq %r12, %rsi
callq 0x1ee115
movq %rax, %r15
movq %r14, 0x38(%rsp)
testl %r14d, %r14d
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %r11
movq 0x48(%rsp), %r14
jle 0x1a5f75
movl 0x38(%rsp), %eax
xorl %ecx, %ecx
xorl %r13d, %r13d
movq (%rbx,%rcx,8), %r9
testl %r9d, %r9d
jle 0x1a5f6d
movslq %r13d, %r8
movl %r9d, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
leaq (%r8,%r8,4), %rsi
leaq (%r15,%rsi,8), %rsi
leal (%r8,%r9), %r10d
decl %r10d
movl %edx, %r13d
addl %r8d, %r13d
movslq %r10d, %r10
movslq (%r14,%r10,4), %r8
movslq 0x4(%r11,%r8,8), %r8
leaq (%r8,%r8,4), %r8
movq 0x20(%rdi,%r8,8), %r9
movq %r9, 0x20(%rsi)
movups (%rdi,%r8,8), %xmm0
movups 0x10(%rdi,%r8,8), %xmm1
movups %xmm1, 0x10(%rsi)
movups %xmm0, (%rsi)
addq $0x28, %rsi
decl %r10d
decq %rdx
jne 0x1a5f36
incq %rcx
cmpq %rax, %rcx
jne 0x1a5f0c
cmpl %ebp, %r13d
jne 0x1a5ffe
movq %r15, %rsi
movq %r12, %rdx
callq 0x2160
movq 0xc0(%rsp), %rax
movl %ebp, (%rax)
movq 0x150(%rsp), %rax
movq %rbx, (%rax)
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0x1ee04f
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1ee04f
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1ee04f
movq 0x38(%rsp), %rbx
movl %ebx, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x9a316(%rip), %rdi     # 0x2402fc
leaq 0x99c6e(%rip), %rsi     # 0x23fc5b
leaq 0x9ee5b(%rip), %rcx     # 0x244e4f
movl $0x3ee, %edx            # imm = 0x3EE
callq 0x2110
leaq 0x99e6c(%rip), %rdi     # 0x23fe71
leaq 0x99c4f(%rip), %rsi     # 0x23fc5b
leaq 0x99e67(%rip), %rcx     # 0x23fe7a
movl $0x724, %edx            # imm = 0x724
callq 0x2110