// File: /workspace/github_c_makefile_star2_O0/lh3[P]minigraph/gcmisc.c
// Function: mg_gchain_set_mapq
void mg_gchain_set_mapq(void *km, mg_gchains_t *gcs, int qlen, int max_mini, int min_gc_score)
{
	static const float q_coef = 40.0f;
	int64_t sum_sc = 0;
	float uniq_ratio, r_sc, r_cnt;
	int i, t_sc, t_cnt;
	if (gcs == 0 || gcs->n_gc == 0) return;
	t_sc = qlen < 100? qlen : 100;
	t_cnt = max_mini < 10? max_mini : 10;
	if (t_cnt < 5) t_cnt = 5;
	r_sc = 1.0 / t_sc;
	r_cnt = 1.0 / t_cnt;
	for (i = 0; i < gcs->n_gc; ++i)
		if (gcs->gc[i].parent == gcs->gc[i].id)
			sum_sc += gcs->gc[i].score;
	uniq_ratio = (float)sum_sc / (sum_sc + gcs->rep_len);
	for (i = 0; i < gcs->n_gc; ++i) {
		mg_gchain_t *r = &gcs->gc[i];
		if (r->parent == r->id) {
			int mapq, subsc;
			float pen_s1 = (r->score > t_sc? 1.0f : r->score * r_sc) * uniq_ratio;
			float x, pen_cm = r->n_anchor > t_cnt? 1.0f : r->n_anchor * r_cnt;
			pen_cm = pen_s1 < pen_cm? pen_s1 : pen_cm;
			subsc = r->subsc > min_gc_score? r->subsc : min_gc_score;
			x = (float)subsc / r->score;
			mapq = (int)(pen_cm * q_coef * (1.0f - x) * logf(r->score));
			mapq -= (int)(4.343f * logf(r->n_sub + 1) + .499f);
			mapq = mapq > 0? mapq : 0;
			if (r->score > subsc && mapq == 0) mapq = 1;
			r->mapq = mapq < 60? mapq : 60;
		} else r->mapq = 0;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movq $0x0, -0x28(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x2c116
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0x2c11b
jmp 0x2c44e
cmpl $0x64, -0x14(%rbp)
jge 0x2c129
movl -0x14(%rbp), %eax
movl %eax, -0x60(%rbp)
jmp 0x2c133
movl $0x64, %eax
movl %eax, -0x60(%rbp)
jmp 0x2c133
movl -0x60(%rbp), %eax
movl %eax, -0x3c(%rbp)
cmpl $0xa, -0x18(%rbp)
jge 0x2c147
movl -0x18(%rbp), %eax
movl %eax, -0x64(%rbp)
jmp 0x2c151
movl $0xa, %eax
movl %eax, -0x64(%rbp)
jmp 0x2c151
movl -0x64(%rbp), %eax
movl %eax, -0x40(%rbp)
cmpl $0x5, -0x40(%rbp)
jge 0x2c164
movl $0x5, -0x40(%rbp)
cvtsi2sdl -0x3c(%rbp), %xmm1
movsd 0x10ea7(%rip), %xmm0    # 0x3d018
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x30(%rbp)
cvtsi2sdl -0x40(%rbp), %xmm1
movsd 0x10e8d(%rip), %xmm0    # 0x3d018
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x2c204
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x38(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movslq -0x38(%rbp), %rdx
imulq $0x68, %rdx, %rdx
addq %rdx, %rcx
cmpl (%rcx), %eax
jne 0x2c1f7
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x38(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movslq 0x14(%rax), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x2c1f9
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x2c19f
cvtsi2ssq -0x28(%rbp), %xmm0
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x14(%rcx), %rcx
addq %rcx, %rax
cvtsi2ss %rax, %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x2c(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x2c44e
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x38(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x48(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x2c42b
movq -0x48(%rbp), %rax
movl 0x14(%rax), %eax
cmpl -0x3c(%rbp), %eax
jle 0x2c283
movss 0x10864(%rip), %xmm0    # 0x3cae0
movss %xmm0, -0x68(%rbp)
jmp 0x2c296
movq -0x48(%rbp), %rax
cvtsi2ssl 0x14(%rax), %xmm0
mulss -0x30(%rbp), %xmm0
movss %xmm0, -0x68(%rbp)
movss -0x68(%rbp), %xmm0
mulss -0x2c(%rbp), %xmm0
movss %xmm0, -0x54(%rbp)
movq -0x48(%rbp), %rax
movl 0x10(%rax), %eax
cmpl -0x40(%rbp), %eax
jle 0x2c2c0
movss 0x10827(%rip), %xmm0    # 0x3cae0
movss %xmm0, -0x6c(%rbp)
jmp 0x2c2d3
movq -0x48(%rbp), %rax
cvtsi2ssl 0x10(%rax), %xmm0
mulss -0x34(%rbp), %xmm0
movss %xmm0, -0x6c(%rbp)
movss -0x6c(%rbp), %xmm0
movss %xmm0, -0x5c(%rbp)
movss -0x54(%rbp), %xmm1
movss -0x5c(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x2c2f8
movss -0x54(%rbp), %xmm0
movss %xmm0, -0x70(%rbp)
jmp 0x2c302
movss -0x5c(%rbp), %xmm0
movss %xmm0, -0x70(%rbp)
movss -0x70(%rbp), %xmm0
movss %xmm0, -0x5c(%rbp)
movq -0x48(%rbp), %rax
movl 0x3c(%rax), %eax
cmpl -0x1c(%rbp), %eax
jle 0x2c324
movq -0x48(%rbp), %rax
movl 0x3c(%rax), %eax
movl %eax, -0x74(%rbp)
jmp 0x2c32a
movl -0x1c(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
movl %eax, -0x50(%rbp)
cvtsi2ssl -0x50(%rbp), %xmm0
movq -0x48(%rbp), %rax
cvtsi2ssl 0x14(%rax), %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x58(%rbp)
movss 0x116c9(%rip), %xmm0    # 0x3da18
mulss -0x5c(%rbp), %xmm0
movss 0x10784(%rip), %xmm1    # 0x3cae0
subss -0x58(%rbp), %xmm1
mulss %xmm1, %xmm0
movss %xmm0, -0x78(%rbp)
movq -0x48(%rbp), %rax
cvtsi2ssl 0x14(%rax), %xmm0
callq 0x21d0
movaps %xmm0, %xmm1
movss -0x78(%rbp), %xmm0
mulss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movl %eax, -0x4c(%rbp)
movq -0x48(%rbp), %rax
movl 0x40(%rax), %eax
addl $0x1, %eax
cvtsi2ss %eax, %xmm0
callq 0x21d0
movss 0x1166a(%rip), %xmm1    # 0x3da10
mulss %xmm1, %xmm0
movss 0x11662(%rip), %xmm1    # 0x3da14
addss %xmm1, %xmm0
cvttss2si %xmm0, %ecx
movl -0x4c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jle 0x2c3d0
movl -0x4c(%rbp), %eax
movl %eax, -0x7c(%rbp)
jmp 0x2c3d7
xorl %eax, %eax
movl %eax, -0x7c(%rbp)
jmp 0x2c3d7
movl -0x7c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movq -0x48(%rbp), %rax
movl 0x14(%rax), %eax
cmpl -0x50(%rbp), %eax
jle 0x2c3f6
cmpl $0x0, -0x4c(%rbp)
jne 0x2c3f6
movl $0x1, -0x4c(%rbp)
cmpl $0x3c, -0x4c(%rbp)
jge 0x2c404
movl -0x4c(%rbp), %eax
movl %eax, -0x80(%rbp)
jmp 0x2c40e
movl $0x3c, %eax
movl %eax, -0x80(%rbp)
jmp 0x2c40e
movl -0x80(%rbp), %edx
movq -0x48(%rbp), %rax
movl 0x44(%rax), %ecx
andl $0xff, %edx
andl $0xffffff00, %ecx       # imm = 0xFFFFFF00
orl %edx, %ecx
movl %ecx, 0x44(%rax)
jmp 0x2c43e
movq -0x48(%rbp), %rax
movl 0x44(%rax), %ecx
andl $0xffffff00, %ecx       # imm = 0xFFFFFF00
orl $0x0, %ecx
movl %ecx, 0x44(%rax)
jmp 0x2c440
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x2c22e
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)