// File: /workspace/github_c_makefile_star2_O2/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
pushq %rax
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 0x7460
movq %rax, %r12
movq %r14, (%rsp)
movslq %r14d, %rcx
movq %rax, %rdx
addq %rcx, %rdx
movq 0x48(%rsp), %rax
movq %rdx, (%rax)
movslq %ebp, %r8
leaq (%rdx,%r8), %rsi
movq 0x50(%rsp), %rax
movq %rsi, (%rax)
leaq (%rsi,%rcx), %rdi
leaq (%rcx,%rsi), %rax
incq %rax
movq 0x58(%rsp), %r9
movq %rax, (%r9)
xorl %r9d, %r9d
testl %r8d, %r8d
cmovlel %r9d, %r8d
cmpq %r9, %r8
je 0x8f57
movq 0x50(%rbx), %r10
movzbl (%r13,%r9), %r11d
movb (%r10,%r11), %r10b
movb %r10b, (%rdx,%r9)
incq %r9
jmp 0x8f3b
xorl %edx, %edx
movq (%rsp), %r9
testl %r9d, %r9d
movl $0x0, %r8d
cmovgl %r9d, %r8d
cmpq %rdx, %r8
je 0x8f85
movq 0x48(%rbx), %r9
movzbl (%r15,%rdx), %r10d
movb (%r9,%r10), %r9b
movb %r9b, (%r12,%rdx)
incq %rdx
jmp 0x8f6a
xorl %edx, %edx
cmpq %rcx, %rdx
jg 0x8f9d
movb 0x2c(%rbx), %r8b
movb %r8b, (%rax,%rdx)
movb %r8b, (%rsi,%rdx)
incq %rdx
jmp 0x8f87
movq (%rsp), %r9
cmpl $0x4, %r9d
pushq $0x3
popq %rdx
movl %edx, %r8d
cmovgel %r9d, %r8d
addl $-0x3, %r8d
xorl %r9d, %r9d
pushq $0x3
popq %r10
pushq $0x1
popq %r11
pushq $0x4
popq %r13
cmpq %r9, %r8
je 0x9036
movzbl 0x1(%r12,%r9), %ebp
testl %ebp, %ebp
je 0x9003
movq %r10, %r14
cmpl $0x2, %ebp
jne 0x9023
movzbl 0x2(%r12,%r9), %ebp
cmpl $0x1, %ebp
je 0x9016
cmpl $0x3, %ebp
jne 0x9020
movzbl 0x3(%r12,%r9), %ebp
testb $-0x3, %bpl
jne 0x9031
cmpb $0x2, (%r12,%r9)
movq %r13, %r14
jne 0x9023
xorl %ebp, %ebp
jmp 0x9028
xorl %r14d, %r14d
cmpb $0x3, 0x2(%r12,%r9)
sete %r14b
xorq $0x3, %r14
jmp 0x9023
cmpb $0x2, (%r12,%r9)
movq %r11, %r14
je 0x9023
movq %r10, %r14
movb 0x20(%rbx,%r14,4), %bpl
movb %bpl, (%rsi,%r9)
incq %r9
jmp 0x8fc2
xorl %r14d, %r14d
jmp 0x9023
pushq $0x1
popq %r8
xorl %r10d, %r10d
cmpq %rcx, %r8
jge 0x90f2
xorl %r11d, %r11d
cmpb $0x0, -0x1(%r12,%r8)
je 0x9055
movl %edx, %ebp
jmp 0x90cd
movb (%r12,%r8), %r14b
cmpb $0x2, %r14b
jne 0x90ba
xorl %r11d, %r11d
movl $0x0, %ebp
cmpq $0x2, %r8
jb 0x9087
movb -0x2(%r12,%r8), %r14b
pushq $-0x1
popq %rbp
cmpb $0x1, %r14b
je 0x9087
xorl %ebp, %ebp
cmpb $0x3, %r14b
sete %bpl
negl %ebp
movl %r8d, %r13d
addl $-0x7, %r13d
pushq $-0x1
popq %r9
cmovsl %r9d, %r13d
leal -0x4(%r8), %r14d
cmpl %r13d, %r14d
jle 0x90c9
movl %r14d, %r9d
movzbl (%r12,%r9), %r9d
orl $0x2, %r9d
cmpl $0x3, %r9d
je 0x90b5
addl 0x34(%rbx), %r11d
decl %r14d
jmp 0x909a
xorl %ebp, %ebp
cmpb $0x1, %r14b
sete %bpl
xorl $0x3, %ebp
jmp 0x90cd
testl %ebp, %ebp
js 0x90ed
movl %ebp, %r9d
movb 0x20(%rbx,%r9,4), %r14b
incl %ebp
cmpl $0x2, %ebp
cmovael %r10d, %r11d
addb %r14b, %r11b
movb %r11b, (%rax,%r8)
incq %r8
jmp 0x903d
xorl %r14d, %r14d
jmp 0x90d5
movq 0x40(%rsp), %r11
testq %r11, %r11
je 0x9160
movl 0xc(%rbx), %eax
incl %eax
pushq $0x2
popq %r8
cltd
idivl %r8d
leal 0xff(%rax), %edx
pushq $0x1
popq %r8
cmpq %rcx, %r8
jge 0x9160
movzbl (%r11,%r8), %r10d
cmpl $0xff, %r10d
je 0x9144
movl %r10d, %r9d
shrl %r9d
addl $-0x40, %r9d
cmpl %eax, %r9d
cmovgel %edx, %r9d
testb $0x1, %r10b
jne 0x9157
subb %r9b, -0x1(%rsi,%r8)
jmp 0x915b
movb 0x38(%rbx), %r9b
subb %r9b, -0x1(%rsi,%r8)
movb 0x38(%rbx), %r9b
subb %r9b, (%rdi,%r8)
jmp 0x915b
subb %r9b, (%rdi,%r8)
incq %r8
jmp 0x9113
movq %r15, %rdi
movq (%rsp), %rsi
movq %rbx, %rdx
movq %r12, %rcx
callq 0xa41f
movq %r12, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq