// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/inter.cpp
// Function: collect_seed_hits(void*, mg_idxopt_t const*, int, void const*, ha_pt_s const*, ma_ug_t const*, ha_mzl_v const*, long*, int*, int*, int**)
mg128_t *collect_seed_hits(void *km, const mg_idxopt_t *opt, int max_occ, const void *ha_flt_tab, const ha_pt_t *ha_idx, 
const ma_ug_t *ug, const ha_mzl_v *mv, int64_t *n_a, int *rep_len, int *n_mini_pos, int32_t **mini_pos)
{
    int i, n_m;
    mg128_t *a = NULL;
    mg_match_t *m = collect_matches(km, &n_m, max_occ, ha_flt_tab, ha_idx, 1, mv, n_a, rep_len, n_mini_pos, mini_pos);
    a = (mg128_t*)kmalloc(km, *n_a * sizeof(mg128_t));///n_a: how many available candidates in total 
    for (i = 0, *n_a = 0; i < n_m; ++i) {///n_m: how many available seeds, instead of candidates
		mg_match_t *q = &m[i];
		const ha_idxposl_t *r = q->cr;
		uint32_t k;
		for (k = 0; k < q->n; ++k) {///q->n: number of candidates belonging to seed m[i]
			mg128_t *p;
			p = &a[(*n_a)++];///pick up a slot for one candidate
			if (r[k].rev == q->rev) // forward strand
				p->x = (uint64_t)(r[k].rid)<<33|r[k].pos; ///reference: rid(31)|rev(1)|pos(32)                
			else // reverse strand
				p->x = (uint64_t)(r[k].rid)<<33 | 1ULL<<32 | (ug->g->seq[r[k].rid].len - (r[k].pos + 1 - r[k].span) - 1);
			p->y = (uint64_t)q->q_span << 32 | q->q_pos;
			p->y |= (uint64_t)q->qid << MG_SEED_SEG_SHIFT;
			if (q->is_tandem) p->y |= MG_SEED_TANDEM;
			p->y |= (uint64_t)q->weight << MG_SEED_WT_SHIFT; 
			///p->y: weight(8)seg_id(8)flag(8)span(8)pos(32)
			///p->x: rid(31)rev(1)pos(33); keep reference
		}
	}
    kfree(km, m);
	radix_sort_128x(a, a + (*n_a));
	return a;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, %rbx
movq %r8, 0x38(%rsp)
movq %rcx, 0x30(%rsp)
movl %edx, 0x18(%rsp)
movq %rdi, %r14
movq 0x98(%rsp), %rax
movq 0x90(%rsp), %r15
movq 0x88(%rsp), %r13
movq 0x80(%rsp), %r12
xorl %ebp, %ebp
movl %ebp, (%rax)
movl (%r12), %esi
shlq $0x2, %rsi
callq 0x1ee115
movq 0xa0(%rsp), %rcx
movq %rax, (%rcx)
movl (%r12), %eax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rsi
movq %r14, 0x20(%rsp)
movq %r14, %rdi
callq 0x1ee115
movq %rax, 0x8(%rsp)
movl %ebp, (%r15)
movq $0x0, (%r13)
cmpl %ebp, (%r12)
je 0x1a21c2
movq %r12, %rcx
xorl %r15d, %r15d
movl $0x10, %r12d
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
addq $0xff, %rax
movq %rax, 0x28(%rsp)
movl $0x0, 0x4(%rsp)
movl $0x0, (%rsp)
movq $0x0, 0x10(%rsp)
xorl %ebp, %ebp
movq 0x8(%rcx), %r14
movq -0x10(%r14,%r12), %rsi
movq 0x38(%rsp), %rdi
leaq 0x1c(%rsp), %rdx
callq 0x119548
movq %rax, 0x40(%rsp)
movq -0x10(%r14,%r12), %rsi
movq 0x30(%rsp), %rdi
callq 0x11a473
cmpl $0x0, 0x18(%rsp)
jle 0x1a214d
cmpl $0x1, %eax
jne 0x1a214d
movq 0x10(%rsp), %rdi
movslq %edi, %rdi
leaq (%rdi,%rdi,2), %rax
movq -0x8(%r14,%r12), %rcx
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
andq %rdx, %rcx
movq 0x8(%rsp), %rsi
movl 0x4(%rsi,%rax,8), %edx
orq %rcx, %rdx
movq %rdx, 0x4(%rsi,%rax,8)
movzbl (%r14,%r12), %ecx
andq $-0x80000000, %rdx      # imm = 0x80000000
orq %rcx, %rdx
movq %rdx, 0x4(%rsi,%rax,8)
movq -0x8(%r14,%r12), %rcx
andl $0x80000000, %ecx       # imm = 0x80000000
andq 0x28(%rsp), %rdx
orq %rcx, %rdx
movq %rdx, 0x4(%rsi,%rax,8)
movq 0x40(%rsp), %rcx
movq %rcx, 0x10(%rsi,%rax,8)
movl 0x1c(%rsp), %ecx
movl %ecx, (%rsi,%rax,8)
movl $0xff0000, 0xc(%rsi,%rax,8) # imm = 0xFF0000
addq %rcx, (%r13)
incl %edi
movq %rdi, 0x10(%rsp)
movl -0x4(%r14,%r12), %eax
movq 0xa0(%rsp), %rcx
movq (%rcx), %rcx
movq 0x98(%rsp), %rdi
movslq (%rdi), %rdx
leal 0x1(%rdx), %esi
movl %esi, (%rdi)
movl %eax, (%rcx,%rdx,4)
jmp 0x1a217d
movl -0x4(%r14,%r12), %eax
incl %eax
movzbl (%r14,%r12), %edx
movl %eax, %ecx
subl %edx, %ecx
movl (%rsp), %esi
cmpl %esi, %ecx
jle 0x1a217a
addl %r15d, %esi
movq 0x90(%rsp), %rdx
addl %esi, (%rdx)
movl %eax, (%rsp)
movl %ecx, 0x4(%rsp)
jmp 0x1a217d
movl %eax, (%rsp)
movq 0x80(%rsp), %rcx
movl 0x4(%rsp), %eax
movl %eax, %r15d
negl %r15d
incq %rbp
movl (%rcx), %eax
addq $0x18, %r12
cmpq %rax, %rbp
jb 0x1a2069
movl (%rsp), %eax
subl 0x4(%rsp), %eax
movq 0x90(%rsp), %r15
addl (%r15), %eax
movq (%r13), %rsi
shlq $0x4, %rsi
movq 0x10(%rsp), %rbp
jmp 0x1a21c6
xorl %esi, %esi
xorl %eax, %eax
movl %eax, (%r15)
movq 0x20(%rsp), %rdi
callq 0x1ee115
movq %rax, %r12
movq $0x0, (%r13)
testl %ebp, %ebp
jle 0x1a22e8
movl %ebp, %eax
xorl %ecx, %ecx
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
leaq (%rcx,%rcx,2), %r8
movq 0x8(%rsp), %rsi
movl (%rsi,%r8,8), %esi
testq %rsi, %rsi
je 0x1a22dc
movq 0x8(%rsp), %r9
leaq (%r9,%r8,8), %rdi
movq 0x10(%r9,%r8,8), %r8
shlq $0x4, %rsi
xorl %r9d, %r9d
movq (%r13), %r10
leaq 0x1(%r10), %r11
movq %r11, (%r13)
movq (%r8,%r9), %r11
movl 0x4(%rdi), %ebp
xorl %r11d, %ebp
js 0x1a2242
movq %r11, %r14
shlq $0x21, %r14
shrq $0x20, %r11
orq %r14, %r11
jmp 0x1a2280
movl %r11d, %r14d
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
movq %r11, %r15
shlq $0x21, %r15
movq 0x18(%rbx), %rbp
movq 0x20(%rbp), %rbp
movl (%rbp,%r14,8), %r14d
andl %edx, %r14d
shrq $0x20, %r11
movzbl 0x8(%r8,%r9), %ebp
subl %r11d, %r14d
leal (%r14,%rbp), %r11d
addl $-0x2, %r11d
orq %r15, %r11
btsq $0x20, %r11
shlq $0x4, %r10
addq %r12, %r10
movq %r11, (%r10)
movq 0x4(%rdi), %r14
rolq $0x20, %r14
btrq $0x3f, %r14
movq %r14, 0x8(%r10)
movl 0xc(%rdi), %r11d
shlq $0x30, %r11
orq %r14, %r11
movq %r11, 0x8(%r10)
movl 0xc(%rdi), %r14d
testl %r14d, %r14d
jns 0x1a22c0
btsq $0x2a, %r11
movq %r11, 0x8(%r10)
movl 0xc(%rdi), %r14d
shrl $0x10, %r14d
shlq $0x38, %r14
orq %r11, %r14
movq %r14, 0x8(%r10)
addq $0x10, %r9
cmpq %r9, %rsi
jne 0x1a221a
incq %rcx
cmpq %rax, %rcx
jne 0x1a21ef
movq 0x20(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x1ee04f
movq (%r13), %rax
shlq $0x4, %rax
movq %r12, %rsi
addq %rax, %rsi
movq %r12, %rdi
callq 0x19febb
movq %r12, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq