// File: /workspace/github_c_makefile_star2_O3/lh3[P]miniprot/sketch.c
// Function: mp_sketch_nt4
void mp_sketch_nt4(void *km, const uint8_t *seq, int64_t len, int32_t min_aa_len, int32_t kmer, int32_t mod_bit, int32_t bbit, int64_t boff, mp64_v *a)
{
	uint8_t codon, p, q;
	int64_t i, j, l, e[3], k[3];
	kv_resize(uint64_t, km, *a, len>>2);
	a->n = 0;
	for (p = 0; p < 3; ++p)
		e[p] = -1, k[p] = 0;
	for (i = 0, p = 1, codon = 0, l = 0; i < len; ++i, ++p) {
		if (p == 3) p = 0;
		if (seq[i] < 4) {
			codon = (codon << 2 | seq[i]) & 0x3f;
			if (++l >= 3) {
				uint8_t aa = ns_tab_codon[codon];
				if (aa >= 20) {
					if (k[p] >= min_aa_len)
						mp_sketch_clean_orf(km, seq, e[p] + 1 - k[p] * 3, e[p] + 1, kmer, mod_bit, bbit, boff, a);
					k[p] = 0, e[p] = -1;
				} else e[p] = i, ++k[p];
			}
		} else {
			for (q = 0; q < 3; ++q) {
				if (k[q] >= min_aa_len)
					mp_sketch_clean_orf(km, seq, e[q] + 1 - k[q] * 3, e[q] + 1, kmer, mod_bit, bbit, boff, a);
				k[q] = 0, e[q] = -1;
			}
			l = 0, codon = 0;
		}
	}
	for (p = 0; p < 3; ++p)
		if (k[p] >= min_aa_len)
			mp_sketch_clean_orf(km, seq, e[p] + 1 - k[p] * 3, e[p] + 1, kmer, mod_bit, bbit, boff, a);
	if (a->n <= 1) return; // the following loop doesn't work when a->n == 0
	radix_sort_mp64(a->a, a->a + a->n);
	for (i = 1, j = 0; i < a->n; ++i) // squeeze out identical entries
		if (a->a[j] != a->a[i])
			a->a[++j] = a->a[i];
	a->n = ++j;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %r9d, 0xc(%rsp)
movl %r8d, 0x8(%rsp)
movl %ecx, %r12d
movq %rdx, %rbp
movq %rsi, %r14
movq %rdi, %r15
movq 0xb0(%rsp), %rbx
movslq 0x4(%rbx), %rcx
movq %rdx, %rax
sarq $0x2, %rax
cmpq %rcx, %rax
jle 0xd7c5
decl %eax
movl %eax, %ecx
sarl %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x2, %eax
orl %ecx, %eax
movl %eax, %ecx
sarl $0x4, %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x8, %eax
orl %ecx, %eax
movl %eax, %ecx
sarl $0x10, %ecx
orl %eax, %ecx
leal 0x1(%rcx), %eax
movl %eax, 0x4(%rbx)
movq 0x8(%rbx), %rsi
movslq %ecx, %rax
leaq 0x8(,%rax,8), %rdx
movq %r15, %rdi
callq 0x85ad
movq %rax, 0x8(%rbx)
movl $0x0, (%rbx)
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, 0x30(%rsp)
movq $-0x1, 0x40(%rsp)
pxor %xmm0, %xmm0
movdqa %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movslq %r12d, %r12
testq %rbp, %rbp
jle 0xd979
movb $0x1, %r13b
xorl %edx, %edx
xorl %eax, %eax
xorl %ebx, %ebx
movq %rbp, 0x60(%rsp)
cmpb $0x3, %r13b
movzbl %r13b, %r13d
movl $0x0, %ecx
cmovel %ecx, %r13d
movzbl (%r14,%rbx), %ecx
cmpq $0x4, %rcx
jae 0xd8dd
andl $0xf, %edx
leaq (%rcx,%rdx,4), %rdx
leaq 0x1(%rax), %rcx
cmpq $0x2, %rax
jl 0xd956
leaq 0xbeb9(%rip), %rax      # 0x19700
cmpb $0x14, (%rax,%rdx)
movzbl %r13b, %esi
jb 0xd96a
movq 0x10(%rsp,%rsi,8), %rax
cmpq %r12, %rax
jl 0xd8c6
movq %rcx, 0x50(%rsp)
movq 0x30(%rsp,%rsi,8), %rcx
leaq (%rax,%rax,2), %rax
negq %rax
movq %rdx, 0x58(%rsp)
leaq (%rcx,%rax), %rdx
incq %rdx
incq %rcx
subq $0x8, %rsp
movq %r15, %rdi
movq %rsi, 0x50(%rsp)
movq %r14, %rsi
movl 0x10(%rsp), %r8d
movl 0x14(%rsp), %r9d
pushq 0xb8(%rsp)
pushq 0xb8(%rsp)
movl 0xb8(%rsp), %eax
pushq %rax
callq 0xd56c
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rcx
movq 0x78(%rsp), %rdx
addq $0x20, %rsp
shll $0x3, %esi
movq $0x0, 0x10(%rsp,%rsi)
movq $-0x1, 0x30(%rsp,%rsi)
jmp 0xd956
xorl %ebp, %ebp
movq 0x10(%rsp,%rbp,8), %rax
cmpq %r12, %rax
jl 0xd932
movq 0x30(%rsp,%rbp,8), %rcx
leaq (%rax,%rax,2), %rax
negq %rax
leaq (%rcx,%rax), %rdx
incq %rdx
incq %rcx
subq $0x8, %rsp
movq %r15, %rdi
movq %r14, %rsi
movl 0x10(%rsp), %r8d
movl 0x14(%rsp), %r9d
pushq 0xb8(%rsp)
pushq 0xb8(%rsp)
movl 0xb8(%rsp), %eax
pushq %rax
callq 0xd56c
addq $0x20, %rsp
movq $0x0, 0x10(%rsp,%rbp,8)
movq $-0x1, 0x30(%rsp,%rbp,8)
incq %rbp
cmpq $0x3, %rbp
jne 0xd8df
xorl %ecx, %ecx
xorl %edx, %edx
movq 0x60(%rsp), %rbp
incq %rbx
incb %r13b
movq %rcx, %rax
cmpq %rbp, %rbx
jne 0xd80b
jmp 0xd979
shll $0x3, %esi
movq %rbx, 0x30(%rsp,%rsi)
incq 0x10(%rsp,%rsi)
jmp 0xd956
xorl %ebx, %ebx
movq 0xb0(%rsp), %r13
movq 0x10(%rsp,%rbx,8), %rax
cmpq %r12, %rax
jl 0xd9d1
movq 0x30(%rsp,%rbx,8), %rcx
leaq (%rax,%rax,2), %rax
negq %rax
leaq (%rcx,%rax), %rdx
incq %rdx
incq %rcx
subq $0x8, %rsp
movq %r15, %rdi
movq %r14, %rsi
movl 0x10(%rsp), %r8d
movl 0x14(%rsp), %r9d
pushq %r13
pushq 0xb8(%rsp)
movl 0xb8(%rsp), %eax
pushq %rax
callq 0xd56c
addq $0x20, %rsp
incq %rbx
cmpq $0x3, %rbx
jne 0xd983
movslq (%r13), %rax
cmpq $0x2, %rax
jl 0xda2b
movq 0x8(%r13), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x4a34
movslq (%r13), %rcx
movl $0x1, %eax
cmpq $0x2, %rcx
jl 0xda27
movq 0x8(%r13), %rdx
movl $0x1, %esi
xorl %eax, %eax
movq (%rdx,%rsi,8), %rdi
cmpq %rdi, (%rdx,%rax,8)
je 0xda1d
movq %rdi, 0x8(%rdx,%rax,8)
incq %rax
incq %rsi
cmpq %rsi, %rcx
jne 0xda0b
incl %eax
movl %eax, (%r13)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop