// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/inter.cpp
// Function: gl_chain_lin(kv_ul_ov_t*, overlap_region*, ul_ov_t*, ul_idx_t const*, ug_opt_t const*, long, double, long, long, long, long, Chain_Data*, long, unsigned long, All_reads*, ma_ug_t*, long, long)
int64_t gl_chain_lin(kv_ul_ov_t *res, overlap_region *ol, ul_ov_t *ex, 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, int64_t trans_sc, 
uint64_t mode, All_reads *ridx, ma_ug_t *ug, int64_t need_srt, int64_t debug_i)
{
	if(res->n == 0) return 0;
	uint32_t rev_n; int32_t *f, *c_n, *c_sc; int64_t *p, *t, res_n = res->n, st, max_ii, max; rtrace_iter tc;
    int64_t mm_ovlp, x, i, j, k, sc, csc, mm_sc, mm_idx, n_skip, end_j, plus; ul_ov_t *li, *lj, rev_t; 
	resize_Chain_Data(dp, res_n, NULL); memset(&tc, 0, sizeof(tc));
	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]); 
        mm_ovlp = mode?max_ovlp_src(uopt, ((li->tn<<1)|li->rev)^1):max_ovlp(uref->ug->g, ((li->tn<<1)|li->rev)^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 = aln_sc(ol[(*li).qn], trans_sc, UG_TRANS_ERR_W);
		// fprintf(stderr, "[M::%s::utg%.6dl] i::%ld, csc::%ld, q::[%u, %u), aln::%u, ol::%u, sec_e::%u\n", 
		// 						__func__, (int32_t)li->tn+1, i, csc, li->qs, li->qe, 
		// 						(ol[(*li).qn]).align_length, (ol[(*li).qn]).overlapLen, 
		// 						(ol[(*li).qn]).non_homopolymer_errors);
		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;
		for (j = x; j >= st; --j) { // collect potential destination vertices
			lj = &(res->a[j]); 
			if(lj->qe+G_CHAIN_INDEL <= li->qs) break;//even this pair has a overlap, its length will be very small; just ignore
			sc = cal_gl_chain_lin_sc(res->a, i, j, &tc, ol, ridx, ug, uref, uopt, bw, diff_ec_ul, mode, trans_sc, UG_TRANS_ERR_W, f, debug_i);
			// char *as = NULL; 
			// asprintf(&as, "-3-[M::%s::] i::%ld(utg%.6dl), j::%ld(utg%.6dl), sc::%ld\n", 
			// __func__, i, (int32_t)li->tn+1, j, (int32_t)lj->tn+1, sc);
			// push_vlog(&(overall_zdbg->a[debug_i]), as); free(as); as = NULL;

			if(sc == INT32_MIN) continue;
			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]); 
			if(lj->qe+G_CHAIN_INDEL > li->qs && lj->qs < li->qs) {
				sc = cal_gl_chain_lin_sc(res->a, i, max_ii, &tc, ol, ridx, ug, uref, uopt, bw, diff_ec_ul, mode, trans_sc, UG_TRANS_ERR_W, f, debug_i);
				if(sc != INT32_MIN) {
					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);
		// char *as = NULL; 
		// asprintf(&as, "-5-[M::%s::utg%.6dl] i::%ld, csc::%ld, f[i]::%d, p[i]::%ld, q::[%u, %u)\n", __func__, (int32_t)li->tn+1, i, csc, f[i], p[i], li->qs, li->qe);
        // push_vlog(&(overall_zdbg->a[debug_i]), as); free(as); as = NULL;
	}
	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
    return n_v;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movsd %xmm0, 0x48(%rsp)
movq %r9, 0x40(%rsp)
movq %r8, 0x70(%rsp)
movq %rcx, 0x68(%rsp)
movq %rsi, 0x78(%rsp)
movq %rdi, (%rsp)
movq 0x8(%rdi), %rsi
testq %rsi, %rsi
je 0x1b55e8
movq %rdx, %r12
movq 0x1e8(%rsp), %rbx
movq 0x1c0(%rsp), %r14
movq %r14, %rdi
movq %rsi, 0x50(%rsp)
xorl %edx, %edx
callq 0x3ecb0
leaq 0xd8(%rsp), %rdi
movl $0x90, %edx
xorl %esi, %esi
callq 0x20e0
movq 0x28(%r14), %rax
movq %rax, 0x30(%rsp)
movq (%r14), %rax
movq %rax, 0x18(%rsp)
movq 0x8(%r14), %rax
movq %rax, 0x38(%rsp)
movq 0x20(%r14), %r13
movq 0x18(%r14), %rbp
testq %rbx, %rbx
je 0x1b4d76
movq (%rsp), %rax
movq (%rax), %rdi
movq 0x50(%rsp), %rbx
leaq (%rbx,%rbx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rdi, %rsi
addq %rbx, %rsi
callq 0x19e2b4
testq %rbx, %rbx
jle 0x1b55ed
negq %rbx
movl $0x1, %r14d
movl $0x1c, %r15d
xorl %eax, %eax
movq %rbx, %rcx
addq %r14, %rcx
je 0x1b4d30
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 0x1b4d30
movq %rax, %rcx
jmp 0x1b4d5f
movq %r14, %rdx
subq %rax, %rdx
movq %r14, %rcx
cmpq $0x2, %rdx
jl 0x1b4d5f
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 0x19e55c
movq %r14, %rcx
leaq (%rbx,%r14), %rdx
incq %rdx
incq %r14
addq $0x1c, %r15
movq %rcx, %rax
cmpq $0x1, %rdx
jne 0x1b4d06
movq 0x50(%rsp), %rbx
leaq (,%rbx,8), %rdx
movq 0x30(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x20e0
testq %rbx, %rbx
jle 0x1b5604
movq %rbp, 0x80(%rsp)
movq %r13, 0x88(%rsp)
movq %r12, 0x90(%rsp)
movq 0x1a0(%rsp), %rax
incq %rax
movq %rax, 0xa0(%rsp)
movq $-0x14, %r13
xorl %esi, %esi
movq $-0x1, 0x98(%rsp)
xorl %r15d, %r15d
xorl %r14d, %r14d
movq $-0x1, %rbp
movq %r13, 0xa8(%rsp)
movq %r15, %rbx
movq (%rsp), %rax
movq (%rax), %r13
leaq (%r14,%r14,8), %rax
leaq (%rax,%rax,2), %rax
addq %r14, %rax
movq %rax, 0x60(%rsp)
leaq (%rax,%r13), %r15
cmpq $0x0, 0x1d0(%rsp)
movq %rsi, 0x28(%rsp)
je 0x1b4e39
movl 0xc(%r15), %eax
movl 0x18(%r15), %esi
shrdl $0x1f, %eax, %esi
xorl $0x1, %esi
movq 0x70(%rsp), %rdi
callq 0x1a4c50
jmp 0x1b4ead
movq 0x68(%rsp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movl 0xc(%r15), %ecx
movl 0x18(%r15), %edx
shrdl $0x1f, %ecx, %edx
xorl $0x1, %edx
movq 0x28(%rax), %rcx
movq (%rcx,%rdx,8), %rcx
movq %rcx, %rdx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rdx
je 0x1b4eab
movq 0x8(%rax), %rsi
shrq $0x20, %rcx
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %rax
leaq (%rcx,%rcx,2), %rcx
leaq (%rsi,%rcx,8), %rcx
addq $0xc, %rcx
xorl %edx, %edx
xorl %esi, %esi
movl %esi, %edi
movl (%rcx,%rdx), %r8d
cmpl %r8d, %esi
movl %r8d, %esi
cmoval %edi, %esi
testl %r8d, %r8d
cmovsl %edi, %esi
addq $0x18, %rdx
cmpq %rdx, %rax
jne 0x1b4e89
movl %esi, %eax
jmp 0x1b4ead
xorl %eax, %eax
movl 0x4(%r15), %ecx
addq %rax, %rcx
cvtsi2sd %rcx, %xmm0
mulsd 0x48(%rsp), %xmm0
cvttsd2si %xmm0, %rdx
movq 0x40(%rsp), %rax
cmpq %rax, %rdx
cmovleq %rax, %rdx
addq %rcx, %rdx
movq 0xa0(%rsp), %rax
cmpq %rax, %rdx
cmovgeq %rax, %rdx
subl $-0x80, %edx
movl %r14d, %edi
movq %r13, %rsi
callq 0x1a83b5
movslq %eax, %r13
movq %r15, 0x20(%rsp)
movl (%r15), %eax
imulq $0xa8, %rax, %rax
movq 0x78(%rsp), %rdx
movl 0x20(%rdx,%rax), %ecx
movl 0x28(%rdx,%rax), %esi
subl %esi, %ecx
imulq 0x1c8(%rsp), %rcx
movl 0x30(%rdx,%rax), %eax
shlq $0x6, %rax
addq %rcx, %rax
subq %rax, %rsi
movq $0x7fffffff, 0xd0(%rsp) # imm = 0x7FFFFFFF
movq %r13, %rax
subq %rbx, %rax
movq %r13, %r15
movq 0x1b0(%rsp), %rcx
subq %rcx, %r15
cmpq %rcx, %rax
cmovleq %rbx, %r15
cmpq %r13, %r15
movq %rsi, 0x58(%rsp)
jle 0x1b4f74
movq $-0x1, 0x10(%rsp)
movq %r13, %rax
movq %rsi, 0x8(%rsp)
movq 0x18(%rsp), %r10
jmp 0x1b5097
leaq (,%r13,8), %rax
addq %r13, %rax
leaq (%rax,%rax,2), %rax
leaq (%rax,%r13), %rbx
addq $0x8, %rbx
movq $-0x1, 0x10(%rsp)
xorl %r12d, %r12d
movq %rsi, 0x8(%rsp)
movq 0x18(%rsp), %r10
movq (%rsp), %rax
movq (%rax), %rdi
movl (%rdi,%rbx), %eax
subl $-0x80, %eax
movq 0x20(%rsp), %rcx
cmpl 0x4(%rcx), %eax
jbe 0x1b5094
subq $0x10, %rsp
movl %r14d, %esi
movl %r13d, %edx
leaq 0xe0(%rsp), %rcx
movq 0x88(%rsp), %r8
movq 0x1e8(%rsp), %r9
movsd 0x58(%rsp), %xmm0
pushq %r10
pushq $0x40
pushq 0x1e8(%rsp)
pushq 0x1f8(%rsp)
pushq 0x70(%rsp)
pushq 0xa8(%rsp)
pushq 0xa8(%rsp)
pushq 0x228(%rsp)
callq 0x1b4a1a
addq $0x50, %rsp
cmpq $-0x80000000, %rax      # imm = 0x80000000
jne 0x1b5027
movq 0x18(%rsp), %r10
jmp 0x1b507e
cmpq 0x8(%rsp), %rax
jle 0x1b504a
xorl %ecx, %ecx
testq %r12, %r12
setg %cl
subq %rcx, %r12
movq %rax, 0x8(%rsp)
movq %r13, 0x10(%rsp)
movq 0x18(%rsp), %r10
jmp 0x1b5067
movq 0x30(%rsp), %rax
cmpq %r14, (%rax,%r13,8)
movq 0x18(%rsp), %r10
jne 0x1b5067
cmpq 0x1a8(%rsp), %r12
jge 0x1b5094
incq %r12
movq 0x38(%rsp), %rax
movq (%rax,%r13,8), %rax
testq %rax, %rax
js 0x1b507e
movq 0x30(%rsp), %rcx
movq %r14, (%rcx,%rax,8)
leaq -0x1(%r13), %rax
addq $-0x1c, %rbx
cmpq %r15, %r13
movq %rax, %r13
jg 0x1b4fa1
jmp 0x1b5097
movq %r13, %rax
testq %rbp, %rbp
movq 0x50(%rsp), %rbx
movq 0x1b8(%rsp), %r12
movq 0xa8(%rsp), %r13
js 0x1b50df
movq (%rsp), %rcx
movq (%rcx), %rcx
movq 0x60(%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 0x1b513b
cmpq %r15, %r14
jle 0x1b524b
movq (%rsp), %rcx
movq (%rcx), %rcx
movq 0x60(%rsp), %rdx
movl 0x8(%rcx,%rdx), %edx
addq %r13, %rcx
movq $-0x80000000, %rsi      # imm = 0x80000000
movq $-0x1, %rbp
movq 0x98(%rsp), %rdi
movl (%rcx), %r8d
addq %r12, %r8
cmpq %rdx, %r8
jl 0x1b513b
movslq (%r10,%rdi,4), %r8
cmpq %r8, %rsi
cmovleq %r8, %rsi
cmovlq %rdi, %rbp
leaq -0x1(%rdi), %r8
addq $-0x1c, %rcx
cmpq %r15, %rdi
movq %r8, %rdi
jg 0x1b5111
testq %rbp, %rbp
js 0x1b5283
cmpq %rax, %rbp
jge 0x1b5283
movq (%rsp), %rax
movq (%rax), %rdi
leaq (,%rbp,8), %rax
addq %rbp, %rax
leaq (%rax,%rax,2), %rax
addq %rbp, %rax
movl 0x8(%rdi,%rax), %edx
subl $-0x80, %edx
movq 0x20(%rsp), %rcx
movl 0x4(%rcx), %ecx
cmpl %ecx, %edx
jbe 0x1b5216
addq %rdi, %rax
cmpl %ecx, 0x4(%rax)
jae 0x1b5216
subq $0x10, %rsp
movl %r14d, %esi
movl %ebp, %edx
leaq 0xe0(%rsp), %rcx
movq 0x88(%rsp), %r8
movq 0x1e8(%rsp), %r9
movsd 0x58(%rsp), %xmm0
pushq %r10
pushq $0x40
pushq 0x1e8(%rsp)
pushq 0x1f8(%rsp)
pushq 0x70(%rsp)
pushq 0xa8(%rsp)
pushq 0xa8(%rsp)
pushq 0x228(%rsp)
callq 0x1b4a1a
movq 0x68(%rsp), %r10
addq $0x50, %rsp
cmpq $-0x80000000, %rax      # imm = 0x80000000
setne %cl
movq 0x8(%rsp), %rsi
cmpq %rsi, %rax
setg %dl
testb %dl, %cl
cmovneq %rax, %rsi
movq %rsi, 0x8(%rsp)
movq 0x10(%rsp), %rax
cmovneq %rbp, %rax
movq %rax, 0x10(%rsp)
movq 0x28(%rsp), %rsi
movq 0x8(%rsp), %rax
testq %rax, %rax
movq 0x58(%rsp), %rdi
cmovnsq %rax, %rdi
movq $-0x1, %rax
movq 0x10(%rsp), %rcx
cmovsq %rax, %rcx
movl %edi, (%r10,%r14,4)
movq 0x38(%rsp), %rax
movq %rcx, (%rax,%r14,8)
jmp 0x1b52be
movq 0x8(%rsp), %rax
testq %rax, %rax
movq 0x58(%rsp), %rdi
cmovnsq %rax, %rdi
movq $-0x1, %rax
movq 0x10(%rsp), %rcx
cmovsq %rax, %rcx
movl %edi, (%r10,%r14,4)
movq 0x38(%rsp), %rax
movq %rcx, (%rax,%r14,8)
movq %r14, %rax
movq 0x28(%rsp), %rsi
jmp 0x1b52f7
movq 0x8(%rsp), %rax
testq %rax, %rax
movq 0x58(%rsp), %rdi
cmovnsq %rax, %rdi
movq $-0x1, %rax
movq 0x10(%rsp), %rcx
cmovsq %rax, %rcx
movl %edi, (%r10,%r14,4)
movq 0x38(%rsp), %rax
movq %rcx, (%rax,%r14,8)
movq %r14, %rax
testq %rbp, %rbp
movq 0x28(%rsp), %rsi
js 0x1b52f7
movq (%rsp), %rax
movq (%rax), %rax
movq 0x60(%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 0x1b52f4
cmpl %edi, (%r10,%rbp,4)
cmovlq %r14, %rbp
movq %rbp, %rax
cmpq %rsi, %rdi
cmovlq %rdi, %rsi
incq %r14
incq 0x98(%rsp)
addq $0x1c, %r13
movq %rax, %rbp
cmpq %rbx, %r14
jne 0x1b4de8
testq %rbx, %rbx
movq 0x90(%rsp), %r15
movq 0x88(%rsp), %r12
movq 0x80(%rsp), %r13
movq 0x30(%rsp), %r14
jle 0x1b5604
xorl %eax, %eax
movq %rbx, %rcx
movl (%r10,%rax,2), %edx
subl %esi, %edx
movl %edx, (%r10,%rax,2)
shlq $0x20, %rdx
addq %rax, %rdx
movq %rdx, (%r14,%rax,4)
addq $0x2, %rax
decq %rcx
jne 0x1b5344
leaq (%r14,%rbx,8), %rsi
movq %r14, %rdi
callq 0x19e008
testq %rbx, %rbx
movq 0x38(%rsp), %rbp
jle 0x1b5610
xorl %eax, %eax
xorl %edx, %edx
movq $0x0, 0x20(%rsp)
movq 0x18(%rsp), %r11
movq %rdx, %rdi
movq %rbx, %rsi
decq %rbx
movl -0x8(%r14,%rsi,8), %r8d
shrl %r8d
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %r9
addq %r15, %r9
addq %rdx, %r9
testb $0x1, (%r14,%r8,8)
jne 0x1b53f2
movq (%rsp), %rcx
movq (%rcx), %rcx
leaq (%r8,%r8,8), %r10
leaq (%r10,%r10,2), %r10
addq %r8, %r10
movupd (%rcx,%r10), %xmm0
movups 0xc(%rcx,%r10), %xmm1
movups %xmm1, 0xc(%r9)
movupd %xmm0, (%r9)
orb $0x1, (%r14,%r8,8)
incq %rdx
movq (%rbp,%r8,8), %r8
addq $0x1c, %r9
testq %r8, %r8
jns 0x1b53ad
cmpq %rdi, %rdx
je 0x1b5429
movslq 0x4(%r14,%rbx,8), %r9
testq %r8, %r8
js 0x1b5408
movslq (%r11,%r8,4), %rcx
subq %rcx, %r9
movl %edx, %ecx
subl %edi, %ecx
movl %ecx, (%r12,%rax,4)
movl %r9d, (%r13,%rax,4)
incq %rax
movq 0x20(%rsp), %rcx
cmpq %rcx, %r9
cmovlq %r9, %rcx
movq %rcx, 0x20(%rsp)
cmpq $0x1, %rsi
jg 0x1b538e
testq %rax, %rax
jle 0x1b5612
leaq 0x18(%r15), %rcx
movq %rcx, 0x48(%rsp)
leaq -0x1c(%r15), %rcx
movq %rcx, 0x40(%rsp)
xorl %r9d, %r9d
movl $0x3fffffff, %edi       # imm = 0x3FFFFFFF
xorl %r8d, %r8d
movslq (%r12,%r8,4), %r14
addq %r9, %r14
movl (%r13,%r8,4), %ecx
subl 0x20(%rsp), %ecx
movq (%rsp), %rdx
movq (%rdx), %rdx
leaq (%r8,%r8,8), %rsi
leaq (%rsi,%rsi,2), %r10
addq %r8, %r10
movl %ecx, (%rdx,%r10)
movl %r9d, 0x10(%rdx,%r10)
movl %r14d, 0x14(%rdx,%r10)
movl (%r12,%r8,4), %r11d
movl $0xffffffff, 0x4(%rdx,%r10) # imm = 0xFFFFFFFF
leaq (%r9,%r9,8), %rcx
leaq (%rcx,%rcx,2), %rbx
leaq (%rbx,%r9), %rcx
movl 0x8(%r15,%rcx), %ecx
movl %ecx, 0x8(%rdx,%r10)
cmpl $0x2, %r11d
jae 0x1b54ba
xorl %r11d, %r11d
jmp 0x1b5598
sarl %r11d
cmpl $0x1, %r11d
adcl $0x0, %r11d
leaq (%r11,%r11,8), %rcx
leaq (%rcx,%rcx,2), %r15
addq %r11, %r15
movq 0x48(%rsp), %rcx
leaq (%rcx,%r9), %r12
addq %rbx, %r12
leaq (%r14,%r14,8), %rcx
leaq (%rcx,%rcx,2), %r13
movq 0x40(%rsp), %rcx
addq %r14, %rcx
addq %rcx, %r13
xorl %ebp, %ebp
movups -0x18(%r12,%rbp), %xmm0
movups -0xc(%r12,%rbp), %xmm1
movups %xmm1, 0xbc(%rsp)
movaps %xmm0, 0xb0(%rsp)
movups (%r13), %xmm0
movups 0xc(%r13), %xmm1
movups %xmm1, -0xc(%r12,%rbp)
movups %xmm0, -0x18(%r12,%rbp)
movups 0xbc(%rsp), %xmm0
movups %xmm0, 0xc(%r13)
movapd 0xb0(%rsp), %xmm0
movupd %xmm0, (%r13)
movq (%rsp), %rcx
movq (%rcx), %rcx
leaq (%rcx,%r10), %rdx
addq $0x4, %rdx
movl (%rdx), %esi
movl -0x14(%r12,%rbp), %ecx
cmpl %ecx, %esi
jbe 0x1b555d
movl %ecx, (%rdx)
movl %ecx, %esi
movl 0x4(%r13), %ecx
cmpl %ecx, %esi
jbe 0x1b5567
movl %ecx, (%rdx)
orl %edi, 0x18(%r13)
orl %edi, (%r12,%rbp)
addq $0x1c, %rbp
addq $-0x1c, %r13
cmpq %rbp, %r15
jne 0x1b54f1
movq 0x90(%rsp), %r15
movq 0x88(%rsp), %r12
movq 0x80(%rsp), %r13
testb $0x1, (%r12,%r8,4)
je 0x1b55d7
movq (%rsp), %rcx
movq (%rcx), %rdx
addq %r15, %r9
addq %rbx, %r9
leaq (%r11,%r11,8), %rcx
leaq (%rcx,%rcx,2), %rbx
addq %r11, %rbx
movl 0x4(%r9,%rbx), %ecx
cmpl %ecx, 0x4(%rdx,%r10)
jbe 0x1b55cc
addq %r10, %rdx
addq $0x4, %rdx
movl %ecx, (%rdx)
addq %rbx, %r9
orl $0x3fffffff, 0x18(%r9)  # imm = 0x3FFFFFFF
incq %r8
movq %r14, %r9
cmpq %rax, %r8
jne 0x1b5459
jmp 0x1b5615
xorl %r14d, %r14d
jmp 0x1b5633
leaq (,%rbx,8), %rdx
movq 0x30(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x20e0
leaq (%r14,%rbx,8), %rsi
movq %r14, %rdi
callq 0x19e008
xorl %eax, %eax
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 0x19ead4
movq %r14, %rax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq