// File: /workspace/github_c_makefile_star2_O0/lh3[P]miniprot/chain.c
// Function: comput_sc
static inline int32_t comput_sc(uint64_t ai, uint64_t aj, int32_t max_dist_x, int32_t max_dist_y, int32_t bw, float chn_ceof_log, int32_t is_spliced, int32_t bbit, int32_t kmer)
{
	int32_t dq = (int32_t)ai - (int32_t)aj, dq3 = dq * 3, dr3, dd, sc, dd_signed = 0;
	if (dq <= 0 || dq3 > max_dist_x) return INT32_MIN;
	if (dq > max_dist_y) return INT32_MIN;
	if (bbit > 0) { // calculate the minimum gap size
		int32_t bs = 1<<bbit;
		dr3 = ((ai>>32) - (aj>>32)) << bbit;
		if (dq3 >= dr3 - bs && dq3 <= dr3 + bs) dd = dd_signed = 0;
		else if (dq3 < dr3 - bs) dd = dr3 - bs - dq3, dd_signed = -dd;
		else dd = dq3 - (dr3 + bs), dd_signed = dd;
	} else {
		dr3 = (ai>>32) - (aj>>32);
		if (dr3 == 0) return INT32_MIN;
		dd = dr3 > dq3? dr3 - dq3 : dq3 - dr3;
		dd_signed = dq3 - dr3;
	}
	if (dd > bw) return INT32_MIN;
	if (bbit > 0) {
		sc = kmer < dq? kmer : dq;
	} else if (kmer <= dq && kmer * 3 <= dr3) {
		sc = kmer;
	} else {
		int32_t dr = dr3 / 3, q = dr3 - dr * 3;
		int32_t dg = dr < dq? dr : dq;
		sc = dg < kmer? dg : kmer;
		if (q != 0) --sc; // frameshift
	}
	if (dd > 0) { // TODO: consider frameshift
		float lin_pen, log_pen;
		lin_pen = (float)dd * .33334f;
		log_pen = dd >= 2? chn_ceof_log * (mp_log2(dd + 1) - 1.0f) + 1.0f : (float)dd; // mp_log2(x) only works for x>=2
		if (is_spliced) {
			if (dd_signed < 0) sc -= (int)(lin_pen < log_pen? lin_pen : log_pen);
			else sc -= (int)(lin_pen + log_pen);
		} else sc -= (int)(lin_pen + log_pen);
	}
	if (bbit > 0 && ai>>32 == aj>>32 && dd == 0) sc += MP_BLOCK_BONUS;
	return sc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movl 0x18(%rbp), %eax
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)
movl %r9d, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
subl %ecx, %eax
movl %eax, -0x30(%rbp)
imull $0x3, -0x30(%rbp), %eax
movl %eax, -0x34(%rbp)
movl $0x0, -0x44(%rbp)
cmpl $0x0, -0x30(%rbp)
jle 0x194c5
movl -0x34(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jle 0x194d1
movl $0x80000000, -0x4(%rbp) # imm = 0x80000000
jmp 0x197a8
movl -0x30(%rbp), %eax
cmpl -0x20(%rbp), %eax
jle 0x194e5
movl $0x80000000, -0x4(%rbp) # imm = 0x80000000
jmp 0x197a8
cmpl $0x0, 0x10(%rbp)
jle 0x1957d
movl 0x10(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
shrq $0x20, %rax
movq -0x18(%rbp), %rcx
shrq $0x20, %rcx
subq %rcx, %rax
movl 0x10(%rbp), %ecx
shlq %cl, %rax
movl %eax, -0x38(%rbp)
movl -0x34(%rbp), %eax
movl -0x38(%rbp), %ecx
subl -0x48(%rbp), %ecx
cmpl %ecx, %eax
jl 0x19542
movl -0x34(%rbp), %eax
movl -0x38(%rbp), %ecx
addl -0x48(%rbp), %ecx
cmpl %ecx, %eax
jg 0x19542
movl $0x0, -0x44(%rbp)
movl $0x0, -0x3c(%rbp)
jmp 0x1957b
movl -0x34(%rbp), %eax
movl -0x38(%rbp), %ecx
subl -0x48(%rbp), %ecx
cmpl %ecx, %eax
jge 0x19565
movl -0x38(%rbp), %eax
subl -0x48(%rbp), %eax
subl -0x34(%rbp), %eax
movl %eax, -0x3c(%rbp)
xorl %eax, %eax
subl -0x3c(%rbp), %eax
movl %eax, -0x44(%rbp)
jmp 0x19579
movl -0x34(%rbp), %eax
movl -0x38(%rbp), %ecx
addl -0x48(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x44(%rbp)
jmp 0x1957b
jmp 0x195d0
movq -0x10(%rbp), %rax
shrq $0x20, %rax
movq -0x18(%rbp), %rcx
shrq $0x20, %rcx
subq %rcx, %rax
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
jne 0x195a5
movl $0x80000000, -0x4(%rbp) # imm = 0x80000000
jmp 0x197a8
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
jle 0x195b8
movl -0x38(%rbp), %eax
subl -0x34(%rbp), %eax
movl %eax, -0x60(%rbp)
jmp 0x195c1
movl -0x34(%rbp), %eax
subl -0x38(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x34(%rbp), %eax
subl -0x38(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jle 0x195e4
movl $0x80000000, -0x4(%rbp) # imm = 0x80000000
jmp 0x197a8
cmpl $0x0, 0x10(%rbp)
jle 0x19608
movl 0x18(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x195fa
movl 0x18(%rbp), %eax
movl %eax, -0x64(%rbp)
jmp 0x19600
movl -0x30(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x19686
movl 0x18(%rbp), %eax
cmpl -0x30(%rbp), %eax
jg 0x19621
imull $0x3, 0x18(%rbp), %eax
cmpl -0x38(%rbp), %eax
jg 0x19621
movl 0x18(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x19684
movl -0x38(%rbp), %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %eax, -0x4c(%rbp)
movl -0x38(%rbp), %eax
imull $0x3, -0x4c(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x50(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x1964b
movl -0x4c(%rbp), %eax
movl %eax, -0x68(%rbp)
jmp 0x19651
movl -0x30(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl 0x18(%rbp), %eax
jge 0x19667
movl -0x54(%rbp), %eax
movl %eax, -0x6c(%rbp)
jmp 0x1966d
movl 0x18(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x50(%rbp)
je 0x19682
movl -0x40(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x19684
jmp 0x19686
cmpl $0x0, -0x3c(%rbp)
jle 0x19778
cvtsi2ssl -0x3c(%rbp), %xmm0
movss 0x864f(%rip), %xmm1     # 0x21cec
mulss %xmm1, %xmm0
movss %xmm0, -0x58(%rbp)
cmpl $0x2, -0x3c(%rbp)
jl 0x196f0
movss -0x28(%rbp), %xmm0
movss %xmm0, -0x74(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
cvtsi2ss %eax, %xmm0
callq 0x19f70
movaps %xmm0, %xmm1
movss -0x74(%rbp), %xmm0
movss 0x7bcb(%rip), %xmm2     # 0x212a0
subss %xmm2, %xmm1
mulss %xmm1, %xmm0
movss 0x7bbb(%rip), %xmm1     # 0x212a0
addss %xmm1, %xmm0
movss %xmm0, -0x70(%rbp)
jmp 0x196fa
cvtsi2ssl -0x3c(%rbp), %xmm0
movss %xmm0, -0x70(%rbp)
movss -0x70(%rbp), %xmm0
movss %xmm0, -0x5c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x19760
cmpl $0x0, -0x44(%rbp)
jge 0x19748
movss -0x58(%rbp), %xmm1
movss -0x5c(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x1972b
movss -0x58(%rbp), %xmm0
movss %xmm0, -0x78(%rbp)
jmp 0x19735
movss -0x5c(%rbp), %xmm0
movss %xmm0, -0x78(%rbp)
movss -0x78(%rbp), %xmm0
cvttss2si %xmm0, %ecx
movl -0x40(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x40(%rbp)
jmp 0x1975e
movss -0x58(%rbp), %xmm0
addss -0x5c(%rbp), %xmm0
cvttss2si %xmm0, %ecx
movl -0x40(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x40(%rbp)
jmp 0x19776
movss -0x58(%rbp), %xmm0
addss -0x5c(%rbp), %xmm0
cvttss2si %xmm0, %ecx
movl -0x40(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x40(%rbp)
jmp 0x19778
cmpl $0x0, 0x10(%rbp)
jle 0x197a2
movq -0x10(%rbp), %rax
shrq $0x20, %rax
movq -0x18(%rbp), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
jne 0x197a2
cmpl $0x0, -0x3c(%rbp)
jne 0x197a2
movl -0x40(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)