// File: chhylp123[P]hifiasm/inter.cpp
// Function: collect_matches(void*, int*, int, void const*, ha_pt_s const*, int, ha_mzl_v const*, long*, int*, int*, int**)
static mg_match_t *collect_matches(void *km, int *_n_m, int max_occ, const void *ha_flt_tab, const ha_pt_t *ha_idx, int check_unique, const ha_mzl_v *mv, int64_t *n_a, int *rep_len, int *n_mini_pos, int32_t **mini_pos)
{
	int rep_st = 0, rep_en = 0, n_m, tn, tw;
	size_t i;
	mg_match_t *m;
	*n_mini_pos = 0;
    KMALLOC(km, *mini_pos, mv->n);///mv->n how many minimizers in query
	m = (mg_match_t*)kmalloc(km, mv->n * sizeof(mg_match_t));
	for (i = 0, n_m = 0, *rep_len = 0, *n_a = 0; i < mv->n; ++i) {
		const ha_idxposl_t *cr;
		ha_mzl_t *z = &mv->a[i];
		cr = ha_ptl_get(ha_idx, z->x, &tn);        
        tw = ha_ft_cnt(ha_flt_tab, z->x);
		if ((tw > max_occ) || (check_unique && tw != 1)) { ///the frequency of repetitive regions; ignore those minimizers
			int en = z->pos + 1, st = en - z->span;//[st, en)
			if (st > rep_en) { ///just record the length of repetive regions
				*rep_len += rep_en - rep_st;
				rep_st = st, rep_en = en;
			} else rep_en = en;
		} else {
			mg_match_t *q = &m[n_m++];
			q->q_pos = z->pos, q->q_span = z->span, q->rev = z->rev, q->cr = cr, q->n = tn, q->qid = 0;
			q->is_tandem = 0, q->weight = 255;
            if(check_unique && tw != 1) q->is_tandem = 1, q->weight = 1;
			*n_a += q->n;///how many candidates 
			(*mini_pos)[(*n_mini_pos)++] = z->pos;///minimizer offset in query
		}
	}
	*rep_len += rep_en - rep_st; ///the length of repetitive regions 
	*_n_m = n_m;
	return m;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq 0x28(%rbp), %rax
movl $0x0, (%rax)
movq -0x8(%rbp), %rdi
movq 0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, %esi
shlq $0x2, %rsi
callq 0x30e4f0
movq %rax, %rcx
movq 0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movq 0x10(%rbp), %rax
movl (%rax), %eax
imulq $0x18, %rax, %rsi
callq 0x30e4f0
movq %rax, -0x50(%rbp)
movq $0x0, -0x48(%rbp)
movl $0x0, -0x38(%rbp)
movq 0x20(%rbp), %rax
movl $0x0, (%rax)
movq 0x18(%rbp), %rax
movq $0x0, (%rax)
movq -0x48(%rbp), %rax
movq 0x10(%rbp), %rcx
movl (%rcx), %ecx
cmpq %rcx, %rax
jae 0x2836d3
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rax
imulq $0x18, -0x48(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x28(%rbp), %rdi
movq -0x60(%rbp), %rax
movq (%rax), %rsi
leaq -0x3c(%rbp), %rdx
callq 0x1878d0
movq %rax, -0x58(%rbp)
movq -0x20(%rbp), %rdi
movq -0x60(%rbp), %rax
movq (%rax), %rsi
callq 0x188d00
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x14(%rbp), %eax
jg 0x2834fb
cmpl $0x0, -0x2c(%rbp)
je 0x28354c
cmpl $0x1, -0x40(%rbp)
je 0x28354c
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
movq -0x60(%rbp), %rcx
movzbl 0x10(%rcx), %ecx
subl %ecx, %eax
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %eax
cmpl -0x34(%rbp), %eax
jle 0x283541
movl -0x34(%rbp), %ecx
subl -0x30(%rbp), %ecx
movq 0x20(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movl -0x68(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x64(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x283547
movl -0x64(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x2836c0
movq -0x50(%rbp), %rax
movl -0x38(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x38(%rbp)
movslq %ecx, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rdx
shrq $0x20, %rdx
movq -0x70(%rbp), %rax
movq 0x4(%rax), %rcx
movabsq $0xffffffff, %rsi       # imm = 0xFFFFFFFF
andq %rsi, %rdx
shlq $0x20, %rdx
movabsq $0xffffffff, %rsi       # imm = 0xFFFFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x4(%rax)
movq -0x60(%rbp), %rax
movzbl 0x10(%rax), %eax
movl %eax, %edx
movq -0x70(%rbp), %rax
movq 0x4(%rax), %rcx
andq $0x7fffffff, %rdx       # imm = 0x7FFFFFFF
andq $-0x80000000, %rcx      # imm = 0x80000000
orq %rdx, %rcx
movq %rcx, 0x4(%rax)
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rdx
shrq $0x1f, %rdx
andq $0x1, %rdx
movq -0x70(%rbp), %rax
movq 0x4(%rax), %rcx
andq $0x1, %rdx
shlq $0x1f, %rdx
movabsq $-0x80000001, %rsi      # imm = 0xFFFFFFFF7FFFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x4(%rax)
movq -0x58(%rbp), %rcx
movq -0x70(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x3c(%rbp), %ecx
movq -0x70(%rbp), %rax
movl %ecx, (%rax)
movq -0x70(%rbp), %rax
movl 0xc(%rax), %ecx
andl $0xffff0000, %ecx       # imm = 0xFFFF0000
orl $0x0, %ecx
movl %ecx, 0xc(%rax)
movq -0x70(%rbp), %rax
movl 0xc(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x0, %ecx
movl %ecx, 0xc(%rax)
movq -0x70(%rbp), %rax
movl 0xc(%rax), %ecx
andl $0x8000ffff, %ecx       # imm = 0x8000FFFF
orl $0xff0000, %ecx         # imm = 0xFF0000
movl %ecx, 0xc(%rax)
cmpl $0x0, -0x2c(%rbp)
je 0x283686
cmpl $0x1, -0x40(%rbp)
je 0x283686
movq -0x70(%rbp), %rax
movl 0xc(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0xc(%rax)
movq -0x70(%rbp), %rax
movl 0xc(%rax), %ecx
andl $0x8000ffff, %ecx       # imm = 0x8000FFFF
orl $0x10000, %ecx          # imm = 0x10000
movl %ecx, 0xc(%rax)
movq -0x70(%rbp), %rax
movl (%rax), %eax
movl %eax, %ecx
movq 0x18(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
movl %eax, %edx
movq 0x30(%rbp), %rax
movq (%rax), %rax
movq 0x28(%rbp), %rsi
movl (%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, (%rsi)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x2836c2
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x283495
movl -0x34(%rbp), %ecx
subl -0x30(%rbp), %ecx
movq 0x20(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movl -0x38(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x50(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)