// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
movq %r9, %r12
movq %r8, %r13
movq %rcx, 0x40(%rsp)
movl %edx, 0x20(%rsp)
movq %rsi, %r14
movq %rdi, %rbx
movq 0x88(%rsp), %rax
movq 0x80(%rsp), %r15
xorl %ebp, %ebp
movl %ebp, (%rax)
movq (%r8), %rsi
shlq $0x2, %rsi
callq 0x30e5
movq 0x90(%rsp), %rcx
movq %rax, (%rcx)
movq (%r13), %rax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rsi
movq %rbx, %rdi
callq 0x30e5
movq %rax, 0x28(%rsp)
movl %ebp, (%r15)
movq %r12, 0x38(%rsp)
movq $0x0, (%r12)
cmpq $0x0, (%r13)
movl $0x0, %eax
je 0x1ec30
movq %r14, 0x30(%rsp)
xorl %r12d, %r12d
xorl %r15d, %r15d
movl $0x0, 0x14(%rsp)
movl $0x0, 0xc(%rsp)
movl $0x0, 0x10(%rsp)
xorl %ebp, %ebp
movq %r13, 0x18(%rsp)
movq 0x10(%r13), %r14
movl 0x8(%r14,%r12), %ebx
movq (%r14,%r12), %rsi
movzbl %sil, %r13d
shrq $0x8, %rsi
movq 0x40(%rsp), %rdi
leaq 0x24(%rsp), %rdx
callq 0x15446
movl 0x24(%rsp), %ecx
cmpl 0x20(%rsp), %ecx
jge 0x1eb68
movl 0x10(%rsp), %r8d
movslq %r8d, %rdx
leaq (%rdx,%rdx,2), %rdi
movq 0x28(%rsp), %r9
leaq (%r9,%rdi,8), %rdx
movl %ebx, 0x4(%r9,%rdi,8)
movl %r13d, 0x8(%r9,%rdi,8)
movq %rax, 0x10(%r9,%rdi,8)
movl %ecx, (%r9,%rdi,8)
movl 0xc(%r14,%r12), %esi
movl %esi, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, 0xc(%r9,%rdi,8)
testq %rbp, %rbp
je 0x1eb9c
movq 0x18(%rsp), %r13
movq 0x10(%r13), %rdi
movq -0x10(%rdi,%r12), %rdi
xorq (%r14,%r12), %rdi
cmpq $0xff, %rdi
ja 0x1eba1
orl $0x80000000, %esi       # imm = 0x80000000
movl %esi, 0xc(%rdx)
movl %esi, %eax
jmp 0x1eba1
shrl %ebx
incl %ebx
movl %ebx, %eax
subl %r13d, %eax
movl 0xc(%rsp), %ecx
cmpl %ecx, %eax
jle 0x1eb91
addl %ecx, %r15d
movq 0x80(%rsp), %rcx
addl %r15d, (%rcx)
movl %ebx, 0xc(%rsp)
movl %eax, 0x14(%rsp)
jmp 0x1eb95
movl %ebx, 0xc(%rsp)
movq 0x18(%rsp), %r13
jmp 0x1ebfb
movq 0x18(%rsp), %r13
movq (%r13), %rsi
decq %rsi
cmpq %rsi, %rbp
jae 0x1ebcb
movq 0x10(%r13), %rsi
movq 0x10(%rsi,%r12), %rsi
xorq (%r14,%r12), %rsi
cmpq $0xff, %rsi
ja 0x1ebcb
orl $0x80000000, %eax       # imm = 0x80000000
movl %eax, 0xc(%rdx)
movq 0x38(%rsp), %rax
addq %rcx, (%rax)
incl %r8d
movl %r8d, 0x10(%rsp)
shrl %ebx
movq 0x90(%rsp), %rax
movq (%rax), %rax
movq 0x88(%rsp), %rsi
movslq (%rsi), %rcx
leal 0x1(%rcx), %edx
movl %edx, (%rsi)
movl %ebx, (%rax,%rcx,4)
incq %rbp
movl 0x14(%rsp), %r15d
negl %r15d
addq $0x10, %r12
cmpq (%r13), %rbp
jb 0x1ead4
movl 0xc(%rsp), %eax
subl 0x14(%rsp), %eax
movq 0x80(%rsp), %r15
addl (%r15), %eax
movq 0x30(%rsp), %r14
movl 0x10(%rsp), %ebp
movl %eax, (%r15)
movl %ebp, (%r14)
movq 0x28(%rsp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq