// File: /workspace/github_c_makefile_star2_O1/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 0x80a1
movq %rax, %r12
movslq %r14d, %rdx
leaq (%rax,%rdx), %rcx
movq 0x58(%rsp), %rax
movq %rcx, (%rax)
movslq %ebp, %rdi
leaq (%rcx,%rdi), %rax
movq 0x60(%rsp), %rsi
movq %rax, (%rsi)
movq %rdx, 0x10(%rsp)
leaq 0x1(%rdx,%rax), %rsi
movq 0x68(%rsp), %rdx
movq %rsi, (%rdx)
movq %rdi, 0x8(%rsp)
testl %edi, %edi
jle 0x9e38
movl %ebp, %edx
xorl %edi, %edi
movq 0x50(%rbx), %r8
movzbl (%r13,%rdi), %r9d
movb (%r8,%r9), %r8b
movb %r8b, (%rcx,%rdi)
incq %rdi
cmpq %rdi, %rdx
jne 0x9e1e
testl %r14d, %r14d
jle 0x9e5b
movl %r14d, %ecx
xorl %edx, %edx
movq 0x48(%rbx), %rdi
movzbl (%r15,%rdx), %r8d
movb (%rdi,%r8), %dil
movb %dil, (%r12,%rdx)
incq %rdx
cmpq %rdx, %rcx
jne 0x9e42
testl %r14d, %r14d
js 0x9e7a
leal 0x1(%r14), %ecx
xorl %edx, %edx
movb 0x2c(%rbx), %dil
movb %dil, (%rsi,%rdx)
movb %dil, (%rax,%rdx)
incq %rdx
cmpq %rdx, %rcx
jne 0x9e66
cmpl $0x4, %r14d
jl 0x9f12
leal -0x3(%r14), %edi
xorl %r8d, %r8d
movb 0x1(%r12,%r8), %dl
cmpb $0x2, %dl
jne 0x9edd
cmpb $0x3, 0x2(%r12,%r8)
jne 0x9ec4
leal 0x3(%r8), %edx
xorl %ecx, %ecx
cmpl %r14d, %edx
jge 0x9ef4
movzbl 0x3(%r12,%r8), %edx
testb $-0x3, %dl
jne 0x9ef4
xorl %ecx, %ecx
cmpb $0x2, (%r12,%r8)
setne %cl
leal (%rcx,%rcx,4), %ecx
decl %ecx
jmp 0x9ef4
cmpb $0x2, %dl
jne 0x9edd
cmpb $0x1, 0x2(%r12,%r8)
jne 0x9edd
movl $0x1, %ecx
cmpb $0x2, (%r12,%r8)
je 0x9ef4
movl $0x3, %ecx
testb %dl, %dl
jne 0x9ef4
xorl %ecx, %ecx
cmpb $0x3, 0x2(%r12,%r8)
sete %cl
xorl $0x3, %ecx
testl %ecx, %ecx
js 0x9f00
movl %ecx, %ecx
movb 0x20(%rbx,%rcx,4), %cl
jmp 0x9f02
xorl %ecx, %ecx
movb %cl, (%rax,%r8)
incq %r8
cmpq %r8, %rdi
jne 0x9e8b
movq 0x50(%rsp), %rdi
cmpl $0x2, %r14d
jl 0x9ff0
movl %r14d, %r8d
movl $0x1, %r9d
xorl %r11d, %r11d
movb -0x1(%r12,%r9), %cl
movl $0x3, %ebp
testb %cl, %cl
je 0x9f4a
xorl %r13d, %r13d
testl %ebp, %ebp
js 0x9fb2
movl %ebp, %ecx
movb 0x20(%rbx,%rcx,4), %cl
jmp 0x9fb4
cmpb $0x2, (%r12,%r9)
jne 0x9fd5
xorl %ebp, %ebp
cmpq $0x2, %r9
jb 0x9f77
movb -0x2(%r12,%r9), %cl
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpb $0x1, %cl
je 0x9f77
xorl %ebp, %ebp
cmpb $0x3, %cl
sete %bpl
negl %ebp
movl %r9d, %ecx
addl $-0x7, %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmovsl %edx, %ecx
leaq -0x4(%r9), %rdx
movslq %ecx, %r10
xorl %r13d, %r13d
cmpq %r10, %rdx
jle 0x9f3e
movl %edx, %r10d
movzbl (%r12,%r10), %r10d
orl $0x2, %r10d
cmpl $0x3, %r10d
je 0x9faa
addl 0x34(%rbx), %r13d
decl %edx
cmpl %ecx, %edx
jg 0x9f94
jmp 0x9f3e
xorl %ecx, %ecx
incl %ebp
cmpl $0x2, %ebp
movzbl %r13b, %edx
cmovael %r11d, %edx
addb %cl, %dl
movb %dl, (%rsi,%r9)
incq %r9
cmpq %r8, %r9
jne 0x9f2d
jmp 0x9ff0
testb %cl, %cl
jne 0x9f3b
xorl %ebp, %ebp
cmpb $0x1, (%r12,%r9)
sete %bpl
xorl $0x3, %ebp
jmp 0x9f3b
testq %rdi, %rdi
je 0xa07d
cmpl $0x2, %r14d
jl 0xa07d
movl 0xc(%rbx), %ecx
movl %ecx, %edx
incl %edx
shrl $0x1f, %edx
leal (%rcx,%rdx), %esi
incl %esi
sarl %esi
leal 0xff(%rsi), %r8d
movl %r14d, %r9d
movq 0x10(%rsp), %rcx
movq 0x8(%rsp), %rdx
leaq (%rdx,%rcx,2), %rcx
addq %r12, %rcx
incq %rcx
decq %r9
xorl %edx, %edx
movzbl 0x1(%rdi,%rdx), %r11d
cmpl $0xff, %r11d
je 0xa05f
movl %r11d, %r10d
shrl %r10d
addl $-0x40, %r10d
cmpl %esi, %r10d
cmovgel %r8d, %r10d
testb $0x1, %r11b
jne 0xa071
subb %r10b, (%rax,%rdx)
jmp 0xa075
movb 0x38(%rbx), %r10b
subb %r10b, (%rax,%rdx)
movb 0x38(%rbx), %r10b
subb %r10b, (%rcx,%rdx)
jmp 0xa075
subb %r10b, (%rcx,%rdx)
incq %rdx
cmpq %rdx, %r9
jne 0xa033
movq %r15, %rdi
movl %r14d, %esi
movq %rbx, %rdx
movq %r12, %rcx
callq 0xb8bc
movq %r12, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq