// File: /workspace/github_cpp_makefile_star2_O1/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 0x12ee5d
movq %r8, %r10
movl %edx, %r11d
movq %rdi, %r12
movq %rcx, 0x28(%rsp)
movq 0x190(%rsp), %r8
movl 0x180(%rsp), %eax
movl 0x178(%rsp), %ecx
movq %rsi, 0x8(%rsp)
movq 0x10(%rsi), %r15
movq (%rdi), %rdx
movq %r13, %rsi
shlq $0x4, %rsi
addq %rdx, %rsi
addq $0x10, %rsi
movl -0x10(%rsi), %edx
movl %edx, %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movq %rdi, 0x18(%rsp)
leaq 0x1(%r13), %rbp
movq %rbp, %r13
cmpq %rbp, %r14
je 0x12eacb
leaq 0x1(%r13), %rbp
movl (%rsi), %edi
addq $0x10, %rsi
xorl %edx, %edi
jns 0x12eab0
decq %rbp
jmp 0x12eace
movq %r14, %rbp
movq %rbp, %rdx
movl %ecx, %ecx
movq %rcx, 0x20(%rsp)
movl %eax, %eax
movq %rax, 0x38(%rsp)
movq %rbx, 0x10(%rsp)
subq 0x1a0(%rsp), %rdx
movq %r12, 0x30(%rsp)
jbe 0x12ec4f
leaq 0x18(%r12), %r8
testq %r10, %r10
movq %r9, 0x48(%rsp)
movq %r10, 0x40(%rsp)
je 0x12eb1a
movq 0x18(%r10), %rax
movq 0x18(%rsp), %rcx
movq (%rax,%rcx,8), %rax
jmp 0x12eb32
movq (%r9), %rax
movq 0x10(%rax), %rax
movq 0x18(%rsp), %rcx
leaq (%rcx,%rcx,4), %rcx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %r10d, %r10d
movq %r12, %rdi
movq 0x1a0(%rsp), %rsi
movq %rbx, %rcx
movq 0x8(%rsp), %r9
movsd %xmm0, 0x50(%rsp)
movsd %xmm1, 0x58(%rsp)
movsd %xmm2, 0x60(%rsp)
movsd %xmm3, 0x68(%rsp)
pushq %r10
pushq 0x40(%rsp)
pushq %r10
pushq 0x38(%rsp)
movl 0x170(%rsp), %r10d
pushq %r10
pushq 0x198(%rsp)
pushq %rax
pushq 0x60(%rsp)
movq %r11, %r12
pushq %r11
pushq 0x1b0(%rsp)
pushq 0x1b0(%rsp)
pushq 0x1b0(%rsp)
callq 0x414f8
movq 0x200(%rsp), %rsi
addq $0x60, %rsp
movq %rax, 0x10(%rsp)
movq 0x190(%rsp), %r8
movq (%r8), %rax
movq 0x188(%rsp), %rdx
cmpq (%rdx), %rax
jae 0x12ebfc
movq 0x10(%rdx), %rcx
cmpq %rsi, (%rcx,%rax,8)
jne 0x12ebfc
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
cmpq %r15, %rax
jbe 0x12ebfc
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
imulq $0xa8, %rax, %rax
movl $0x1, -0x9c(%rcx,%rax)
addq %rbx, 0x10(%rsp)
movq (%r8), %rax
cmpq (%rdx), %rax
movq %r12, %r11
movsd 0x68(%rsp), %xmm3
movsd 0x60(%rsp), %xmm2
movsd 0x58(%rsp), %xmm1
movsd 0x50(%rsp), %xmm0
movq 0x48(%rsp), %r9
movq 0x40(%rsp), %r10
jae 0x12ec4a
movq 0x10(%rdx), %rcx
movq 0x30(%rsp), %r12
cmpq %rsi, (%rcx,%rax,8)
jne 0x12ec4f
incq %rax
movq %rax, (%r8)
cmpq (%rdx), %rax
jb 0x12ec37
jmp 0x12ec4f
movq 0x30(%rsp), %r12
cmpq %r14, %r13
jae 0x12ed59
movq %r8, %r13
subq %rbp, %r14
leaq 0x18(%r12), %r8
testq %r10, %r10
je 0x12ec77
movq 0x18(%r10), %rax
movq 0x18(%rsp), %rcx
movq (%rax,%rcx,8), %rax
jmp 0x12ec8f
movq (%r9), %rax
movq 0x10(%rax), %rax
movq 0x18(%rsp), %rcx
leaq (%rcx,%rcx,4), %rcx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x8(%rsp), %r9
movq 0x10(%r9), %rcx
movq %rcx, 0x18(%rsp)
xorl %r10d, %r10d
movq %r12, %rdi
movq %rbp, %rsi
movq %r14, %rdx
movq 0x10(%rsp), %rcx
pushq %r10
pushq 0x40(%rsp)
pushq %r10
pushq 0x38(%rsp)
movl 0x170(%rsp), %r10d
pushq %r10
pushq 0x198(%rsp)
pushq %rax
pushq 0x60(%rsp)
pushq %r11
pushq 0x1b0(%rsp)
pushq 0x1b0(%rsp)
pushq 0x1b0(%rsp)
callq 0x414f8
addq $0x60, %rsp
movq (%r13), %rcx
movq 0x188(%rsp), %rsi
cmpq (%rsi), %rcx
jae 0x12ed35
movq 0x10(%rsi), %rdx
cmpq %rbp, (%rdx,%rcx,8)
jne 0x12ed35
movq 0x8(%rsp), %rcx
movq 0x10(%rcx), %rcx
cmpq 0x18(%rsp), %rcx
jbe 0x12ed35
movq 0x8(%rsp), %rdx
movq (%rdx), %rdx
imulq $0xa8, %rcx, %rcx
movl $0x1, -0x9c(%rdx,%rcx)
addq %rax, 0x10(%rsp)
movq (%r13), %rax
cmpq (%rsi), %rax
jae 0x12ed59
movq 0x10(%rsi), %rcx
cmpq %rbp, (%rcx,%rax,8)
jne 0x12ed59
incq %rax
movq %rax, (%r13)
cmpq (%rsi), %rax
jb 0x12ed47
movq 0x8(%rsp), %rbp
movq 0x10(%rbp), %rax
cmpq %r15, %rax
jbe 0x12ee58
imulq $0xa8, %r15, %r14
movq (%rbp), %rcx
addq %r14, %rcx
movq %r15, %r8
movq %rcx, %rsi
movq %r15, %rdx
movl 0x24(%rcx), %edi
cmpl %edi, 0x24(%rsi)
jge 0x12ed92
movq %rcx, %rsi
movq %rdx, %r8
jmp 0x12ed9a
jne 0x12ed9a
cmpl $0x1, 0xc(%rcx)
je 0x12ed8a
incq %rdx
addq $0xa8, %rcx
cmpq %rdx, %rax
jne 0x12ed82
movq 0x10(%rbp), %rax
movq %r15, %r12
movq %r15, 0x20(%rsp)
cmpq %rax, %r15
jae 0x12ee53
movq 0x20(%rsp), %r15
movq %r15, %r12
movq (%rbp), %r13
cmpl $0x0, 0xc(%r13,%r14)
setne %al
cmpq %r15, %r8
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x12ee3c
cmpq %r12, %r15
je 0x12ee39
imulq $0xa8, %r12, %rbp
addq %r13, %rbp
movl $0xa8, %edx
leaq 0x70(%rsp), %rdi
movq %rbp, %rsi
movq %r8, 0x28(%rsp)
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
incq %r12
incq %r15
movq 0x10(%rbp), %rax
addq $0xa8, %r14
cmpq %rax, %r15
jb 0x12edc6
cmpq %rax, %r12
jne 0x12ee72
movq 0x10(%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
jae 0x12ee5d
movl $0x80000000, %eax       # imm = 0x80000000
movq 0x30(%rsp), %r11
movq 0x10(%rsp), %r15
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 0x12ef09
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 0x12ef09
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 0x12eec8
incq %r14
cmpq 0x10(%rbp), %r14
jb 0x12ee8f
jmp 0x12ee5d
nop