// File: /workspace/github_c_makefile_star2_O2/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, 0x4(%rsp)
movl %r8d, (%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 0xbee1
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 0x7568
movq %rax, 0x8(%rbx)
andl $0x0, (%rbx)
xorl %eax, %eax
cmpq $0x3, %rax
je 0xbefd
orq $-0x1, 0x30(%rsp,%rax,8)
andq $0x0, 0x10(%rsp,%rax,8)
incq %rax
jmp 0xbee6
movslq %r12d, %r12
xorl %eax, %eax
testq %rbp, %rbp
cmovleq %rax, %rbp
movb $0x1, %r13b
xorl %edx, %edx
xorl %eax, %eax
xorl %esi, %esi
movq %rbp, 0x60(%rsp)
cmpq %rbp, %rdx
je 0xc081
cmpb $0x3, %r13b
movzbl %r13b, %r13d
movl $0x0, %ecx
cmovel %ecx, %r13d
movq %rdx, 0x8(%rsp)
movzbl (%r14,%rdx), %ecx
cmpq $0x4, %rcx
jae 0xbfe8
andl $0xf, %esi
leaq (%rcx,%rsi,4), %rsi
leaq 0x1(%rax), %rcx
cmpq $0x2, %rax
jl 0xc05a
leaq 0xc7af(%rip), %rax      # 0x18710
cmpb $0x14, (%rax,%rsi)
movzbl %r13b, %edi
jb 0xc06d
movq 0x10(%rsp,%rdi,8), %rax
cmpq %r12, %rax
jl 0xbfd7
movq %rcx, 0x50(%rsp)
movq 0x30(%rsp,%rdi,8), %rcx
imulq $-0x3, %rax, %rax
leaq (%rcx,%rax), %rdx
incq %rdx
incq %rcx
subq $0x8, %rsp
movq %rdi, 0x50(%rsp)
movq %r15, %rdi
movq %rsi, 0x60(%rsp)
movq %r14, %rsi
movl 0x8(%rsp), %r8d
movl 0xc(%rsp), %r9d
pushq %rbx
pushq 0xb8(%rsp)
movl 0xb8(%rsp), %eax
pushq %rax
callq 0xbce6
movq 0x68(%rsp), %rdi
movq 0x70(%rsp), %rcx
movq 0x78(%rsp), %rsi
addq $0x20, %rsp
shll $0x3, %edi
andq $0x0, 0x10(%rsp,%rdi)
orq $-0x1, 0x30(%rsp,%rdi)
jmp 0xc05a
movq %rbx, %rbp
xorl %ebx, %ebx
cmpq $0x3, %rbx
je 0xc04e
movq 0x10(%rsp,%rbx,8), %rax
cmpq %r12, %rax
jl 0xc03d
movq 0x30(%rsp,%rbx,8), %rcx
imulq $-0x3, %rax, %rax
leaq (%rcx,%rax), %rdx
incq %rdx
incq %rcx
subq $0x8, %rsp
movq %r15, %rdi
movq %r14, %rsi
movl 0x8(%rsp), %r8d
movl 0xc(%rsp), %r9d
pushq %rbp
pushq 0xb8(%rsp)
movl 0xb8(%rsp), %eax
pushq %rax
callq 0xbce6
addq $0x20, %rsp
andq $0x0, 0x10(%rsp,%rbx,8)
orq $-0x1, 0x30(%rsp,%rbx,8)
incq %rbx
jmp 0xbfed
xorl %ecx, %ecx
xorl %esi, %esi
movq %rbp, %rbx
movq 0x60(%rsp), %rbp
movq 0x8(%rsp), %rdx
incq %rdx
incb %r13b
movq %rcx, %rax
jmp 0xbf17
shll $0x3, %edi
movq 0x8(%rsp), %rdx
movq %rdx, 0x30(%rsp,%rdi)
incq 0x10(%rsp,%rdi)
jmp 0xc05f
xorl %r13d, %r13d
cmpq $0x3, %r13
je 0xc0d9
movq 0x10(%rsp,%r13,8), %rax
cmpq %r12, %rax
jl 0xc0d4
movq 0x30(%rsp,%r13,8), %rcx
imulq $-0x3, %rax, %rax
leaq (%rcx,%rax), %rdx
incq %rdx
incq %rcx
subq $0x8, %rsp
movq %r15, %rdi
movq %r14, %rsi
movl 0x8(%rsp), %r8d
movl 0xc(%rsp), %r9d
pushq %rbx
pushq 0xb8(%rsp)
movl 0xb8(%rsp), %eax
pushq %rax
callq 0xbce6
addq $0x20, %rsp
incq %r13
jmp 0xc084
movslq (%rbx), %rax
cmpq $0x2, %rax
jl 0xc11b
movq 0x8(%rbx), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x3a66
movslq (%rbx), %rcx
pushq $0x1
popq %rdx
xorl %eax, %eax
cmpq %rcx, %rdx
jge 0xc117
movq 0x8(%rbx), %rsi
movq (%rsi,%rdx,8), %rdi
cmpq %rdi, (%rsi,%rax,8)
je 0xc112
movq %rdi, 0x8(%rsi,%rax,8)
incq %rax
incq %rdx
jmp 0xc0f7
incl %eax
movl %eax, (%rbx)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop