// File: /workspace/github_c_makefile_star2_O2/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 0x19f65
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 0x1a109
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 0x1a03e
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
cvtsi2sd %edx, %xmm0
divsd %xmm0, %xmm1
movsd 0x9502(%rip), %xmm4     # 0x234c8
movapd %xmm4, %xmm3
subsd %xmm1, %xmm3
movss 0xac(%r14), %xmm1
xorps %xmm2, %xmm2
ucomiss %xmm2, %xmm1
jbe 0x1a042
cvtsi2ss %edx, %xmm2
ucomiss %xmm2, %xmm1
ja 0x1a016
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
cvtsi2sd %ecx, %xmm0
mulsd 0x9808(%rip), %xmm0     # 0x23830
cvtsi2sd %eax, %xmm1
mulsd %xmm4, %xmm3
divsd %xmm1, %xmm0
mulsd %xmm3, %xmm0
mulsd %xmm3, %xmm0
jmp 0x1a0a0
xorl %ebp, %ebp
jmp 0x1a0ac
cvtsi2sd %ebp, %xmm0
cvtsi2sd %ecx, %xmm1
divsd %xmm1, %xmm0
subsd %xmm0, %xmm4
mulsd 0x97ce(%rip), %xmm4     # 0x23828
movsd %xmm4, (%rsp)
cvtsi2sdl 0x38(%rbx), %xmm0
movsd %xmm3, 0x8(%rsp)
callq 0x3250
movsd 0x8(%rsp), %xmm1
mulsd (%rsp), %xmm0
addsd 0x671e(%rip), %xmm0     # 0x207a0
cvttsd2si %xmm0, %ebp
movsd 0x9792(%rip), %xmm0     # 0x23820
ucomisd %xmm1, %xmm0
jbe 0x1a0ac
cvtsi2sd %ebp, %xmm0
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
addsd 0x66f8(%rip), %xmm0     # 0x207a0
cvttsd2si %xmm0, %ebp
movl 0x30(%rbx), %eax
testl %eax, %eax
jle 0x1a0d4
incl %eax
cvtsi2sd %eax, %xmm0
callq 0x3250
mulsd 0x9772(%rip), %xmm0     # 0x23838
addsd 0x66d2(%rip), %xmm0     # 0x207a0
cvttsd2si %xmm0, %eax
subl %eax, %ebp
cmpl $0x3c, %ebp
pushq $0x3c
popq %rax
cmovll %ebp, %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovgl %eax, %ecx
cvtsi2sd %ecx, %xmm0
cvtss2sd 0x50(%rbx), %xmm1
movsd 0x93d3(%rip), %xmm2     # 0x234c8
subsd %xmm1, %xmm2
mulsd %xmm0, %xmm2
addsd 0x669b(%rip), %xmm2     # 0x207a0
cvttsd2si %xmm2, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq