// File: /workspace/github_c_makefile_star2_O1/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 0x1dd3c
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 0x1df02
movslq 0x14(%rbx), %rdx
movslq 0x10(%rbx), %rax
subq %rax, %rdx
movq 0x8(%rbx), %rax
subq (%rbx), %rax
cmpq %rdx, %rax
cmovll %edx, %eax
testl %ecx, %ecx
je 0x1de20
movl (%r14), %edx
movl %eax, %esi
imull %edx, %esi
subl %ecx, %esi
cvtsi2sd %esi, %xmm1
addl 0x4(%r14), %edx
cvtsi2sd %edx, %xmm0
divsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd %xmm0, %xmm1
movsd 0xa6fa(%rip), %xmm4     # 0x28498
movapd %xmm4, %xmm3
subsd %xmm1, %xmm3
movss 0xac(%r14), %xmm1
xorps %xmm2, %xmm2
ucomiss %xmm2, %xmm1
jbe 0x1de24
xorps %xmm2, %xmm2
cvtsi2ss %eax, %xmm2
ucomiss %xmm2, %xmm1
ja 0x1ddee
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
mulsd %xmm3, %xmm3
movl 0x1c(%rbx), %eax
subl %ebp, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0xa9aa(%rip), %xmm0     # 0x287b0
xorps %xmm1, %xmm1
cvtsi2sdl (%r14), %xmm1
mulsd %xmm4, %xmm3
divsd %xmm1, %xmm0
mulsd %xmm3, %xmm0
mulsd %xmm3, %xmm0
jmp 0x1de8e
xorl %ebp, %ebp
jmp 0x1de9a
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
divsd %xmm1, %xmm0
subsd %xmm0, %xmm4
mulsd 0xa966(%rip), %xmm4     # 0x287a8
movsd %xmm4, (%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x38(%rbx), %xmm0
movsd %xmm3, 0x8(%rsp)
callq 0x3250
movsd 0x8(%rsp), %xmm1
mulsd (%rsp), %xmm0
addsd 0x7933(%rip), %xmm0     # 0x257a0
cvttsd2si %xmm0, %ebp
movsd 0xa927(%rip), %xmm0     # 0x287a0
ucomisd %xmm1, %xmm0
jbe 0x1de9a
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
addsd 0x790a(%rip), %xmm0     # 0x257a0
cvttsd2si %xmm0, %ebp
movl 0x30(%rbx), %eax
testl %eax, %eax
jle 0x1dec5
incl %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
callq 0x3250
mulsd 0xa901(%rip), %xmm0     # 0x287b8
addsd 0x78e1(%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 0xa5aa(%rip), %xmm2     # 0x28498
subsd %xmm1, %xmm2
mulsd %xmm0, %xmm2
addsd 0x78a2(%rip), %xmm2     # 0x257a0
cvttsd2si %xmm2, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq