// File: /workspace/github_cpp_makefile_star2_O1/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 0x150(%rsp), %rax
movslq (%rcx), %rbx
movq %rsi, 0x70(%rsp)
movq 0x18(%rsi), %rdx
movq %rdx, 0x60(%rsp)
movq $0x0, (%rax)
testq %rbx, %rbx
je 0x19c6ae
movl %r9d, %ebp
movss %xmm0, 0x48(%rsp)
movss %xmm1, 0x98(%rsp)
movq %rcx, 0xc0(%rsp)
movq %r8, (%rsp)
leaq (,%rbx,8), %rsi
movq %rdi, 0x28(%rsp)
movq %rsi, 0x10(%rsp)
callq 0x1e36fd
movq %rax, 0x8(%rsp)
movslq %ebp, %rax
movq %rax, 0x90(%rsp)
testl %ebx, %ebx
movq %rbx, 0xb8(%rsp)
jle 0x19c6b5
movq 0x70(%rsp), %rax
movq 0x10(%rax), %r14
xorl %r13d, %r13d
leaq 0xb4(%rsp), %r15
movq (%rsp), %r12
xorl %ebx, %ebx
movl 0x8(%r12), %ebp
shrl %ebp
leaq (,%rbp,4), %rax
addq %rbp, %rax
movl (%r14,%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 0x19bc39
addq $0x10, %rsp
movl $0xffffffff, 0x20(%r12) # imm = 0xFFFFFFFF
movq 0x60(%rsp), %rax
movq 0x20(%rax), %rax
movl (%rax,%rbp,8), %ecx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %ecx
subl 0xb0(%rsp), %ecx
movl 0xb4(%rsp), %eax
cmpl %ecx, %eax
cmovll %eax, %ecx
movl $0x80000000, %eax       # imm = 0x80000000
movl $0x0, %edx
cmpl 0x110(%rsp), %ecx
jg 0x19c67f
sarl $0x3, %ecx
xorl %eax, %eax
xorl %edx, %edx
cmpl 0x1c(%r12), %ecx
setg %al
setle %dl
shll $0x1f, %eax
addl %edx, %ebx
orl 0x18(%r12), %eax
movq 0x8(%rsp), %rcx
movl %eax, (%rcx,%r13,8)
movl %r13d, 0x4(%rcx,%r13,8)
incq %r13
addq $0x28, %r12
movq 0xb8(%rsp), %rbp
cmpq %r13, %rbp
jne 0x19c5e3
jmp 0x19c6ba
xorl %ebp, %ebp
jmp 0x19d373
movq %rbx, %rbp
xorl %ebx, %ebx
cmpl $0x1, %ebx
jg 0x19c715
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0x1e3632
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0x1e36fd
testl %ebp, %ebp
movq (%rsp), %rsi
jle 0x19c705
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, %rbp
jne 0x19c6ec
movq 0x150(%rsp), %rcx
movq %rax, (%rcx)
jmp 0x19d373
movl 0x120(%rsp), %r13d
movq 0x8(%rsp), %r12
leaq (%r12,%rbp,8), %rsi
movq %r12, %rdi
movl %ebx, %r14d
callq 0x197e9b
shlq $0x2, %rbp
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x1e36fd
movq %rax, 0x30(%rsp)
movl %r14d, 0x44(%rsp)
movl %r14d, %r14d
leaq (,%r14,4), %rsi
movq %rbx, %rdi
callq 0x1e36fd
movq %rax, 0x68(%rsp)
leaq (,%r14,8), %rsi
movq %rbx, %rdi
callq 0x1e36fd
movq %rax, 0x88(%rsp)
movl $0x4, %edx
movq %rbx, %rdi
movq %r14, 0x78(%rsp)
movq %r14, %rsi
callq 0x1e3590
movq %rax, 0x58(%rsp)
movl 0x110(%rsp), %eax
negl %eax
movl %eax, 0x9c(%rsp)
xorl %edx, %edx
movl $0x0, 0x10(%rsp)
xorl %ebp, %ebp
movq (%rsp), %r11
movq %rdx, 0x38(%rsp)
movslq 0x4(%r12,%rdx,8), %rax
leaq (%rax,%rax,4), %rcx
movq 0x70(%rsp), %rax
movq 0x18(%rax), %rdx
movl 0x8(%r11,%rcx,8), %eax
movq %rax, %rsi
xorq $0x1, %rsi
movq 0x28(%rdx), %rdi
movq (%rdi,%rsi,8), %rsi
movq %rsi, %rdi
movl $0x0, %ebx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
andq %r8, %rdi
je 0x19c835
movq 0x8(%rdx), %r8
shrq $0x20, %rsi
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %rdx
leaq (%rsi,%rsi,2), %rsi
leaq (%r8,%rsi,8), %rsi
addq $0xc, %rsi
xorl %edi, %edi
xorl %ebx, %ebx
movl (%rsi,%rdi), %r8d
cmpl %r8d, %ebx
movl %r8d, %r9d
cmoval %ebx, %r9d
testl %r8d, %r8d
cmovnsl %r9d, %ebx
addq $0x18, %rdi
cmpq %rdi, %rdx
jne 0x19c817
leaq (%r11,%rcx,8), %r15
movq 0x70(%rsp), %rcx
movq 0x10(%rcx), %rcx
shrl %eax
leaq (%rax,%rax,4), %rax
movl (%rcx,%rax,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
subq $0x8, %rsp
movq %r15, %rdi
movq 0x98(%rsp), %r14
movq %r14, %rsi
leaq 0xb4(%rsp), %rcx
leaq 0xdc(%rsp), %r8
leaq 0xb0(%rsp), %r9
leaq 0xd8(%rsp), %rax
pushq %rax
callq 0x19bc39
addq $0x10, %rsp
addl %r13d, %ebx
addl 0x14(%r15), %ebx
cmpl %r14d, %ebx
cmovgel %r14d, %ebx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq 0x38(%rsp), %rcx
testq %rcx, %rcx
je 0x19c8b9
cmpl %ebx, -0x8(%r12,%rcx,8)
jae 0x19d11d
leaq -0x1(%rcx), %rax
movq (%rsp), %r11
movq %r15, 0x20(%rsp)
testl %eax, %eax
js 0x19cc5f
movl %eax, %r13d
movl $0x0, 0x1c(%rsp)
movq $0x0, 0x80(%rsp)
movslq 0x4(%r12,%r13,8), %rax
leaq (%rax,%rax,4), %rax
leaq (%r11,%rax,8), %r15
movq 0x70(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x8(%r15), %r12d
movl %r12d, %ebx
shrl %ebx
leaq (%rbx,%rbx,4), %rcx
movl (%rax,%rcx,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
subq $0x8, %rsp
movq %r15, %rdi
movq 0x98(%rsp), %rsi
leaq 0xd4(%rsp), %rcx
leaq 0xac(%rsp), %r8
leaq 0xd0(%rsp), %r9
leaq 0xa8(%rsp), %rax
pushq %rax
callq 0x19bc39
addq $0x10, %rsp
movq 0x20(%rsp), %r9
movl 0x14(%r9), %eax
movb $0x1, %r14b
cmpl %eax, 0x14(%r15)
jge 0x19c972
movl 0xac(%rsp), %ecx
subl 0xa4(%rsp), %ecx
cmpl 0x118(%rsp), %ecx
jle 0x19c9a1
xorl %r14d, %r14d
movq (%rsp), %r11
movq 0x8(%rsp), %r12
movl 0x10(%rsp), %eax
testb %r14b, %r14b
movl %eax, 0x10(%rsp)
je 0x19cc67
leaq -0x1(%r13), %rax
testq %r13, %r13
movq %rax, %r13
jg 0x19c8e1
jmp 0x19cc67
movl 0x8(%r9), %ecx
cmpl %r12d, %ecx
jne 0x19ca33
movl 0xc(%r15), %r10d
movl 0xc(%r9), %edx
cmpl %edx, %r10d
jge 0x19c972
movl 0x10(%r15), %esi
movl 0x10(%r9), %r9d
cmpl %r9d, %esi
jge 0x19c972
movl %edx, %r11d
subl %esi, %r11d
movl 0x18(%r15), %edi
movl %r11d, %r8d
subl %eax, %r8d
addl %edi, %r8d
movl %r8d, %r12d
negl %r12d
cmovsl %r8d, %r12d
movl $0xd, %r8d
cmpl 0x120(%rsp), %r12d
jg 0x19ca16
cmpl 0x110(%rsp), %r11d
setg %r12b
cmpl 0x9c(%rsp), %r11d
setl %r11b
orb %r12b, %r11b
je 0x19cbc5
movq (%rsp), %r11
movq 0x8(%rsp), %r12
testl %r8d, %r8d
movl 0x10(%rsp), %eax
movq 0x20(%rsp), %r9
jne 0x19c97f
jmp 0x19ca99
movl 0xa8(%rsp), %edi
movq 0x60(%rsp), %rdx
movq 0x20(%rdx), %rsi
movl (%rsi,%rbx,8), %edx
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andl %r8d, %edx
subl 0xa0(%rsp), %edi
addl %edx, %edi
cmpl 0x110(%rsp), %edi
jle 0x19ca65
xorl %ecx, %ecx
jmp 0x19ca84
shrl %ecx
movl (%rsi,%rcx,8), %ecx
andl %r8d, %ecx
addl 0x18(%r15), %edx
addl 0x10(%r15), %eax
addl 0xc(%r9), %edx
subl %edx, %eax
addl %ecx, %eax
setns %cl
movl %eax, 0x4c(%rsp)
movq (%rsp), %r11
movq 0x8(%rsp), %r12
movl 0x10(%rsp), %eax
testb %cl, %cl
je 0x19c97f
cmpl %eax, 0x1c(%rsp)
jne 0x19cad8
movl %eax, %ebx
sarl %ebx
addl %eax, %ebx
cmpl $0x4, %eax
movl $0x10, %eax
cmovll %eax, %ebx
movslq %ebx, %rax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rdx
movq 0x28(%rsp), %rdi
movq %rbp, %rsi
callq 0x1e3800
movq 0x20(%rsp), %r9
movq (%rsp), %r11
movq %rax, %rbp
movl %ebx, 0x10(%rsp)
movl 0x1c(%rsp), %ecx
movslq %ecx, %rax
incl %ecx
movl %ecx, 0x1c(%rsp)
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rbp,%rax)
movups %xmm0, 0x10(%rbp,%rax)
movups %xmm0, (%rbp,%rax)
movl 0x8(%r9), %edx
xorl %ecx, %ecx
cmpl 0x8(%r15), %edx
sete %cl
shll $0x1f, %ecx
movl 0xc(%rbp,%rax), %edx
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl %esi, %edx
orl %ecx, %edx
movl %edx, 0xc(%rbp,%rax)
movl 0x8(%r15), %esi
xorl $0x1, %esi
movl %esi, (%rbp,%rax)
movl %r13d, %esi
andl $0x3fffffff, %esi       # imm = 0x3FFFFFFF
andl $0xc0000000, %edx       # imm = 0xC0000000
orl %esi, %edx
movl %edx, 0xc(%rbp,%rax)
movl 0x14(%r9), %edx
subl 0x18(%r15), %edx
movl %edx, 0x10(%rbp,%rax)
movl 0x4c(%rsp), %edx
movl %edx, 0x4(%rbp,%rax)
movl $0x0, 0x8(%rbp,%rax)
orl %ecx, %esi
movl %esi, 0xc(%rbp,%rax)
movq 0x58(%rsp), %rax
movl (%rax,%r13,4), %eax
cmpq %rax, 0x38(%rsp)
jne 0x19cb8e
movq 0x80(%rsp), %rcx
leal 0x1(%rcx), %eax
cmpl 0x128(%rsp), %ecx
jge 0x19cbb5
movq %rax, 0x80(%rsp)
movq 0x88(%rsp), %rax
movq (%rax,%r13,8), %rax
testq %rax, %rax
js 0x19c97b
movq 0x58(%rsp), %rcx
movq 0x38(%rsp), %rdx
movl %edx, (%rcx,%rax,4)
jmp 0x19c97b
xorl %r14d, %r14d
movq %rax, 0x80(%rsp)
jmp 0x19c97b
movl %esi, %r8d
subl %edx, %r8d
movq (%rsp), %r11
movq 0x8(%rsp), %r12
jle 0x19cc29
cvtsi2ss %r8d, %xmm0
movl %esi, %r8d
subl %r10d, %r8d
cvtsi2ss %r8d, %xmm1
movss 0x98(%rsp), %xmm2
mulss %xmm2, %xmm1
movl $0xd, %r8d
ucomiss %xmm1, %xmm0
jbe 0x19cc03
xorl %r9d, %r9d
jmp 0x19cc20
subl %edx, %r9d
xorps %xmm1, %xmm1
cvtsi2ss %r9d, %xmm1
mulss %xmm2, %xmm1
xorl %r9d, %r9d
ucomiss %xmm1, %xmm0
ja 0x19cc20
movb $0x1, %r9b
xorl %r8d, %r8d
testb %r9b, %r9b
je 0x19ca1f
movq 0x60(%rsp), %r8
movq 0x20(%r8), %r8
movl (%r8,%rbx,8), %r9d
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
andl %r10d, %r9d
shrl %ecx
movl (%r8,%rcx,8), %ecx
andl %r10d, %ecx
addl %esi, %eax
addl %edi, %edx
addl %r9d, %edx
subl %edx, %eax
addl %ecx, %eax
xorl %r8d, %r8d
movl %eax, 0x4c(%rsp)
jmp 0x19ca1f
movl $0x0, 0x1c(%rsp)
movq 0x20(%rsp), %rbx
movl 0x8(%rbx), %eax
movl %eax, %edx
xorl $0x1, %edx
movq 0x60(%rsp), %rsi
movq 0x20(%rsi), %rcx
shrl %eax
movl (%rcx,%rax,8), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
movl 0x110(%rsp), %r9d
subl 0xc(%rbx), %r9d
addl %eax, %r9d
movq 0x28(%rsp), %rdi
movl 0x1c(%rsp), %r14d
movl %r14d, %ecx
movq %rbp, %r8
pushq $0x0
pushq $0xf
callq 0x19a639
movl %r14d, %eax
movq %rbx, %r10
movq 0x10(%rsp), %r11
addq $0x10, %rsp
testl %r14d, %r14d
movss 0x48(%rsp), %xmm5
movl 0x120(%rsp), %r13d
movsd 0x85337(%rip), %xmm6    # 0x222010
movss 0x96bef(%rip), %xmm7    # 0x2338d0
movss 0x96bea(%rip), %xmm8    # 0x2338d4
movss 0x96be5(%rip), %xmm9    # 0x2338d8
movl $0x0, %r14d
jle 0x19ce7f
movl %eax, %eax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rax
xorl %ecx, %ecx
xorl %r14d, %r14d
movl 0x14(%rbp,%rcx), %edx
testl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
je 0x19ce72
movl 0x1c(%rbp,%rcx), %esi
subl 0x4(%rbp,%rcx), %esi
movl %esi, %r8d
negl %r8d
cmovsl %esi, %r8d
movl $0x80000000, %esi       # imm = 0x80000000
cmpl %r13d, %r8d
jg 0x19ce23
movl 0xc(%rbp,%rcx), %edi
andl $0x3fffffff, %edi       # imm = 0x3FFFFFFF
movslq 0x4(%r12,%rdi,8), %rsi
leaq (%rsi,%rsi,4), %rsi
movl 0x18(%r11,%rsi,8), %r9d
movl 0x14(%r10), %esi
cmpl %esi, %r9d
jle 0x19cda5
movq 0x20(%rsp), %r10
movl 0x18(%r10), %r10d
movl %r10d, %r11d
subl %r9d, %r11d
xorps %xmm0, %xmm0
cvtsi2sd %r11d, %xmm0
movq (%rsp), %r11
subl %esi, %r10d
xorps %xmm1, %xmm1
cvtsi2sd %r10d, %xmm1
movq 0x20(%rsp), %r10
divsd %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0x1c(%r10), %xmm1
mulsd %xmm0, %xmm1
addsd %xmm6, %xmm1
cvttsd2si %xmm1, %esi
jmp 0x19cda9
movl 0x1c(%r10), %esi
xorps %xmm0, %xmm0
cvtsi2ss %r8d, %xmm0
xorps %xmm1, %xmm1
cmpl $0x2, %r8d
jb 0x19cdff
movd %xmm0, %r8d
movl %r8d, %r9d
shrl $0x17, %r9d
addl $-0x80, %r9d
xorps %xmm2, %xmm2
cvtsi2ss %r9, %xmm2
andl $0x7fffff, %r8d         # imm = 0x7FFFFF
orl $0x3f800000, %r8d       # imm = 0x3F800000
movd %r8d, %xmm3
movdqa %xmm3, %xmm1
mulss %xmm7, %xmm1
addss %xmm8, %xmm1
mulss %xmm3, %xmm1
addss %xmm9, %xmm1
addss %xmm2, %xmm1
sarl $0x1f, %edx
andl 0x130(%rsp), %edx
mulss %xmm5, %xmm0
addss %xmm1, %xmm0
cvttss2si %xmm0, %r8d
addl %edx, %esi
movq 0x68(%rsp), %rdx
addl (%rdx,%rdi,4), %esi
subl %r8d, %esi
movl %esi, %edx
negl %edx
jo 0x19ce72
movl 0x1c(%r10), %edx
addl %esi, %edx
js 0x19ce72
leaq (%rcx,%rbp), %rdx
movslq %r14d, %r14
leaq (%r14,%r14,2), %rdi
shlq $0x4, %rdi
movups (%rdx), %xmm0
movups 0x10(%rdx), %xmm1
movups 0x20(%rdx), %xmm2
movups %xmm2, 0x20(%rbp,%rdi)
movups %xmm1, 0x10(%rbp,%rdi)
movups %xmm0, (%rbp,%rdi)
movslq %esi, %rdx
movabsq $0x3fffffffffffffff, %rsi # imm = 0x3FFFFFFFFFFFFFFF
subq %rdx, %rsi
incl %r14d
movq %rsi, 0x28(%rbp,%rdi)
addq $0x30, %rcx
cmpq %rcx, %rax
jne 0x19cd0e
testl %r14d, %r14d
jle 0x19cf15
movl %r14d, %ebx
leaq (%rbx,%rbx,2), %rsi
shlq $0x4, %rsi
addq %rbp, %rsi
movq %rbp, %rdi
callq 0x198175
movq 0x20(%rsp), %r10
movq (%rsp), %r11
cmpl $0x1, %r14d
movl $0x1, %r14d
je 0x19cedf
movq 0x28(%rbp), %rax
movslq 0x1c(%r10), %rcx
leaq 0x58(%rbp), %rdx
movl $0x1, %r14d
movq (%rdx), %rsi
subq %rax, %rsi
cmpq %rcx, %rsi
jg 0x19cedf
incq %r14
addq $0x30, %rdx
cmpq %r14, %rbx
jne 0x19cec5
movl %ebx, %r14d
movl 0x138(%rsp), %eax
cmpl %eax, %r14d
cmovgel %eax, %r14d
movss 0x48(%rsp), %xmm5
movsd 0x85115(%rip), %xmm6    # 0x222010
movss 0x969cd(%rip), %xmm7    # 0x2338d0
movss 0x969c8(%rip), %xmm8    # 0x2338d4
movss 0x969c3(%rip), %xmm9    # 0x2338d8
movl 0x1c(%r10), %r9d
testl %r14d, %r14d
jle 0x19d0ad
xorps %xmm0, %xmm0
cvtsi2sd %r9d, %xmm0
movl %r14d, %ecx
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %r8
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl %r9d, %r10d
xorl %r9d, %r9d
xorl %edi, %edi
xorl %ecx, %ecx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %r10d, 0x1c(%rsp)
movl 0x14(%rbp,%r9), %ebx
movl $0x80000000, %r11d      # imm = 0x80000000
testl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
je 0x19d066
movl 0x1c(%rbp,%r9), %r14d
subl 0x4(%rbp,%r9), %r14d
movl %r14d, %r15d
negl %r15d
cmovsl %r14d, %r15d
cmpl %r13d, %r15d
jg 0x19d066
movl 0xc(%rbp,%r9), %r14d
andl $0x3fffffff, %r14d      # imm = 0x3FFFFFFF
movslq 0x4(%r12,%r14,8), %r11
leaq (%r11,%r11,4), %r11
movq (%rsp), %rax
movl 0x18(%rax,%r11,8), %r13d
movq 0x20(%rsp), %rax
movl 0x14(%rax), %r12d
movl 0x1c(%rsp), %r11d
cmpl %r12d, %r13d
jle 0x19cfe4
movq 0x20(%rsp), %rax
movl 0x18(%rax), %eax
movl %eax, %r11d
subl %r13d, %r11d
xorps %xmm1, %xmm1
cvtsi2sd %r11d, %xmm1
subl %r12d, %eax
xorps %xmm2, %xmm2
cvtsi2sd %eax, %xmm2
divsd %xmm2, %xmm1
mulsd %xmm0, %xmm1
addsd %xmm6, %xmm1
cvttsd2si %xmm1, %r11d
xorps %xmm1, %xmm1
cvtsi2ss %r15d, %xmm1
xorps %xmm2, %xmm2
cmpl $0x2, %r15d
jb 0x19d034
movd %xmm1, %eax
movl %eax, %r15d
shrl $0x17, %r15d
addl $-0x80, %r15d
xorps %xmm3, %xmm3
cvtsi2ss %r15, %xmm3
andl $0x7fffff, %eax         # imm = 0x7FFFFF
orl $0x3f800000, %eax       # imm = 0x3F800000
movd %eax, %xmm4
movdqa %xmm4, %xmm2
mulss %xmm7, %xmm2
addss %xmm8, %xmm2
mulss %xmm4, %xmm2
addss %xmm9, %xmm2
addss %xmm3, %xmm2
sarl $0x1f, %ebx
andl 0x130(%rsp), %ebx
mulss %xmm5, %xmm1
addss %xmm2, %xmm1
cvttss2si %xmm1, %eax
addl %ebx, %r11d
movq 0x68(%rsp), %rbx
addl (%rbx,%r14,4), %r11d
subl %eax, %r11d
movq 0x8(%rsp), %r12
movl 0x120(%rsp), %r13d
movl %r11d, %eax
negl %eax
jo 0x19d08f
cmpl %r10d, %r11d
jle 0x19d08f
movl 0xc(%rbp,%r9), %ecx
movl 0x1c(%rbp,%r9), %edx
movl %ecx, %esi
andl $0x3fffffff, %esi       # imm = 0x3FFFFFFF
movl 0x24(%rbp,%r9), %edi
shrl $0x1f, %ecx
movl %r11d, %r10d
addq $0x30, %r9
cmpq %r9, %r8
jne 0x19cf4e
shll $0x1f, %ecx
movl %r10d, %r9d
movq (%rsp), %r11
movq 0x20(%rsp), %r10
jmp 0x19d0bb
xorl %ecx, %ecx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %edi, %edi
movq 0x68(%rsp), %rax
movq 0x38(%rsp), %r8
movl %r9d, (%rax,%r8,4)
movslq %esi, %rsi
movq 0x88(%rsp), %rax
movq %rsi, (%rax,%r8,8)
movl %edx, 0x20(%r10)
movl %edi, 0x24(%r10)
movl 0x4(%r10), %eax
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %eax
orl %ecx, %eax
movl %eax, 0x4(%r10)
testl %esi, %esi
movq 0x30(%rsp), %rax
js 0x19d102
movl (%rax,%rsi,4), %ecx
cmpl %r9d, %ecx
jg 0x19d105
movl %r9d, %ecx
movq 0x38(%rsp), %rdx
movl %ecx, (%rax,%rdx,4)
incq %rdx
cmpq 0x78(%rsp), %rdx
jne 0x19c7b9
jmp 0x19d177
cmpl %ebx, (%r12)
movq (%rsp), %r11
jae 0x19c8bd
xorl %eax, %eax
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 %ebx, (%r12,%rdi,8)
jb 0x19d14a
movl %esi, %ecx
jmp 0x19d14e
addl %edx, %eax
incl %eax
cmpl %eax, %ecx
jg 0x19d12d
je 0x19c8bd
leaq 0x96ecd(%rip), %rdi     # 0x23402c
leaq 0x96825(%rip), %rsi     # 0x23398b
leaq 0x9ba12(%rip), %rcx     # 0x238b7f
movl $0x3ee, %edx            # imm = 0x3EE
callq 0x2110
movq 0x28(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
callq 0x1e3632
subq $0x8, %rsp
leaq 0x58(%rsp), %r10
leaq 0x5c(%rsp), %r11
movq 0xc0(%rsp), %rbp
movl %ebp, %eax
subl 0x4c(%rsp), %eax
xorl %r14d, %r14d
movq %r13, %rdi
movq 0x80(%rsp), %rsi
movq 0x70(%rsp), %r15
movq %r15, %rdx
movq 0x90(%rsp), %r12
movq %r12, %rcx
movq 0x38(%rsp), %r8
movq 0x60(%rsp), %r9
pushq %r10
pushq %r11
pushq %rax
pushq %r14
pushq %r14
callq 0x1997be
addq $0x30, %rsp
movq %rax, %rbx
movq %r13, %rdi
movq %r15, %rsi
callq 0x1e3632
movq %r13, %rdi
movq %r12, %rsi
callq 0x1e3632
movq %r13, %rdi
movq 0x58(%rsp), %rsi
callq 0x1e3632
leaq 0x54(%rsp), %rax
movl (%rax), %eax
leaq 0x50(%rsp), %rcx
movl (%rcx), %r13d
subl 0x44(%rsp), %ebp
jle 0x19d277
movslq %eax, %rsi
movslq %r13d, %rdx
movl %ebp, %ecx
movq 0x30(%rsp), %rdi
leaq (%rdi,%rdx,4), %rdx
leaq (%rbx,%rsi,8), %rsi
movq 0x8(%rsp), %rdi
movq 0x78(%rsp), %r15
leaq (%rdi,%r15,8), %rdi
addq $0x4, %rdi
xorl %ebp, %ebp
movq (%rsp), %r9
movslq (%rdi,%rbp,8), %r8
leaq (%r8,%r8,4), %r8
movl 0x1c(%r9,%r8,8), %r8d
shlq $0x20, %r8
incq %r8
movq %r8, (%rsi,%rbp,8)
leal (%r15,%rbp), %r8d
movl %r8d, (%rdx,%rbp,4)
incq %rbp
cmpq %rbp, %rcx
jne 0x19d248
addl %ebp, %r13d
addl %eax, %ebp
jmp 0x19d279
movl %eax, %ebp
movl %ebp, 0x54(%rsp)
movl %r13d, 0x50(%rsp)
movslq %r13d, %rax
shlq $0x3, %rax
leaq (%rax,%rax,4), %rsi
movq 0x28(%rsp), %rdi
movq %rsi, 0x10(%rsp)
callq 0x1e36fd
movq %rax, %r15
testl %ebp, %ebp
movq (%rsp), %rdi
jle 0x19d321
movl %ebp, %eax
xorl %ecx, %ecx
xorl %r14d, %r14d
movq 0x8(%rsp), %r11
movq 0x30(%rsp), %r12
movq (%rbx,%rcx,8), %r9
testl %r9d, %r9d
jle 0x19d319
movslq %r14d, %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, %r14d
addl %r8d, %r14d
movslq %r10d, %r10
movslq (%r12,%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 0x19d2e2
incq %rcx
cmpq %rax, %rcx
jne 0x19d2b8
cmpl %r13d, %r14d
jne 0x19d387
movq %r15, %rsi
movq 0x10(%rsp), %rdx
callq 0x2160
movq 0xc0(%rsp), %rax
movl %r13d, (%rax)
movq 0x150(%rsp), %rax
movq %rbx, (%rax)
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0x1e3632
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1e3632
movq %rbx, %rdi
movq 0x30(%rsp), %rsi
callq 0x1e3632
movl %ebp, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x96813(%rip), %rdi     # 0x233ba1
leaq 0x965f6(%rip), %rsi     # 0x23398b
leaq 0x9680e(%rip), %rcx     # 0x233baa
movl $0x724, %edx            # imm = 0x724
callq 0x2110