// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x1, %edi
movl $0x10, %esi
callq 0x2140
movq %rax, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq $0x0, 0x8(%rax)
movl $0x1, -0x24(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x24(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
ja 0x277c84
movl -0x24(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
je 0x277751
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x24(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
movl -0x20(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
je 0x277c74
movl -0x24(%rbp), %eax
subl -0x20(%rbp), %eax
cmpl $0x1, %eax
je 0x277767
movl -0x24(%rbp), %eax
subl -0x20(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jbe 0x27776c
jmp 0x277c6e
movl -0x20(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jae 0x277c6c
jmp 0x277780
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x2777e9
movq -0x18(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x2777ae
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0x58(%rbp)
jmp 0x2777b9
movl $0x2, %eax
movq %rax, -0x58(%rbp)
jmp 0x2777b9
movq -0x58(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x3c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movabsq $0xffffffff, %rdx       # imm = 0xFFFFFFFF
andq 0x8(%rax), %rdx
shlq $0x20, %rdx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movl -0x3c(%rbp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rcx
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
andq 0x10(%rcx), %rax
orq %rax, %rdx
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rsi
movq 0x8(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x8(%rsi)
movq %rdx, (%rax,%rcx,8)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x24(%rbp), %eax
jae 0x277c5c
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x3c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
shrq $0x3f, %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
movl -0x40(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq 0x10(%rcx), %rcx
shrq $0x3f, %rcx
cmpl %ecx, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rdx
movl -0x3c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rdx
movabsq $0xffffffff, %rcx       # imm = 0xFFFFFFFF
andq 0x8(%rdx), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x4c(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rdx
movl -0x40(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rdx
movabsq $0xffffffff, %rcx       # imm = 0xFFFFFFFF
andq 0x8(%rdx), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x50(%rbp)
movq -0x30(%rbp), %rax
movl (%rax), %eax
movq -0x30(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jne 0x277977
movq -0x30(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x27793e
movq -0x30(%rbp), %rax
movl 0x4(%rax), %eax
shll %eax
movl %eax, -0x5c(%rbp)
jmp 0x277948
movl $0x2, %eax
movl %eax, -0x5c(%rbp)
jmp 0x277948
movl -0x5c(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x30(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %esi
shlq $0x4, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x30(%rbp), %rdx
movl (%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, (%rdx)
movl %ecx, %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x40(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x3c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movabsq $0xffffffff, %rcx       # imm = 0xFFFFFFFF
andq 0x8(%rax), %rcx
shlq $0x21, %rcx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
movl -0x40(%rbp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rdx
movabsq $0xffffffff, %rax       # imm = 0xFFFFFFFF
andq 0x8(%rdx), %rax
shll %eax
movl %eax, %eax
orq %rax, %rcx
movl -0x48(%rbp), %eax
orq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movl -0x3c(%rbp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rcx
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
andq 0x10(%rcx), %rax
shlq $0x20, %rax
movq %rax, -0x68(%rbp)
cmpl $0x0, -0x48(%rbp)
je 0x277a77
movslq -0x50(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rdx
movl -0x40(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rdx
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
andq 0x10(%rdx), %rcx
addq $0x1, %rcx
movl -0x44(%rbp), %edx
subq %rdx, %rcx
subq %rcx, %rax
subq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x277a9b
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movl -0x40(%rbp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rcx
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
andq 0x10(%rcx), %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rcx
movq -0x70(%rbp), %rax
orq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movl (%rax), %eax
movq -0x30(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jne 0x277b0e
movq -0x30(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x277ad5
movq -0x30(%rbp), %rax
movl 0x4(%rax), %eax
shll %eax
movl %eax, -0x74(%rbp)
jmp 0x277adf
movl $0x2, %eax
movl %eax, -0x74(%rbp)
jmp 0x277adf
movl -0x74(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x30(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %esi
shlq $0x4, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x30(%rbp), %rdx
movl (%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, (%rdx)
movl %ecx, %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x3c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x40(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movabsq $0xffffffff, %rcx       # imm = 0xFFFFFFFF
andq 0x8(%rax), %rcx
shlq $0x21, %rcx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
movl -0x3c(%rbp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rdx
movabsq $0xffffffff, %rax       # imm = 0xFFFFFFFF
andq 0x8(%rdx), %rax
shll %eax
movl %eax, %eax
orq %rax, %rcx
movl -0x48(%rbp), %eax
orq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movl -0x40(%rbp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rcx
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
andq 0x10(%rcx), %rax
shlq $0x20, %rax
movq %rax, -0x80(%rbp)
cmpl $0x0, -0x48(%rbp)
je 0x277c11
movslq -0x4c(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rdx
movl -0x3c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rdx
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
andq 0x10(%rdx), %rcx
addq $0x1, %rcx
movl -0x44(%rbp), %edx
subq %rdx, %rcx
subq %rcx, %rax
subq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x277c38
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movl -0x3c(%rbp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rcx
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
andq 0x10(%rcx), %rax
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rcx
movq -0x88(%rbp), %rax
orq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x277858
jmp 0x277c5e
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x277772
jmp 0x277c6e
movl -0x24(%rbp), %eax
movl %eax, -0x20(%rbp)
jmp 0x277c76
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x277707
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x30(%rbp), %rax
movl (%rax), %eax
shlq $0x4, %rax
addq %rax, %rsi
callq 0x276050
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x2764b0
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movl $0x8, %esi
callq 0x2140
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x20(%rbp)
movl $0x1, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpq 0x8(%rcx), %rax
ja 0x277d84
movl -0x24(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpq 0x8(%rcx), %rax
je 0x277d3c
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x24(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl -0x20(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
je 0x277d74
movl -0x20(%rbp), %eax
movl %eax, %edx
shlq $0x20, %rdx
movl -0x24(%rbp), %eax
subl -0x20(%rbp), %eax
movl %eax, %eax
orq %rax, %rdx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl -0x20(%rbp), %esi
movq (%rcx,%rsi,8), %rcx
shrq $0x20, %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x24(%rbp), %eax
movl %eax, -0x20(%rbp)
jmp 0x277d76
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x277cf3
movq -0x30(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)