// File: /workspace/github_c_makefile_star2_O1/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, 0x8(%rsp)
movq 0x58(%rsp), %r12
leal (%r14,%r14,2), %eax
addl %ebp, %eax
addl $0x2, %eax
movslq %eax, %rsi
callq 0x80a1
movq %rax, %r15
movslq %r14d, %rdx
addq %rdx, %rax
movq %rax, (%r12)
movslq %ebp, %rcx
addq %rcx, %rax
movq 0x60(%rsp), %rsi
movq %rax, (%rsi)
leaq (%rdx,%rax), %rdi
incq %rdi
movq 0x68(%rsp), %rsi
movq %rdi, (%rsi)
movq %rcx, 0x10(%rsp)
testl %ecx, %ecx
jle 0x9a8b
movl %ebp, %ecx
leaq (%rdx,%r15), %r8
decq %r8
movq 0x50(%rbx), %r9
movzbl (%r13), %r10d
movb (%r9,%r10), %r9b
movb %r9b, (%r8,%rcx)
incq %r13
decq %rcx
jne 0x9a72
movl %r14d, %ecx
testl %r14d, %r14d
jle 0x9ab4
movq %rcx, %r8
movq 0x8(%rsp), %r9
movq 0x48(%rbx), %r10
movzbl (%r9), %r11d
movb (%r10,%r11), %r10b
movb %r10b, -0x1(%r15,%r8)
incq %r9
decq %r8
jne 0x9a9b
testl %r14d, %r14d
js 0x9ad4
leal 0x1(%r14), %r8d
xorl %r9d, %r9d
movb 0x2c(%rbx), %r10b
movb %r10b, (%rdi,%r9)
movb %r10b, (%rax,%r9)
incq %r9
cmpq %r9, %r8
jne 0x9ac0
cmpl $0x4, %r14d
jl 0x9bca
leal -0x3(%r14), %edi
movl $0x6, %r12d
xorl %r9d, %r9d
xorl %r10d, %r10d
movzbl 0x1(%r15,%r10), %r8d
cmpl $0x1, %r8d
je 0x9b0e
cmpl $0x2, %r8d
jne 0x9b22
cmpb $0x0, 0x2(%r15,%r10)
je 0x9b63
cmpb $0x1, %r8b
jne 0x9b22
cmpb $0x1, 0x2(%r15,%r10)
movl $0x3, %r11d
sbbl $0x0, %r11d
xorl %ebp, %ebp
jmp 0x9b2a
xorl %ebp, %ebp
movl $0x3, %r11d
testl %r11d, %r11d
js 0x9b39
movl %r11d, %esi
movb 0x20(%rbx,%rsi,4), %r8b
jmp 0x9b3c
xorl %r8d, %r8d
incl %r11d
cmpl $0x2, %r11d
movzbl %bpl, %esi
cmovael %r9d, %esi
addb %r8b, %sil
movb %sil, (%rax,%r10)
leaq 0x1(%r10), %rsi
incq %r12
movq %rsi, %r10
cmpq %rdi, %rsi
jne 0x9aee
jmp 0x9bca
leaq 0x3(%r10), %r8
xorl %r11d, %r11d
cmpl %r14d, %r8d
jge 0x9b8d
movb (%r15,%r8), %r8b
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
cmpb $0x1, %r8b
je 0x9b8d
xorl %r11d, %r11d
cmpb $0x3, %r8b
sete %r11b
negl %r11d
leal 0x5(%r10), %r8d
xorl %ebp, %ebp
cmpl %r14d, %r8d
jge 0x9b2a
leaq 0x8(%r10), %r13
movq %r12, %r8
movzbl -0x1(%r15,%r8), %esi
orl $0x2, %esi
cmpl $0x3, %esi
je 0x9bb0
addl 0x34(%rbx), %ebp
cmpl %r14d, %r8d
jge 0x9b2a
leaq 0x1(%r8), %rsi
cmpq %r13, %r8
movq %rsi, %r8
jb 0x9b9f
jmp 0x9b2a
movq 0x50(%rsp), %rdi
addq %rdx, %rax
cmpl $0x2, %r14d
jl 0x9cbd
movl $0x1, %r8d
subq %rcx, %r8
movl $0x2, %r9d
movb -0x2(%r15,%r9), %r11b
cmpb $0x3, %r11b
jne 0x9c3a
cmpb $0x2, -0x1(%r15,%r9)
jne 0x9c3a
leaq -0x1(%r9), %rsi
xorl %r10d, %r10d
cmpq $0x2, %rsi
jb 0x9c93
movzbl -0x3(%r15,%r9), %esi
testb $-0x3, %sil
jne 0x9c93
movl $0x4, %r10d
cmpq %rcx, %r9
jae 0x9c93
xorl %esi, %esi
cmpb $0x2, (%r15,%r9)
setne %sil
leal (%rsi,%rsi,4), %r10d
decl %r10d
jmp 0x9c93
cmpb $0x1, %r11b
jne 0x9c77
cmpb $0x2, -0x1(%r15,%r9)
jne 0x9c77
cmpq %rcx, %r9
jae 0x9c77
cmpb $0x3, %r11b
setne %sil
xorl %r10d, %r10d
cmpb $0x1, (%r15,%r9)
setne %r11b
sete %bpl
orb %sil, %bpl
je 0x9c83
movb %r11b, %r10b
leal 0x1(,%r10,2), %r10d
jmp 0x9c93
movl $0x3, %r10d
cmpb $0x3, %r11b
jne 0x9c93
cmpb $0x1, -0x1(%r15,%r9)
movl $0x3, %r10d
sbbl $0x0, %r10d
testl %r10d, %r10d
js 0x9ca2
movl %r10d, %esi
movb 0x20(%rbx,%rsi,4), %r10b
jmp 0x9ca5
xorl %r10d, %r10d
movb %r10b, (%rax,%r9)
leaq (%r8,%r9), %rsi
incq %rsi
incq %r9
cmpq $0x2, %rsi
jne 0x9beb
testq %rdi, %rdi
je 0x9d39
testl %r14d, %r14d
jle 0x9d39
movl 0xc(%rbx), %esi
movl %esi, %r8d
incl %r8d
shrl $0x1f, %r8d
addl %esi, %r8d
incl %r8d
sarl %r8d
leal 0xff(%r8), %r9d
movq 0x10(%rsp), %rsi
addq %rdx, %rsi
leaq (%r15,%rsi), %rdx
decq %rdx
movzbl (%rdi), %r10d
cmpl $0xff, %r10d
je 0x9d1b
movl %r10d, %esi
shrl %esi
addl $-0x40, %esi
cmpl %r8d, %esi
cmovgel %r9d, %esi
testb $0x1, %r10b
jne 0x9d2d
subb %sil, (%rax,%rcx)
jmp 0x9d31
movb 0x38(%rbx), %sil
subb %sil, (%rdx,%rcx)
movb 0x38(%rbx), %sil
subb %sil, (%rax,%rcx)
jmp 0x9d31
subb %sil, (%rdx,%rcx)
incq %rdi
decq %rcx
jne 0x9cf3
movq 0x8(%rsp), %rdi
movl %r14d, %esi
movq %rbx, %rdx
movq %r15, %rcx
callq 0xb8bc
movl %r14d, %eax
sarl %eax
testl %eax, %eax
jle 0x9d7a
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 0x9d5d
movq %r15, %rdi
addq $0x2, %rdi
addl $-0x2, %r14d
movslq %r14d, %rdx
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