// File: chhylp123[P]hifiasm/inter.cpp
// Function: mg_gchain_flt_sub(float, int, int, int, mg_gchain_t*)
int mg_gchain_flt_sub(float pri_ratio, int min_diff, int best_n, int n, mg_gchain_t *r)
{
	if (pri_ratio > 0.0f && n > 0) {
		int i, k, n_2nd = 0;
		for (i = k = 0; i < n; ++i) {
			int p = r[i].parent;
			if (p == i) { // primary
				r[i].flt = 0, ++k;
			} else if ((r[i].score >= r[p].score * pri_ratio || r[i].score + min_diff >= r[p].score) && n_2nd < best_n) {
				if (!(r[i].qs == r[p].qs && r[i].qe == r[p].qe && r[i].ps == r[p].ps && r[i].pe == r[p].pe)) // not identical hits; TODO: check path as well
					r[i].flt = 0, ++n_2nd, ++k;
				else r[i].flt = 1;
			} else r[i].flt = 1;
		}
		return k;
	}
	return n;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movss %xmm0, -0x8(%rbp)
movl %edi, -0xc(%rbp)
movl %esi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movss -0x8(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x28b65e
cmpl $0x0, -0x14(%rbp)
jle 0x28b65e
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x28b656
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x24(%rbp), %eax
jne 0x28b4cb
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl 0x44(%rax), %ecx
andl $0xfffffeff, %ecx       # imm = 0xFFFFFEFF
orl $0x0, %ecx
movl %ecx, 0x44(%rax)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x28b646
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cvtsi2ssl 0x14(%rax), %xmm0
movq -0x20(%rbp), %rax
movslq -0x30(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cvtsi2ssl 0x14(%rax), %xmm1
mulss -0x8(%rbp), %xmm1
ucomiss %xmm1, %xmm0
jae 0x28b52a
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
addl -0xc(%rbp), %eax
movq -0x20(%rbp), %rcx
movslq -0x30(%rbp), %rdx
imulq $0x48, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x14(%rcx), %eax
jl 0x28b623
movl -0x2c(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x28b623
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
movq -0x20(%rbp), %rcx
movslq -0x30(%rbp), %rdx
imulq $0x48, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x18(%rcx), %eax
jne 0x28b5ce
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl 0x1c(%rax), %eax
movq -0x20(%rbp), %rcx
movslq -0x30(%rbp), %rdx
imulq $0x48, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x1c(%rcx), %eax
jne 0x28b5ce
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl 0x24(%rax), %eax
movq -0x20(%rbp), %rcx
movslq -0x30(%rbp), %rdx
imulq $0x48, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x24(%rcx), %eax
jne 0x28b5ce
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl 0x28(%rax), %eax
movq -0x20(%rbp), %rcx
movslq -0x30(%rbp), %rdx
imulq $0x48, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x28(%rcx), %eax
je 0x28b600
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl 0x44(%rax), %ecx
andl $0xfffffeff, %ecx       # imm = 0xFFFFFEFF
orl $0x0, %ecx
movl %ecx, 0x44(%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x28b621
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl 0x44(%rax), %ecx
andl $0xfffffeff, %ecx       # imm = 0xFFFFFEFF
orl $0x100, %ecx            # imm = 0x100
movl %ecx, 0x44(%rax)
jmp 0x28b644
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl 0x44(%rax), %ecx
andl $0xfffffeff, %ecx       # imm = 0xFFFFFEFF
orl $0x100, %ecx            # imm = 0x100
movl %ecx, 0x44(%rax)
jmp 0x28b646
jmp 0x28b648
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x28b476
movl -0x28(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x28b664
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopl (%rax)