// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/anchor.cpp
// Function: special_lchain(Candidates_list*, overlap_region_alloc*, unsigned int, unsigned long, All_reads*, ul_idx_t const*, unsigned int, long, long, long, double, double, double, long, unsigned int, double, unsigned int, st_mt_t*, unsigned long*, unsigned long, unsigned long, unsigned long)
inline uint64_t special_lchain(Candidates_list* cl, overlap_region_alloc* ol, uint32_t rid, uint64_t rl, All_reads* rdb, 
				const ul_idx_t *udb, uint32_t apend_be, int64_t max_skip, int64_t max_iter, int64_t max_dis, double chn_pen_gap, 
				double chn_pen_skip, double bw_rate, int64_t quick_check, uint32_t gen_off, double mcopy_rate, uint32_t mcopy_khit_cut, 
				st_mt_t *sp, uint64_t *si, uint64_t m, uint64_t l, uint64_t k)
{
	uint64_t z, s, e, yid, ol0 = ol->length, ol1, m0 = m; 
	if(l >= k) return m;
	yid = cl->list[l].readID;
	for (z = l; z < k && cl->list[z].strand == cl->list[l].strand; z++);
	if(z > l) {
		s = l; e = z; ol1 = ol->length; // m0 = m;
		m += lchain_qdp_mcopy(cl, s, e-s, m, &(cl->chainDP), ol, max_skip, max_iter, max_dis, chn_pen_gap, chn_pen_skip, bw_rate, 
						rid, rl, rdb?Get_READ_LENGTH((*rdb), yid):udb->ug->u.a[yid].len, quick_check, apend_be, gen_off, 0, mcopy_rate, mcopy_khit_cut, 0);
		// if(rid == 7) {
		// 	fprintf(stderr, "+[M::%s::utg%.6ul] inn::[%lu, %lu), (*si)::%lu, ol1::%lu, ol->length::%lu\n", 
		// 	__func__, rid+1, s, e, (*si), ol1, ol->length);
		// }
		if(((*si) < sp->n) && (sp->a[(*si)] == s) && (ol->length > ol1)) {
			ol->list[ol->length-1].x_pos_strand = 1;
			// fprintf(stderr, "+[M::%s] utg%.6u%c -> utg%.6u%c, n_khits0::%lu, n_khits::%lu\n", __func__, rid+1, "lc"[udb->ug->u.a[rid].circ], 
			// ol->list[ol->length-1].y_id+1, "lc"[udb->ug->u.a[ol->list[ol->length-1].y_id].circ], e-s, m-m0);
		}
		for (; (*si) < sp->n && sp->a[(*si)] == s; (*si)++);
	}

	if(z < k) {
		s = z; e = k; ol1 = ol->length;	// m0 = m;
		m += lchain_qdp_mcopy(cl, s, e-s, m, &(cl->chainDP), ol, max_skip, max_iter, max_dis, chn_pen_gap, chn_pen_skip, bw_rate, 
						rid, rl, rdb?Get_READ_LENGTH((*rdb), yid):udb->ug->u.a[yid].len, quick_check, apend_be, gen_off, 0, mcopy_rate, mcopy_khit_cut, 0);
		// if(rid == 7) {
		// 	fprintf(stderr, "-[M::%s::utg%.6ul] inn::[%lu, %lu), (*si)::%lu, ol1::%lu, ol->length::%lu\n", 
		// 	__func__, rid+1, s, e, (*si), ol1, ol->length);
		// }
		if(((*si) < sp->n) && (sp->a[(*si)] == s) && (ol->length > ol1)) {
			ol->list[ol->length-1].x_pos_strand = 1;
			// fprintf(stderr, "-[M::%s] utg%.6u%c -> utg%.6u%c, n_khits0::%lu, n_khits::%lu\n", __func__, rid+1, "lc"[udb->ug->u.a[rid].circ], 
			// ol->list[ol->length-1].y_id+1, "lc"[udb->ug->u.a[ol->list[ol->length-1].y_id].circ], e-s, m-m0);
		}
		for (; (*si) < sp->n && sp->a[(*si)] == s; (*si)++);
	}
	if(ol->length > ol0) {
		overlap_region *p = &(ol->list[ol0]); uint64_t pi = ol0; overlap_region t;
		for (z = ol0; z < ol->length; z++) {
			if((p->shared_seed < ol->list[z].shared_seed) || 
				((p->shared_seed == ol->list[z].shared_seed) && (ol->list[z].x_pos_strand == 1))) {
				p = &(ol->list[z]); pi = z;
			}
		}

		// if(rid == 7) {
		// 	fprintf(stderr, ">[M::%s::] utg%.6ul\t->\tutg%.6ul\tflag::%u\n", 
		// 	__func__, p->x_id+1, p->y_id+1, p->x_pos_strand);
		// }

		for (z = s = ol0; z < ol->length; z++) {
			if((ol->list[z].x_pos_strand == 0) && (z != pi)) continue;
			if(s != z) {
				t = ol->list[s];
    			ol->list[s] = ol->list[z];
    			ol->list[z] = t;
			}
			s++;
		}

		if(s != ol->length) {
			ol->length = s;
			for (z = ol0; z < ol->length; z++) {
				s = ol->list[z].non_homopolymer_errors;
				pi = cl->list[s].readID;
				ol->list[z].non_homopolymer_errors = m0;
				for (; s < m && cl->list[s].readID == pi; s++) {
					cl->list[m0] = cl->list[s];
					cl->list[m0].readID = z; m0++;
				}
			}
			m = m0;
		}
		
	}
	return m;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq 0x1a8(%rsp), %r14
movq 0x1a0(%rsp), %r13
movq 0x198(%rsp), %rbx
cmpq %r14, %r13
jae 0xee9fe
movl %edx, %r10d
movq %rsi, %r11
movq %rdi, %r15
movq %r8, (%rsp)
movq %r9, 0x28(%rsp)
movq %rcx, 0x18(%rsp)
movq 0x188(%rsp), %rbp
movl 0x180(%rsp), %eax
movl 0x178(%rsp), %ecx
movq 0x10(%rsi), %rdx
movq %rdx, 0x10(%rsp)
movq (%rdi), %rdi
movq %r13, %rdx
shlq $0x4, %rdx
movl (%rdi,%rdx), %esi
movl %esi, %r8d
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movq %r8, 0x8(%rsp)
addq %rdi, %rdx
movq %r13, %r12
movq %r13, %r8
cmpq %r14, %r12
jae 0xee681
movl (%rdx), %edi
xorl %esi, %edi
js 0xee686
incq %r12
addq $0x10, %rdx
jmp 0xee66d
movq %r14, %rsi
jmp 0xee689
movq %r12, %rsi
movq %rsi, %rdx
movl %ecx, %ecx
movq %rcx, 0x38(%rsp)
movl %eax, %eax
movq %rax, 0x30(%rsp)
movq 0x10(%rsp), %r13
movq %rbx, %r9
subq %r8, %rdx
movq %r11, 0x20(%rsp)
jbe 0xee7ee
movq %r8, %r13
leaq 0x18(%r15), %r8
movq (%rsp), %rax
testq %rax, %rax
movq %rsi, 0x68(%rsp)
je 0xee6d4
movq 0x18(%rax), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
jmp 0xee6ee
movq 0x28(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
imulq $0x28, 0x8(%rsp), %rcx
movl (%rax,%rcx), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %r15, %rdi
movq %r13, %rsi
movq %rbx, %rcx
movq %r11, %r9
movsd %xmm0, 0x40(%rsp)
movsd %xmm1, 0x48(%rsp)
movsd %xmm2, 0x50(%rsp)
movsd %xmm3, 0x58(%rsp)
pushq $0x0
pushq 0x38(%rsp)
pushq $0x0
pushq 0x50(%rsp)
movl 0x170(%rsp), %r11d
pushq %r11
pushq 0x198(%rsp)
pushq %rax
pushq 0x50(%rsp)
movq %r10, 0xa0(%rsp)
pushq %r10
pushq 0x1b0(%rsp)
pushq 0x1b0(%rsp)
pushq 0x1b0(%rsp)
callq 0x14f8d
movq %r13, %rdi
movq 0x80(%rsp), %r11
addq $0x60, %rsp
movq %rax, %r9
movq 0x190(%rsp), %r13
movq (%r13), %rax
movq (%rbp), %rcx
cmpq %rcx, %rax
jae 0xee7a9
movq 0x10(%rbp), %rdx
cmpq %rdi, (%rdx,%rax,8)
jne 0xee7a9
movq 0x10(%r11), %rdx
cmpq 0x10(%rsp), %rdx
jbe 0xee7a9
movq (%r11), %rsi
imulq $0xa8, %rdx, %rdx
movl $0x1, -0x9c(%rsi,%rdx)
addq %rbx, %r9
movq 0x68(%rsp), %rsi
movq 0x60(%rsp), %r10
movsd 0x58(%rsp), %xmm3
movsd 0x50(%rsp), %xmm2
movsd 0x48(%rsp), %xmm1
movsd 0x40(%rsp), %xmm0
cmpq %rcx, %rax
jae 0xee7ea
movq 0x10(%rbp), %rcx
cmpq %rdi, (%rcx,%rax,8)
jne 0xee7ea
incq %rax
movq %rax, (%r13)
movq (%rbp), %rcx
jmp 0xee7ce
movq 0x10(%r11), %r13
cmpq %r14, %r12
movq (%rsp), %rax
jae 0xee812
subq %rsi, %r14
leaq 0x18(%r15), %r8
testq %rax, %rax
je 0xee81f
movq 0x18(%rax), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
jmp 0xee839
movq %r9, %r12
movq 0x10(%rsp), %rdi
jmp 0xee903
movq 0x28(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
imulq $0x28, 0x8(%rsp), %rcx
movl (%rax,%rcx), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x18(%rsp), %r12
movq %r15, %rdi
movq %r14, %rdx
movq %r9, (%rsp)
movq %r9, %rcx
movq %r11, %r9
pushq $0x0
pushq 0x38(%rsp)
pushq $0x0
pushq 0x50(%rsp)
movl 0x170(%rsp), %r11d
pushq %r11
pushq 0x198(%rsp)
pushq %rax
pushq %r12
pushq %r10
pushq 0x1b0(%rsp)
pushq 0x1b0(%rsp)
pushq 0x1b0(%rsp)
movq %rsi, %r14
callq 0x14f8d
movq %r14, %r9
movq 0x80(%rsp), %r11
addq $0x60, %rsp
movq %rax, %r12
movq 0x190(%rsp), %r8
movq (%r8), %rax
movq (%rbp), %rcx
cmpq %rcx, %rax
jae 0xee8db
movq 0x10(%rbp), %rdx
cmpq %r9, (%rdx,%rax,8)
jne 0xee8db
movq 0x10(%r11), %rdx
cmpq %r13, %rdx
jbe 0xee8db
movq (%r11), %rsi
imulq $0xa8, %rdx, %rdx
movl $0x1, -0x9c(%rsi,%rdx)
addq (%rsp), %r12
movq 0x10(%rsp), %rdi
cmpq %rcx, %rax
jae 0xee8ff
movq 0x10(%rbp), %rcx
cmpq %r9, (%rcx,%rax,8)
jne 0xee8ff
incq %rax
movq %rax, (%r8)
movq (%rbp), %rcx
jmp 0xee8e4
movq 0x10(%r11), %r13
cmpq %rdi, %r13
jbe 0xee9fb
imulq $0xa8, %rdi, %r8
movq (%r11), %rax
addq %r8, %rax
movq %rdi, %rcx
movq %rax, %rdx
movq %rdi, %r9
cmpq %r13, %rcx
jae 0xee94a
movl 0x24(%rax), %esi
cmpl %esi, 0x24(%rdx)
jge 0xee937
movq %rax, %rdx
movq %rcx, %r9
jmp 0xee93f
jne 0xee93f
cmpl $0x1, 0xc(%rax)
je 0xee92f
incq %rcx
addq $0xa8, %rax
jmp 0xee922
movq %rdi, %r14
movq %r9, 0x8(%rsp)
cmpq %r13, %r14
jae 0xee9f6
movq (%r11), %rbp
cmpl $0x0, 0xc(%rbp,%r8)
setne %al
cmpq %r14, %r9
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0xee9e7
cmpq %rdi, %r14
je 0xee9e4
imulq $0xa8, %rdi, %r13
addq %rbp, %r13
movq %rdi, 0x18(%rsp)
movl $0xa8, %edx
leaq 0x70(%rsp), %rdi
movq %r13, %rsi
movq %r8, (%rsp)
callq 0x2160
addq (%rsp), %rbp
movl $0xa8, %edx
movq %r13, %rdi
movq %rbp, %rsi
callq 0x2160
movq 0x20(%rsp), %rax
movq (%rax), %rdi
addq (%rsp), %rdi
movl $0xa8, %edx
leaq 0x70(%rsp), %rsi
callq 0x2160
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %r9
movq (%rsp), %r8
movq 0x20(%rsp), %r11
movq 0x10(%r11), %r13
incq %rdi
incq %r14
addq $0xa8, %r8
jmp 0xee952
cmpq %r13, %rdi
jne 0xeea13
movq %r12, %rbx
movq %rbx, %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, 0x10(%r11)
movl $0x80000000, %eax       # imm = 0x80000000
movq 0x10(%rsp), %r14
cmpq %rdi, %r14
jae 0xee9fe
movq (%r11), %rdi
imulq $0xa8, %r14, %r8
movl 0x30(%rdi,%r8), %ecx
movq (%r15), %rsi
movq %rcx, %rdx
shlq $0x4, %rdx
movl (%rsi,%rdx), %esi
movl %ebx, 0x30(%rdi,%r8)
movl %r14d, %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movq %rbx, %r8
shlq $0x4, %r8
cmpq %r12, %rcx
jae 0xeea9d
movq (%r15), %r9
movl (%r9,%rdx), %r10d
xorl %esi, %r10d
testl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
jne 0xeea9d
leaq (%r9,%rdx), %r10
movups (%r10), %xmm0
movups %xmm0, (%r9,%r8)
movq (%r15), %r9
movl (%r9,%r8), %r10d
andl %eax, %r10d
orl %edi, %r10d
movl %r10d, (%r9,%r8)
incq %rbx
incq %rcx
addq $0x10, %rdx
addq $0x10, %r8
jmp 0xeea57
incq %r14
movq 0x10(%r11), %rdi
jmp 0xeea21