// File: /workspace/github_c_makefile_star2_O0/rikuu[P]kermit/miniasm/hit.c
// Function: ma_hit_sub
ma_sub_t *ma_hit_sub(int min_dp, float min_iden, int end_clip, size_t n, const ma_hit_t *a, size_t n_sub)
{
	size_t i, j, last, n_remained = 0;
	kvec_t(uint32_t) b = {0,0,0};
	ma_sub_t *sub = 0;

	sub = (ma_sub_t*)calloc(n_sub, sizeof(ma_sub_t));
	for (i = 1, last = 0; i <= n; ++i) {
		if (i == n || a[i].qns>>32 != a[i-1].qns>>32) { // we come to a new query sequence
			size_t start = 0;
			int dp, qid = a[i-1].qns>>32;
			ma_sub_t max, max2;
			kv_resize(uint32_t, b, i - last);
			b.n = 0;
			for (j = last; j < i; ++j) { // collect all starts and ends
				uint32_t qs, qe;
				if (a[j].tn == qid || a[j].ml < a[j].bl * min_iden) continue; // skip self match
				qs = (uint32_t)a[j].qns + end_clip, qe = a[j].qe - end_clip;
				if (qe > qs) {
					kv_push(uint32_t, b, qs<<1);
					kv_push(uint32_t, b, qe<<1|1);
				}
			}
			ks_introsort_uint32_t(b.n, b.a);
			max.s = max.e = max.del = max2.s = max2.e = max2.del = 0;
			for (j = 0, dp = 0; j < b.n; ++j) {
				int old_dp = dp;
				if (b.a[j]&1) --dp;
				else ++dp;
				if (old_dp < min_dp && dp >= min_dp) {
					start = b.a[j]>>1;
				} else if (old_dp >= min_dp && dp < min_dp) {
					int len = (b.a[j]>>1) - start;
					if (len > max.e - max.s) max2 = max, max.s = start, max.e = b.a[j]>>1;
					else if (len > max2.e - max2.s) max2.s = start, max2.e = b.a[j]>>1;
				}
			}
			if (max.e - max.s > 0) {
				assert(qid < n_sub);
				sub[qid].s = max.s - end_clip;
				sub[qid].e = max.e + end_clip;
				sub[qid].del = 0;
				++n_remained;
			} else sub[qid].del = 1;
			last = i;
		}
	}
	free(b.a);
	if (ma_verbose >= 3)
		fprintf(stderr, "[M::%s::%s] %ld query sequences remain after sub\n", __func__, sys_timestamp(), n_remained);
	return sub;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movl %edi, -0x4(%rbp)
movss %xmm0, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq $0x0, -0x48(%rbp)
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x10c0
movq $0x0, -0x68(%rbp)
movq -0x28(%rbp), %rdi
movl $0x8, %esi
callq 0x10e0
movq %rax, -0x68(%rbp)
movq $0x1, -0x30(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x18(%rbp), %rax
ja 0x6ed4
movq -0x30(%rbp), %rax
cmpq -0x18(%rbp), %rax
je 0x69b5
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
movq -0x20(%rbp), %rcx
movq -0x30(%rbp), %rdx
subq $0x1, %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
je 0x6ec1
movq $0x0, -0x70(%rbp)
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
subq $0x1, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, -0x78(%rbp)
movq -0x58(%rbp), %rax
movq -0x30(%rbp), %rcx
subq -0x40(%rbp), %rcx
cmpq %rcx, %rax
jae 0x6a77
movq -0x30(%rbp), %rax
subq -0x40(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
shrq %rax
orq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
shrq $0x2, %rax
orq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
shrq $0x4, %rax
orq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
shrq $0x8, %rax
orq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
shrq $0x10, %rax
orq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
shlq $0x2, %rsi
callq 0x1170
movq %rax, -0x50(%rbp)
jmp 0x6a79
movq $0x0, -0x60(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0x6c39
movq -0x20(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
cmpl -0x78(%rbp), %eax
je 0x6af6
movq -0x20(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
andq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
cvtsi2ss %eax, %xmm1
movq -0x20(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
shrq $0x20, %rax
andq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
cvtsi2ss %eax, %xmm0
mulss -0x8(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x6afb
jmp 0x6c28
movq -0x20(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
addl -0xc(%rbp), %eax
movl %eax, -0x8c(%rbp)
movq -0x20(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
subl -0xc(%rbp), %eax
movl %eax, -0x90(%rbp)
movl -0x90(%rbp), %eax
cmpl -0x8c(%rbp), %eax
jbe 0x6c26
jmp 0x6b45
movq -0x60(%rbp), %rax
cmpq -0x58(%rbp), %rax
jne 0x6b94
cmpq $0x0, -0x58(%rbp)
je 0x6b66
movq -0x58(%rbp), %rax
shlq %rax
movq %rax, -0xa0(%rbp)
jmp 0x6b74
movl $0x2, %eax
movq %rax, -0xa0(%rbp)
jmp 0x6b74
movq -0xa0(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
shlq $0x2, %rsi
callq 0x1170
movq %rax, -0x50(%rbp)
movl -0x8c(%rbp), %edx
shll %edx
movq -0x50(%rbp), %rax
movq -0x60(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x60(%rbp)
movl %edx, (%rax,%rcx,4)
jmp 0x6bb4
movq -0x60(%rbp), %rax
cmpq -0x58(%rbp), %rax
jne 0x6c03
cmpq $0x0, -0x58(%rbp)
je 0x6bd5
movq -0x58(%rbp), %rax
shlq %rax
movq %rax, -0xa8(%rbp)
jmp 0x6be3
movl $0x2, %eax
movq %rax, -0xa8(%rbp)
jmp 0x6be3
movq -0xa8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
shlq $0x2, %rsi
callq 0x1170
movq %rax, -0x50(%rbp)
movl -0x90(%rbp), %edx
shll %edx
orl $0x1, %edx
movq -0x50(%rbp), %rax
movq -0x60(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x60(%rbp)
movl %edx, (%rax,%rcx,4)
jmp 0x6c26
jmp 0x6c28
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x6a89
movq -0x60(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x5c50
movl -0x88(%rbp), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
orl $0x0, %eax
movl %eax, -0x88(%rbp)
movl $0x0, -0x84(%rbp)
movl -0x88(%rbp), %eax
andl $0x80000000, %eax       # imm = 0x80000000
orl $0x0, %eax
movl %eax, -0x88(%rbp)
movl -0x80(%rbp), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
orl $0x0, %eax
movl %eax, -0x80(%rbp)
movl $0x0, -0x7c(%rbp)
movl -0x80(%rbp), %eax
andl $0x80000000, %eax       # imm = 0x80000000
orl $0x0, %eax
movl %eax, -0x80(%rbp)
movq $0x0, -0x38(%rbp)
movl $0x0, -0x74(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x60(%rbp), %rax
jae 0x6dfe
movl -0x74(%rbp), %eax
movl %eax, -0x94(%rbp)
movq -0x50(%rbp), %rax
movq -0x38(%rbp), %rcx
movl (%rax,%rcx,4), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x6cdf
movl -0x74(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x6ce8
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
movl -0x94(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x6d13
movl -0x74(%rbp), %eax
cmpl -0x4(%rbp), %eax
jl 0x6d13
movq -0x50(%rbp), %rax
movq -0x38(%rbp), %rcx
movl (%rax,%rcx,4), %eax
shrl %eax
movl %eax, %eax
movq %rax, -0x70(%rbp)
jmp 0x6deb
movl -0x94(%rbp), %eax
cmpl -0x4(%rbp), %eax
jl 0x6de9
movl -0x74(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x6de9
movq -0x50(%rbp), %rax
movq -0x38(%rbp), %rcx
movl (%rax,%rcx,4), %eax
shrl %eax
movl %eax, %eax
subq -0x70(%rbp), %rax
movl %eax, -0x98(%rbp)
movl -0x98(%rbp), %eax
movl -0x7c(%rbp), %ecx
movl -0x80(%rbp), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
subl %edx, %ecx
cmpl %ecx, %eax
jbe 0x6d95
movq -0x80(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x70(%rbp), %rax
movl %eax, %ecx
movl -0x80(%rbp), %eax
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl $0x80000000, %eax       # imm = 0x80000000
orl %ecx, %eax
movl %eax, -0x80(%rbp)
movq -0x50(%rbp), %rax
movq -0x38(%rbp), %rcx
movl (%rax,%rcx,4), %eax
shrl %eax
movl %eax, -0x7c(%rbp)
jmp 0x6de7
movl -0x98(%rbp), %eax
movl -0x84(%rbp), %ecx
movl -0x88(%rbp), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
subl %edx, %ecx
cmpl %ecx, %eax
jbe 0x6de5
movq -0x70(%rbp), %rax
movl %eax, %ecx
movl -0x88(%rbp), %eax
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl $0x80000000, %eax       # imm = 0x80000000
orl %ecx, %eax
movl %eax, -0x88(%rbp)
movq -0x50(%rbp), %rax
movq -0x38(%rbp), %rcx
movl (%rax,%rcx,4), %eax
shrl %eax
movl %eax, -0x84(%rbp)
jmp 0x6de7
jmp 0x6de9
jmp 0x6deb
jmp 0x6ded
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x6caa
movl -0x7c(%rbp), %eax
movl -0x80(%rbp), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
subl %ecx, %eax
cmpl $0x0, %eax
jbe 0x6e9f
movslq -0x78(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x6e21
jmp 0x6e40
leaq 0x8565(%rip), %rdi      # 0xf38d
leaq 0x856a(%rip), %rsi      # 0xf399
movl $0x93, %edx
leaq 0x856c(%rip), %rcx      # 0xf3a7
callq 0x10b0
movl -0x80(%rbp), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
subl -0xc(%rbp), %esi
movq -0x68(%rbp), %rax
movslq -0x78(%rbp), %rcx
movl (%rax,%rcx,8), %edx
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %edx       # imm = 0x80000000
orl %esi, %edx
movl %edx, (%rax,%rcx,8)
movl -0x7c(%rbp), %edx
addl -0xc(%rbp), %edx
movq -0x68(%rbp), %rax
movslq -0x78(%rbp), %rcx
movl %edx, 0x4(%rax,%rcx,8)
movq -0x68(%rbp), %rax
movslq -0x78(%rbp), %rcx
movl (%rax,%rcx,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
orl $0x0, %edx
movl %edx, (%rax,%rcx,8)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x6eb9
movq -0x68(%rbp), %rax
movslq -0x78(%rbp), %rcx
movl (%rax,%rcx,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
orl $0x80000000, %edx       # imm = 0x80000000
movl %edx, (%rax,%rcx,8)
movq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x6ec3
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x6964
movq -0x50(%rbp), %rdi
callq 0x1040
leaq 0xc24c(%rip), %rax      # 0x13130
cmpl $0x3, (%rax)
jl 0x6f24
movq 0xc108(%rip), %rax      # 0x12ff8
movq (%rax), %rax
movq %rax, -0xb0(%rbp)
movb $0x0, %al
callq 0x1430
movq -0xb0(%rbp), %rdi
movq %rax, %rcx
movq -0x48(%rbp), %r8
leaq 0x84d9(%rip), %rsi      # 0xf3ef
leaq 0x8504(%rip), %rdx      # 0xf421
movb $0x0, %al
callq 0x1110
movq -0x68(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)