// File: /workspace/github_c_makefile_star2_O2/lh3[P]minimap2/esterr.c
// Function: mm_est_err
void mm_est_err(const mm_idx_t *mi, int qlen, int n_regs, mm_reg1_t *regs, const mm128_t *a, int32_t n, const uint64_t *mini_pos)
{
	int i;
	uint64_t sum_k = 0;
	float avg_k;

	if (n == 0) return;
	for (i = 0; i < n; ++i)
		sum_k += mini_pos[i] >> 32 & 0xff;
	avg_k = (float)sum_k / n;

	for (i = 0; i < n_regs; ++i) {
		mm_reg1_t *r = &regs[i];
		int32_t st, en, j, k, n_match, n_tot, l_ref;
		r->div = -1.0f;
		if (r->cnt == 0) continue;
		st = en = get_mini_idx(qlen, r->rev? &a[r->as + r->cnt - 1] : &a[r->as], n, mini_pos);
		if (st < 0) {
			if (mm_verbose >= 2)
				fprintf(stderr, "[WARNING] logic inconsistency in mm_est_err(). Please contact the developer.\n");
			continue;
		}
		l_ref = mi->seq[r->rid].len;
		for (k = 1, j = st + 1, n_match = 1; j < n && k < r->cnt; ++j) {
			int32_t x;
			x = get_for_qpos(qlen, r->rev? &a[r->as + r->cnt - 1 - k] : &a[r->as + k]);
			if (x == (int32_t)mini_pos[j])
				++k, en = j, ++n_match;
		}
		n_tot = en - st + 1;
		if (r->qs > avg_k && r->rs > avg_k) ++n_tot;
		if (qlen - r->qs > avg_k && l_ref - r->re > avg_k) ++n_tot;
		r->div = n_match >= n_tot? 0.0f : (float)(1.0 - pow((double)n_match / n_tot, 1.0 / avg_k));
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %esi, 0x14(%rsp)
movq %rdi, 0x58(%rsp)
testl %r9d, %r9d
je 0x1011b
movl %r9d, %r14d
movq %r8, %r15
movq %rcx, %rbx
movq 0xa0(%rsp), %r13
xorl %ecx, %ecx
testl %r9d, %r9d
movl $0x0, %edi
cmovgl %r9d, %edi
xorl %eax, %eax
cmpq %rcx, %rdi
je 0xfe7c
movzbl 0x4(%r13,%rcx,8), %esi
addq %rsi, %rax
incq %rcx
jmp 0xfe69
testq %rax, %rax
js 0xfe88
cvtsi2ss %rax, %xmm1
jmp 0xfe9d
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
cvtsi2ss %rax, %xmm1
addss %xmm1, %xmm1
cvtsi2ss %r14d, %xmm0
divss %xmm0, %xmm1
movss %xmm1, 0xc(%rsp)
cvtss2sd %xmm1, %xmm0
movsd 0x16158(%rip), %xmm1    # 0x26010
divsd %xmm0, %xmm1
movsd %xmm1, 0x50(%rsp)
xorl %eax, %eax
testl %edx, %edx
cmovlel %eax, %edx
movq %rdx, 0x60(%rsp)
movq %rbx, 0x28(%rsp)
cmpq 0x60(%rsp), %rax
je 0x1011b
imulq $0x50, %rax, %rcx
movl $0xbf800000, 0x44(%rbx,%rcx) # imm = 0xBF800000
movl 0x4(%rbx,%rcx), %r12d
testl %r12d, %r12d
je 0x1003b
movq %rax, 0x30(%rsp)
addq %rbx, %rcx
movl 0x28(%rcx), %edx
movq %rcx, 0x18(%rsp)
movl 0x3c(%rcx), %esi
movl %esi, %eax
shll $0x15, %eax
sarl $0x1f, %eax
xorl %ecx, %ecx
movl %esi, 0x48(%rsp)
btl $0xa, %esi
setae %cl
andl %r12d, %eax
movl %edx, 0x4c(%rsp)
addl %edx, %eax
shll $0x4, %ecx
addq %r15, %rcx
cltq
shlq $0x4, %rax
leaq (%rax,%rcx), %rsi
addq $-0x10, %rsi
movl 0x14(%rsp), %edi
callq 0x1012a
xorl %ecx, %ecx
movl %r14d, %edx
leal -0x1(%rdx), %esi
movslq %esi, %rsi
cmpl %edx, %ecx
jge 0x10025
movslq %ecx, %rbx
addq %rsi, %rbx
shrq %rbx
cmpl (%r13,%rbx,8), %eax
jle 0xff6e
leal 0x1(%rbx), %ecx
jmp 0xff51
movl %ebx, %edx
jl 0xff4b
testl %ebx, %ebx
js 0x10025
movq %r15, 0x20(%rsp)
movl %r14d, 0x10(%rsp)
movq 0x58(%rsp), %rax
movq 0x20(%rax), %rax
movq 0x18(%rsp), %rcx
movslq 0x8(%rcx), %rcx
imulq $0x18, %rcx, %rcx
movl 0x10(%rax,%rcx), %eax
movl %eax, 0x3c(%rsp)
movl %ebx, %r15d
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
movl %ebx, %edx
pushq $0x1
popq %rax
movl %eax, %ebp
movl %eax, %esi
movl %r12d, 0x40(%rsp)
leaq 0x1(%r15), %r14
cmpl 0x10(%rsp), %r14d
jge 0x10064
cmpl %r12d, %ebp
jge 0x10064
movl %ebp, %eax
notl %eax
addl %r12d, %eax
btl $0xa, 0x48(%rsp)
cmovael %ebp, %eax
addl 0x4c(%rsp), %eax
movl %esi, 0x44(%rsp)
movslq %eax, %rsi
shlq $0x4, %rsi
addq 0x20(%rsp), %rsi
movl 0x14(%rsp), %edi
movq %rdx, %r12
callq 0x1012a
movq %r12, %rdx
movl 0x44(%rsp), %esi
movl 0x40(%rsp), %r12d
xorl %ecx, %ecx
cmpl 0x8(%r13,%r15,8), %eax
cmovel %r14d, %edx
sete %cl
addl %ecx, %ebp
addl %ecx, %esi
movq %r14, %r15
jmp 0xffba
leaq 0x226d4(%rip), %rax     # 0x32700
cmpl $0x2, (%rax)
movq 0x28(%rsp), %rbx
movq 0x30(%rsp), %rax
jge 0x10043
incq %rax
jmp 0xfed3
movq 0x21fae(%rip), %rax     # 0x31ff8
movq (%rax), %rcx
leaq 0x18f59(%rip), %rdi     # 0x28fad
pushq $0x4d
popq %rsi
pushq $0x1
popq %rdx
callq 0x23f0
jmp 0x10111
movq 0x18(%rsp), %rdi
movl 0x10(%rdi), %ecx
cvtsi2ss %ecx, %xmm0
subl %ebx, %edx
leal 0x1(%rdx), %eax
movss 0xc(%rsp), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x100a0
cvtsi2ssl 0x18(%rdi), %xmm0
ucomiss %xmm1, %xmm0
movl 0x10(%rsp), %r14d
movq 0x20(%rsp), %r15
movq 0x28(%rsp), %rbx
jbe 0x100af
addl $0x2, %edx
movl %edx, %eax
jmp 0x100af
movl 0x10(%rsp), %r14d
movq 0x20(%rsp), %r15
movq 0x28(%rsp), %rbx
movl 0x14(%rsp), %edx
subl %ecx, %edx
cvtsi2ss %edx, %xmm0
ucomiss 0xc(%rsp), %xmm0
jbe 0x100d9
movl 0x3c(%rsp), %ecx
movq 0x18(%rsp), %rdx
subl 0x1c(%rdx), %ecx
cvtsi2ss %ecx, %xmm0
ucomiss 0xc(%rsp), %xmm0
jbe 0x100d9
incl %eax
xorps %xmm0, %xmm0
cmpl %eax, %esi
jge 0x10107
cvtsi2sd %esi, %xmm0
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd 0x50(%rsp), %xmm1
callq 0x2110
movsd 0x15f11(%rip), %xmm1    # 0x26010
subsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
movq 0x18(%rsp), %rax
movss %xmm0, 0x44(%rax)
movq 0x30(%rsp), %rax
jmp 0x1003b
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq