// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/tovlp.cpp
// Function: pt_collect_anchors(ma_ug_t*, pt_mz1_v*, mz_ds_t*, unsigned int)
pt128_v *pt_collect_anchors(ma_ug_t *ug, pt_mz1_v *mz, mz_ds_t *mz_idx, uint32_t max_occ)
{
	uint32_t st, j;
    pt128_v *pa = NULL; CALLOC(pa, 1);
    pt128_t *p = NULL;
    mz_idx->pos.n = 0;
	///all minimizers
	for (j = 1, st = 0; j <= mz->n; ++j) {
		if (j == mz->n || mz->a[j].x != mz->a[st].x) {
			uint32_t k, l;
			// if (j - st == 1) ++info[mz->a[st].rid].cnt1; ///of size n_seg
			///max_occ is the frquency threshold of minimizer
			///if (j - st) == 1, means minimizer only occurs in one read, it is not useful
			if (j - st == 1 || j - st > max_occ) goto end_anchor;
			for (k = st; k < j; ++k) {
				// ++info[mz->a[k].rid].cnt2;
                kv_push(uint64_t, mz_idx->pos, (uint64_t)(mz->a[k].rid)<<32|(uint64_t)(mz->a[k].pos));
				for (l = k + 1; l < j; ++l) {
					///k is current minimizer
					uint32_t span, rev = (mz->a[k].rev != mz->a[l].rev);
					int32_t lk = ug->u.a[mz->a[k].rid].len, ll = ug->u.a[mz->a[l].rid].len;
                    kv_pushp(pt128_t, *pa, &p);
					span = mz->a[l].span;
                    p->x = (uint64_t)mz->a[k].rid << 33 | mz->a[l].rid << 1 | rev;
					p->y = (uint64_t)mz->a[k].pos << 32 | (rev? ll - (mz->a[l].pos + 1 - span) - 1 : mz->a[l].pos);
					kv_pushp(pt128_t, *pa, &p);
                    span = mz->a[k].span;
					p->x = (uint64_t)mz->a[l].rid << 33 | mz->a[k].rid << 1 | rev;
					p->y = (uint64_t)mz->a[l].pos << 32 | (rev? lk - (mz->a[k].pos + 1 - span) - 1 : mz->a[k].pos);
				}
			}
            end_anchor:	st = j;
		}
	}

	radix_sort_pt128x(pa->a, pa->a + pa->n);

    radix_sort_tb64(mz_idx->pos.a, mz_idx->pos.a + mz_idx->pos.n);
    CALLOC(mz_idx->idx, ug->u.n);
    for (st = 0, j = 1; j <= mz_idx->pos.n; ++j)
    {
        if (j == mz_idx->pos.n || (mz_idx->pos.a[j]>>32) != (mz_idx->pos.a[st]>>32))
        {
            mz_idx->idx[mz_idx->pos.a[st]>>32] = (uint64_t)st << 32 | (j - st), st = j;
        }
    }
	
    return pa;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %ecx, 0x1c(%rsp)
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, 0x28(%rsp)
movl $0x1, %edi
movl $0x10, %esi
callq 0x2120
movq %rax, 0x20(%rsp)
movq $0x0, 0x8(%rbx)
movq %r14, (%rsp)
movl (%r14), %eax
xorl %r10d, %r10d
testl %eax, %eax
je 0x19c3be
movl $0x1, %edx
xorl %r9d, %r9d
xorl %r15d, %r15d
xorl %ecx, %ecx
movq %rbx, 0x38(%rsp)
cmpl %eax, %edx
je 0x19c0a8
movl %edx, %r8d
movq (%rsp), %rdx
movq 0x8(%rdx), %rdx
movl %r8d, %esi
leaq (%rsi,%rsi,2), %rsi
movq (%rdx,%rsi,8), %rsi
movl %ecx, %edi
leaq (%rdi,%rdi,2), %rdi
cmpq (%rdx,%rdi,8), %rsi
movl %r8d, %edx
je 0x19c3af
movl %edx, %r8d
subl %ecx, %edx
seta %sil
cmpl $0x1, %edx
setne %dil
cmpl 0x1c(%rsp), %edx
setbe %dl
andb %sil, %dil
andb %dl, %dil
cmpb $0x1, %dil
jne 0x19c3a9
movl %ecx, %ebp
movl %r8d, 0x18(%rsp)
movl %r8d, %eax
movq %rax, 0x10(%rsp)
leaq (,%rbp,8), %rax
leaq (%rax,%rax,2), %r14
movq 0x8(%rbx), %rdx
movq 0x18(%rbx), %rax
cmpq 0x10(%rbx), %rdx
jne 0x19c132
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
movq %r14, %r13
movq %r9, %r14
movq %r10, %r12
callq 0x2370
movq %r12, %r10
movq %r14, %r9
movq %r13, %r14
movq %rax, 0x18(%rbx)
movq 0x8(%rbx), %rdx
movq (%rsp), %rcx
movq 0x8(%rcx), %rcx
leaq (,%rbp,2), %r11
addq %rbp, %r11
incq %rbp
movq 0x8(%rcx,%r11,8), %rsi
shlq $0x20, %rsi
movq 0x10(%rcx,%r11,8), %rdi
movabsq $0x7fffffffffffffff, %r8 # imm = 0x7FFFFFFFFFFFFFFF
andq %r8, %rdi
orq %rsi, %rdi
leaq 0x1(%rdx), %rsi
movq %rsi, 0x8(%rbx)
movq %rdi, (%rax,%rdx,8)
cmpq 0x10(%rsp), %rbp
jae 0x19c38c
movq %r14, 0x40(%rsp)
movq %rbp, 0x48(%rsp)
movabsq $0x7fffffffffffffff, %r12 # imm = 0x7FFFFFFFFFFFFFFF
movq %r11, 0x30(%rsp)
movl %r15d, %r8d
movq 0x28(%rcx,%r14), %rbx
xorq 0x10(%rcx,%r11,8), %rbx
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x8(%rcx,%r11,8), %edx
leaq (%rdx,%rdx,4), %rdx
movl (%rax,%rdx,8), %edx
movq %rdx, 0x50(%rsp)
movl 0x20(%rcx,%r14), %edx
leaq (%rdx,%rdx,4), %rdx
movl (%rax,%rdx,8), %r15d
cmpl %r10d, %r8d
jne 0x19c21d
leal (%r10,%r10), %r13d
testl %r10d, %r10d
movl $0x2, %eax
cmovel %eax, %r13d
movq %r13, %rsi
shlq $0x4, %rsi
movq %r9, %rdi
movq %r15, 0x8(%rsp)
movq %r12, %r15
movq %rbx, %r12
movq %r8, %rbx
callq 0x2370
movq %rbx, %r8
movq %r12, %rbx
movq %r15, %r12
movq 0x8(%rsp), %r15
movq 0x30(%rsp), %r11
movq %rax, %r9
movq (%rsp), %rax
movq 0x8(%rax), %rcx
movl %r13d, %r10d
movq %rbx, %r13
shrq $0x3f, %r13
movl %r8d, %eax
shlq $0x4, %rax
movq 0x20(%rcx,%r14), %rsi
movq 0x8(%rcx,%r11,8), %rdx
shlq $0x21, %rdx
leal (%rsi,%rsi), %edi
orq %rdx, %rdi
orq %r13, %rdi
movq %rdi, (%r9,%rax)
movq 0x10(%rcx,%r11,8), %rdx
testq %rbx, %rbx
js 0x19c25a
movq 0x28(%rcx,%r14), %rsi
andq %r12, %rsi
jmp 0x19c27a
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
andq %rdi, %r15
shrq $0x20, %rsi
movq 0x28(%rcx,%r14), %rdi
andq %r12, %rdi
notq %rdi
addq %r15, %rsi
addq %rdi, %rsi
decq %rsi
leal 0x1(%r8), %r15d
addq %r9, %rax
shlq $0x20, %rdx
orq %rsi, %rdx
movq %rdx, 0x8(%rax)
cmpl %r10d, %r15d
jne 0x19c2e8
movq %rbx, 0x8(%rsp)
leal (%r10,%r10), %ebx
testl %r10d, %r10d
movl $0x2, %eax
cmovel %eax, %ebx
movq %rbx, %rsi
shlq $0x4, %rsi
movq %r9, %rdi
movl %r15d, %r12d
movq %rbp, %r15
movq %r8, %rbp
callq 0x2370
movq %rbp, %r8
movq %r15, %rbp
movl %r12d, %r15d
movq 0x30(%rsp), %r11
movq %rax, %r9
movq (%rsp), %rax
movq 0x8(%rax), %rcx
movl %ebx, %r10d
movabsq $0x7fffffffffffffff, %r12 # imm = 0x7FFFFFFFFFFFFFFF
movq 0x8(%rsp), %rbx
movl %r15d, %eax
shlq $0x4, %rax
movq 0x8(%rcx,%r11,8), %rsi
movq 0x20(%rcx,%r14), %rdx
shlq $0x21, %rdx
leal (%rsi,%rsi), %edi
orq %rdx, %rdi
orq %r13, %rdi
movq %rdi, (%r9,%rax)
movq 0x28(%rcx,%r14), %rdx
testq %rbx, %rbx
js 0x19c31e
movq 0x10(%rcx,%r11,8), %rsi
andq %r12, %rsi
jmp 0x19c343
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movq 0x50(%rsp), %rbx
andq %rdi, %rbx
shrq $0x20, %rsi
movq 0x10(%rcx,%r11,8), %rdi
andq %r12, %rdi
notq %rdi
addq %rbx, %rsi
addq %rdi, %rsi
decq %rsi
addq %r9, %rax
shlq $0x20, %rdx
orq %rsi, %rdx
movq %rdx, 0x8(%rax)
incq %rbp
addq $0x18, %r14
incl %r15d
cmpq 0x10(%rsp), %rbp
jb 0x19c196
addl $0x2, %r8d
movq 0x20(%rsp), %rax
movl %r8d, (%rax)
movl %r10d, 0x4(%rax)
movq %r9, 0x8(%rax)
movl %r8d, %r15d
movq 0x38(%rsp), %rbx
movq 0x48(%rsp), %rbp
movq 0x40(%rsp), %r14
addq $0x18, %r14
cmpq 0x10(%rsp), %rbp
jne 0x19c0ea
movq (%rsp), %rax
movl (%rax), %eax
movl 0x18(%rsp), %edx
movl %edx, %ecx
jmp 0x19c3af
movl %r8d, %ecx
movl %r8d, %edx
incl %edx
cmpl %eax, %edx
jbe 0x19c07b
movl %r15d, %r10d
jmp 0x19c3c1
xorl %r9d, %r9d
shlq $0x4, %r10
addq %r9, %r10
movq %r9, %rdi
movq %r10, %rsi
callq 0x19b20b
movq 0x8(%rbx), %rax
movq 0x18(%rbx), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x19b437
movq 0x28(%rsp), %rax
movq (%rax), %rdi
movl $0x8, %esi
callq 0x2120
movq %rax, (%rbx)
movq 0x8(%rbx), %rcx
testq %rcx, %rcx
je 0x19c453
movq 0x18(%rbx), %rdx
movl $0x1, %esi
xorl %edi, %edi
movl $0x1, %r10d
movl %edi, %r8d
cmpq %r10, %rcx
jne 0x19c421
movq (%rdx,%r8,8), %r9
jmp 0x19c432
movq (%rdx,%r8,8), %r9
movq (%rdx,%r10,8), %r10
xorq %r9, %r10
shrq $0x20, %r10
je 0x19c449
shlq $0x20, %r8
movl %esi, %r10d
subl %edi, %r10d
orq %r8, %r10
shrq $0x20, %r9
movq %r10, (%rax,%r9,8)
movl %esi, %edi
incl %esi
movq %rsi, %r10
cmpq %rsi, %rcx
jae 0x19c413
movq 0x20(%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq