// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/anchor.cpp
// Function: lchain_qgen_mcopy_fast_re0(ha_abuf_s*, ha_pt_s*, ha_mz1_t*, unsigned long, ha_mz1_t*, unsigned long, unsigned long, Candidates_list*, unsigned int*, unsigned int*)
uint64_t lchain_qgen_mcopy_fast_re0(ha_abuf_t *ab, ha_pt_t *ha_idx, ha_mz1_t *ra, uint64_t rn, ha_mz1_t *qa, uint64_t qn, uint64_t qid, Candidates_list *cl, uint32_t *high_occ, uint32_t *low_occ)
{
	// fprintf(stderr, "+[M::%s]\n", __func__);
	uint64_t i, k, l, max_cnt = UINT32_MAX, min_cnt = 0, ri, qi, sn; anchor1_t *an; k_mer_hit *p;
	if(high_occ) {
		max_cnt = (*high_occ);
		if(max_cnt < 2) max_cnt = 2;
	}
	if(low_occ) {
		min_cnt = (*low_occ);
		if(min_cnt < 2) min_cnt = 2;
	}
	// clear_Candidates_list(cl); 

	///first try
	for (k = 1, l = i = ab->n_a = 0; k <= rn; ++k) {
		if (k == rn || ra[k].x != ra[l].x) {
			for (; i < qn && qa[i].x < ra[l].x; i++);
			if(i < qn && qa[i].x == ra[l].x) {
				sn = 0;
				if(ab->n_a < ab->m_a) sn = ab->seed[l].n;///ha_pt_cnt(ha_idx, ra[l].x);
							
				for (qi = i; qi < qn && qa[qi].x == ra[l].x; qi++) {
					for (ri = l; ri < k; ri++) {
						if(qa[qi].rev != ra[ri].rev) continue;
						if(ab->n_a < ab->m_a) {
							an = &(ab->a[ab->n_a++]); 

							an->other_off = qa[qi].pos;
							an->self_off = ra[ri].pos;
							///an->cnt: cnt<<8|span
							an->cnt = sn; if(an->cnt > ((uint32_t)(0xffffffu))) an->cnt = 0xffffffu;
							an->cnt <<= 8; an->cnt |= ((ra[ri].span <= ((uint32_t)(0xffu)))?ra[ri].span:((uint32_t)(0xffu)));
							an->srt = (((uint64_t)(an->self_off))<<32)|((uint64_t)(an->other_off));
						} else {
							ab->n_a++;
						}
					}
				}
			}
			l = k;
		}
	}

	
	if (ab->n_a > ab->m_a) {
		ab->m_a = ab->n_a; REALLOC(ab->a, ab->m_a);

		for (k = 1, l = i = ab->n_a = 0; k <= rn; ++k) {
			if (k == rn || ra[k].x != ra[l].x) {
				for (; i < qn && qa[i].x < ra[l].x; i++);
				if(i < qn && qa[i].x == ra[l].x) {
					sn = ab->seed[l].n;///ha_pt_cnt(ha_idx, ra[l].x);
					
					for (qi = i; qi < qn && qa[qi].x == ra[l].x; qi++) {
						for (ri = l; ri < k; ri++) {
							if(qa[qi].rev != ra[ri].rev) continue;

							an = &(ab->a[ab->n_a++]); 

							an->other_off = qa[qi].pos;
							an->self_off = ra[ri].pos;
							///an->cnt: cnt<<8|span
							an->cnt = sn; if(an->cnt > ((uint32_t)(0xffffffu))) an->cnt = 0xffffffu;
							an->cnt <<= 8; an->cnt |= ((ra[ri].span <= ((uint32_t)(0xffu)))?ra[ri].span:((uint32_t)(0xffu)));
							an->srt = (((uint64_t)(an->self_off))<<32)|((uint64_t)(an->other_off));
						}
					}
				}
				l = k;
			}
		}
	}

	// copy over to _cl_
	sn = ab->n_a + cl->length;
	if (sn > (uint64_t)cl->size) {
		cl->size = sn;
		REALLOC(cl->list, cl->size);
	}

	radix_sort_ha_an1(ab->a, ab->a + ab->n_a);
	for (i = 0; i < ab->n_a; i++) {
		p = &cl->list[cl->length++];
		p->readID = qid;
		p->strand = 0;
		p->offset = ab->a[i].other_off;
		p->self_offset = ab->a[i].self_off;

		if(((ab->a[i].cnt>>8) < max_cnt) && ((ab->a[i].cnt>>8) > min_cnt)){
			p->cnt = 1;
		} else if((ab->a[i].cnt>>8) <= min_cnt) {
			p->cnt = 2;
		} else{
			p->cnt = 1 + (((ab->a[i].cnt>>8) + (max_cnt<<1) - 1)/(max_cnt<<1));
			p->cnt = pow(p->cnt, 1.1);
		}
		if(p->cnt > ((uint32_t)(0xffffffu))) p->cnt = 0xffffffu;
		p->cnt <<= 8; p->cnt |= (((uint32_t)(0xffu))&(ab->a[i].cnt));
	}
	// cl->length = ab->n_a;
	return ab->n_a;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r9, %r14
movq %r8, 0x20(%rsp)
movq %rcx, %r15
movq %rdx, %r13
movq %rdi, %rbx
movq 0xb8(%rsp), %rax
movq 0xb0(%rsp), %rcx
testq %rcx, %rcx
je 0x12601c
movl (%rcx), %ecx
cmpl $0x3, %ecx
movl $0x2, %edx
cmovael %ecx, %edx
jmp 0x126021
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rdx, 0x60(%rsp)
testq %rax, %rax
je 0x12603f
movl (%rax), %eax
cmpl $0x3, %eax
movl $0x2, %ecx
cmovael %eax, %ecx
movq %rcx, 0x50(%rsp)
jmp 0x126048
movq $0x0, 0x50(%rsp)
movq $0x0, (%rbx)
testq %r15, %r15
movq %r14, 0x40(%rsp)
movq %r15, 0x38(%rsp)
movq %r13, 0x30(%rsp)
je 0x12626e
movabsq $0x80000000000000, %rcx # imm = 0x80000000000000
leaq 0x1(%r15), %rax
cmpq $0x3, %rax
movl $0x2, %esi
cmovaeq %rax, %rsi
leaq 0x8(%r13), %rax
movq %rax, 0x48(%rsp)
movl $0x1, %edi
xorl %r9d, %r9d
xorl %r8d, %r8d
movq %rsi, 0x18(%rsp)
cmpq %r15, %rdi
je 0x1260be
movq %rdi, %rax
shlq $0x4, %rax
movq (%r13,%rax), %rax
movq %r8, %rdx
shlq $0x4, %rdx
cmpq (%r13,%rdx), %rax
je 0x126242
cmpq %r14, %r9
jae 0x12623f
movq %r8, %rdx
shlq $0x4, %rdx
movq (%r13,%rdx), %r10
movq %r9, %rax
shlq $0x4, %rax
addq 0x20(%rsp), %rax
cmpq %r10, (%rax)
jae 0x1260fb
incq %r9
addq $0x10, %rax
cmpq %r9, %r14
jne 0x1260df
movq %rdi, %r8
movq %r14, %r9
jmp 0x126242
jne 0x12623f
movq 0x8(%rbx), %rsi
xorl %r11d, %r11d
cmpq %rsi, (%rbx)
jae 0x126115
movq 0x28(%rbx), %rax
movl (%rax,%rdx), %r11d
cmpq %r14, %r9
jae 0x126250
movl $0xffffff, %eax         # imm = 0xFFFFFF
cmpl %eax, %r11d
cmovael %eax, %r11d
shll $0x8, %r11d
movl %r11d, 0x28(%rsp)
addq 0x48(%rsp), %rdx
movq %rdx, 0x58(%rsp)
movq %r9, %rdx
movq %r8, 0x10(%rsp)
movq %r10, 0x8(%rsp)
movq %rdx, %r13
shlq $0x4, %r13
movq 0x20(%rsp), %rax
cmpq %r10, (%rax,%r13)
jne 0x126255
cmpq %rdi, %r8
jae 0x12621f
addq 0x20(%rsp), %r13
movq 0x58(%rsp), %rbp
movq 0x10(%rsp), %r11
movq (%rbp), %rax
xorq 0x8(%r13), %rax
testq %rcx, %rax
jne 0x12620f
movq (%rbx), %r15
cmpq %rsi, %r15
jae 0x126209
movq 0x30(%rbx), %rax
leaq 0x1(%r15), %r10
movq %r10, (%rbx)
leaq (%r15,%r15,2), %r10
movq 0x8(%r13), %r15
shrq $0x1c, %r15
movl %r15d, %r14d
movl $0x7ffffff, %r12d       # imm = 0x7FFFFFF
andl %r12d, %r14d
movl %r14d, 0xc(%rax,%r10,8)
movq (%rbp), %r14
shrq $0x1c, %r14
movq %rcx, %r8
movl %r14d, %ecx
andl %r12d, %ecx
movl %ecx, 0x8(%rax,%r10,8)
movl 0x28(%rsp), %r12d
movl %r12d, 0x10(%rax,%r10,8)
movzbl 0x7(%rbp), %ecx
orl %r12d, %ecx
movl %ecx, 0x10(%rax,%r10,8)
shlq $0x20, %r14
movabsq $0x7ffffff00000000, %rcx # imm = 0x7FFFFFF00000000
andq %rcx, %r14
movq %r8, %rcx
andl $0x7ffffff, %r15d       # imm = 0x7FFFFFF
orq %r14, %r15
movq %r15, (%rax,%r10,8)
jmp 0x12620f
incq %r15
movq %r15, (%rbx)
incq %r11
addq $0x10, %rbp
cmpq %r11, %rdi
jne 0x126178
incq %rdx
movq 0x40(%rsp), %r14
cmpq %r14, %rdx
movq 0x10(%rsp), %r8
movq 0x8(%rsp), %r10
jb 0x12614a
movq %rdi, %r8
jmp 0x12625d
movq %rdi, %r8
incq %rdi
cmpq %rsi, %rdi
jne 0x12609b
jmp 0x12626e
movq %rdi, %r8
jmp 0x126267
movq %rdi, %r8
movq 0x40(%rsp), %r14
movq 0x38(%rsp), %r15
movq 0x30(%rsp), %r13
movq 0x18(%rsp), %rsi
jmp 0x126242
movq 0xa8(%rsp), %rbp
movq (%rbx), %rax
cmpq 0x8(%rbx), %rax
jbe 0x12649f
movq %rax, 0x8(%rbx)
movq 0x30(%rbx), %rdi
shlq $0x3, %rax
leaq (%rax,%rax,2), %rsi
callq 0x2370
movq %rax, 0x30(%rbx)
movq $0x0, (%rbx)
testq %r15, %r15
je 0x12649f
movabsq $0x80000000000000, %r11 # imm = 0x80000000000000
leaq 0x1(%r15), %rsi
cmpq $0x3, %rsi
movl $0x2, %ecx
cmovaeq %rsi, %rcx
leaq 0x8(%r13), %rsi
movq %rsi, 0x48(%rsp)
movl $0x1, %r8d
xorl %r10d, %r10d
movq $0x0, 0x8(%rsp)
movq %rcx, 0x18(%rsp)
movl $0x7ffffff, %r12d       # imm = 0x7FFFFFF
cmpq %r15, %r8
je 0x126312
movq %r8, %rsi
shlq $0x4, %rsi
movq (%r13,%rsi), %rsi
movq 0x8(%rsp), %r9
shlq $0x4, %r9
cmpq (%r13,%r9), %rsi
je 0x126493
cmpq %r14, %r10
jae 0x12635c
movq 0x8(%rsp), %rdi
shlq $0x4, %rdi
movq %rdi, %rsi
movq (%r13,%rdi), %rdi
movq %rdi, 0x10(%rsp)
movq %r10, %r9
shlq $0x4, %r9
addq 0x20(%rsp), %r9
movq 0x10(%rsp), %rdi
cmpq %rdi, (%r9)
jae 0x126366
incq %r10
addq $0x10, %r9
cmpq %r10, %r14
jne 0x126339
movq %r8, 0x8(%rsp)
movq %r14, %r10
jmp 0x126493
movq %r8, 0x8(%rsp)
jmp 0x126493
setne %r9b
cmpq %r14, %r10
setae %bpl
orb %r9b, %bpl
jne 0x126463
movq 0x28(%rbx), %r9
movl (%r9,%rsi), %edi
movl $0xffffff, %ecx         # imm = 0xFFFFFF
cmpl %ecx, %edi
cmovael %ecx, %edi
shll $0x8, %edi
movl %edi, 0x28(%rsp)
addq 0x48(%rsp), %rsi
movq %rsi, 0x58(%rsp)
movq %r10, %rbp
movq %rbp, %r13
shlq $0x4, %r13
movq 0x20(%rsp), %rcx
movq 0x10(%rsp), %rsi
cmpq %rsi, (%rcx,%r13)
jne 0x126472
cmpq %r8, 0x8(%rsp)
jae 0x12644b
addq 0x20(%rsp), %r13
movq 0x58(%rsp), %r15
movq 0x8(%rsp), %r9
movq (%r15), %r14
xorq 0x8(%r13), %r14
testq %r11, %r14
jne 0x12643f
movq (%rbx), %r14
leaq 0x1(%r14), %rdi
movq %rdi, (%rbx)
leaq (%r14,%r14,2), %rdi
movq 0x8(%r13), %r14
shrq $0x1c, %r14
movl %r14d, %ecx
andl %r12d, %ecx
movl %ecx, 0xc(%rax,%rdi,8)
movq (%r15), %rdx
movq %rdx, %rcx
shrq $0x1c, %rcx
movl %ecx, %esi
andl %r12d, %esi
movl %esi, 0x8(%rax,%rdi,8)
shrq $0x38, %rdx
orl 0x28(%rsp), %edx
movl %edx, 0x10(%rax,%rdi,8)
shlq $0x20, %rcx
movabsq $0x7ffffff00000000, %rdx # imm = 0x7FFFFFF00000000
andq %rdx, %rcx
andl $0x7ffffff, %r14d       # imm = 0x7FFFFFF
orq %rcx, %r14
movq %r14, (%rax,%rdi,8)
incq %r9
addq $0x10, %r15
cmpq %r9, %r8
jne 0x1263d5
incq %rbp
movq 0x40(%rsp), %r14
cmpq %r14, %rbp
jb 0x1263a0
movq %r8, 0x8(%rsp)
jmp 0x12647c
movq %r8, 0x8(%rsp)
movq 0xa8(%rsp), %rbp
jmp 0x126493
movq %r8, 0x8(%rsp)
movq 0x40(%rsp), %r14
movq 0x38(%rsp), %r15
movq 0x30(%rsp), %r13
movq 0xa8(%rsp), %rbp
movq 0x18(%rsp), %rcx
incq %r8
cmpq %rcx, %r8
jne 0x1262ed
movq 0x8(%rbp), %rsi
addq (%rbx), %rsi
cmpq 0x10(%rbp), %rsi
jbe 0x1264c1
movq %rsi, 0x10(%rbp)
movq (%rbp), %rdi
shlq $0x4, %rsi
callq 0x2370
movq %rax, (%rbp)
movq (%rbx), %rax
movq 0x30(%rbx), %rdi
leaq (%rax,%rax,2), %rax
leaq (%rdi,%rax,8), %rsi
callq 0x11fe18
movq (%rbx), %rax
testq %rax, %rax
movq 0x60(%rsp), %rdi
movq 0x50(%rsp), %r8
je 0x1265fc
movq 0xa0(%rsp), %r14
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
leaq (%rdi,%rdi), %rax
movq %rax, 0x28(%rsp)
leaq -0x1(,%rdi,2), %rax
movq %rax, 0x10(%rsp)
movl $0x10, %r13d
xorl %r15d, %r15d
movq (%rbp), %rax
movq 0x8(%rbp), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rbp)
shlq $0x4, %rcx
leaq (%rax,%rcx), %r12
movl %r14d, (%rax,%rcx)
movq 0x30(%rbx), %rdx
movl -0x4(%rdx,%r13), %esi
movl %esi, 0x4(%rax,%rcx)
movl -0x8(%rdx,%r13), %esi
movl %esi, 0x8(%rax,%rcx)
movl (%rdx,%r13), %ecx
shrl $0x8, %ecx
movl %ecx, %eax
cmpl %ecx, %edi
seta %cl
cmpq %rax, %r8
setb %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x126571
movl $0x1, 0xc(%r12)
jmp 0x1265b8
cmpl %eax, %r8d
jae 0x1265af
addq 0x10(%rsp), %rax
xorl %edx, %edx
divq 0x28(%rsp)
incl %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd 0x1035dc(%rip), %xmm1   # 0x229b70
callq 0x23a0
movq 0x50(%rsp), %r8
movq 0x60(%rsp), %rdi
cvttsd2si %xmm0, %rax
movl %eax, 0xc(%r12)
jmp 0x1265b8
movl $0x2, 0xc(%r12)
cmpl $0x1000000, 0xc(%r12)   # imm = 0x1000000
jb 0x1265cc
movl $0xffffff, 0xc(%r12)    # imm = 0xFFFFFF
movl 0xc(%r12), %eax
shll $0x8, %eax
movl %eax, 0xc(%r12)
movq 0x30(%rbx), %rcx
movzbl (%rcx,%r13), %ecx
orl %eax, %ecx
movl %ecx, 0xc(%r12)
incq %r15
movq (%rbx), %rax
addq $0x18, %r13
cmpq %rax, %r15
jb 0x126519
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq