// File: /workspace/github_c_makefile_star2_O2/lh3[P]minigraph/map-algo.c
// Function: collect_matches
static mg_match_t *collect_matches(void *km, int *_n_m, int max_occ, const mg_idx_t *gi, const mg128_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;
	size_t i;
	mg_match_t *m;
	*n_mini_pos = 0;
	KMALLOC(km, *mini_pos, mv->n);
	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 uint64_t *cr;
		mg128_t *p = &mv->a[i];
		uint32_t q_pos = (uint32_t)p->y, q_span = p->x & 0xff;
		int t;
		cr = mg_idx_get(gi, p->x>>8, &t);
		if (t >= max_occ) {
			int en = (q_pos >> 1) + 1, st = en - q_span;
			if (st > rep_en) {
				*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 = q_pos, q->q_span = q_span, q->cr = cr, q->n = t, q->seg_id = p->y >> 32;
			q->is_tandem = 0;
			if (i > 0 && p->x>>8 == mv->a[i - 1].x>>8) q->is_tandem = 1;
			if (i < mv->n - 1 && p->x>>8 == mv->a[i + 1].x>>8) q->is_tandem = 1;
			*n_a += q->n;
			(*mini_pos)[(*n_mini_pos)++] = q_pos>>1;
		}
	}
	*rep_len += rep_en - rep_st;
	*_n_m = n_m;
	return m;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %r14
movq %r8, %r15
movq %rcx, 0x30(%rsp)
movl %edx, 0x10(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdi, %rbx
movq 0x78(%rsp), %rax
andl $0x0, (%rax)
movq 0x80(%rsp), %r13
movq 0x70(%rsp), %r12
movq (%r8), %rsi
shlq $0x2, %rsi
callq 0x266c
movq %rax, (%r13)
imulq $0x18, (%r15), %rsi
movq %rbx, %rdi
callq 0x266c
andl $0x0, (%r12)
movq %r14, 0x28(%rsp)
andq $0x0, (%r14)
movq %rax, 0x18(%rsp)
xorl %r14d, %r14d
xorl %r12d, %r12d
movl $0x0, 0xc(%rsp)
movl $0x0, 0x4(%rsp)
movl $0x0, 0x8(%rsp)
cmpq (%r15), %r12
jae 0x1b155
movq %r15, %r13
movq 0x10(%r15), %rbx
movl 0x8(%rbx,%r14), %ebp
movq (%rbx,%r14), %rsi
movzbl %sil, %r15d
shrq $0x8, %rsi
movq 0x30(%rsp), %rdi
leaq 0x14(%rsp), %rdx
callq 0x126d7
movl 0x14(%rsp), %ecx
cmpl 0x10(%rsp), %ecx
jge 0x1b0c5
movslq 0xc(%rsp), %rdx
imulq $0x18, %rdx, %rdi
movq 0x18(%rsp), %r8
leaq (%r8,%rdi), %rdx
movl %ebp, 0x4(%r8,%rdi)
movl %r15d, 0x8(%r8,%rdi)
movq %rax, 0x10(%r8,%rdi)
movl %ecx, (%r8,%rdi)
movl 0xc(%rbx,%r14), %esi
movl %esi, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, 0xc(%r8,%rdi)
testq %r12, %r12
je 0x1b0f4
movq %r13, %r15
movq 0x10(%r13), %rdi
movq -0x10(%rdi,%r14), %rdi
xorq (%rbx,%r14), %rdi
cmpq $0xff, %rdi
ja 0x1b0f7
orl $0x80000000, %esi       # imm = 0x80000000
movl %esi, 0xc(%rdx)
movl %esi, %eax
jmp 0x1b0f7
shrl %ebp
incl %ebp
movl %ebp, %eax
subl %r15d, %eax
movl 0x4(%rsp), %edx
cmpl %edx, %eax
jle 0x1b0eb
subl 0x8(%rsp), %edx
movq 0x70(%rsp), %rcx
addl %edx, (%rcx)
movl %ebp, 0x4(%rsp)
movl %eax, 0x8(%rsp)
jmp 0x1b0ef
movl %ebp, 0x4(%rsp)
movq %r13, %r15
jmp 0x1b149
movq %r13, %r15
movq (%r15), %rsi
decq %rsi
cmpq %rsi, %r12
jae 0x1b120
movq 0x10(%r15), %rsi
movq 0x10(%rsi,%r14), %rsi
xorq (%rbx,%r14), %rsi
cmpq $0xff, %rsi
ja 0x1b120
orl $0x80000000, %eax       # imm = 0x80000000
movl %eax, 0xc(%rdx)
movq 0x28(%rsp), %rax
addq %rcx, (%rax)
incl 0xc(%rsp)
shrl %ebp
movq 0x80(%rsp), %rax
movq (%rax), %rax
movq 0x78(%rsp), %rsi
movslq (%rsi), %rcx
leal 0x1(%rcx), %edx
movl %edx, (%rsi)
movl %ebp, (%rax,%rcx,4)
incq %r12
addq $0x10, %r14
jmp 0x1b02a
movl 0x4(%rsp), %ecx
subl 0x8(%rsp), %ecx
movq 0x70(%rsp), %rax
addl %ecx, (%rax)
movq 0x20(%rsp), %rax
movl 0xc(%rsp), %ecx
movl %ecx, (%rax)
movq 0x18(%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq