// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movss %xmm0, -0x28(%rbp)
movss %xmm1, -0x2c(%rbp)
movl %r9d, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
subl %ecx, %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rcx
movabsq $0xff000000000000, %rax # imm = 0xFF000000000000
andq 0x8(%rcx), %rax
shrq $0x30, %rax
movl %eax, -0x4c(%rbp)
movq -0x18(%rbp), %rcx
movabsq $0xff000000000000, %rax # imm = 0xFF000000000000
andq 0x8(%rcx), %rax
shrq $0x30, %rax
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x34(%rbp)
jle 0x22940
movl -0x34(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jle 0x2294c
movl $0x80000000, -0x4(%rbp) # imm = 0x80000000
jmp 0x22b64
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
subq (%rcx), %rax
movl %eax, -0x38(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x50(%rbp), %eax
jne 0x2297f
cmpl $0x0, -0x38(%rbp)
je 0x22973
movl -0x34(%rbp), %eax
cmpl -0x20(%rbp), %eax
jle 0x2297f
movl $0x80000000, -0x4(%rbp) # imm = 0x80000000
jmp 0x22b64
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
jle 0x22992
movl -0x38(%rbp), %eax
subl -0x34(%rbp), %eax
movl %eax, -0x5c(%rbp)
jmp 0x2299b
movl -0x34(%rbp), %eax
subl -0x38(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x50(%rbp), %eax
jne 0x229bd
movl -0x3c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jle 0x229bd
movl $0x80000000, -0x4(%rbp) # imm = 0x80000000
jmp 0x22b64
cmpl $0x1, 0x10(%rbp)
jle 0x229e5
cmpl $0x0, -0x30(%rbp)
jne 0x229e5
movl -0x4c(%rbp), %eax
cmpl -0x50(%rbp), %eax
jne 0x229e5
movl -0x38(%rbp), %eax
cmpl -0x20(%rbp), %eax
jle 0x229e5
movl $0x80000000, -0x4(%rbp) # imm = 0x80000000
jmp 0x22b64
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x229f5
movl -0x38(%rbp), %eax
movl %eax, -0x60(%rbp)
jmp 0x229fb
movl -0x34(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
andq $0xff, %rax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x22a26
movl -0x44(%rbp), %eax
movl %eax, -0x64(%rbp)
jmp 0x22a2c
movl -0x40(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x3c(%rbp)
jne 0x22a44
movl -0x40(%rbp), %eax
cmpl -0x44(%rbp), %eax
jle 0x22b5e
movss -0x28(%rbp), %xmm0
cvtsi2ssl -0x3c(%rbp), %xmm2
movss -0x2c(%rbp), %xmm1
cvtsi2ssl -0x40(%rbp), %xmm3
mulss %xmm3, %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x54(%rbp)
cmpl $0x1, -0x3c(%rbp)
jl 0x22a85
movl -0x3c(%rbp), %eax
addl $0x1, %eax
cvtsi2ss %eax, %xmm0
callq 0x25e60
movss %xmm0, -0x68(%rbp)
jmp 0x22a8f
xorps %xmm0, %xmm0
movss %xmm0, -0x68(%rbp)
jmp 0x22a8f
movss -0x68(%rbp), %xmm0
movss %xmm0, -0x58(%rbp)
cmpl $0x0, -0x30(%rbp)
jne 0x22aab
movl -0x4c(%rbp), %eax
cmpl -0x50(%rbp), %eax
je 0x22b36
movl -0x4c(%rbp), %eax
cmpl -0x50(%rbp), %eax
je 0x22ac4
cmpl $0x0, -0x38(%rbp)
jne 0x22ac4
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x22b34
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
jg 0x22ad4
movl -0x4c(%rbp), %eax
cmpl -0x50(%rbp), %eax
je 0x22b0c
movss -0x54(%rbp), %xmm1
movss -0x58(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x22aef
movss -0x54(%rbp), %xmm0
movss %xmm0, -0x6c(%rbp)
jmp 0x22af9
movss -0x58(%rbp), %xmm0
movss %xmm0, -0x6c(%rbp)
movss -0x6c(%rbp), %xmm0
cvttss2si %xmm0, %ecx
movl -0x48(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x48(%rbp)
jmp 0x22b32
movss -0x54(%rbp), %xmm1
movss -0x58(%rbp), %xmm0
movss 0x19fba(%rip), %xmm2    # 0x3cad8
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
cvttss2si %xmm0, %ecx
movl -0x48(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x48(%rbp)
jmp 0x22b34
jmp 0x22b5c
movss -0x54(%rbp), %xmm1
movss -0x58(%rbp), %xmm0
movss 0x19f90(%rip), %xmm2    # 0x3cad8
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
cvttss2si %xmm0, %ecx
movl -0x48(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x48(%rbp)
jmp 0x22b5e
movl -0x48(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)