// File: chhylp123[P]hifiasm/inter.cpp
// Function: gl_rchain_lin(overlap_region_alloc*, kv_ul_ov_t*, ul_ov_t*, kv_rtrace_t*, ul_idx_t const*, ug_opt_t const*, long, double, long, long, long, long, Chain_Data*, bit_extz_t*, long, All_reads*, char*, UC_Read*, long, double, long)
int64_t gl_rchain_lin(overlap_region_alloc* ol, kv_ul_ov_t *res, ul_ov_t *ex, kv_rtrace_t *trace, const ul_idx_t *uref, const ug_opt_t *uopt, int64_t bw, 
double diff_ec_ul, int64_t qlen, int64_t max_skip, int64_t max_iter, int64_t max_dis, Chain_Data* dp, bit_extz_t *exz,
int64_t trans_sc, All_reads *ridx, char* qstr, UC_Read *tu, int64_t rid, double e_rate, int64_t need_srt)
{
	if(res->n == 0) return 0;
    uint32_t li_v, lj_v, rev_n; int32_t *f, *c_n, *c_sc; int64_t *p, *t, res_n = res->n, st, max_ii, max, err; 
    int64_t mm_ovlp, x, i, j, k, sc, csc, mm_sc, mm_idx, qo, n_skip, end_j, plus; ul_ov_t *li, *lj, rev_t; rtrace_iter tc;
    resize_Chain_Data(dp, res_n, NULL);
    t = dp->tmp; f = dp->score; p = dp->pre; c_n = dp->occ; c_sc = dp->self_length;
	if(need_srt) {
        radix_sort_ul_ov_srt_qe(res->a, res->a + res_n);
        for (i = 1, j = 0; i <= res_n; i++) {
            if (i == res_n || res->a[i].qe != res->a[j].qe) {
                if(i-j>1) radix_sort_ul_ov_srt_qs(res->a+j, res->a+i);
                j = i;
            }
        }
    }

	memset(t, 0, (res_n*sizeof((*t))));
	for (i = st = plus = 0, max_ii = -1; i < res_n; ++i) {
        li = &(res->a[i]); li_v = (li->tn<<1)|li->rev;
        mm_ovlp = max_ovlp_src(uopt, li_v^1);        
        x = (li->qs + mm_ovlp)*diff_ec_ul; 
        if(x < bw) x = bw; 
        x += li->qs + mm_ovlp;
        if (x > qlen+1) x = qlen+1;
        x = find_ul_ov_max(i, res->a, x+G_CHAIN_INDEL); 
        csc = li->qe - li->qs; csc -= (((int64_t)li->sec)*trans_sc);
        mm_sc = csc; mm_idx = -1; 
        n_skip = 0; end_j = -1; tc.k = INT32_MAX;
        if ((x-st) > max_iter) st = x-max_iter;
		// fprintf(stderr, "[M::%s] i::%ld, iq::[%u, %u)\n", __func__, i, li->qs, li->qe);
        for (j = x; j >= st; --j) { // collect potential destination vertices
            lj = &(res->a[j]); lj_v = (lj->tn<<1)|lj->rev;
            if(lj->qe <= li->qs) break;//even this pair has a overlap, its length will be very small; just ignore
			if(lj->qs >= li->qs) continue;///no contain
            qo = infer_rovlp(li, lj, NULL, NULL, ridx, NULL); ///overlap length in query (UL read)
            if(li_v != lj_v && get_ecov_contain_adv(uref, uopt, li_v^1, lj_v^1, bw, diff_ec_ul, qo, NULL)) {
				// fprintf(stderr, "[M::%s] j::%ld, jq::[%u, %u)\n", __func__, j, lj->qs, lj->qe);
				err = get_rid_backward_cigar_err(&tc, li, trace, NULL, uref, qstr, tu, ol, NULL, exz, e_rate, lj->qe);
                sc = f[j] + (li->qe - lj->qe) - (err*trans_sc);
                if(sc > mm_sc) {
                    mm_sc = sc, mm_idx = j;
                    if (n_skip > 0) --n_skip;
                } else if (t[j] == i) {
                    if (++n_skip > max_skip)
                        break;
                }
                if (p[j] >= 0) t[p[j]] = i;
            }
        }
    
        end_j = j;
        if (max_ii < 0 || (res->a[i].qe>(res->a[max_ii].qe+max_dis))) {//too long
            max = INT32_MIN; max_ii = -1;
            for (j = i - 1; (j >= st) && (res->a[i].qe<=(max_dis+res->a[j].qe)); --j) {
                if (max < f[j]) {
                    max = f[j], max_ii = j;
                }
            }
        }
        
        if (max_ii >= 0 && max_ii < end_j) {///just have a try with a[i]<->a[max_ii]
            lj = &(res->a[max_ii]); lj_v = (lj->tn<<1)|lj->rev;
            if(lj->qe > li->qs && lj->qs < li->qs) {
                qo = infer_rovlp(li, lj, NULL, NULL, ridx, NULL); ///overlap length in query (UL read)
                if(li_v != lj_v && get_ecov_contain_adv(uref, uopt, li_v^1, lj_v^1, bw, diff_ec_ul, qo, NULL)) {
					///as max_ii < end_j, get_rid_backward_cigar_err still works
					// fprintf(stderr, "[M::%s] max_ii::%ld, max_ii::[%u, %u)\n", __func__, max_ii, lj->qs, lj->qe);
                    err = get_rid_backward_cigar_err(&tc, li, trace, NULL, uref, qstr, tu, ol, NULL, exz, e_rate, lj->qe);
                	sc = f[max_ii] + (li->qe - lj->qe) - (err*trans_sc);
                    if(sc > mm_sc) {
                        mm_sc = sc; mm_idx = max_ii;
                    }
                }
            }
        }
        if(mm_sc < 0) {
            mm_sc = csc; mm_idx = -1; 
        }
        f[i] = mm_sc; p[i] = mm_idx;
        if ((max_ii < 0) || ((res->a[i].qe<=max_dis+res->a[max_ii].qe) && (f[max_ii]<f[i]))) {
            max_ii = i;
        }
        if(mm_sc < plus) plus = mm_sc;//minmun negative
        // fprintf(stderr, "-5-[M::%s::utg%.6dl] i::%ld, res_n::%ld, csc::%ld, f[i]::%d, p[i]::%ld, q::[%u, %u)\n", 
        //                      __func__, (int32_t)li->tn+1, i, res_n, csc, f[i], p[i], li->qs, li->qe);
    }

	for (i = 0; i < res_n; ++i) {///make all f[] positive
        f[i] -= plus; t[i] = ((uint64_t)f[i])<<32; t[i] += (i<<1);
    }

	int64_t n_v, n_u, n_v0; 
    radix_sort_gfa64i(t, t + res_n); plus = 0;
    for (k = res_n-1, n_v = n_u = 0; k >= 0; --k) {
        n_v0 = n_v;
        for (i = ((uint32_t)t[k])>>1; i >= 0 && (t[i]&1) == 0; ) {
            ex[n_v++] = res->a[i]; t[i] |= 1; i = p[i];
        }
        if(n_v0 == n_v) continue;
        sc = (i<0?(t[k]>>32):((t[k]>>32)-f[i]));
        // fprintf(stderr, "[M::%s::] n_v::%ld, n_v0::%ld, t[k]::%ld, sc::%ld\n", 
        //                      __func__, n_v, n_v0, t[k]>>32, sc);
        c_n[n_u] = n_v-n_v0; c_sc[n_u] = sc; n_u++; if(sc < plus) plus = sc;
    }
    // fprintf(stderr, "---[M::%s] n_u:%ld, n_v:%ld\n", __func__, n_u, n_v);
    for (k = 0, n_v = n_v0 = 0; k < n_u; k++) {
        n_v0 = n_v; n_v += c_n[k];
        res->a[k].qn = c_sc[k]-plus;//score
        res->a[k].ts = n_v0; res->a[k].te = n_v;///idx
        // fprintf(stderr, "[M::%s] k:%ld, c_sc:%d\n", __func__, k, c_sc[k]);

        rev_n = c_n[k]>>1; 
        ///we need to consider contained reads; so determining qs is not such easy
        res->a[k].qs = (uint32_t)-1; res->a[k].qe = ex[n_v0].qe;
        for (i = 0; i < rev_n; i++) {
            rev_t = ex[n_v0+i]; ex[n_v0+i] = ex[n_v-i-1]; ex[n_v-i-1] = rev_t;
            
            if(res->a[k].qs > ex[n_v0+i].qs) res->a[k].qs = ex[n_v0+i].qs;
            if(res->a[k].qs > ex[n_v-i-1].qs) res->a[k].qs = ex[n_v-i-1].qs;
            ex[n_v0+i].sec = ex[n_v-i-1].sec = SEC_MODE; 
        }
        if(c_n[k]&1) {
            if(res->a[k].qs > ex[n_v0+i].qs) res->a[k].qs = ex[n_v0+i].qs;
            ex[n_v0+i].sec = SEC_MODE; 
        }
    }
    res->n = n_u;
    radix_sort_ul_ov_srt_qn(res->a, res->a + res->n);//sort by score
	// if(res->n > 0) {
	// 	fprintf(stderr, "[M::%s::rid->%ld] qlen::%ld, q::[%u, %u), sc::%u\n", 
	// 	__func__, rid, qlen, res->a[res->n-1].qs, res->a[res->n-1].qe, res->a[res->n-1].qn);
	// }
    return n_v;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movq 0x70(%rbp), %rax
movq 0x68(%rbp), %rax
movq 0x60(%rbp), %rax
movq 0x58(%rbp), %rax
movq 0x50(%rbp), %rax
movq 0x48(%rbp), %rax
movq 0x40(%rbp), %rax
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq %r9, -0x40(%rbp)
movsd %xmm0, -0x48(%rbp)
movsd %xmm1, -0x50(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x2b10da
movq $0x0, -0x10(%rbp)
jmp 0x2b21b7
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x90(%rbp)
movq 0x38(%rbp), %rdi
movq -0x90(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x226f0
movq 0x38(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x88(%rbp)
movq 0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movq 0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x80(%rbp)
movq 0x38(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x70(%rbp)
movq 0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, 0x70(%rbp)
je 0x2b1230
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rax
movq (%rax), %rsi
imulq $0x1c, -0x90(%rbp), %rax
addq %rax, %rsi
callq 0x27b350
movq $0x1, -0xc8(%rbp)
movq $0x0, -0xd0(%rbp)
movq -0xc8(%rbp), %rax
cmpq -0x90(%rbp), %rax
jg 0x2b122e
movq -0xc8(%rbp), %rax
cmpq -0x90(%rbp), %rax
je 0x2b11ca
movq -0x20(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0xc8(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x1c, -0xd0(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
je 0x2b1215
movq -0xc8(%rbp), %rax
subq -0xd0(%rbp), %rax
cmpq $0x1, %rax
jle 0x2b1207
movq -0x20(%rbp), %rax
movq (%rax), %rdi
imulq $0x1c, -0xd0(%rbp), %rax
addq %rax, %rdi
movq -0x20(%rbp), %rax
movq (%rax), %rsi
imulq $0x1c, -0xc8(%rbp), %rax
addq %rax, %rsi
callq 0x27b890
movq -0xc8(%rbp), %rax
movq %rax, -0xd0(%rbp)
jmp 0x2b1217
movq -0xc8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xc8(%rbp)
jmp 0x2b117a
jmp 0x2b1230
movq -0x88(%rbp), %rdi
movq -0x90(%rbp), %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x2100
movq $0x0, -0x118(%rbp)
movq $0x0, -0x98(%rbp)
movq $0x0, -0xc8(%rbp)
movq $-0x1, -0xa0(%rbp)
movq -0xc8(%rbp), %rax
cmpq -0x90(%rbp), %rax
jge 0x2b1a88
movq -0x20(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0xc8(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x120(%rbp)
movq -0x120(%rbp), %rax
movl 0xc(%rax), %eax
shll %eax
movq -0x120(%rbp), %rcx
movl 0x18(%rcx), %ecx
shrl $0x1f, %ecx
orl %ecx, %eax
movl %eax, -0x54(%rbp)
movq -0x40(%rbp), %rdi
movl -0x54(%rbp), %esi
xorl $0x1, %esi
callq 0x287de0
movq %rax, -0xb8(%rbp)
movq -0x120(%rbp), %rax
movl 0x4(%rax), %eax
addq -0xb8(%rbp), %rax
cvtsi2sd %rax, %xmm0
mulsd -0x48(%rbp), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
cmpq 0x10(%rbp), %rax
jge 0x2b1315
movq 0x10(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x120(%rbp), %rax
movl 0x4(%rax), %eax
addq -0xb8(%rbp), %rax
addq -0xc0(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
movq 0x18(%rbp), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jle 0x2b1357
movq 0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xc0(%rbp)
movq -0xc8(%rbp), %rax
movl %eax, %edi
movq -0x20(%rbp), %rax
movq (%rax), %rsi
movq -0xc0(%rbp), %rax
addq $0x80, %rax
movl %eax, %edx
callq 0x28cf00
cltq
movq %rax, -0xc0(%rbp)
movq -0x120(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x120(%rbp), %rcx
subl 0x4(%rcx), %eax
movl %eax, %eax
movq %rax, -0xe8(%rbp)
movq -0x120(%rbp), %rax
movl 0x18(%rax), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, %eax
movl %eax, %ecx
imulq 0x48(%rbp), %rcx
movq -0xe8(%rbp), %rax
subq %rcx, %rax
movq %rax, -0xe8(%rbp)
movq -0xe8(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq $-0x1, -0xf8(%rbp)
movq $0x0, -0x108(%rbp)
movq $-0x1, -0x110(%rbp)
movq $0x7fffffff, -0x1e0(%rbp) # imm = 0x7FFFFFFF
movq -0xc0(%rbp), %rax
subq -0x98(%rbp), %rax
cmpq 0x28(%rbp), %rax
jle 0x2b142a
movq -0xc0(%rbp), %rax
subq 0x28(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
cmpq -0x98(%rbp), %rax
jl 0x2b1697
movq -0x20(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0xd0(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x128(%rbp)
movq -0x128(%rbp), %rax
movl 0xc(%rax), %eax
shll %eax
movq -0x128(%rbp), %rcx
movl 0x18(%rcx), %ecx
shrl $0x1f, %ecx
orl %ecx, %eax
movl %eax, -0x58(%rbp)
movq -0x128(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x120(%rbp), %rcx
cmpl 0x4(%rcx), %eax
ja 0x2b149e
jmp 0x2b1697
movq -0x128(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x120(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jb 0x2b14b9
jmp 0x2b1680
movq -0x120(%rbp), %rdi
movq -0x128(%rbp), %rsi
movq 0x50(%rbp), %r8
xorl %eax, %eax
movl %eax, %r9d
movq %r9, %rdx
movq %r9, %rcx
callq 0x71a90
movq %rax, -0x100(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x58(%rbp), %eax
je 0x2b167e
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl -0x54(%rbp), %edx
xorl $0x1, %edx
movl -0x58(%rbp), %ecx
xorl $0x1, %ecx
movq 0x10(%rbp), %r8
movsd -0x48(%rbp), %xmm0
movq -0x100(%rbp), %r9
xorl %eax, %eax
movq $0x0, (%rsp)
callq 0x2b0c90
cmpq $0x0, %rax
je 0x2b167e
movq -0x120(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %r8
movq 0x58(%rbp), %r9
movq 0x60(%rbp), %rbx
movq -0x18(%rbp), %r11
movq 0x40(%rbp), %r10
movsd -0x50(%rbp), %xmm0
movq -0x128(%rbp), %rax
movl 0x8(%rax), %eax
leaq -0x1e0(%rbp), %rdi
xorl %ecx, %ecx
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x93360
movq %rax, -0xb0(%rbp)
movq -0x68(%rbp), %rax
movq -0xd0(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x120(%rbp), %rcx
movl 0x8(%rcx), %ecx
movq -0x128(%rbp), %rdx
subl 0x8(%rdx), %ecx
addl %ecx, %eax
movl %eax, %eax
movq -0xb0(%rbp), %rcx
imulq 0x48(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
cmpq -0xf0(%rbp), %rax
jle 0x2b1610
movq -0xe0(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0xf8(%rbp)
cmpq $0x0, -0x108(%rbp)
jle 0x2b160e
movq -0x108(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x108(%rbp)
jmp 0x2b1649
movq -0x88(%rbp), %rax
movq -0xd0(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0xc8(%rbp), %rax
jne 0x2b1647
movq -0x108(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x108(%rbp)
cmpq 0x20(%rbp), %rax
jle 0x2b1645
jmp 0x2b1697
jmp 0x2b1647
jmp 0x2b1649
movq -0x80(%rbp), %rax
movq -0xd0(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jl 0x2b167c
movq -0xc8(%rbp), %rdx
movq -0x88(%rbp), %rax
movq -0x80(%rbp), %rcx
movq -0xd0(%rbp), %rsi
movq (%rcx,%rsi,8), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x2b167e
jmp 0x2b1680
movq -0xd0(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0xd0(%rbp)
jmp 0x2b1438
movq -0xd0(%rbp), %rax
movq %rax, -0x110(%rbp)
cmpq $0x0, -0xa0(%rbp)
jl 0x2b16e6
movq -0x20(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0xc8(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x1c, -0xa0(%rbp), %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
addq 0x30(%rbp), %rcx
cmpq %rcx, %rax
jle 0x2b17c9
movq $-0x80000000, -0xa8(%rbp) # imm = 0x80000000
movq $-0x1, -0xa0(%rbp)
movq -0xc8(%rbp), %rax
subq $0x1, %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rcx
xorl %eax, %eax
cmpq -0x98(%rbp), %rcx
movb %al, -0x1f9(%rbp)
jl 0x2b1763
movq -0x20(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0xc8(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq 0x30(%rbp), %rcx
movq -0x20(%rbp), %rdx
movq (%rdx), %rdx
imulq $0x1c, -0xd0(%rbp), %rsi
addq %rsi, %rdx
movl 0x8(%rdx), %edx
addq %rdx, %rcx
cmpq %rcx, %rax
setle %al
movb %al, -0x1f9(%rbp)
movb -0x1f9(%rbp), %al
testb $0x1, %al
jne 0x2b176f
jmp 0x2b17c7
movq -0xa8(%rbp), %rax
movq -0x68(%rbp), %rcx
movq -0xd0(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
cmpq %rcx, %rax
jge 0x2b17ae
movq -0x68(%rbp), %rax
movq -0xd0(%rbp), %rcx
movslq (%rax,%rcx,4), %rax
movq %rax, -0xa8(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0xa0(%rbp)
jmp 0x2b17b0
movq -0xd0(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0xd0(%rbp)
jmp 0x2b170e
jmp 0x2b17c9
cmpq $0x0, -0xa0(%rbp)
jl 0x2b1995
movq -0xa0(%rbp), %rax
cmpq -0x110(%rbp), %rax
jge 0x2b1995
movq -0x20(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0xa0(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x128(%rbp)
movq -0x128(%rbp), %rax
movl 0xc(%rax), %eax
shll %eax
movq -0x128(%rbp), %rcx
movl 0x18(%rcx), %ecx
shrl $0x1f, %ecx
orl %ecx, %eax
movl %eax, -0x58(%rbp)
movq -0x128(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x120(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jbe 0x2b1993
movq -0x128(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x120(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jae 0x2b1993
movq -0x120(%rbp), %rdi
movq -0x128(%rbp), %rsi
movq 0x50(%rbp), %r8
xorl %eax, %eax
movl %eax, %r9d
movq %r9, %rdx
movq %r9, %rcx
callq 0x71a90
movq %rax, -0x100(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x58(%rbp), %eax
je 0x2b1991
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl -0x54(%rbp), %edx
xorl $0x1, %edx
movl -0x58(%rbp), %ecx
xorl $0x1, %ecx
movq 0x10(%rbp), %r8
movsd -0x48(%rbp), %xmm0
movq -0x100(%rbp), %r9
xorl %eax, %eax
movq $0x0, (%rsp)
callq 0x2b0c90
cmpq $0x0, %rax
je 0x2b1991
movq -0x120(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %r8
movq 0x58(%rbp), %r9
movq 0x60(%rbp), %rbx
movq -0x18(%rbp), %r11
movq 0x40(%rbp), %r10
movsd -0x50(%rbp), %xmm0
movq -0x128(%rbp), %rax
movl 0x8(%rax), %eax
leaq -0x1e0(%rbp), %rdi
xorl %ecx, %ecx
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x93360
movq %rax, -0xb0(%rbp)
movq -0x68(%rbp), %rax
movq -0xa0(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x120(%rbp), %rcx
movl 0x8(%rcx), %ecx
movq -0x128(%rbp), %rdx
subl 0x8(%rdx), %ecx
addl %ecx, %eax
movl %eax, %eax
movq -0xb0(%rbp), %rcx
imulq 0x48(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
cmpq -0xf0(%rbp), %rax
jle 0x2b198f
movq -0xe0(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0xf8(%rbp)
jmp 0x2b1991
jmp 0x2b1993
jmp 0x2b1995
cmpq $0x0, -0xf0(%rbp)
jge 0x2b19b8
movq -0xe8(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq $-0x1, -0xf8(%rbp)
movq -0xf0(%rbp), %rax
movl %eax, %edx
movq -0x68(%rbp), %rax
movq -0xc8(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0xf8(%rbp), %rdx
movq -0x80(%rbp), %rax
movq -0xc8(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
cmpq $0x0, -0xa0(%rbp)
jl 0x2b1a43
movq -0x20(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0xc8(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq 0x30(%rbp), %rcx
movq -0x20(%rbp), %rdx
movq (%rdx), %rdx
imulq $0x1c, -0xa0(%rbp), %rsi
addq %rsi, %rdx
movl 0x8(%rdx), %edx
addq %rdx, %rcx
cmpq %rcx, %rax
jg 0x2b1a51
movq -0x68(%rbp), %rax
movq -0xa0(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x68(%rbp), %rcx
movq -0xc8(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x2b1a51
movq -0xc8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xf0(%rbp), %rax
cmpq -0x118(%rbp), %rax
jge 0x2b1a6f
movq -0xf0(%rbp), %rax
movq %rax, -0x118(%rbp)
jmp 0x2b1a71
movq -0xc8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xc8(%rbp)
jmp 0x2b1275
movq $0x0, -0xc8(%rbp)
movq -0xc8(%rbp), %rax
cmpq -0x90(%rbp), %rax
jge 0x2b1b1b
movq -0x118(%rbp), %rsi
movq -0x68(%rbp), %rax
movq -0xc8(%rbp), %rcx
movslq (%rax,%rcx,4), %rdx
subq %rsi, %rdx
movl %edx, (%rax,%rcx,4)
movq -0x68(%rbp), %rax
movq -0xc8(%rbp), %rcx
movslq (%rax,%rcx,4), %rdx
shlq $0x20, %rdx
movq -0x88(%rbp), %rax
movq -0xc8(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0xc8(%rbp), %rdx
shlq %rdx
movq -0x88(%rbp), %rax
movq -0xc8(%rbp), %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq -0xc8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xc8(%rbp)
jmp 0x2b1a93
movq -0x88(%rbp), %rdi
movq -0x88(%rbp), %rsi
movq -0x90(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x27ae10
movq $0x0, -0x118(%rbp)
movq -0x90(%rbp), %rax
subq $0x1, %rax
movq %rax, -0xd8(%rbp)
movq $0x0, -0x1f0(%rbp)
movq $0x0, -0x1e8(%rbp)
cmpq $0x0, -0xd8(%rbp)
jl 0x2b1d68
movq -0x1e8(%rbp), %rax
movq %rax, -0x1f8(%rbp)
movq -0x88(%rbp), %rax
movq -0xd8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrl %eax
movl %eax, %eax
movq %rax, -0xc8(%rbp)
xorl %eax, %eax
cmpq $0x0, -0xc8(%rbp)
movb %al, -0x1fa(%rbp)
jl 0x2b1bdd
movq -0x88(%rbp), %rax
movq -0xc8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
andq $0x1, %rax
cmpq $0x0, %rax
sete %al
movb %al, -0x1fa(%rbp)
movb -0x1fa(%rbp), %al
testb $0x1, %al
jne 0x2b1bec
jmp 0x2b1c6f
movq -0x20(%rbp), %rax
movq (%rax), %rcx
imulq $0x1c, -0xc8(%rbp), %rax
addq %rax, %rcx
movq -0x28(%rbp), %rax
movq -0x1e8(%rbp), %rdx
movq %rdx, %rsi
addq $0x1, %rsi
movq %rsi, -0x1e8(%rbp)
imulq $0x1c, %rdx, %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rax)
movl 0x18(%rcx), %ecx
movl %ecx, 0x18(%rax)
movq -0x88(%rbp), %rax
movq -0xc8(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
orq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x80(%rbp), %rax
movq -0xc8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xc8(%rbp)
jmp 0x2b1ba8
movq -0x1f8(%rbp), %rax
cmpq -0x1e8(%rbp), %rax
jne 0x2b1c84
jmp 0x2b1d51
cmpq $0x0, -0xc8(%rbp)
jge 0x2b1cad
movq -0x88(%rbp), %rax
movq -0xd8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
sarq $0x20, %rax
movq %rax, -0x208(%rbp)
jmp 0x2b1cdc
movq -0x88(%rbp), %rax
movq -0xd8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
sarq $0x20, %rax
movq -0x68(%rbp), %rcx
movq -0xc8(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
subq %rcx, %rax
movq %rax, -0x208(%rbp)
movq -0x208(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x1e8(%rbp), %rax
subq -0x1f8(%rbp), %rax
movl %eax, %edx
movq -0x70(%rbp), %rax
movq -0x1f0(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0xe0(%rbp), %rax
movl %eax, %edx
movq -0x78(%rbp), %rax
movq -0x1f0(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x1f0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1f0(%rbp)
movq -0xe0(%rbp), %rax
cmpq -0x118(%rbp), %rax
jge 0x2b1d4f
movq -0xe0(%rbp), %rax
movq %rax, -0x118(%rbp)
jmp 0x2b1d51
movq -0xd8(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0xd8(%rbp)
jmp 0x2b1b6f
movq $0x0, -0xd8(%rbp)
movq $0x0, -0x1f8(%rbp)
movq $0x0, -0x1e8(%rbp)
movq -0xd8(%rbp), %rax
cmpq -0x1f0(%rbp), %rax
jge 0x2b217e
movq -0x1e8(%rbp), %rax
movq %rax, -0x1f8(%rbp)
movq -0x70(%rbp), %rax
movq -0xd8(%rbp), %rcx
movslq (%rax,%rcx,4), %rax
addq -0x1e8(%rbp), %rax
movq %rax, -0x1e8(%rbp)
movq -0x78(%rbp), %rax
movq -0xd8(%rbp), %rcx
movslq (%rax,%rcx,4), %rax
subq -0x118(%rbp), %rax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0xd8(%rbp), %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x1f8(%rbp), %rax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0xd8(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x10(%rax)
movq -0x1e8(%rbp), %rax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0xd8(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x14(%rax)
movq -0x70(%rbp), %rax
movq -0xd8(%rbp), %rcx
movl (%rax,%rcx,4), %eax
sarl %eax
movl %eax, -0x5c(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0xd8(%rbp), %rcx
addq %rcx, %rax
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
movq -0x28(%rbp), %rax
imulq $0x1c, -0x1f8(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
movq -0x20(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0xd8(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movq $0x0, -0xc8(%rbp)
movq -0xc8(%rbp), %rax
movl -0x5c(%rbp), %ecx
cmpq %rcx, %rax
jge 0x2b20bc
movq -0x28(%rbp), %rax
movq -0x1f8(%rbp), %rcx
addq -0xc8(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x144(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x13c(%rbp)
movq 0x10(%rax), %rcx
movq %rcx, -0x134(%rbp)
movl 0x18(%rax), %eax
movl %eax, -0x12c(%rbp)
movq -0x28(%rbp), %rcx
movq -0x1e8(%rbp), %rax
subq -0xc8(%rbp), %rax
subq $0x1, %rax
imulq $0x1c, %rax, %rax
addq %rax, %rcx
movq -0x28(%rbp), %rax
movq -0x1f8(%rbp), %rdx
addq -0xc8(%rbp), %rdx
imulq $0x1c, %rdx, %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rax)
movl 0x18(%rcx), %ecx
movl %ecx, 0x18(%rax)
movq -0x28(%rbp), %rax
movq -0x1e8(%rbp), %rcx
subq -0xc8(%rbp), %rcx
subq $0x1, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq -0x144(%rbp), %rcx
movq %rcx, (%rax)
movq -0x13c(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x134(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0x12c(%rbp), %ecx
movl %ecx, 0x18(%rax)
movq -0x20(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0xd8(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x28(%rbp), %rcx
movq -0x1f8(%rbp), %rdx
addq -0xc8(%rbp), %rdx
imulq $0x1c, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jbe 0x2b1fdf
movq -0x28(%rbp), %rax
movq -0x1f8(%rbp), %rcx
addq -0xc8(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
movq -0x20(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0xd8(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movq -0x20(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0xd8(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x28(%rbp), %rcx
movq -0x1e8(%rbp), %rdx
subq -0xc8(%rbp), %rdx
subq $0x1, %rdx
imulq $0x1c, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jbe 0x2b204b
movq -0x28(%rbp), %rax
movq -0x1e8(%rbp), %rcx
subq -0xc8(%rbp), %rcx
subq $0x1, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
movq -0x20(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0xd8(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movq -0x28(%rbp), %rax
movq -0x1e8(%rbp), %rcx
subq -0xc8(%rbp), %rcx
subq $0x1, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %ecx
andl $0xc0000000, %ecx       # imm = 0xC0000000
orl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
movl %ecx, 0x18(%rax)
movq -0x28(%rbp), %rax
movq -0x1f8(%rbp), %rcx
addq -0xc8(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %ecx
andl $0xc0000000, %ecx       # imm = 0xC0000000
orl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
movl %ecx, 0x18(%rax)
movq -0xc8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xc8(%rbp)
jmp 0x2b1e8e
movq -0x70(%rbp), %rax
movq -0xd8(%rbp), %rcx
movl (%rax,%rcx,4), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2b2165
movq -0x20(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0xd8(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x28(%rbp), %rcx
movq -0x1f8(%rbp), %rdx
addq -0xc8(%rbp), %rdx
imulq $0x1c, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jbe 0x2b213a
movq -0x28(%rbp), %rax
movq -0x1f8(%rbp), %rcx
addq -0xc8(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
movq -0x20(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, -0xd8(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movq -0x28(%rbp), %rax
movq -0x1f8(%rbp), %rcx
addq -0xc8(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %ecx
andl $0xc0000000, %ecx       # imm = 0xC0000000
orl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
movl %ecx, 0x18(%rax)
jmp 0x2b2167
movq -0xd8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xd8(%rbp)
jmp 0x2b1d89
movq -0x1f0(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rax
movq (%rax), %rsi
movq -0x20(%rbp), %rax
imulq $0x1c, 0x8(%rax), %rax
addq %rax, %rsi
callq 0x27c310
movq -0x1e8(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %rbp
retq
nopw %cs:(%rax,%rax)