// File: /workspace/github_c_makefile_star2_O3/lh3[P]miniprot/nasw-sse.c
// Function: ns_prep_seq
static uint8_t *ns_prep_seq(void *km, const char *ns, int32_t nl, const char *as, int32_t al, const ns_opt_t *opt, const uint8_t *ss, uint8_t **aas_, int8_t **donor_, int8_t **acceptor_)
{
	int32_t i, j;
	uint8_t *nas, *aas;
	int8_t *donor, *acceptor;
	nas = Kmalloc(km, uint8_t, nl + al + (nl + 1) * 2); // nas and aas are allocated together
	*aas_ = aas = nas + nl;
	*donor_ = donor = (int8_t*)aas + al, *acceptor_ = acceptor = donor + nl + 1;
	for (j = 0; j < al; ++j) // generate aas[]
		aas[j] = opt->aa20[(uint8_t)as[j]];
	for (i = 0; i < nl; ++i) // nt4 encoding of ns[] for computing donor[] and acceptor[]
		nas[i] = opt->nt4[(uint8_t)ns[i]];
	for (i = 0; i < nl + 1; ++i)
		donor[i] = acceptor[i] = opt->sp[3];
	for (i = 0; i < nl - 3; ++i) { // generate donor[]
		int32_t t = 3;
		if (nas[i+1] == 2 && nas[i+2] == 3) // GT.
			t = i + 3 < nl && (nas[i+3] == 0 || nas[i+3] == 2)? (nas[i] == 2? -1 : 4) : 0;
		else if (nas[i+1] == 2 && nas[i+2] == 1 && nas[i] == 2) t = 1; // GC.
		else if (nas[i+1] == 0 && nas[i+2] == 3) t = 2; // AT.
		donor[i] = t < 0? 0 : opt->sp[t];
	}
	for (i = 1; i < nl; ++i) { // generate acceptor[]
		int32_t t = 3, penY = 0;
		if (nas[i-1] == 0 && nas[i] == 2) { // .AG
			t = i >= 2 && (nas[i-2] == 1 || nas[i-2] == 3)? -1 : 0;
			for (j = i - 4; j >= 0 && j > i - 7; --j)
				if (nas[j] != 1 && nas[j] != 3) penY += opt->sp[5];
		} else if (nas[i-1] == 0 && nas[i] == 1) t = 2; // .AC
		acceptor[i] = t < 0? 0 : opt->sp[t];
		if (t == -1 || t == 0) acceptor[i] += penY;
	}
	if (ss) { // NB: ss[] uses the offset rule to specify a splice site; donor/acceptor[] uses a different rule. The ss[] way is better but too tricky to change now
		int32_t max_spsc = (opt->io + 1) / 2 - 1;
		for (i = 1; i < nl; ++i) {
			int32_t spsc = (int8_t)(ss[i]>>1) - (int8_t)NS_SPSC_OFFSET;
			if (spsc > max_spsc) spsc = max_spsc; // otherwise two strong signals may create an intron out of nothing
			if (ss[i] == 0xff) { // score not set
				donor[i-1] -= opt->sp_null_bonus;
				acceptor[i-1] -= opt->sp_null_bonus;
			} else if (ss[i]&1) { // acceptor
				acceptor[i-1] -= spsc;
			} else { // donor
				donor[i-1] -= spsc;
			}
		}
	}
	ns_prep_nas(ns, nl, opt, nas);
	return nas;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, %rbx
movl %r8d, %ebp
movq %rcx, %r13
movl %edx, %r14d
movq %rsi, %r15
leal (%r14,%r14,2), %eax
addl %ebp, %eax
addl $0x2, %eax
movslq %eax, %rsi
callq 0x84a5
movq %rax, %r12
movq %r14, 0x8(%rsp)
movslq %r14d, %r11
leaq (%rax,%r11), %rcx
movq 0x58(%rsp), %rax
movq %rcx, (%rax)
movslq %ebp, %rdx
leaq (%rcx,%rdx), %rax
movq 0x60(%rsp), %rsi
movq %rax, (%rsi)
leaq (%r11,%rax), %rdi
incq %rdi
movq 0x68(%rsp), %rsi
movq %rdi, (%rsi)
testl %edx, %edx
jle 0xa190
movl %ebp, %esi
xorl %r8d, %r8d
movq 0x50(%rbx), %r9
movzbl (%r13,%r8), %r10d
movb (%r9,%r10), %r9b
movb %r9b, (%rcx,%r8)
incq %r8
cmpq %r8, %rsi
jne 0xa176
movq 0x8(%rsp), %rsi
testl %esi, %esi
jle 0xa1b7
movl %esi, %ecx
xorl %r10d, %r10d
movq 0x48(%rbx), %r8
movzbl (%r15,%r10), %r9d
movb (%r8,%r9), %r8b
movb %r8b, (%r12,%r10)
incq %r10
cmpq %r10, %rcx
jne 0xa19e
movq 0x50(%rsp), %r14
testl %esi, %esi
js 0xa35f
leal 0x1(%rsi), %ecx
xorl %r8d, %r8d
movb 0x2c(%rbx), %r9b
movb %r9b, (%rdi,%r8)
movb %r9b, (%rax,%r8)
incq %r8
cmpq %r8, %rcx
jne 0xa1ca
cmpl $0x4, %esi
jl 0xa267
leal -0x3(%rsi), %r8d
xorl %r9d, %r9d
movzbl 0x1(%r12,%r9), %r10d
testl %r10d, %r10d
je 0xa22f
movl $0x3, %ecx
cmpl $0x2, %r10d
jne 0xa251
movzbl 0x2(%r12,%r9), %ecx
cmpl $0x1, %ecx
je 0xa240
cmpl $0x3, %ecx
jne 0xa24c
movzbl 0x3(%r12,%r9), %ecx
testb $-0x3, %cl
jne 0xa263
movl $0x4, %ecx
cmpb $0x2, (%r12,%r9)
jne 0xa251
xorl %ecx, %ecx
jmp 0xa255
xorl %ecx, %ecx
cmpb $0x3, 0x2(%r12,%r9)
sete %cl
xorq $0x3, %rcx
jmp 0xa251
movl $0x1, %ecx
cmpb $0x2, (%r12,%r9)
je 0xa251
movl $0x3, %ecx
movb 0x20(%rbx,%rcx,4), %cl
movb %cl, (%rax,%r9)
incq %r9
cmpq %r9, %r8
jne 0xa1ee
jmp 0xa267
xorl %ecx, %ecx
jmp 0xa251
xorl %r8d, %r8d
cmpl $0x2, %esi
setge %cl
jl 0xa362
movb %cl, 0x7(%rsp)
movq %r11, 0x10(%rsp)
movl %esi, %r10d
movl $0x1, %r11d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x3, %r9d
xorl %r13d, %r13d
cmpb $0x0, -0x1(%r12,%r11)
jne 0xa322
movb (%r12,%r11), %cl
cmpb $0x2, %cl
jne 0xa314
xorl %r13d, %r13d
movl $0x0, %r9d
cmpq $0x2, %r11
jb 0xa2d7
movb -0x2(%r12,%r11), %cl
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
cmpb $0x1, %cl
je 0xa2d7
xorl %r9d, %r9d
cmpb $0x3, %cl
sete %r9b
negl %r9d
leaq -0x4(%r11), %rbp
movl %r11d, %ecx
addl $-0x7, %ecx
cmovsl %esi, %ecx
movslq %ecx, %r14
cmpq %r14, %rbp
jle 0xa30b
xorl %r13d, %r13d
movl %ebp, %r14d
movzbl (%r12,%r14), %r14d
orl $0x2, %r14d
cmpl $0x3, %r14d
je 0xa305
addl 0x34(%rbx), %r13d
decl %ebp
cmpl %ecx, %ebp
jg 0xa2ef
testl %r9d, %r9d
jns 0xa322
xorl %ecx, %ecx
jmp 0xa329
xorl %r9d, %r9d
cmpb $0x1, %cl
sete %r9b
xorl $0x3, %r9d
movl %r9d, %ecx
movb 0x20(%rbx,%rcx,4), %cl
incl %r9d
cmpl $0x2, %r9d
cmovael %r8d, %r13d
addb %cl, %r13b
movb %r13b, (%rdi,%r11)
incq %r11
cmpq %r10, %r11
jne 0xa28d
movb 0x7(%rsp), %cl
movl %ecx, %r8d
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %r11
movq 0x50(%rsp), %r14
jmp 0xa362
xorl %r8d, %r8d
testq %r14, %r14
je 0xa3df
testb %r8b, %r8b
je 0xa3df
movl 0xc(%rbx), %ecx
movl %ecx, %edi
incl %edi
shrl $0x1f, %edi
addl %ecx, %edi
incl %edi
sarl %edi
leal 0xff(%rdi), %r8d
movl %esi, %r9d
leaq (%rdx,%r11,2), %rcx
addq %r12, %rcx
incq %rcx
decq %r9
xorl %edx, %edx
movzbl 0x1(%r14,%rdx), %r11d
cmpl $0xff, %r11d
je 0xa3c1
movl %r11d, %r10d
shrl %r10d
addl $-0x40, %r10d
cmpl %edi, %r10d
cmovgel %r8d, %r10d
testb $0x1, %r11b
jne 0xa3d3
subb %r10b, (%rax,%rdx)
jmp 0xa3d7
movb 0x38(%rbx), %r10b
subb %r10b, (%rax,%rdx)
movb 0x38(%rbx), %r10b
subb %r10b, (%rcx,%rdx)
jmp 0xa3d7
subb %r10b, (%rcx,%rdx)
incq %rdx
cmpq %rdx, %r9
jne 0xa395
movq %r15, %rdi
movq %rbx, %rdx
movq %r12, %rcx
callq 0xbb50
movq %r12, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq