// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x24(%rax)
je 0x2adb6
movq -0x18(%rbp), %rax
movl 0x24(%rax), %eax
movl %eax, -0x3c(%rbp)
jmp 0x2adc7
movq -0x10(%rbp), %rax
movl 0x78(%rax), %eax
movq -0x10(%rbp), %rcx
imull (%rcx), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x18(%rbp), %rax
movl 0x2c(%rax), %eax
cmpl -0x24(%rbp), %eax
jle 0x2ade5
movq -0x18(%rbp), %rax
movl 0x2c(%rax), %eax
movl %eax, -0x40(%rbp)
jmp 0x2adeb
movl -0x24(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jl 0x2ae09
movl $0x0, -0x4(%rbp)
jmp 0x2b0c1
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x18(%rbp), %rcx
subl 0x10(%rcx), %eax
cltq
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq -0x18(%rbp), %rdx
subq (%rdx), %rcx
cmpq %rcx, %rax
jle 0x2ae43
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x18(%rbp), %rcx
subl 0x10(%rcx), %eax
cltq
movq %rax, -0x48(%rbp)
jmp 0x2ae56
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
subq (%rcx), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x10(%rbp), %rcx
imull (%rcx), %eax
movq -0x18(%rbp), %rcx
subl 0x1c(%rcx), %eax
cvtsi2sd %eax, %xmm1
movq -0x10(%rbp), %rax
movl (%rax), %eax
movq -0x10(%rbp), %rcx
addl 0x4(%rcx), %eax
cvtsi2sd %eax, %xmm0
divsd %xmm0, %xmm1
cvtsi2sdl -0x20(%rbp), %xmm0
divsd %xmm0, %xmm1
movsd 0xf4f0(%rip), %xmm0     # 0x3a388
subsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
jne 0x2aeb7
movl $0x0, -0x1c(%rbp)
jmp 0x2b02b
movq -0x10(%rbp), %rax
movss 0xac(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x2af8a
cvtsi2ssl -0x20(%rbp), %xmm1
movq -0x10(%rbp), %rax
movss 0xac(%rax), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x2aef4
movsd 0xf49b(%rip), %xmm0     # 0x3a388
movsd %xmm0, -0x50(%rbp)
jmp 0x2af20
movq -0x10(%rbp), %rax
cvtsi2sdl 0xb0(%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
cvtsi2sdl -0x20(%rbp), %xmm0
callq 0x3240
movaps %xmm0, %xmm1
movsd -0x58(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x30(%rbp), %xmm0
mulsd -0x30(%rbp), %xmm0
mulsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %eax
subl -0x24(%rbp), %eax
cvtsi2sd %eax, %xmm1
movsd 0xf74c(%rip), %xmm0     # 0x3a6a0
mulsd %xmm1, %xmm0
movq -0x10(%rbp), %rax
cvtsi2sdl (%rax), %xmm1
divsd %xmm1, %xmm0
mulsd -0x38(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0xc82e(%rip), %xmm1     # 0x377a8
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x1c(%rbp)
jmp 0x2b029
cvtsi2sdl -0x24(%rbp), %xmm0
movq -0x18(%rbp), %rax
cvtsi2sdl 0x1c(%rax), %xmm1
divsd %xmm1, %xmm0
movsd 0xf3e4(%rip), %xmm1     # 0x3a388
subsd %xmm0, %xmm1
movsd 0xf6e8(%rip), %xmm0     # 0x3a698
mulsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x18(%rbp), %rax
cvtsi2sdl 0x38(%rax), %xmm0
callq 0x3240
movaps %xmm0, %xmm1
movsd -0x60(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd 0xc7cd(%rip), %xmm1     # 0x377a8
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x1c(%rbp)
movsd 0xf6a2(%rip), %xmm0     # 0x3a690
ucomisd -0x30(%rbp), %xmm0
jbe 0x2b01d
cvtsi2sdl -0x1c(%rbp), %xmm0
mulsd -0x30(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0xc798(%rip), %xmm1     # 0x377a8
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x64(%rbp)
jmp 0x2b023
movl -0x1c(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x2b02b
movq -0x18(%rbp), %rax
cmpl $0x0, 0x30(%rax)
jle 0x2b06c
movq -0x18(%rbp), %rax
movl 0x30(%rax), %eax
addl $0x1, %eax
cvtsi2sd %eax, %xmm0
callq 0x3240
movsd 0xf658(%rip), %xmm1     # 0x3a6a8
mulsd %xmm1, %xmm0
movsd 0xc74c(%rip), %xmm1     # 0x377a8
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movl -0x1c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x1c(%rbp)
cmpl $0x3c, -0x1c(%rbp)
jle 0x2b079
movl $0x3c, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x2b086
movl $0x0, -0x1c(%rbp)
cvtsi2sdl -0x1c(%rbp), %xmm0
movq -0x18(%rbp), %rax
movss 0x50(%rax), %xmm1
cvtss2sd %xmm1, %xmm2
movsd 0xf2e8(%rip), %xmm1     # 0x3a388
subsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd 0xc6f8(%rip), %xmm1     # 0x377a8
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)