// File: /workspace/github_c_makefile_star2_O2/lh3[P]minigraph/lchain.c
// Function: comput_sc
static inline int32_t comput_sc(const mg128_t *ai, const mg128_t *aj, int32_t max_dist_x, int32_t max_dist_y, int32_t bw, float chn_pen_gap, float chn_pen_skip, int is_cdna, int n_seg)
{
	int32_t dq = (int32_t)ai->y - (int32_t)aj->y, dr, dd, dg, q_span, sc;
	int32_t sidi = (ai->y & MG_SEED_SEG_MASK) >> MG_SEED_SEG_SHIFT;
	int32_t sidj = (aj->y & MG_SEED_SEG_MASK) >> MG_SEED_SEG_SHIFT;
	if (dq <= 0 || dq > max_dist_x) return INT32_MIN;
	dr = (int32_t)(ai->x - aj->x);
	if (sidi == sidj && (dr == 0 || dq > max_dist_y)) return INT32_MIN;
	dd = dr > dq? dr - dq : dq - dr;
	if (sidi == sidj && dd > bw) return INT32_MIN;
	if (n_seg > 1 && !is_cdna && sidi == sidj && dr > max_dist_y) return INT32_MIN;
	dg = dr < dq? dr : dq;
	q_span = aj->y>>32&0xff;
	sc = q_span < dg? q_span : dg;
	if (dd || dg > q_span) {
		float lin_pen, log_pen;
		lin_pen = chn_pen_gap * (float)dd + chn_pen_skip * (float)dg;
		log_pen = dd >= 1? mg_log2(dd + 1) : 0.0f; // mg_log2() only works for dd>=2
		if (is_cdna || sidi != sidj) {
			if (sidi != sidj && dr == 0) ++sc; // possibly due to overlapping paired ends; give a minor bonus
			else if (dr > dq || sidi != sidj) sc -= (int)(lin_pen < log_pen? lin_pen : log_pen); // deletion or jump between paired ends
			else sc -= (int)(lin_pen + .5f * log_pen);
		} else sc -= (int)(lin_pen + .5f * log_pen);
	}
	return sc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %r9d, %ebp
movq 0x8(%rdi), %r15
movq 0x8(%rsi), %rax
movl %r15d, %r14d
subl %eax, %r14d
setle %r9b
cmpl %edx, %r14d
setg %dl
orb %r9b, %dl
movl $0x80000000, %ebx       # imm = 0x80000000
jne 0x13c21
movaps %xmm0, %xmm2
shrq $0x30, %r15
movl $0xff, %edx
andl %edx, %r15d
movq %rax, %r12
shrq $0x30, %r12
andl %edx, %r12d
movl (%rdi), %r13d
subl (%rsi), %r13d
cmpl %r12d, %r15d
jne 0x13b4c
testl %r13d, %r13d
sete %dl
cmpl %ecx, %r14d
setg %sil
orb %dl, %sil
jne 0x13c21
movl %r14d, %esi
subl %r13d, %esi
movl %esi, %edx
negl %edx
cmovsl %esi, %edx
cmpl %r12d, %r15d
jne 0x13b67
cmpl %r8d, %edx
jg 0x13c21
movl %r15d, %esi
xorl %r12d, %esi
cmpl $0x2, 0x40(%rsp)
setge %dil
orl %ebp, %esi
sete %sil
cmpl %ecx, %r13d
setg %cl
andb %dil, %cl
testb %sil, %cl
jne 0x13c21
shrq $0x20, %rax
cmpl %r13d, %r14d
movl %r13d, %ecx
cmovll %r14d, %ecx
movzbl %al, %ebx
setne %al
cmpl %ecx, %ebx
cmovgel %ecx, %ebx
setl %sil
orb %al, %sil
cmpb $0x1, %sil
jne 0x13c21
cvtsi2ss %edx, %xmm0
cvtsi2ss %ecx, %xmm3
mulss %xmm1, %xmm3
mulss %xmm0, %xmm2
xorps %xmm0, %xmm0
cmpl %r13d, %r14d
je 0x13bed
incl %edx
cvtsi2ss %edx, %xmm0
movss %xmm2, 0x4(%rsp)
movss %xmm3, (%rsp)
callq 0x15687
movss (%rsp), %xmm3
movss 0x4(%rsp), %xmm2
addss %xmm3, %xmm2
testl %ebp, %ebp
jne 0x13c0e
cmpl %r12d, %r15d
jne 0x13c0e
mulss 0x10632(%rip), %xmm0    # 0x24234
addss %xmm2, %xmm0
cvttss2si %xmm0, %eax
subl %eax, %ebx
jmp 0x13c21
cmpl %r12d, %r15d
setne %al
testl %r13d, %r13d
sete %cl
testb %cl, %al
je 0x13c32
pushq $0x1
popq %rbx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl %r12d, %r15d
jne 0x13c3c
cmpl %r13d, %r14d
jge 0x13bfa
minss %xmm0, %xmm2
cvttss2si %xmm2, %eax
jmp 0x13c0a