// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
movq %rdi, 0x38(%rsp)
movq %r9, 0x10(%rsp)
testl %r9d, %r9d
je 0x11cdd
movq %r8, %r14
movq %rcx, %rbx
movl %esi, %r15d
movq 0x80(%rsp), %rbp
jle 0x11a20
movl 0x10(%rsp), %ecx
xorl %esi, %esi
xorl %eax, %eax
movzbl 0x4(%rbp,%rsi,8), %edi
addq %rdi, %rax
incq %rsi
cmpq %rsi, %rcx
jne 0x11a04
testq %rax, %rax
js 0x11a25
cvtsi2ss %rax, %xmm1
jmp 0x11a3a
xorps %xmm1, %xmm1
jmp 0x11a3a
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
cvtsi2ss %rax, %xmm1
addss %xmm1, %xmm1
testl %edx, %edx
jle 0x11cdd
movq 0x10(%rsp), %rax
cvtsi2ss %eax, %xmm0
divss %xmm0, %xmm1
leal -0x1(%rax), %r10d
leal -0x1(%r15), %eax
movl %eax, 0x1c(%rsp)
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
movsd 0x195be(%rip), %xmm2    # 0x2b028
divsd %xmm0, %xmm2
movsd %xmm2, 0x30(%rsp)
movl %edx, %eax
movq %rax, 0x40(%rsp)
xorl %r12d, %r12d
movss %xmm1, 0x18(%rsp)
movl %r10d, 0xc(%rsp)
movq %rbx, 0x28(%rsp)
movq %r15, 0x20(%rsp)
leaq (%r12,%r12,4), %r13
shlq $0x4, %r13
movl $0xbf800000, 0x44(%rbx,%r13) # imm = 0xBF800000
movl 0x4(%rbx,%r13), %eax
testl %eax, %eax
je 0x11b3f
addq %rbx, %r13
movl 0x28(%r13), %ecx
movl 0x3c(%r13), %edx
movl %edx, %esi
shll $0x15, %esi
sarl $0x1f, %esi
xorl %edi, %edi
btl $0xa, %edx
setae %dil
andl %eax, %esi
addl %ecx, %esi
shll $0x4, %edi
addq %r14, %rdi
movslq %esi, %r8
shlq $0x4, %r8
movq -0x8(%r8,%rdi), %rsi
cmpq $0x0, -0x10(%r8,%rdi)
jns 0x11aff
movq %rsi, %rdi
shrq $0x20, %rdi
movzbl %dil, %edi
notl %esi
addl 0x1c(%rsp), %esi
addl %edi, %esi
cmpl $0x0, 0x10(%rsp)
jle 0x11b2f
xorl %edi, %edi
movl %r10d, %r11d
movslq %edi, %r9
movslq %r11d, %r8
addq %r9, %r8
shrq %r8
cmpl (%rbp,%r8,8), %esi
jle 0x11b24
leal 0x1(%r8), %edi
jmp 0x11b2a
jge 0x11b52
leal -0x1(%r8), %r11d
cmpl %r11d, %edi
jle 0x11b0b
leaq 0x24bca(%rip), %rax     # 0x36700
cmpl $0x2, (%rax)
jge 0x11bf5
incq %r12
cmpq 0x40(%rsp), %r12
jne 0x11a93
jmp 0x11cdd
testl %r8d, %r8d
js 0x11b2f
leal 0x1(%r8), %r9d
movl $0x1, %esi
cmpl 0x10(%rsp), %r9d
jge 0x11c0a
movl %r8d, %r9d
cmpl $0x2, %eax
jl 0x11c0d
movl %r8d, %r10d
andl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
incq %r10
addl %r11d, %edi
shrl %edi
addl $0x2, %edi
movl $0x1, %r11d
movl %r8d, %r9d
movl %r11d, %ebx
notl %ebx
addl %eax, %ebx
btl $0xa, %edx
cmovael %r11d, %ebx
addl %ecx, %ebx
movslq %ebx, %r15
shlq $0x4, %r15
movq 0x8(%r14,%r15), %rbx
cmpq $0x0, (%r14,%r15)
jns 0x11bcd
movq %rbx, %r15
shrq $0x20, %r15
movzbl %r15b, %r15d
notl %ebx
addl 0x1c(%rsp), %ebx
addl %r15d, %ebx
xorl %r15d, %r15d
cmpl (%rbp,%r10,8), %ebx
sete %r15b
cmovel %r10d, %r9d
addl %r15d, %esi
cmpl 0x10(%rsp), %edi
jge 0x11c0d
addl %r15d, %r11d
incq %r10
incl %edi
cmpl %eax, %r11d
jl 0x11b95
jmp 0x11c0d
callq 0x30a3
movl 0xc(%rsp), %r10d
movss 0x18(%rsp), %xmm1
jmp 0x11b3f
movl %r8d, %r9d
movl 0x10(%r13), %ecx
xorps %xmm0, %xmm0
cvtsi2ss %ecx, %xmm0
subl %r8d, %r9d
leal 0x1(%r9), %eax
ucomiss %xmm1, %xmm0
jbe 0x11c45
xorps %xmm0, %xmm0
cvtsi2ssl 0x18(%r13), %xmm0
ucomiss %xmm1, %xmm0
movq 0x28(%rsp), %rbx
movq 0x20(%rsp), %r15
jbe 0x11c4f
addl $0x2, %r9d
movl %r9d, %eax
jmp 0x11c4f
movq 0x28(%rsp), %rbx
movq 0x20(%rsp), %r15
movl %r15d, %edx
subl %ecx, %edx
xorps %xmm0, %xmm0
cvtsi2ss %edx, %xmm0
ucomiss %xmm1, %xmm0
jbe 0x11c8e
movq 0x38(%rsp), %rcx
movq 0x20(%rcx), %rcx
movslq 0x8(%r13), %rdx
leaq (%rdx,%rdx,2), %rdx
movl 0x10(%rcx,%rdx,8), %ecx
subl 0x1c(%r13), %ecx
xorps %xmm0, %xmm0
cvtsi2ss %ecx, %xmm0
ucomiss %xmm1, %xmm0
movl 0xc(%rsp), %r10d
jbe 0x11c93
incl %eax
jmp 0x11c93
movl 0xc(%rsp), %r10d
xorps %xmm0, %xmm0
cmpl %eax, %esi
jge 0x11cd2
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd 0x30(%rsp), %xmm1
callq 0x2110
movl 0xc(%rsp), %r10d
movsd 0x19367(%rip), %xmm1    # 0x2b028
subsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss 0x18(%rsp), %xmm1
movss %xmm0, 0x44(%r13)
jmp 0x11b3f
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq