// File: /workspace/github_c_makefile_star2_O0/lh3[P]minigraph/gchain1.c
// Function: cal_sc
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, segi, segj;
	float lin_pen, log_pen;
	if (dj->n_path == 0) return INT32_MIN;
	segi = (an[li->off].y & MG_SEED_SEG_MASK) >> MG_SEED_SEG_SHIFT;
	gap = dj->dist - dj->target_dist;
	lj = &lc[a[dj->meta].i];
	segj = (an[lj->off + lj->cnt - 1].y & MG_SEED_SEG_MASK) >> MG_SEED_SEG_SHIFT;
	if (gap < 0) gap = -gap;
	if (segi == segj && 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 $0x70, %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 0x277b8
movl $0x80000000, -0x4(%rbp) # imm = 0x80000000
jmp 0x2796b
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %rax
movslq (%rax), %rax
shlq $0x4, %rax
addq %rax, %rcx
movabsq $0xff000000000000, %rax # imm = 0xFF000000000000
andq 0x8(%rcx), %rax
shrq $0x30, %rax
movl %eax, -0x54(%rbp)
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)
movq -0x28(%rbp), %rcx
movq -0x48(%rbp), %rax
movl (%rax), %eax
movq -0x48(%rbp), %rdx
movl 0x4(%rdx), %edx
shll %edx
sarl %edx
addl %edx, %eax
subl $0x1, %eax
cltq
shlq $0x4, %rax
addq %rax, %rcx
movabsq $0xff000000000000, %rax # imm = 0xFF000000000000
andq 0x8(%rcx), %rax
shrq $0x30, %rax
movl %eax, -0x58(%rbp)
cmpl $0x0, -0x4c(%rbp)
jge 0x2785d
xorl %eax, %eax
subl -0x4c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x58(%rbp), %eax
jne 0x27879
movl -0x4c(%rbp), %eax
cmpl 0x10(%rbp), %eax
jle 0x27879
movl $0x80000000, -0x4(%rbp) # imm = 0x80000000
jmp 0x2796b
movq -0x48(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jg 0x27895
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x50(%rbp)
jmp 0x278dd
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 0x15ad6(%rip), %xmm1    # 0x3d3a8
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 0x278f5
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, -0x5c(%rbp)
cmpl $0x2, -0x4c(%rbp)
jl 0x2791f
cvtsi2ssl -0x4c(%rbp), %xmm0
callq 0x28f20
movss %xmm0, -0x64(%rbp)
jmp 0x27929
xorps %xmm0, %xmm0
movss %xmm0, -0x64(%rbp)
jmp 0x27929
movss -0x64(%rbp), %xmm0
movss %xmm0, -0x60(%rbp)
movss -0x5c(%rbp), %xmm0
addss -0x60(%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 $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)