// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
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)
movq %r9, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movq 0x18(%rbp), %rax
movl $0x0, (%rax)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rsi
shlq $0x2, %rsi
callq 0x2890
movq %rax, %rcx
movq 0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
imulq $0x18, (%rax), %rsi
callq 0x2890
movq %rax, -0x50(%rbp)
movq $0x0, -0x48(%rbp)
movl $0x0, -0x3c(%rbp)
movq 0x10(%rbp), %rax
movl $0x0, (%rax)
movq -0x30(%rbp), %rax
movq $0x0, (%rax)
movq -0x48(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x2f53d
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x48(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, -0x64(%rbp)
movq -0x60(%rbp), %rax
movq (%rax), %rax
andq $0xff, %rax
movl %eax, -0x68(%rbp)
movq -0x20(%rbp), %rdi
movq -0x60(%rbp), %rax
movq (%rax), %rsi
shrq $0x8, %rsi
leaq -0x6c(%rbp), %rdx
callq 0x20640
movq %rax, -0x58(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jl 0x2f3d7
movl -0x64(%rbp), %eax
shrl %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
movl -0x70(%rbp), %eax
subl -0x68(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
cmpl -0x38(%rbp), %eax
jle 0x2f3cc
movl -0x38(%rbp), %ecx
subl -0x34(%rbp), %ecx
movq 0x10(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movl -0x74(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x70(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x2f3d2
movl -0x70(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x2f52a
movq -0x50(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x3c(%rbp)
movslq %ecx, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movl -0x64(%rbp), %ecx
movq -0x80(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x68(%rbp), %ecx
movq -0x80(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x58(%rbp), %rcx
movq -0x80(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x6c(%rbp), %ecx
movq -0x80(%rbp), %rax
movl %ecx, (%rax)
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
movl %eax, %edx
movq -0x80(%rbp), %rax
movl 0xc(%rax), %ecx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %edx, %ecx
movl %ecx, 0xc(%rax)
movq -0x80(%rbp), %rax
movl 0xc(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x0, %ecx
movl %ecx, 0xc(%rax)
cmpq $0x0, -0x48(%rbp)
jbe 0x2f4a1
movq -0x60(%rbp), %rax
movq (%rax), %rax
shrq $0x8, %rax
movq -0x28(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x48(%rbp), %rdx
subq $0x1, %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
shrq $0x8, %rcx
cmpq %rcx, %rax
jne 0x2f4a1
movq -0x80(%rbp), %rax
movl 0xc(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0xc(%rax)
movq -0x48(%rbp), %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x2f4f9
movq -0x60(%rbp), %rax
movq (%rax), %rax
shrq $0x8, %rax
movq -0x28(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x48(%rbp), %rdx
addq $0x1, %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
shrq $0x8, %rcx
cmpq %rcx, %rax
jne 0x2f4f9
movq -0x80(%rbp), %rax
movl 0xc(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0xc(%rax)
movq -0x80(%rbp), %rax
movl (%rax), %eax
movl %eax, %ecx
movq -0x30(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movl -0x64(%rbp), %edx
shrl %edx
movq 0x20(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rbp), %rsi
movl (%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, (%rsi)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x2f52c
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x2f32d
movl -0x38(%rbp), %ecx
subl -0x34(%rbp), %ecx
movq 0x10(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movl -0x3c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x50(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)