// File: /workspace/github_c_makefile_star2_O3/lh3[P]miniprot/nasw-sse.c
// Function: ns_prep_seq_left
static uint8_t *ns_prep_seq_left(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, tmp;
	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[]. NB: this is reversed
		aas[al - 1 - j] = opt->aa20[(uint8_t)as[j]];
	for (i = 0; i < nl; ++i) // nt4 encoding of ns[] for computing donor[] and acceptor[]. NB: this is reversed
		nas[nl - 1 - 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[] (actually acceptor as the string is reversed)
		int32_t t = 3, penY = 0;
		if (nas[i+1] == 2 && nas[i+2] == 0) { // GA. (the reverse of .AG)
			t = i + 3 < nl && (nas[i+3] == 1 || nas[i+3] == 3)? -1 : 0;
			for (j = i + 5; j < nl && j < i + 8; ++j)
				if (nas[j] != 1 && nas[j] != 3) penY += opt->sp[5];
		} else if (nas[i+1] == 1 && nas[i+2] == 0) t = 2; // CA.
		donor[i] = t < 0? 0 : opt->sp[t];
		if (t == -1 || t == 0) donor[i] += penY;
	}
	for (i = 1; i < nl; ++i) { // generate acceptor[] (actually donor)
		int32_t t = 3;
		if (nas[i-1] == 3 && nas[i] == 2) // .TG (the reverse of GT.)
			t = i >= 2 && (nas[i-2] == 0 || nas[i-2] == 2)? (i+1 < nl && nas[i+1] == 2? -1 : 4) : 0;
		else if (nas[i-1] == 1 && nas[i] == 2 && i+1 < nl && nas[i+1] == 1) t = 1; // .CG
		else if (nas[i-1] == 3 && nas[i] == 0) t = 2; // .TA
		acceptor[i] = t < 0? 0 : opt->sp[t];
	}
	if (ss) {
		int32_t max_spsc = (opt->io + 1) / 2 - 1;
		for (i = 0; i < nl; ++i) {
			int32_t spsc = (int8_t)(ss[i]>>1) - (int8_t)NS_SPSC_OFFSET;
			if (spsc > max_spsc) spsc = max_spsc;
			if (ss[i] == 0xff) {
				donor[nl - i - 1] -= opt->sp_null_bonus;
				acceptor[nl - i - 1] -= opt->sp_null_bonus;
			} else if (ss[i]&1) {
				donor[nl - i - 1] -= spsc;
			} else {
				acceptor[nl - i - 1] -= spsc;
			}
		}
	}
	ns_prep_nas(ns, nl, opt, nas);
	for (i = 0; i < nl>>1; ++i) // reverse
		tmp = nas[i], nas[i] = nas[nl - 1 - i], nas[nl - 1 - i] = tmp;
	memmove(nas + 2, nas, nl - 2);
	nas[0] = nas[1] = opt->aa20['X'];
	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, %r12
leal (%r14,%r14,2), %eax
addl %ebp, %eax
addl $0x2, %eax
movslq %eax, %rsi
callq 0x84a5
movq %rax, %r15
movslq %r14d, %r10
leaq (%rax,%r10), %rdi
movq 0x58(%rsp), %rax
movq %rdi, (%rax)
movslq %ebp, %r11
addq %r11, %rdi
movq 0x60(%rsp), %rax
movq %rdi, (%rax)
leaq (%r10,%rdi), %rsi
incq %rsi
movq 0x68(%rsp), %rax
movq %rsi, (%rax)
testl %r11d, %r11d
jle 0x9e19
movl %r11d, %eax
leaq (%r11,%r10), %rcx
addq %r15, %rcx
decq %rcx
xorl %edx, %edx
movq 0x50(%rbx), %r8
movzbl (%r13,%rdx), %r9d
movb (%r8,%r9), %r8b
movb %r8b, (%rcx)
incq %rdx
decq %rcx
cmpq %rdx, %rax
jne 0x9dfd
testl %r14d, %r14d
jle 0x9e45
movl %r14d, %eax
leaq (%r10,%r15), %rcx
decq %rcx
xorl %edx, %edx
movq 0x48(%rbx), %r8
movzbl (%r12,%rdx), %r9d
movb (%r8,%r9), %r8b
movb %r8b, (%rcx)
incq %rdx
decq %rcx
cmpq %rdx, %rax
jne 0x9e2a
movq 0x50(%rsp), %rdx
testl %r14d, %r14d
js 0x9ffa
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
leal 0x1(%r14), %eax
xorl %ecx, %ecx
movb 0x2c(%rbx), %r8b
movb %r8b, (%rsi,%rcx)
movb %r8b, (%rdi,%rcx)
incq %rcx
cmpq %rcx, %rax
jne 0x9e62
leaq 0x2(%r15), %r9
cmpl $0x4, %r14d
jl 0x9f51
leal -0x3(%r14), %r8d
movl $0x6, %r13d
xorl %r10d, %r10d
xorl %r11d, %r11d
movq %r9, 0x10(%rsp)
movzbl 0x1(%r15,%r11), %eax
cmpl $0x1, %eax
je 0x9f0b
movl $0x0, %ebp
movl $0x3, %ecx
cmpl $0x2, %eax
jne 0x9f1a
cmpb $0x0, (%r9,%r11)
jne 0x9f1a
leal 0x5(%r11), %eax
xorl %ecx, %ecx
cmpl %r14d, %eax
jge 0x9ef2
leaq 0x8(%r11), %rax
xorl %ebp, %ebp
movq %r13, %r9
movzbl -0x1(%r15,%r9), %r10d
orl $0x2, %r10d
cmpl $0x3, %r10d
je 0x9ee1
addl 0x34(%rbx), %ebp
cmpl %r14d, %r9d
jge 0x9ef2
leaq 0x1(%r9), %r10
cmpq %rax, %r9
movq %r10, %r9
jb 0x9ece
movb 0x3(%r15,%r11), %al
andb $-0x3, %al
cmpb $0x1, %al
jne 0x9f47
movb $0x1, %cl
xorl %eax, %eax
movq 0x10(%rsp), %r9
xorl %r10d, %r10d
jmp 0x9f25
cmpb $0x1, (%r9,%r11)
movl $0x3, %ecx
sbbl $0x0, %ecx
xorl %ebp, %ebp
movl %ecx, %eax
movb 0x20(%rbx,%rax,4), %al
testl %ecx, %ecx
sete %cl
testb %cl, %cl
cmovel %r10d, %ebp
addb %al, %bpl
movb %bpl, (%rdi,%r11)
leaq 0x1(%r11), %rax
incq %r13
movq %rax, %r11
cmpq %r8, %rax
jne 0x9e99
jmp 0x9f51
movq 0x10(%rsp), %r9
xorl %r10d, %r10d
jmp 0x9f1a
cmpl $0x2, %r14d
jl 0xa000
movl %r14d, %edi
movl $0x1, %r8d
movq 0x8(%rsp), %r10
movq (%rsp), %r11
movzbl -0x1(%r15,%r8), %eax
cmpl $0x1, %eax
je 0x9fae
cmpl $0x3, %eax
jne 0x9fca
movb (%r15,%r8), %al
cmpb $0x2, %al
jne 0x9fd1
cmpq $0x2, %r8
jb 0x9fde
movzbl -0x2(%r15,%r8), %eax
testb $-0x3, %al
jne 0x9fde
leaq 0x1(%r8), %rcx
movl $0x4, %eax
cmpq %r10, %rcx
jge 0x9fe0
cmpb $0x2, (%r15,%rcx)
jne 0x9fe0
xorl %eax, %eax
jmp 0x9fe8
cmpb $0x2, (%r15,%r8)
jne 0x9fca
leaq 0x1(%r8), %rcx
cmpq %r10, %rcx
jge 0x9fca
movl $0x1, %eax
cmpb $0x1, (%r15,%rcx)
je 0x9fe0
movl $0x3, %eax
jmp 0x9fe0
cmpb $0x1, %al
movl $0x3, %eax
sbbq $0x0, %rax
jmp 0x9fe0
xorl %eax, %eax
movb 0x20(%rbx,%rax,4), %al
leaq 0x1(%r8), %rcx
movb %al, (%rsi,%r8)
movq %rcx, %r8
cmpq %rdi, %rcx
jne 0x9f6d
jmp 0xa009
leaq 0x2(%r15), %r9
jmp 0xa009
movq 0x8(%rsp), %r10
movq (%rsp), %r11
movq %r9, %r13
testq %rdx, %rdx
je 0xa099
testl %r14d, %r14d
jle 0xa099
movl 0xc(%rbx), %eax
movl %eax, %ecx
incl %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
incl %ecx
sarl %ecx
leal 0xff(%rcx), %esi
movl %r14d, %edi
leaq (%r11,%r10,2), %rax
leaq (%r15,%rax), %r8
decq %r8
leaq (%r10,%r10,2), %rax
addq %r11, %rax
addq %r15, %rax
negq %rdi
xorl %r9d, %r9d
movzbl (%rdx), %r11d
cmpl $0xff, %r11d
je 0xa078
movl %r11d, %r10d
shrl %r10d
addl $-0x40, %r10d
cmpl %ecx, %r10d
cmovgel %esi, %r10d
testb $0x1, %r11b
jne 0xa08a
subb %r10b, (%rax,%r9)
jmp 0xa08e
movb 0x38(%rbx), %r10b
subb %r10b, (%r8,%r9)
movb 0x38(%rbx), %r10b
subb %r10b, (%rax,%r9)
jmp 0xa08e
subb %r10b, (%r8,%r9)
incq %rdx
decq %r9
cmpq %r9, %rdi
jne 0xa04e
movq %r12, %rdi
movl %r14d, %esi
movq %rbx, %rdx
movq %r15, %rcx
callq 0xbb50
movl %r14d, %eax
sarl %eax
testl %eax, %eax
jle 0xa0d8
movl %eax, %eax
leal -0x1(%r14), %ecx
xorl %edx, %edx
movb (%r15,%rdx), %sil
movslq %ecx, %rcx
movb (%r15,%rcx), %dil
movb %dil, (%r15,%rdx)
movb %sil, (%r15,%rcx)
incq %rdx
decl %ecx
cmpq %rdx, %rax
jne 0xa0bb
addl $-0x2, %r14d
movslq %r14d, %rdx
movq %r13, %rdi
movq %r15, %rsi
callq 0x2250
movq 0x50(%rbx), %rax
movb 0x58(%rax), %al
movb %al, 0x1(%r15)
movb %al, (%r15)
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq