// File: /workspace/github_c_makefile_star2_O0/lh3[P]minimap2/hit.c
// Function: mm_set_mapq2
void mm_set_mapq2(void *km, int n_regs, mm_reg1_t *regs, int min_chain_sc, int match_sc, int rep_len, int is_sr, int is_splice)
{
	static const float q_coef = 40.0f;
	int64_t sum_sc = 0;
	float uniq_ratio;
	int i, n_2nd_splice = 0;
	if (n_regs == 0) return;
	for (i = 0; i < n_regs; ++i) {
		if (regs[i].parent == regs[i].id)
			sum_sc += regs[i].score;
		else if (regs[i].is_spliced)
			++n_2nd_splice;
	}
	uniq_ratio = (float)sum_sc / (sum_sc + rep_len);
	for (i = 0; i < n_regs; ++i) {
		mm_reg1_t *r = &regs[i];
		if (r->inv) {
			r->mapq = 0;
		} else if (r->parent == r->id) {
			int mapq, subsc;
			float pen_s1 = (r->score > 100? 1.0f : 0.01f * r->score) * uniq_ratio;
			float pen_cm = r->cnt > 10? 1.0f : 0.1f * r->cnt;
			pen_cm = pen_s1 < pen_cm? pen_s1 : pen_cm;
			subsc = r->subsc > min_chain_sc? r->subsc : min_chain_sc;
			if (r->p && r->p->dp_max2 > 0 && r->p->dp_max > 0) {
				float x, identity = (float)r->mlen / r->blen;
				if (is_sr && is_splice)
					x = (float)r->p->dp_max2 / r->p->dp_max; // ignore chaining score; for short RNA-seq reads, unspliced chaining score tends to be higher
				else
					x = (float)r->p->dp_max2 * subsc / r->p->dp_max / r->score0;
				mapq = (int)(identity * pen_cm * q_coef * (1.0f - x * x) * logf((float)r->p->dp_max / match_sc));
				if (!is_sr) {
					int mapq_alt = (int)(6.02f * identity * identity * (r->p->dp_max - r->p->dp_max2) / match_sc + .499f); // BWA-MEM like mapQ, mostly for short reads
					mapq = mapq < mapq_alt? mapq : mapq_alt; // in case the long-read heuristic fails
				}
				if (is_splice && is_sr && r->is_spliced && n_2nd_splice == 0)
					mapq += 10;
			} else {
				float x = (float)subsc / r->score0;
				if (r->p) {
					float identity = (float)r->mlen / r->blen;
					mapq = (int)(identity * pen_cm * q_coef * (1.0f - x) * logf((float)r->p->dp_max / match_sc));
				} else {
					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;
			r->mapq = mapq < 60? mapq : 60;
			if (r->p && r->p->dp_max > r->p->dp_max2 && r->mapq == 0) r->mapq = 1;
		} else r->mapq = 0;
	}
	mm_set_inv_mapq(km, n_regs, regs);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, -0x3c(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x2beb1
jmp 0x2c460
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x2bf37
movq -0x18(%rbp), %rax
movslq -0x38(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
movq -0x18(%rbp), %rcx
movslq -0x38(%rbp), %rdx
imulq $0x50, %rdx, %rdx
addq %rdx, %rcx
cmpl (%rcx), %eax
jne 0x2bf02
movq -0x18(%rbp), %rax
movslq -0x38(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movslq 0xc(%rax), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x2bf2a
movq -0x18(%rbp), %rax
movslq -0x38(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movl 0x3c(%rax), %eax
shrl $0x1b, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2bf28
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2bf2a
jmp 0x2bf2c
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x2beb8
cvtsi2ssq -0x30(%rbp), %xmm0
movq -0x30(%rbp), %rax
movslq -0x24(%rbp), %rcx
addq %rcx, %rax
cvtsi2ss %rax, %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x2c450
movq -0x18(%rbp), %rax
movslq -0x38(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movl 0x3c(%rax), %eax
shrl $0xb, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2bfa6
movq -0x48(%rbp), %rax
movl 0x3c(%rax), %ecx
andl $0xffffff00, %ecx       # imm = 0xFFFFFF00
orl $0x0, %ecx
movl %ecx, 0x3c(%rax)
jmp 0x2c440
movq -0x48(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x48(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x2c42b
movq -0x48(%rbp), %rax
cmpl $0x64, 0xc(%rax)
jle 0x2bfd2
movss 0x2a845(%rip), %xmm0    # 0x56810
movss %xmm0, -0x70(%rbp)
jmp 0x2bfec
movq -0x48(%rbp), %rax
cvtsi2ssl 0xc(%rax), %xmm1
movss 0x2a841(%rip), %xmm0    # 0x56824
mulss %xmm1, %xmm0
movss %xmm0, -0x70(%rbp)
movss -0x70(%rbp), %xmm0
mulss -0x34(%rbp), %xmm0
movss %xmm0, -0x54(%rbp)
movq -0x48(%rbp), %rax
cmpl $0xa, 0x4(%rax)
jle 0x2c014
movss 0x2a803(%rip), %xmm0    # 0x56810
movss %xmm0, -0x74(%rbp)
jmp 0x2c02e
movq -0x48(%rbp), %rax
cvtsi2ssl 0x4(%rax), %xmm1
movss 0x2a7fb(%rip), %xmm0    # 0x56820
mulss %xmm1, %xmm0
movss %xmm0, -0x74(%rbp)
movss -0x74(%rbp), %xmm0
movss %xmm0, -0x58(%rbp)
movss -0x54(%rbp), %xmm1
movss -0x58(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x2c053
movss -0x54(%rbp), %xmm0
movss %xmm0, -0x78(%rbp)
jmp 0x2c05d
movss -0x58(%rbp), %xmm0
movss %xmm0, -0x78(%rbp)
movss -0x78(%rbp), %xmm0
movss %xmm0, -0x58(%rbp)
movq -0x48(%rbp), %rax
movl 0x24(%rax), %eax
cmpl -0x1c(%rbp), %eax
jle 0x2c07f
movq -0x48(%rbp), %rax
movl 0x24(%rax), %eax
movl %eax, -0x7c(%rbp)
jmp 0x2c085
movl -0x1c(%rbp), %eax
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x48(%rbp), %rax
cmpq $0x0, 0x48(%rax)
je 0x2c260
movq -0x48(%rbp), %rax
movq 0x48(%rax), %rax
cmpl $0x0, 0xc(%rax)
jle 0x2c260
movq -0x48(%rbp), %rax
movq 0x48(%rax), %rax
cmpl $0x0, 0x8(%rax)
jle 0x2c260
movq -0x48(%rbp), %rax
cvtsi2ssl 0x2c(%rax), %xmm0
movq -0x48(%rbp), %rax
cvtsi2ssl 0x30(%rax), %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x60(%rbp)
cmpl $0x0, 0x10(%rbp)
je 0x2c10a
cmpl $0x0, 0x18(%rbp)
je 0x2c10a
movq -0x48(%rbp), %rax
movq 0x48(%rax), %rax
cvtsi2ssl 0xc(%rax), %xmm0
movq -0x48(%rbp), %rax
movq 0x48(%rax), %rax
cvtsi2ssl 0x8(%rax), %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x5c(%rbp)
jmp 0x2c143
movq -0x48(%rbp), %rax
movq 0x48(%rax), %rax
cvtsi2ssl 0xc(%rax), %xmm0
cvtsi2ssl -0x50(%rbp), %xmm1
mulss %xmm1, %xmm0
movq -0x48(%rbp), %rax
movq 0x48(%rax), %rax
cvtsi2ssl 0x8(%rax), %xmm1
divss %xmm1, %xmm0
movq -0x48(%rbp), %rax
cvtsi2ssl 0x38(%rax), %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x5c(%rbp)
movss -0x60(%rbp), %xmm0
mulss -0x58(%rbp), %xmm0
movss 0x2c3fb(%rip), %xmm1    # 0x58550
mulss %xmm1, %xmm0
movss -0x5c(%rbp), %xmm1
movss -0x5c(%rbp), %xmm2
movd %xmm1, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm1
mulss %xmm2, %xmm1
movss 0x2a694(%rip), %xmm2    # 0x56810
addss %xmm2, %xmm1
mulss %xmm1, %xmm0
movss %xmm0, -0x80(%rbp)
movq -0x48(%rbp), %rax
movq 0x48(%rax), %rax
cvtsi2ssl 0x8(%rax), %xmm0
cvtsi2ssl -0x20(%rbp), %xmm1
divss %xmm1, %xmm0
callq 0x2200
movaps %xmm0, %xmm1
movss -0x80(%rbp), %xmm0
mulss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movl %eax, -0x4c(%rbp)
cmpl $0x0, 0x10(%rbp)
jne 0x2c22e
movss 0x2b98b(%rip), %xmm0    # 0x57b50
mulss -0x60(%rbp), %xmm0
mulss -0x60(%rbp), %xmm0
movq -0x48(%rbp), %rax
movq 0x48(%rax), %rax
movl 0x8(%rax), %eax
movq -0x48(%rbp), %rcx
movq 0x48(%rcx), %rcx
subl 0xc(%rcx), %eax
cvtsi2ss %eax, %xmm1
mulss %xmm1, %xmm0
cvtsi2ssl -0x20(%rbp), %xmm1
divss %xmm1, %xmm0
movss 0x2b956(%rip), %xmm1    # 0x57b54
addss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movl %eax, -0x64(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x64(%rbp), %eax
jge 0x2c21c
movl -0x4c(%rbp), %eax
movl %eax, -0x84(%rbp)
jmp 0x2c225
movl -0x64(%rbp), %eax
movl %eax, -0x84(%rbp)
movl -0x84(%rbp), %eax
movl %eax, -0x4c(%rbp)
cmpl $0x0, 0x18(%rbp)
je 0x2c25b
cmpl $0x0, 0x10(%rbp)
je 0x2c25b
movq -0x48(%rbp), %rax
movl 0x3c(%rax), %eax
shrl $0x1b, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2c25b
cmpl $0x0, -0x3c(%rbp)
jne 0x2c25b
movl -0x4c(%rbp), %eax
addl $0xa, %eax
movl %eax, -0x4c(%rbp)
jmp 0x2c34b
cvtsi2ssl -0x50(%rbp), %xmm0
movq -0x48(%rbp), %rax
cvtsi2ssl 0x38(%rax), %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x68(%rbp)
movq -0x48(%rbp), %rax
cmpq $0x0, 0x48(%rax)
je 0x2c2ff
movq -0x48(%rbp), %rax
cvtsi2ssl 0x2c(%rax), %xmm0
movq -0x48(%rbp), %rax
cvtsi2ssl 0x30(%rax), %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x6c(%rbp)
movss -0x6c(%rbp), %xmm0
mulss -0x58(%rbp), %xmm0
movss 0x2c2a1(%rip), %xmm1    # 0x58550
mulss %xmm1, %xmm0
movss 0x2a555(%rip), %xmm1    # 0x56810
subss -0x68(%rbp), %xmm1
mulss %xmm1, %xmm0
movss %xmm0, -0x88(%rbp)
movq -0x48(%rbp), %rax
movq 0x48(%rax), %rax
cvtsi2ssl 0x8(%rax), %xmm0
cvtsi2ssl -0x20(%rbp), %xmm1
divss %xmm1, %xmm0
callq 0x2200
movaps %xmm0, %xmm1
movss -0x88(%rbp), %xmm0
mulss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movl %eax, -0x4c(%rbp)
jmp 0x2c349
movss 0x2c249(%rip), %xmm0    # 0x58550
mulss -0x58(%rbp), %xmm0
movss 0x2a4fc(%rip), %xmm1    # 0x56810
subss -0x68(%rbp), %xmm1
mulss %xmm1, %xmm0
movss %xmm0, -0x8c(%rbp)
movq -0x48(%rbp), %rax
cvtsi2ssl 0xc(%rax), %xmm0
callq 0x2200
movaps %xmm0, %xmm1
movss -0x8c(%rbp), %xmm0
mulss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movl %eax, -0x4c(%rbp)
jmp 0x2c34b
movq -0x48(%rbp), %rax
movl 0x34(%rax), %eax
addl $0x1, %eax
cvtsi2ss %eax, %xmm0
callq 0x2200
movss 0x2c1ee(%rip), %xmm1    # 0x58554
mulss %xmm1, %xmm0
movss 0x2b7e2(%rip), %xmm1    # 0x57b54
addss %xmm1, %xmm0
cvttss2si %xmm0, %ecx
movl -0x4c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jle 0x2c393
movl -0x4c(%rbp), %eax
movl %eax, -0x90(%rbp)
jmp 0x2c39d
xorl %eax, %eax
movl %eax, -0x90(%rbp)
jmp 0x2c39d
movl -0x90(%rbp), %eax
movl %eax, -0x4c(%rbp)
cmpl $0x3c, -0x4c(%rbp)
jge 0x2c3b7
movl -0x4c(%rbp), %eax
movl %eax, -0x94(%rbp)
jmp 0x2c3c4
movl $0x3c, %eax
movl %eax, -0x94(%rbp)
jmp 0x2c3c4
movl -0x94(%rbp), %edx
movq -0x48(%rbp), %rax
movl 0x3c(%rax), %ecx
andl $0xff, %edx
andl $0xffffff00, %ecx       # imm = 0xFFFFFF00
orl %edx, %ecx
movl %ecx, 0x3c(%rax)
movq -0x48(%rbp), %rax
cmpq $0x0, 0x48(%rax)
je 0x2c429
movq -0x48(%rbp), %rax
movq 0x48(%rax), %rax
movl 0x8(%rax), %eax
movq -0x48(%rbp), %rcx
movq 0x48(%rcx), %rcx
cmpl 0xc(%rcx), %eax
jle 0x2c429
movq -0x48(%rbp), %rax
movl 0x3c(%rax), %eax
andl $0xff, %eax
cmpl $0x0, %eax
jne 0x2c429
movq -0x48(%rbp), %rax
movl 0x3c(%rax), %ecx
andl $0xffffff00, %ecx       # imm = 0xFFFFFF00
orl $0x1, %ecx
movl %ecx, 0x3c(%rax)
jmp 0x2c43e
movq -0x48(%rbp), %rax
movl 0x3c(%rax), %ecx
andl $0xffffff00, %ecx       # imm = 0xFFFFFF00
orl $0x0, %ecx
movl %ecx, 0x3c(%rax)
jmp 0x2c440
jmp 0x2c442
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x2bf5d
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movq -0x18(%rbp), %rdx
callq 0x2c470
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax)