// File: chhylp123[P]hifiasm/inter.cpp
// Function: cal_sc(mg_path_dst_t const*, mg_lchain_t const*, mg_lchain_t const*, mg128_t const*, gc_frag_t const*, int const*, int, int, float)
static inline int32_t cal_sc(const mg_path_dst_t *dj, const mg_lchain_t *li, const mg_lchain_t *lc, const mg128_t *an, const gc_frag_t *a, const int32_t *f,
							 int bw, int ref_bonus, float chn_pen_gap)
{
	const mg_lchain_t *lj;
	int32_t gap, sc;
	float lin_pen, log_pen;
	if (dj->n_path == 0) return INT32_MIN;
	gap = dj->dist - dj->target_dist;
	lj = &lc[a[dj->meta].i];
	if (gap < 0) gap = -gap;
	if (gap > bw) return INT32_MIN;
	if (lj->qe <= li->qs) sc = li->score;
	else sc = (int32_t)((double)(li->qe - lj->qe) / (li->qe - li->qs) * li->score + .499); // dealing with overlap on query
	//sc += dj->mlen; // TODO: is this line the right thing to do?
	if (dj->is_0) sc += ref_bonus;
	lin_pen = chn_pen_gap * (float)gap;
	log_pen = gap >= 2? mg_log2(gap) : 0.0f;
	sc -= (int32_t)(lin_pen + log_pen);
	sc += f[dj->meta];
	return sc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movss %xmm0, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x0, %eax
jne 0x289958
movl $0x80000000, -0x4(%rbp) # imm = 0x80000000
jmp 0x289aa4
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0x4(%rcx), %eax
movl %eax, -0x4c(%rbp)
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rdx
movl 0xc(%rdx), %edx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
movl %edx, %edx
movslq 0x4(%rcx,%rdx,8), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
cmpl $0x0, -0x4c(%rbp)
jge 0x28999e
xorl %eax, %eax
subl -0x4c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl 0x10(%rbp), %eax
jle 0x2899b2
movl $0x80000000, -0x4(%rbp) # imm = 0x80000000
jmp 0x289aa4
movq -0x48(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jg 0x2899ce
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x50(%rbp)
jmp 0x289a16
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x48(%rbp), %rcx
subl 0x18(%rcx), %eax
cvtsi2sd %eax, %xmm0
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x18(%rbp), %rcx
subl 0x14(%rcx), %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movq -0x18(%rbp), %rax
cvtsi2sdl 0x1c(%rax), %xmm1
mulsd %xmm1, %xmm0
movsd 0xf5635(%rip), %xmm1    # 0x37f040
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x289a2e
movl 0x18(%rbp), %eax
addl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
movss -0x3c(%rbp), %xmm0
cvtsi2ssl -0x4c(%rbp), %xmm1
mulss %xmm1, %xmm0
movss %xmm0, -0x54(%rbp)
cmpl $0x2, -0x4c(%rbp)
jl 0x289a58
cvtsi2ssl -0x4c(%rbp), %xmm0
callq 0x30a670
movss %xmm0, -0x5c(%rbp)
jmp 0x289a62
xorps %xmm0, %xmm0
movss %xmm0, -0x5c(%rbp)
jmp 0x289a62
movss -0x5c(%rbp), %xmm0
movss %xmm0, -0x58(%rbp)
movss -0x54(%rbp), %xmm0
addss -0x58(%rbp), %xmm0
cvttss2si %xmm0, %ecx
movl -0x50(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x50(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0xc(%rcx), %ecx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
addl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)