// File: 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
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x90, %rsp
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movl %edx, -0x24(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq %r9, -0x40(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x18(%rbp), %rdi
movl -0x24(%rbp), %edx
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %r8
movq 0x10(%rbp), %r14
movq 0x18(%rbp), %rbx
movq 0x20(%rbp), %r11
movq 0x28(%rbp), %r10
movq 0x30(%rbp), %rax
leaq -0x48(%rbp), %rsi
movl $0x1, %r9d
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x2833f0
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rdi
movq 0x18(%rbp), %rax
movq (%rax), %rsi
shlq $0x4, %rsi
callq 0x30e4f0
movq %rax, -0x50(%rbp)
movl $0x0, -0x44(%rbp)
movq 0x18(%rbp), %rax
movq $0x0, (%rax)
movl -0x44(%rbp), %eax
cmpl -0x48(%rbp), %eax
jge 0x2833a9
movq -0x58(%rbp), %rax
movslq -0x44(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x68(%rbp)
movl $0x0, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movq -0x60(%rbp), %rcx
cmpl (%rcx), %eax
jae 0x283399
movq -0x50(%rbp), %rax
movq 0x18(%rbp), %rdx
movq (%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, (%rdx)
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x68(%rbp), %rax
movl -0x6c(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x1f, %rax
andq $0x1, %rax
movq -0x60(%rbp), %rcx
movq 0x4(%rcx), %rcx
shrq $0x1f, %rcx
andq $0x1, %rcx
cmpl %ecx, %eax
jne 0x283267
movq -0x68(%rbp), %rax
movl -0x6c(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
andq $0x7fffffff, %rcx       # imm = 0x7FFFFFFF
shlq $0x21, %rcx
movq -0x68(%rbp), %rax
movl -0x6c(%rbp), %edx
shlq $0x4, %rdx
addq %rdx, %rax
movq (%rax), %rax
shrq $0x20, %rax
orq %rax, %rcx
movq -0x78(%rbp), %rax
movq %rcx, (%rax)
jmp 0x2832f9
movq -0x68(%rbp), %rax
movl -0x6c(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
andq $0x7fffffff, %rcx       # imm = 0x7FFFFFFF
shlq $0x21, %rcx
movabsq $0x100000000, %rax      # imm = 0x100000000
orq %rax, %rcx
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x68(%rbp), %rdx
movl -0x6c(%rbp), %esi
shlq $0x4, %rsi
addq %rsi, %rdx
movq (%rdx), %rdx
andq $0x7fffffff, %rdx       # imm = 0x7FFFFFFF
movl (%rax,%rdx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x68(%rbp), %rdx
movl -0x6c(%rbp), %esi
shlq $0x4, %rsi
addq %rsi, %rdx
movq (%rdx), %rdx
shrq $0x20, %rdx
addl $0x1, %edx
movq -0x68(%rbp), %rsi
movl -0x6c(%rbp), %edi
shlq $0x4, %rdi
addq %rdi, %rsi
movzbl 0x8(%rsi), %esi
subl %esi, %edx
subl %edx, %eax
subl $0x1, %eax
movl %eax, %eax
orq %rax, %rcx
movq -0x78(%rbp), %rax
movq %rcx, (%rax)
movq -0x60(%rbp), %rax
movq 0x4(%rax), %rcx
andq $0x7fffffff, %rcx       # imm = 0x7FFFFFFF
shlq $0x20, %rcx
movq -0x60(%rbp), %rax
movq 0x4(%rax), %rax
shrq $0x20, %rax
orq %rax, %rcx
movq -0x78(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x60(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xffff, %eax           # imm = 0xFFFF
movl %eax, %eax
movl %eax, %ecx
shlq $0x30, %rcx
movq -0x78(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x60(%rbp), %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x283368
movq -0x78(%rbp), %rax
movabsq $0x40000000000, %rcx    # imm = 0x40000000000
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x60(%rbp), %rax
movl 0xc(%rax), %eax
shrl $0x10, %eax
andl $0x7fff, %eax           # imm = 0x7FFF
movl %eax, %eax
movl %eax, %ecx
shlq $0x38, %rcx
movq -0x78(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x2831cb
jmp 0x28339b
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x283199
movq -0x18(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x30e2d0
movq -0x50(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq 0x18(%rbp), %rax
movq (%rax), %rax
shlq $0x4, %rax
addq %rax, %rsi
callq 0x27ea40
movq -0x50(%rbp), %rax
addq $0x90, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nopw %cs:(%rax,%rax)