// File: /workspace/github_cpp_makefile_star2_O3/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 %r8, %r10
movq 0x1a8(%rsp), %r14
movq 0x1a0(%rsp), %r8
movq 0x198(%rsp), %rbx
cmpq %r14, %r8
jae 0x135074
movq %rcx, %r12
movl %edx, %r11d
movq %rdi, %r15
movl 0x180(%rsp), %eax
movl 0x178(%rsp), %ecx
movq %rsi, 0x8(%rsp)
movq 0x10(%rsi), %rdx
movq %rdx, 0x20(%rsp)
movq (%rdi), %rdx
movq %r8, %rsi
shlq $0x4, %rsi
addq %rdx, %rsi
addq $0x10, %rsi
movl -0x10(%rsi), %edx
movl %edx, %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movq %rdi, 0x10(%rsp)
leaq 0x1(%r8), %rbp
movq %rbp, %r13
cmpq %rbp, %r14
je 0x134cd5
leaq 0x1(%r13), %rbp
movl (%rsi), %edi
addq $0x10, %rsi
xorl %edx, %edi
jns 0x134cba
decq %rbp
jmp 0x134cd8
movq %r14, %rbp
movq %rbp, %rdx
movl %ecx, %ecx
movq %rcx, 0x28(%rsp)
movl %eax, %eax
movq %rax, 0x60(%rsp)
movq %rbx, 0x18(%rsp)
subq %r8, %rdx
movq %r12, 0x68(%rsp)
jbe 0x134e5f
movq %r8, %rsi
leaq 0x18(%r15), %r8
testq %r10, %r10
movq %r9, 0x38(%rsp)
movq %r10, 0x30(%rsp)
je 0x134d21
movq 0x18(%r10), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %rax
jmp 0x134d39
movq (%r9), %rax
movq 0x10(%rax), %rax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rcx,4), %rcx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %r10d, %r10d
movq %r15, %rdi
movq %rbx, %rcx
movq 0x8(%rsp), %r9
movsd %xmm0, 0x40(%rsp)
movsd %xmm1, 0x48(%rsp)
movsd %xmm2, 0x50(%rsp)
movsd %xmm3, 0x58(%rsp)
pushq %r10
pushq 0x68(%rsp)
pushq %r10
pushq 0x40(%rsp)
movl 0x170(%rsp), %r10d
pushq %r10
pushq 0x198(%rsp)
pushq %rax
pushq %r12
movq %r11, %r12
pushq %r11
pushq 0x1b0(%rsp)
pushq 0x1b0(%rsp)
pushq 0x1b0(%rsp)
callq 0x40ceb
addq $0x60, %rsp
addq %rbx, %rax
movq %rax, 0x18(%rsp)
movq 0x190(%rsp), %r8
movq (%r8), %rax
movq 0x188(%rsp), %rsi
cmpq (%rsi), %rax
jae 0x134e3a
movq 0x10(%rsi), %rcx
movq 0x1a0(%rsp), %rdi
cmpq %rdi, (%rcx,%rax,8)
jne 0x134dfe
movq 0x8(%rsp), %rcx
movq 0x10(%rcx), %rcx
cmpq 0x20(%rsp), %rcx
jbe 0x134dfe
movq 0x8(%rsp), %rdx
movq (%rdx), %rdx
imulq $0xa8, %rcx, %rcx
movl $0x1, -0x9c(%rdx,%rcx)
movq 0x10(%rsi), %rcx
movq %r12, %r11
movsd 0x58(%rsp), %xmm3
movsd 0x50(%rsp), %xmm2
movsd 0x48(%rsp), %xmm1
movsd 0x40(%rsp), %xmm0
movq 0x38(%rsp), %r9
movq 0x30(%rsp), %r10
cmpq %rdi, (%rcx,%rax,8)
jne 0x134e5f
incq %rax
movq %rax, (%r8)
cmpq (%rsi), %rax
jb 0x134e27
jmp 0x134e5f
movq %r12, %r11
movsd 0x58(%rsp), %xmm3
movsd 0x50(%rsp), %xmm2
movsd 0x48(%rsp), %xmm1
movsd 0x40(%rsp), %xmm0
movq 0x38(%rsp), %r9
movq 0x30(%rsp), %r10
cmpq %r14, %r13
jae 0x134e87
subq %rbp, %r14
leaq 0x18(%r15), %r8
testq %r10, %r10
movq 0x20(%rsp), %r13
movq %r15, %r12
je 0x134e91
movq 0x18(%r10), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %rax
jmp 0x134ea9
movq 0x20(%rsp), %r13
jmp 0x134f82
movq (%r9), %rax
movq 0x10(%rax), %rax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rcx,4), %rcx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x8(%rsp), %r9
movq 0x10(%r9), %r15
xorl %r10d, %r10d
movq %r12, %rdi
movq %rbp, %rsi
movq %r14, %rdx
movq 0x18(%rsp), %r14
movq %r14, %rcx
pushq %r10
pushq 0x68(%rsp)
pushq %r10
pushq 0x40(%rsp)
movl 0x170(%rsp), %r10d
pushq %r10
pushq 0x198(%rsp)
pushq %rax
pushq 0xa0(%rsp)
pushq %r11
pushq 0x1b0(%rsp)
pushq 0x1b0(%rsp)
pushq 0x1b0(%rsp)
callq 0x40ceb
addq $0x60, %rsp
addq %rax, %r14
movq %r14, 0x18(%rsp)
movq 0x190(%rsp), %rax
movq (%rax), %rax
movq 0x188(%rsp), %rsi
cmpq (%rsi), %rax
jae 0x134f7f
movq 0x10(%rsi), %rcx
cmpq %rbp, (%rcx,%rax,8)
jne 0x134f5d
movq 0x8(%rsp), %rcx
movq 0x10(%rcx), %rcx
cmpq %r15, %rcx
jbe 0x134f5d
movq 0x8(%rsp), %rdx
movq (%rdx), %rdx
imulq $0xa8, %rcx, %rcx
movl $0x1, -0x9c(%rdx,%rcx)
movq 0x10(%rsi), %rcx
movq %r12, %r15
movq 0x190(%rsp), %rdx
cmpq %rbp, (%rcx,%rax,8)
jne 0x134f82
incq %rax
movq %rax, (%rdx)
cmpq (%rsi), %rax
jb 0x134f6c
jmp 0x134f82
movq %r12, %r15
movq 0x8(%rsp), %rbp
movq 0x10(%rbp), %rax
cmpq %r13, %rax
jbe 0x13506f
imulq $0xa8, %r13, %r14
movq (%rbp), %rcx
addq %r14, %rcx
movq %r13, %r8
movq %rcx, %rsi
movq %r13, %rdx
movl 0x24(%rcx), %edi
cmpl %edi, 0x24(%rsi)
jge 0x134fbb
movq %rcx, %rsi
movq %rdx, %r8
jmp 0x134fc3
jne 0x134fc3
cmpl $0x1, 0xc(%rcx)
je 0x134fb3
incq %rdx
addq $0xa8, %rcx
cmpq %rdx, %rax
jne 0x134fab
movq %r15, 0x10(%rsp)
movq %r13, %r12
movq %r13, %r15
movq %r8, 0x28(%rsp)
movq (%rbp), %r13
cmpl $0x0, 0xc(%r13,%r14)
setne %cl
cmpq %r15, %r8
sete %dl
orb %cl, %dl
cmpb $0x1, %dl
jne 0x135057
cmpq %r12, %r15
je 0x135054
imulq $0xa8, %r12, %rbp
addq %r13, %rbp
movl $0xa8, %edx
leaq 0x70(%rsp), %rdi
movq %rbp, %rsi
callq 0x2160
addq %r14, %r13
movl $0xa8, %edx
movq %rbp, %rdi
movq 0x8(%rsp), %rbp
movq %r13, %rsi
callq 0x2160
movq (%rbp), %rdi
addq %r14, %rdi
movl $0xa8, %edx
leaq 0x70(%rsp), %rsi
callq 0x2160
movq 0x28(%rsp), %r8
movq 0x10(%rbp), %rax
incq %r12
incq %r15
addq $0xa8, %r14
cmpq %rax, %r15
jb 0x134fe2
cmpq %rax, %r12
jne 0x135089
movq 0x18(%rsp), %rbx
movq %rbx, %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, 0x10(%rbp)
movq 0x20(%rsp), %r14
cmpq %r12, %r14
movq 0x18(%rsp), %r15
jae 0x135074
movl $0x80000000, %eax       # imm = 0x80000000
movq 0x10(%rsp), %r11
movq (%rbp), %rsi
imulq $0xa8, %r14, %rdi
movl 0x30(%rsi,%rdi), %r8d
movq (%r11), %rdx
movq %r8, %rcx
shlq $0x4, %rcx
movl (%rdx,%rcx), %edx
movl %ebx, 0x30(%rsi,%rdi)
movq %r15, %rsi
subq %r8, %rsi
jbe 0x135124
movl %r14d, %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movq %rbx, %r8
shlq $0x4, %r8
movq (%r11), %r9
movl (%r9,%rcx), %r10d
xorl %edx, %r10d
testl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
jne 0x135120
leaq (%r9,%rcx), %r10
movups (%r10), %xmm0
movups %xmm0, (%r9,%r8)
movq (%r11), %r9
movl (%r9,%r8), %r10d
andl %eax, %r10d
orl %edi, %r10d
movl %r10d, (%r9,%r8)
incq %rbx
addq $0x10, %r8
addq $0x10, %rcx
decq %rsi
jne 0x1350df
movq 0x10(%rbp), %r12
incq %r14
cmpq %r12, %r14
jb 0x1350a6
jmp 0x135074
nopl (%rax)