// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movq %rsi, 0x18(%rsp)
movq %rdi, 0x28(%rsp)
testl %r9d, %r9d
je 0x11d68
movl %r9d, %ebx
movq %r8, %r14
movq 0x70(%rsp), %rbp
jle 0x11ac3
movq %rcx, %r8
movl %ebx, %ecx
xorl %esi, %esi
xorl %eax, %eax
movzbl 0x4(%rbp,%rsi,8), %edi
addq %rdi, %rax
incq %rsi
cmpq %rsi, %rcx
jne 0x11aa7
testq %rax, %rax
js 0x11ac8
cvtsi2ss %rax, %xmm1
jmp 0x11add
xorps %xmm1, %xmm1
jmp 0x11ae0
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
cvtsi2ss %rax, %xmm1
addss %xmm1, %xmm1
movq %r8, %rcx
testl %edx, %edx
jle 0x11d68
cvtsi2ss %ebx, %xmm0
divss %xmm0, %xmm1
leal -0x1(%rbx), %eax
movl %eax, 0x14(%rsp)
movq 0x18(%rsp), %rax
decl %eax
movl %eax, 0x4(%rsp)
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
movsd 0x18517(%rip), %xmm2    # 0x2a028
divsd %xmm0, %xmm2
movsd %xmm2, 0x20(%rsp)
movl %edx, %eax
movq %rax, 0x30(%rsp)
xorl %r13d, %r13d
movss %xmm1, (%rsp)
movq %rcx, 0x8(%rsp)
leaq (,%r13,4), %r15
addq %r13, %r15
shlq $0x4, %r15
movl $0xbf800000, 0x44(%rcx,%r15) # imm = 0xBF800000
movl 0x4(%rcx,%r15), %eax
testl %eax, %eax
je 0x11d4c
addq %rcx, %r15
movl 0x3c(%r15), %ecx
movl %ecx, %edx
shll $0x15, %edx
sarl $0x1f, %edx
xorl %edi, %edi
btl $0xa, %ecx
setae %dil
movslq 0x28(%r15), %rsi
andl %eax, %edx
movslq %edx, %rdx
addq %rsi, %rdx
shll $0x4, %edi
addq %r14, %rdi
shlq $0x4, %rdx
movq -0x8(%rdx,%rdi), %rsi
cmpq $0x0, -0x10(%rdx,%rdi)
jns 0x11ba2
movq %rsi, %rdx
shrq $0x20, %rdx
movzbl %dl, %edx
notl %esi
addl 0x4(%rsp), %esi
addl %edx, %esi
xorl %edi, %edi
movl 0x14(%rsp), %r8d
cmpl %r8d, %edi
jg 0x11be2
movslq %r8d, %r9
movslq %edi, %r10
addq %r9, %r10
shrq %r10
movl (%rbp,%r10,8), %r9d
cmpl %r9d, %esi
jle 0x11bca
leal 0x1(%r10), %edi
jmp 0x11bd0
jge 0x11bd5
leal -0x1(%r10), %r8d
movb $0x1, %r9b
jmp 0x11bdb
xorl %r9d, %r9d
movl %r10d, %edx
testb %r9b, %r9b
jne 0x11ba9
jmp 0x11be7
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
testl %edx, %edx
js 0x11d3b
leal 0x1(%rdx), %r8d
movl $0x1, %esi
movl %edx, %edi
cmpl %ebx, %r8d
jge 0x11c90
cmpl $0x2, %eax
jl 0x11c90
movl %edx, %esi
leaq 0x8(,%rsi,8), %r9
addq %rbp, %r9
movl $0x1, %esi
movl $0x1, %r10d
movl %edx, %edi
btl $0xa, %ecx
jb 0x11c35
movl 0x28(%r15), %r11d
addl %r10d, %r11d
jmp 0x11c42
movl %r10d, %r11d
notl %r11d
addl %eax, %r11d
addl 0x28(%r15), %r11d
movslq %r11d, %r12
shlq $0x4, %r12
movq 0x8(%r14,%r12), %r11
cmpq $0x0, (%r14,%r12)
jns 0x11c6b
movq %r11, %r12
shrq $0x20, %r12
movzbl %r12b, %r12d
notl %r11d
addl 0x4(%rsp), %r11d
addl %r12d, %r11d
xorl %r12d, %r12d
cmpl (%r9), %r11d
cmovel %r8d, %edi
sete %r12b
addl %r12d, %esi
incl %r8d
cmpl %ebx, %r8d
jge 0x11c90
addl %r12d, %r10d
addq $0x8, %r9
cmpl %eax, %r10d
jl 0x11c26
movl 0x10(%r15), %ecx
xorps %xmm0, %xmm0
cvtsi2ss %ecx, %xmm0
subl %edx, %edi
leal 0x1(%rdi), %eax
ucomiss %xmm1, %xmm0
jbe 0x11cb8
xorps %xmm0, %xmm0
cvtsi2ssl 0x18(%r15), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x11cb8
addl $0x2, %edi
movl %edi, %eax
movq 0x18(%rsp), %rdx
subl %ecx, %edx
xorps %xmm0, %xmm0
cvtsi2ss %edx, %xmm0
ucomiss %xmm1, %xmm0
jbe 0x11cf2
movq 0x28(%rsp), %rcx
movq 0x20(%rcx), %rcx
movslq 0x8(%r15), %rdx
leaq (%rdx,%rdx,2), %rdx
movl 0x10(%rcx,%rdx,8), %ecx
subl 0x1c(%r15), %ecx
xorps %xmm0, %xmm0
cvtsi2ss %ecx, %xmm0
ucomiss %xmm1, %xmm0
jbe 0x11cf2
incl %eax
xorps %xmm0, %xmm0
cmpl %eax, %esi
jge 0x11d2e
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd 0x20(%rsp), %xmm1
callq 0x2110
movsd 0x1830a(%rip), %xmm1    # 0x2a028
subsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss (%rsp), %xmm1
movss %xmm0, 0x44(%r15)
movq 0x8(%rsp), %rcx
jmp 0x11d4c
leaq 0x239be(%rip), %rax     # 0x35700
cmpl $0x2, (%rax)
movq 0x8(%rsp), %rcx
jge 0x11d5c
incq %r13
cmpq 0x30(%rsp), %r13
jne 0x11b2f
jmp 0x11d68
callq 0x30ad
movss (%rsp), %xmm1
jmp 0x11d34
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop