// File: /workspace/github_c_makefile_star2_O3/ToniWestbrook[P]paladin/bwamem.c
// Function: mem_approx_mapq_se
int mem_approx_mapq_se(const mem_opt_t *opt, const mem_alnreg_t *a)
{
	int mapq, l, sub = a->sub? a->sub : opt->min_seed_len * opt->a;
	double identity;
	sub = a->csub > sub? a->csub : sub;
	if (sub >= a->score) return 0;
	l = a->qe - a->qb > a->re - a->rb? a->qe - a->qb : a->re - a->rb;
	identity = 1. - (double)(l * opt->a - a->score) / (opt->a + opt->b) / l;
	if (a->score == 0) {
		mapq = 0;
	} else if (opt->mapQ_coef_len > 0) {
		double tmp;
		tmp = l < opt->mapQ_coef_len? 1. : opt->mapQ_coef_fac / log(l);
		tmp *= identity * identity;
		mapq = (int)(13.01 * (a->score - sub) / opt->a * tmp * tmp + .499);
	} else {
		mapq = (int)(MEM_MAPQ_COEF * (1. - (double)sub / a->score) * log(a->seedcov) + .499);
		mapq = identity < 0.95? (int)(mapq * identity * identity + .499) : mapq;
	}
	if (a->sub_n > 0) mapq -= (int)(4.343 * log(a->sub_n+1) + .499);
	if (mapq > 60) mapq = 60;
	if (mapq < 0) mapq = 0;
	mapq = (int)(mapq * (1. - a->frac_rep) + .499);
	return mapq;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movl 0x24(%rsi), %ebp
testl %ebp, %ebp
jne 0x1e426
movl (%r14), %ebp
imull 0x78(%r14), %ebp
movl 0x1c(%rbx), %ecx
movl 0x2c(%rbx), %eax
cmpl %ebp, %eax
cmovgl %eax, %ebp
xorl %eax, %eax
cmpl %ecx, %ebp
jge 0x1e5f0
movslq 0x14(%rbx), %rax
movslq 0x10(%rbx), %rdx
subq %rdx, %rax
movq 0x8(%rbx), %rdx
subq (%rbx), %rdx
cmpq %rax, %rdx
cmovll %eax, %edx
testl %ecx, %ecx
je 0x1e50e
movl (%r14), %eax
movl %edx, %esi
imull %eax, %esi
subl %ecx, %esi
cvtsi2sd %esi, %xmm1
movl 0x4(%r14), %esi
addl %eax, %esi
cvtsi2sd %esi, %xmm0
divsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
divsd %xmm0, %xmm1
movsd 0xa0a6(%rip), %xmm4     # 0x28530
movapd %xmm4, %xmm3
subsd %xmm1, %xmm3
movss 0xac(%r14), %xmm1
xorps %xmm2, %xmm2
ucomiss %xmm2, %xmm1
jbe 0x1e512
xorps %xmm2, %xmm2
cvtsi2ss %edx, %xmm2
ucomiss %xmm2, %xmm1
ja 0x1e4e0
xorps %xmm1, %xmm1
cvtsi2sdl 0xb0(%r14), %xmm1
movsd %xmm1, (%rsp)
movsd %xmm3, 0x8(%rsp)
callq 0x3250
movsd (%rsp), %xmm4
movsd 0x8(%rsp), %xmm3
divsd %xmm0, %xmm4
movl 0x1c(%rbx), %ecx
movl (%r14), %eax
mulsd %xmm3, %xmm3
subl %ebp, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
mulsd 0xa3ab(%rip), %xmm0     # 0x288a0
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd %xmm4, %xmm3
divsd %xmm1, %xmm0
mulsd %xmm3, %xmm0
mulsd %xmm3, %xmm0
jmp 0x1e57c
xorl %ebp, %ebp
jmp 0x1e588
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
divsd %xmm1, %xmm0
subsd %xmm0, %xmm4
mulsd 0xa368(%rip), %xmm4     # 0x28898
movsd %xmm4, (%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x38(%rbx), %xmm0
movsd %xmm3, 0x8(%rsp)
callq 0x3250
movsd 0x8(%rsp), %xmm1
mulsd (%rsp), %xmm0
addsd 0x7245(%rip), %xmm0     # 0x257a0
cvttsd2si %xmm0, %ebp
movsd 0xa329(%rip), %xmm0     # 0x28890
ucomisd %xmm1, %xmm0
jbe 0x1e588
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
addsd 0x721c(%rip), %xmm0     # 0x257a0
cvttsd2si %xmm0, %ebp
movl 0x30(%rbx), %eax
testl %eax, %eax
jle 0x1e5b3
incl %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
callq 0x3250
mulsd 0xa303(%rip), %xmm0     # 0x288a8
addsd 0x71f3(%rip), %xmm0     # 0x257a0
cvttsd2si %xmm0, %eax
subl %eax, %ebp
cmpl $0x3c, %ebp
movl $0x3c, %eax
cmovll %ebp, %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovgl %eax, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x50(%rbx), %xmm1
movsd 0x9f54(%rip), %xmm2     # 0x28530
subsd %xmm1, %xmm2
mulsd %xmm0, %xmm2
addsd 0x71b4(%rip), %xmm2     # 0x257a0
cvttsd2si %xmm2, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq