// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
movsd %xmm1, 0x90(%rsp)
movsd %xmm0, 0x60(%rsp)
movq %r9, 0x58(%rsp)
movq %r8, 0x88(%rsp)
movq %rcx, 0x80(%rsp)
movq %rdi, 0x78(%rsp)
movq %rsi, (%rsp)
movq 0x8(%rsi), %rbp
testq %rbp, %rbp
je 0x1b411c
movq %rdx, %r12
movq 0x220(%rsp), %rbx
movq 0x1e8(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x3f828
movq 0x28(%r14), %rax
movq %rax, 0x30(%rsp)
movq (%r14), %rax
movq %rax, 0x48(%rsp)
movq 0x8(%r14), %rax
movq %rax, 0x40(%rsp)
movq 0x20(%r14), %r13
movq 0x18(%r14), %rax
movq %rax, 0xa0(%rsp)
testq %rbx, %rbx
je 0x1b3a26
movq (%rsp), %rax
movq (%rax), %rdi
leaq (,%rbp,8), %rax
addq %rbp, %rax
leaq (%rax,%rax,2), %rsi
addq %rdi, %rsi
addq %rbp, %rsi
callq 0x195511
testq %rbp, %rbp
jle 0x1b3a26
movq %rbp, %rbx
negq %rbx
movl $0x1, %r14d
movl $0x1c, %r15d
xorl %eax, %eax
movq %rbx, %rcx
addq %r14, %rcx
je 0x1b39e0
movq (%rsp), %rcx
movq (%rcx), %rcx
movl 0x8(%rcx,%r15), %edx
leaq (%rax,%rax,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rax, %rsi
cmpl 0x8(%rcx,%rsi), %edx
jne 0x1b39e0
movq %rax, %rcx
jmp 0x1b3a0f
movq %r14, %rdx
subq %rax, %rdx
movq %r14, %rcx
cmpq $0x2, %rdx
jl 0x1b3a0f
movq (%rsp), %rcx
movq (%rcx), %rsi
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rdi
addq %rax, %rdi
addq %rsi, %rdi
addq %r15, %rsi
callq 0x1957bd
movq %r14, %rcx
leaq (%rbx,%r14), %rdx
incq %rdx
incq %r14
addq $0x1c, %r15
movq %rcx, %rax
cmpq $0x1, %rdx
jne 0x1b39b6
leaq (,%rbp,8), %rdx
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x20e0
testq %rbp, %rbp
movq %r12, 0x70(%rsp)
movq 0x48(%rsp), %r14
movl $0x0, %esi
jle 0x1b402e
movq %rbp, 0x68(%rsp)
movq %r13, 0xa8(%rsp)
movq 0x1c8(%rsp), %rax
incq %rax
movq %rax, 0xb0(%rsp)
movq $-0x14, %r13
xorl %esi, %esi
movq $-0x1, 0x98(%rsp)
xorl %edi, %edi
movq $-0x1, %rbp
xorl %r9d, %r9d
movq %r13, 0xc0(%rsp)
movq %rsi, 0xc8(%rsp)
movq %r9, 0x8(%rsp)
movq %rdi, %r12
movq (%rsp), %r15
movq (%r15), %rbx
leaq (%rdi,%rdi,8), %rax
leaq (%rax,%rax,2), %r14
addq %rdi, %r14
leaq (%rbx,%r14), %rax
movq %rax, 0x18(%rsp)
movl 0xc(%rbx,%r14), %eax
movl 0x18(%rbx,%r14), %esi
shrdl $0x1f, %eax, %esi
movl %esi, 0x2c(%rsp)
xorl $0x1, %esi
movq 0x58(%rsp), %rdi
movl %esi, 0x28(%rsp)
callq 0x19c00f
movl 0x4(%rbx,%r14), %ecx
addq %rax, %rcx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
mulsd 0x60(%rsp), %xmm0
cvttsd2si %xmm0, %rdx
movq 0x1c0(%rsp), %rax
cmpq %rax, %rdx
cmovleq %rax, %rdx
addq %rcx, %rdx
movq 0xb0(%rsp), %rax
cmpq %rax, %rdx
cmovgeq %rax, %rdx
movq (%r15), %rsi
subl $-0x80, %edx
movq %r12, 0x38(%rsp)
movl %r12d, %edi
callq 0x19f679
movslq %eax, %r13
movl 0x8(%rbx,%r14), %r15d
movl 0x18(%rbx,%r14), %eax
movq %r14, 0x50(%rsp)
subl 0x4(%rbx,%r14), %r15d
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
imulq 0x1f8(%rsp), %rax
subq %rax, %r15
movq $0x7fffffff, 0xf0(%rsp) # imm = 0x7FFFFFFF
movq %r13, %rax
movq 0x8(%rsp), %rdx
subq %rdx, %rax
movq %r13, %r9
movq 0x1d8(%rsp), %rcx
subq %rcx, %r9
cmpq %rcx, %rax
cmovleq %rdx, %r9
cmpq %r13, %r9
movq %r15, 0xb8(%rsp)
jle 0x1b3bb2
movq %r13, %rax
movq $-0x1, 0x20(%rsp)
movq 0x18(%rsp), %rdi
jmp 0x1b3d95
leaq (,%r13,8), %rax
addq %r13, %rax
leaq (%rax,%rax,2), %r14
addq %r13, %r14
movq $-0x1, 0x20(%rsp)
movq $0x0, 0x10(%rsp)
movq %r15, %r12
movq 0x18(%rsp), %rdi
movq %r9, 0x8(%rsp)
movq (%rsp), %rax
movq (%rax), %rbx
movl 0x4(%rdi), %eax
cmpl %eax, 0x8(%rbx,%r14)
jbe 0x1b3d8f
cmpl %eax, 0x4(%rbx,%r14)
jae 0x1b3d0d
leaq (%rbx,%r14), %rsi
movl 0xc(%rbx,%r14), %eax
movl 0x18(%rbx,%r14), %r15d
shrdl $0x1f, %eax, %r15d
xorl %edx, %edx
xorl %ecx, %ecx
movq 0x200(%rsp), %r8
xorl %r9d, %r9d
callq 0x6f050
cmpl %r15d, 0x2c(%rsp)
je 0x1b3d12
xorl $0x1, %r15d
subq $0x8, %rsp
movq 0x60(%rsp), %rsi
movl 0x30(%rsp), %edx
movl %r15d, %ecx
movq 0x1c8(%rsp), %r8
movsd 0x68(%rsp), %xmm0
movq %rax, %r9
pushq $0x0
callq 0x1b3728
addq $0x10, %rsp
testq %rax, %rax
je 0x1b3d12
movl 0x8(%rbx,%r14), %eax
subq $0x8, %rsp
leaq 0xf8(%rsp), %rdi
movq 0x20(%rsp), %r15
movq %r15, %rsi
movq 0x88(%rsp), %rdx
xorl %ecx, %ecx
movq 0x90(%rsp), %r8
movq 0x210(%rsp), %r9
movsd 0x98(%rsp), %xmm0
pushq %rax
pushq 0x200(%rsp)
pushq $0x0
pushq 0x98(%rsp)
pushq 0x238(%rsp)
callq 0x80597
movq %r15, %rdi
addq $0x30, %rsp
movl 0x8(%r15), %r15d
movq 0x48(%rsp), %rcx
addl (%rcx,%r13,4), %r15d
subl 0x8(%rbx,%r14), %r15d
imulq 0x1f8(%rsp), %rax
subq %rax, %r15
cmpq %r12, %r15
jle 0x1b3d21
xorl %eax, %eax
movq 0x10(%rsp), %rcx
testq %rcx, %rcx
setg %al
subq %rax, %rcx
movq %rcx, 0x10(%rsp)
movq %r13, 0x20(%rsp)
jmp 0x1b3d55
movq %r12, %r15
jmp 0x1b3d76
movq %r12, %r15
movq 0x8(%rsp), %r9
movq 0x18(%rsp), %rdi
jmp 0x1b3d76
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
cmpq %rcx, (%rax,%r13,8)
jne 0x1b3d52
movq 0x10(%rsp), %rax
cmpq 0x1d0(%rsp), %rax
movq 0x8(%rsp), %r9
jge 0x1b3d8f
incq %rax
movq %rax, 0x10(%rsp)
movq %r12, %r15
jmp 0x1b3d5a
movq %r12, %r15
movq 0x8(%rsp), %r9
movq 0x40(%rsp), %rax
movq (%rax,%r13,8), %rax
testq %rax, %rax
js 0x1b3d76
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %rdx
movq %rdx, (%rcx,%rax,8)
leaq -0x1(%r13), %rax
addq $-0x1c, %r14
movq %r15, %r12
cmpq %r9, %r13
movq %rax, %r13
jg 0x1b3be3
jmp 0x1b3d95
movq %r13, %rax
movq %r12, %r15
testq %rbp, %rbp
movq 0x48(%rsp), %r14
movq 0x1e0(%rsp), %r12
movq 0xc0(%rsp), %r13
js 0x1b3ddd
movq (%rsp), %rcx
movq (%rcx), %rcx
movq 0x50(%rsp), %rdx
movl 0x8(%rcx,%rdx), %edx
leaq (,%rbp,8), %rsi
addq %rbp, %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rbp, %rsi
movl 0x8(%rcx,%rsi), %ecx
addq %r12, %rcx
cmpq %rdx, %rcx
jge 0x1b3e37
movq $-0x1, %rbp
cmpq %r9, 0x38(%rsp)
jle 0x1b3e37
movq (%rsp), %rcx
movq (%rcx), %rcx
movq 0x50(%rsp), %rdx
movl 0x8(%rcx,%rdx), %edx
addq %r13, %rcx
movq $-0x80000000, %rsi      # imm = 0x80000000
movq 0x98(%rsp), %r10
movl (%rcx), %r8d
addq %r12, %r8
cmpq %rdx, %r8
jl 0x1b3e37
movslq (%r14,%r10,4), %r8
cmpq %r8, %rsi
cmovlq %r10, %rbp
cmovleq %r8, %rsi
leaq -0x1(%r10), %r8
addq $-0x1c, %rcx
cmpq %r9, %r10
movq %r8, %r10
jg 0x1b3e0d
testq %rbp, %rbp
js 0x1b3f81
cmpq %rax, %rbp
jge 0x1b3f81
movq (%rsp), %rax
movq (%rax), %rax
leaq (,%rbp,8), %rcx
addq %rbp, %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rbp, %rcx
movl 0x4(%rdi), %edx
cmpl %edx, 0x8(%rax,%rcx)
jbe 0x1b3f81
leaq (%rax,%rcx), %rsi
movq %rsi, 0x10(%rsp)
cmpl %edx, 0x4(%rsi)
jae 0x1b3f81
movq %r9, 0x8(%rsp)
movl 0xc(%rax,%rcx), %edx
movl 0x18(%rax,%rcx), %ebx
shrdl $0x1f, %edx, %ebx
movq 0x10(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movq 0x200(%rsp), %r8
xorl %r9d, %r9d
callq 0x6f050
cmpl %ebx, 0x2c(%rsp)
je 0x1b3f7c
xorl $0x1, %ebx
subq $0x8, %rsp
movq 0x60(%rsp), %rsi
movl 0x30(%rsp), %edx
movl %ebx, %ecx
movq 0x1c8(%rsp), %r8
movsd 0x68(%rsp), %xmm0
movq %rax, %r9
pushq $0x0
callq 0x1b3728
addq $0x10, %rsp
testq %rax, %rax
je 0x1b3f7c
movq 0x10(%rsp), %rax
movl 0x8(%rax), %eax
subq $0x8, %rsp
leaq 0xf8(%rsp), %rdi
movq 0x20(%rsp), %rbx
movq %rbx, %rsi
movq 0x88(%rsp), %rdx
xorl %ecx, %ecx
movq 0x90(%rsp), %r8
movq 0x210(%rsp), %r9
movsd 0x98(%rsp), %xmm0
pushq %rax
pushq 0x200(%rsp)
pushq $0x0
pushq 0x98(%rsp)
pushq 0x238(%rsp)
callq 0x80597
addq $0x30, %rsp
movl 0x8(%rbx), %ecx
addl (%r14,%rbp,4), %ecx
movq 0x10(%rsp), %rdx
subl 0x8(%rdx), %ecx
imulq 0x1f8(%rsp), %rax
subq %rax, %rcx
cmpq %r15, %rcx
cmovgq %rcx, %r15
movq 0x20(%rsp), %rax
cmovgq %rbp, %rax
movq %rax, 0x20(%rsp)
movq 0x8(%rsp), %r9
testq %r15, %r15
movq 0xb8(%rsp), %r8
cmovnsq %r15, %r8
movq $-0x1, %rax
movq 0x20(%rsp), %rcx
cmovsq %rax, %rcx
movq 0x38(%rsp), %rdi
movl %r8d, (%r14,%rdi,4)
movq 0x40(%rsp), %rax
movq %rcx, (%rax,%rdi,8)
testq %rbp, %rbp
movq 0x30(%rsp), %rbx
movq 0xc8(%rsp), %rsi
js 0x1b3ff8
movq (%rsp), %rax
movq (%rax), %rax
movq 0x50(%rsp), %rcx
movl 0x8(%rax,%rcx), %ecx
leaq (,%rbp,8), %rdx
addq %rbp, %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rbp, %rdx
movl 0x8(%rax,%rdx), %eax
addq %r12, %rax
cmpq %rcx, %rax
jl 0x1b3ffb
cmpl %r8d, (%r14,%rbp,4)
jge 0x1b3ffb
movq %rdi, %rbp
cmpq %rsi, %r8
cmovlq %r8, %rsi
incq %rdi
incq 0x98(%rsp)
addq $0x1c, %r13
cmpq 0x68(%rsp), %rdi
jne 0x1b3a96
movq 0x70(%rsp), %r12
movq 0xa8(%rsp), %r13
movq 0x68(%rsp), %rbp
testq %rbp, %rbp
jle 0x1b4056
xorl %eax, %eax
movq %rbp, %rcx
movl (%r14,%rax,2), %edx
subl %esi, %edx
movl %edx, (%r14,%rax,2)
shlq $0x20, %rdx
addq %rax, %rdx
movq %rdx, (%rbx,%rax,4)
addq $0x2, %rax
decq %rcx
jne 0x1b4038
leaq (%rbx,%rbp,8), %rsi
movq %rbx, %rdi
callq 0x19525e
testq %rbp, %rbp
jle 0x1b4124
xorl %eax, %eax
xorl %edx, %edx
xorl %ecx, %ecx
movq 0x40(%rsp), %r15
movq %rdx, %rdi
movq %rbp, %rsi
decq %rbp
movl -0x8(%rbx,%rsi,8), %r8d
shrl %r8d
leaq (%rdx,%rdx,8), %r9
leaq (%r9,%r9,2), %r9
addq %r12, %r9
addq %rdx, %r9
testb $0x1, (%rbx,%r8,8)
jne 0x1b40d9
movq (%rsp), %r10
movq (%r10), %r10
leaq (%r8,%r8,8), %r11
leaq (%r11,%r11,2), %r11
addq %r8, %r11
movupd (%r10,%r11), %xmm0
movups 0xc(%r10,%r11), %xmm1
movups %xmm1, 0xc(%r9)
movupd %xmm0, (%r9)
orb $0x1, (%rbx,%r8,8)
incq %rdx
movq (%r15,%r8,8), %r8
addq $0x1c, %r9
testq %r8, %r8
jns 0x1b4095
cmpq %rdi, %rdx
je 0x1b4110
movslq 0x4(%rbx,%rbp,8), %r9
testq %r8, %r8
js 0x1b40ef
movslq (%r14,%r8,4), %r8
subq %r8, %r9
movl %edx, %r8d
subl %edi, %r8d
movl %r8d, (%r13,%rax,4)
movq 0xa0(%rsp), %rdi
movl %r9d, (%rdi,%rax,4)
incq %rax
cmpq %rcx, %r9
cmovlq %r9, %rcx
cmpq $0x1, %rsi
jg 0x1b4076
jmp 0x1b4128
xorl %r14d, %r14d
jmp 0x1b42e3
xorl %ecx, %ecx
xorl %eax, %eax
testq %rax, %rax
jle 0x1b42c2
leaq -0x1c(%r12), %rdx
movq %rdx, 0x18(%rsp)
xorl %r8d, %r8d
movl $0x3fffffff, %esi       # imm = 0x3FFFFFFF
xorl %edi, %edi
movslq (%r13,%rdi,4), %r14
addq %r8, %r14
movq 0xa0(%rsp), %rdx
movl (%rdx,%rdi,4), %r10d
subl %ecx, %r10d
movq (%rsp), %r9
movq (%r9), %rbx
leaq (%rdi,%rdi,8), %r9
leaq (%r9,%r9,2), %r9
addq %rdi, %r9
movl %r10d, (%rbx,%r9)
movl %r8d, 0x10(%rbx,%r9)
movl %r14d, 0x14(%rbx,%r9)
movq %r13, %rdx
movl (%r13,%rdi,4), %r11d
movl $0xffffffff, 0x4(%rbx,%r9) # imm = 0xFFFFFFFF
leaq (%r8,%r8,8), %r10
leaq (%r10,%r10,2), %r10
leaq (%r10,%r8), %r15
movl 0x8(%r12,%r15), %ebp
movl %ebp, 0x8(%rbx,%r9)
cmpl $0x2, %r11d
jae 0x1b41b0
xorl %ebx, %ebx
jmp 0x1b426a
sarl %r11d
leaq (%r12,%r8), %r15
addq %r10, %r15
cmpl $0x1, %r11d
adcl $0x0, %r11d
leaq (%r14,%r14,8), %rbx
leaq (%rbx,%rbx,2), %r12
movq 0x18(%rsp), %rbx
addq %r14, %rbx
addq %rbx, %r12
xorl %ebx, %ebx
movups (%r15), %xmm0
movups 0xc(%r15), %xmm1
movups %xmm1, 0xdc(%rsp)
movaps %xmm0, 0xd0(%rsp)
movups (%r12), %xmm0
movups 0xc(%r12), %xmm1
movups %xmm1, 0xc(%r15)
movups %xmm0, (%r15)
movups 0xdc(%rsp), %xmm0
movups %xmm0, 0xc(%r12)
movapd 0xd0(%rsp), %xmm0
movupd %xmm0, (%r12)
movq (%rsp), %r13
movq (%r13), %r13
addq %r9, %r13
addq $0x4, %r13
movl 0x4(%r15), %ebp
cmpl %ebp, (%r13)
jbe 0x1b423e
movl %ebp, (%r13)
movl 0x4(%r12), %ebp
cmpl %ebp, (%r13)
jbe 0x1b424d
movl %ebp, (%r13)
orl %esi, 0x18(%r12)
orl %esi, 0x18(%r15)
incq %rbx
addq $0x1c, %r15
addq $-0x1c, %r12
cmpq %rbx, %r11
jne 0x1b41d7
movq %rdx, %r13
testb $0x1, (%rdx,%rdi,4)
movq 0x70(%rsp), %r12
je 0x1b42b1
movq (%rsp), %r11
movq (%r11), %r11
addq %r12, %r8
addq %r10, %r8
leaq (%rbx,%rbx,8), %r10
leaq (%r10,%r10,2), %r10
addq %rbx, %r10
movl 0x4(%r8,%r10), %ebx
cmpl %ebx, 0x4(%r11,%r9)
jbe 0x1b42a6
addq %r11, %r9
addq $0x4, %r9
movl %ebx, (%r9)
addq %r10, %r8
orl $0x3fffffff, 0x18(%r8)  # imm = 0x3FFFFFFF
incq %rdi
movq %r14, %r8
cmpq %rax, %rdi
jne 0x1b4145
jmp 0x1b42c5
xorl %r14d, %r14d
movq (%rsp), %rcx
movq %rax, 0x8(%rcx)
movq (%rcx), %rdi
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rsi
addq %rax, %rsi
addq %rdi, %rsi
callq 0x195d3d
movq %r14, %rax
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq