// File: /workspace/github_c_makefile_star2_O2/lh3[P]miniprot/nasw-sse.c
// Function: ns_backtrack
static void ns_backtrack(void *km, int32_t vs, const __m128i *tb, int32_t nl, int32_t al, uint32_t **cigar_, int32_t *n_cigar, int32_t *m_cigar)
{
	int32_t i = nl - 1, j = al - 1, last = 0, slen = (al + vs - 1) / vs;
	uint32_t *cigar = *cigar_, tmp;
	assert(vs == 4 || vs == 8);
	while (i >= 2 && j >= 0) {
		const __m128i *tbi = &tb[i * slen];
		int32_t x = *((int16_t*)&tbi[j%slen] + j/slen);
		int32_t state, ext;
		if (vs == 4) x = *((int32_t*)&tbi[j%slen] + j/slen);
		if (x>>9&1) x = 1|x>>4<<4;
		state = last == 0? x&0xf : last;
		ext = state >= 1 && state <= 5? x>>(state+3)&1 : 0;
		if (state == 0) {
			cigar = ns_push_cigar(km, n_cigar, m_cigar, cigar, NS_CIGAR_M, 1), i -= 3, --j;
		} else if (state == 1) {
			cigar = ns_push_cigar(km, n_cigar, m_cigar, cigar, NS_CIGAR_I, 1), --j;
		} else if (state == 2) {
			cigar = ns_push_cigar(km, n_cigar, m_cigar, cigar, NS_CIGAR_D, 1), i -= 3;
		} else if (state == 3) {
			cigar = ns_push_cigar(km, n_cigar, m_cigar, cigar, NS_CIGAR_N, 1), --i;
		} else if (state == 4) {
			cigar = ns_push_cigar(km, n_cigar, m_cigar, cigar, NS_CIGAR_U, 1), --i;
			if (!ext) --j;
		} else if (state == 5) {
			cigar = ns_push_cigar(km, n_cigar, m_cigar, cigar, NS_CIGAR_V, 1), --i;
			if (!ext) --j;
		} else if (state == 6) {
			cigar = ns_push_cigar(km, n_cigar, m_cigar, cigar, NS_CIGAR_F, 1), --i;
		} else if (state == 7) {
			cigar = ns_push_cigar(km, n_cigar, m_cigar, cigar, NS_CIGAR_F, 2), i -= 2;
		} else if (state == 8) {
			cigar = ns_push_cigar(km, n_cigar, m_cigar, cigar, NS_CIGAR_G, 1), --i, --j;
		} else if (state == 9) {
			cigar = ns_push_cigar(km, n_cigar, m_cigar, cigar, NS_CIGAR_G, 2), i -= 2, --j;
		}
		last = state >= 1 && state <= 5 && ext? state : 0;
	}
	if (j > 0) cigar = ns_push_cigar(km, n_cigar, m_cigar, cigar, NS_CIGAR_I, j);
	if (i >= 0) {
		int32_t l = (i+1) / 3 * 3, t = (i+1) % 3;
		if (l > 0) cigar = ns_push_cigar(km, n_cigar, m_cigar, cigar, NS_CIGAR_D, l);
		if (t != 0) cigar = ns_push_cigar(km, n_cigar, m_cigar, cigar, NS_CIGAR_F, t);
	}
	for (i = 0; i < (*n_cigar)>>1; ++i) // reverse CIGAR
		tmp = cigar[i], cigar[i] = cigar[(*n_cigar) - 1 - i], cigar[(*n_cigar) - 1 - i] = tmp;
	//fprintf(stderr, "%d\t", nl); for (i = 0; i < (*n_cigar); ++i) fprintf(stderr, "%d%c", cigar[i]>>4, NS_CIGAR_STR[cigar[i]&0xf]); fputc('\n', stderr);
	ns_fix_tiny_UV(*n_cigar, cigar);
	*cigar_ = cigar;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, 0x10(%rsp)
movl %r8d, %r13d
movl %ecx, %ebp
movq %rdx, 0x20(%rsp)
movq %rdi, 0x8(%rsp)
leal (%rsi,%r13), %eax
decl %eax
cltd
idivl %esi
movl %eax, %r15d
movq %rsi, 0x18(%rsp)
cmpl $0x8, %esi
je 0x91e5
cmpl $0x4, 0x18(%rsp)
jne 0x94ec
decl %r13d
movq 0x10(%rsp), %rax
movq (%rax), %rcx
decl %ebp
xorl %esi, %esi
cmpl $0x2, %ebp
jl 0x93ee
testl %r13d, %r13d
js 0x93ee
movl %r13d, %eax
cltd
idivl %r15d
movl %ebp, %edi
imull %r15d, %edi
movslq %edi, %rdi
shlq $0x4, %rdi
shlq $0x4, %rdx
addq 0x20(%rsp), %rdx
addq %rdi, %rdx
cltq
cmpl $0x4, 0x18(%rsp)
jne 0x9234
movl (%rdx,%rax,4), %eax
jmp 0x9238
movswl (%rdx,%rax,2), %eax
movl %eax, %edx
andl $-0x10, %edx
incl %edx
btl $0x9, %eax
cmovael %eax, %edx
movl %edx, %ebx
andl $0xf, %ebx
testl %esi, %esi
cmovnel %esi, %ebx
leal -0x1(%rbx), %r12d
leal 0x3(%rbx), %eax
movzbl %al, %eax
xorl %r14d, %r14d
btl %eax, %edx
setb %r14b
cmpl $0x9, %ebx
ja 0x93d4
leaq 0x99fc(%rip), %rdx      # 0x12c70
movslq (%rdx,%rbx,4), %rax
addq %rdx, %rax
jmpq *%rax
movq 0x8(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
xorl %r8d, %r8d
pushq $0x1
popq %r9
callq 0xa4a1
movq %rax, %rcx
addl $-0x3, %ebp
jmp 0x93d1
movq 0x8(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
pushq $0xc
jmp 0x9375
movq 0x8(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
pushq $0xb
popq %r8
pushq $0x2
popq %r9
callq 0xa4a1
movq %rax, %rcx
addl $-0x2, %ebp
jmp 0x93d1
movq 0x8(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
pushq $0x2
popq %r8
pushq $0x1
popq %r9
callq 0xa4a1
movq %rax, %rcx
addl $-0x3, %ebp
jmp 0x93d4
movq 0x8(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
pushq $0x3
jmp 0x939e
movq 0x8(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
pushq $0xa
popq %r8
pushq $0x2
popq %r9
callq 0xa4a1
movq %rax, %rcx
addl $-0x2, %ebp
jmp 0x93d4
movq 0x8(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
pushq $0x1
popq %r8
movl %r8d, %r9d
callq 0xa4a1
movq %rax, %rcx
jmp 0x93d1
movq 0x8(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
pushq $0xd
popq %r8
pushq $0x1
popq %r9
callq 0xa4a1
movq %rax, %rcx
decl %ebp
addl %r14d, %r13d
decl %r13d
jmp 0x93d4
movq 0x8(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
pushq $0xa
popq %r8
pushq $0x1
popq %r9
callq 0xa4a1
movq %rax, %rcx
decl %ebp
jmp 0x93d4
movq 0x8(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
pushq $0xb
popq %r8
pushq $0x1
popq %r9
callq 0xa4a1
movq %rax, %rcx
decl %ebp
decl %r13d
testl %r14d, %r14d
cmovel %r14d, %ebx
cmpl $0x5, %r12d
movl $0x0, %eax
cmovael %eax, %ebx
movl %ebx, %esi
jmp 0x91f4
testl %r13d, %r13d
jle 0x9416
pushq $0x1
popq %r8
movq 0x8(%rsp), %rdi
movq 0x60(%rsp), %r14
movq %r14, %rsi
movq 0x68(%rsp), %rdx
movl %r13d, %r9d
callq 0xa4a1
movq %rax, %rcx
jmp 0x941b
movq 0x60(%rsp), %r14
testl %ebp, %ebp
js 0x946e
incl %ebp
movl %ebp, %eax
xorl %edx, %edx
pushq $0x3
popq %rsi
divl %esi
movl %edx, %ebx
subl %edx, %ebp
testl %ebp, %ebp
jle 0x944e
pushq $0x2
popq %r8
movq 0x8(%rsp), %rdi
movq %r14, %rsi
movq 0x68(%rsp), %rdx
movl %ebp, %r9d
callq 0xa4a1
movq %rax, %rcx
testl %ebx, %ebx
je 0x946e
pushq $0xa
popq %r8
movq 0x8(%rsp), %rdi
movq %r14, %rsi
movq 0x68(%rsp), %rdx
movl %ebx, %r9d
callq 0xa4a1
movq %rax, %rcx
pushq $-0x1
popq %rdx
xorl %esi, %esi
movl (%r14), %eax
movl %eax, %edi
sarl %edi
movslq %edi, %rdi
cmpq %rdi, %rsi
jge 0x94a0
movl (%rcx,%rsi,4), %edi
addl %edx, %eax
cltq
movl (%rcx,%rax,4), %eax
movl %eax, (%rcx,%rsi,4)
movl (%r14), %eax
addl %edx, %eax
cltq
movl %edi, (%rcx,%rax,4)
incq %rsi
decl %edx
jmp 0x9473
xorl %edx, %edx
testl %eax, %eax
cmovlel %edx, %eax
cmpq %rdx, %rax
je 0x94d5
movl (%rcx,%rdx,4), %esi
movl %esi, %edi
andl $0xe, %edi
cmpl $0xc, %edi
setne %dil
cmpl $0x30, %esi
setae %r8b
orb %dil, %r8b
jne 0x94d0
andl $0x30, %esi
orl $0xb, %esi
movl %esi, (%rcx,%rdx,4)
incq %rdx
jmp 0x94a7
movq 0x10(%rsp), %rax
movq %rcx, (%rax)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x9831(%rip), %rdi      # 0x12d24
leaq 0x97a5(%rip), %rsi      # 0x12c9f
leaq 0x9836(%rip), %rcx      # 0x12d37
pushq $0x2c
popq %rdx
callq 0x2150