// File: /workspace/github_c_makefile_star2_O2/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, %r12d
movq %rcx, %rbp
movl %edx, %r14d
movq %rsi, 0x10(%rsp)
leal (%r14,%r14,2), %eax
addl %r12d, %eax
addl $0x2, %eax
movslq %eax, %rsi
callq 0x7460
movq %rax, %r15
movslq %r14d, %rsi
movq %rax, %r13
leaq (%rax,%rsi), %rdx
movq 0x58(%rsp), %rax
movq %rdx, (%rax)
movslq %r12d, %rdi
leaq (%rdx,%rdi), %rcx
movq 0x60(%rsp), %rax
movq %rcx, (%rax)
leaq (%rsi,%rcx), %rax
incq %rax
movq 0x68(%rsp), %r8
movq %rax, (%r8)
xorl %r8d, %r8d
testl %edi, %edi
movl $0x0, %r9d
cmovgl %edi, %r9d
decl %edi
cmpq %r8, %r9
je 0x8c00
movq 0x50(%rbx), %r10
movzbl (%rbp,%r8), %r11d
movb (%r10,%r11), %r10b
movslq %edi, %rdi
movb %r10b, (%rdx,%rdi)
incq %r8
jmp 0x8bdf
movq %rax, 0x8(%rsp)
xorl %edx, %edx
testl %r14d, %r14d
movl $0x0, %edi
cmovgl %r14d, %edi
leal -0x1(%r14), %r8d
movq 0x10(%rsp), %rax
cmpq %rdx, %rdi
je 0x8c3d
movq 0x48(%rbx), %r9
movzbl (%rax,%rdx), %r10d
movb (%r9,%r10), %r9b
movslq %r8d, %r8
movb %r9b, (%r15,%r8)
incq %rdx
decl %r8d
jmp 0x8c1c
xorl %edx, %edx
movq 0x8(%rsp), %rax
cmpq %rsi, %rdx
jg 0x8c5a
movb 0x2c(%rbx), %r8b
movb %r8b, (%rax,%rdx)
movb %r8b, (%rcx,%rdx)
incq %rdx
jmp 0x8c44
addq $0x2, %r13
cmpl $0x4, %r14d
pushq $0x3
popq %rdx
movl %edx, %r8d
cmovgel %r14d, %r8d
addl $-0x3, %r8d
pushq $0x5
popq %rdx
xorl %r11d, %r11d
cmpq %r8, %r11
je 0x8d3a
movzbl 0x1(%r15,%r11), %r9d
xorl %ebp, %ebp
cmpl $0x1, %r9d
je 0x8cd5
cmpl $0x2, %r9d
jne 0x8ce5
cmpb $0x0, (%r13,%r11)
pushq $0x3
popq %r9
jne 0x8ce9
movq %r13, %rax
movb 0x3(%r15,%r11), %r12b
andb $-0x3, %r12b
leaq 0x8(%r11), %r13
xorl %ebp, %ebp
movq %rdx, %r9
cmpl %r14d, %r9d
jge 0x8d17
cmpq %r13, %r9
jae 0x8d17
movzbl (%r15,%r9), %r10d
orl $0x2, %r10d
cmpl $0x3, %r10d
je 0x8cd0
addl 0x34(%rbx), %ebp
incq %r9
jmp 0x8cb4
cmpb $0x1, (%r13,%r11)
pushq $0x3
popq %r9
sbbl $0x0, %r9d
jmp 0x8ce9
pushq $0x3
popq %r9
movl %r9d, %r10d
movb 0x20(%rbx,%r10,4), %r12b
testl %r9d, %r9d
sete %r9b
testb %r9b, %r9b
movl $0x0, %r9d
cmovel %r9d, %ebp
addb %r12b, %bpl
movb %bpl, (%rcx,%r11)
incq %r11
incq %rdx
jmp 0x8c76
xorl %r9d, %r9d
cmpb $0x1, %r12b
jne 0x8d30
movb $0x1, %r9b
xorl %r12d, %r12d
movq %rax, %r13
movq 0x8(%rsp), %rax
jmp 0x8cf8
movq %rax, %r13
movq 0x8(%rsp), %rax
jmp 0x8ce9
pushq $0x1
popq %rdx
pushq $0x3
popq %r8
pushq $0x4
popq %r9
movq %rdx, %r10
cmpq %rsi, %r10
jge 0x8ddd
movzbl -0x1(%r15,%r10), %r11d
cmpl $0x1, %r11d
je 0x8d99
cmpl $0x3, %r11d
jne 0x8db3
movb (%r15,%r10), %r11b
cmpb $0x2, %r11b
jne 0x8db8
cmpq $0x2, %r10
jb 0x8dc5
movzbl -0x2(%r15,%r10), %r11d
testb $-0x3, %r11b
jne 0x8dc5
leaq 0x1(%r10), %r11
movq %r9, %r12
cmpl %r14d, %r11d
jge 0x8dc8
cmpb $0x2, (%r15,%r11)
movq %r9, %r12
jne 0x8dc8
xorl %ebp, %ebp
jmp 0x8dd1
cmpb $0x2, (%r15,%r10)
jne 0x8db3
leaq 0x1(%r10), %r11
cmpl %r14d, %r11d
jge 0x8db3
cmpb $0x1, (%r15,%r11)
movq %rdx, %r12
je 0x8dc8
movq %r8, %r12
jmp 0x8dc8
cmpb $0x1, %r11b
movq %r8, %r12
sbbq $0x0, %r12
jmp 0x8dc8
xorl %r12d, %r12d
movb 0x20(%rbx,%r12,4), %bpl
leaq 0x1(%r10), %r11
movb %bpl, (%rax,%r10)
movq %r11, %r10
jmp 0x8d48
movq 0x50(%rsp), %rsi
testq %rsi, %rsi
je 0x8e58
movl 0xc(%rbx), %eax
incl %eax
pushq $0x2
popq %r8
cltd
idivl %r8d
leal 0xff(%rax), %edx
leal -0x1(%r14), %r8d
xorl %r9d, %r9d
movq 0x8(%rsp), %r12
cmpq %r9, %rdi
je 0x8e58
movzbl (%rsi,%r9), %r11d
movslq %r8d, %r10
cmpl $0xff, %r11d
je 0x8e3a
movl %r11d, %ebp
shrl %ebp
addl $-0x40, %ebp
cmpl %eax, %ebp
cmovgel %edx, %ebp
testb $0x1, %r11b
jne 0x8e4c
movq 0x8(%rsp), %r11
subb %bpl, (%r11,%r10)
jmp 0x8e50
movb 0x38(%rbx), %r11b
subb %r11b, (%rcx,%r10)
movb 0x38(%rbx), %r11b
subb %r11b, (%r12,%r10)
jmp 0x8e50
subb %bpl, (%rcx,%r10)
incq %r9
decl %r8d
jmp 0x8e06
movq 0x10(%rsp), %rdi
movl %r14d, %esi
movq %rbx, %rdx
movq %r15, %rcx
callq 0xa41f
movl %r14d, %eax
sarl %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
leal -0x1(%r14), %edx
cmpq %rcx, %rax
je 0x8e9a
movb (%r15,%rcx), %sil
movslq %edx, %rdx
movb (%r15,%rdx), %dil
movb %dil, (%r15,%rcx)
movb %sil, (%r15,%rdx)
incq %rcx
decl %edx
jmp 0x8e7b
addl $-0x2, %r14d
movslq %r14d, %rdx
movq %r13, %rdi
movq %r15, %rsi
callq 0x2270
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