// File: /workspace/github_c_makefile_star2_O1/lh3[P]minimap2/sketch.c
// Function: mm_sketch
void mm_sketch(void *km, const char *str, int len, int w, int k, uint32_t rid, int is_hpc, mm128_v *p)
{
	uint64_t shift1 = 2 * (k - 1), mask = (1ULL<<2*k) - 1, kmer[2] = {0,0};
	int i, j, l, buf_pos, min_pos, kmer_span = 0;
	mm128_t buf[256], min = { UINT64_MAX, UINT64_MAX };
	tiny_queue_t tq;

	assert(len > 0 && (w > 0 && w < 256) && (k > 0 && k <= 28)); // 56 bits for k-mer; could use long k-mers, but 28 enough in practice
	memset(buf, 0xff, w * 16);
	memset(&tq, 0, sizeof(tiny_queue_t));
	kv_resize(mm128_t, km, *p, p->n + len/w);

	for (i = l = buf_pos = min_pos = 0; i < len; ++i) {
		int c = seq_nt4_table[(uint8_t)str[i]];
		mm128_t info = { UINT64_MAX, UINT64_MAX };
		if (c < 4) { // not an ambiguous base
			int z;
			if (is_hpc) {
				int skip_len = 1;
				if (i + 1 < len && seq_nt4_table[(uint8_t)str[i + 1]] == c) {
					for (skip_len = 2; i + skip_len < len; ++skip_len)
						if (seq_nt4_table[(uint8_t)str[i + skip_len]] != c)
							break;
					i += skip_len - 1; // put $i at the end of the current homopolymer run
				}
				tq_push(&tq, skip_len);
				kmer_span += skip_len;
				if (tq.count > k) kmer_span -= tq_shift(&tq);
			} else kmer_span = l + 1 < k? l + 1 : k;
			kmer[0] = (kmer[0] << 2 | c) & mask;           // forward k-mer
			kmer[1] = (kmer[1] >> 2) | (3ULL^c) << shift1; // reverse k-mer
			if (kmer[0] == kmer[1]) continue; // skip "symmetric k-mers" as we don't know it strand
			z = kmer[0] < kmer[1]? 0 : 1; // strand
			++l;
			if (l >= k && kmer_span < 256) {
				info.x = hash64(kmer[z], mask) << 8 | kmer_span;
				info.y = (uint64_t)rid<<32 | (uint32_t)i<<1 | z;
			}
		} else l = 0, tq.count = tq.front = 0, kmer_span = 0;
		buf[buf_pos] = info; // need to do this here as appropriate buf_pos and buf[buf_pos] are needed below
		if (l == w + k - 1 && min.x != UINT64_MAX) { // special case for the first window - because identical k-mers are not stored yet
			for (j = buf_pos + 1; j < w; ++j)
				if (min.x == buf[j].x && buf[j].y != min.y) kv_push(mm128_t, km, *p, buf[j]);
			for (j = 0; j < buf_pos; ++j)
				if (min.x == buf[j].x && buf[j].y != min.y) kv_push(mm128_t, km, *p, buf[j]);
		}
		if (info.x <= min.x) { // a new minimum; then write the old min
			if (l >= w + k && min.x != UINT64_MAX) kv_push(mm128_t, km, *p, min);
			min = info, min_pos = buf_pos;
		} else if (buf_pos == min_pos) { // old min has moved outside the window
			if (l >= w + k - 1 && min.x != UINT64_MAX) kv_push(mm128_t, km, *p, min);
			for (j = buf_pos + 1, min.x = UINT64_MAX; j < w; ++j) // the two loops are necessary when there are identical k-mers
				if (min.x >= buf[j].x) min = buf[j], min_pos = j; // >= is important s.t. min is always the closest k-mer
			for (j = 0; j <= buf_pos; ++j)
				if (min.x >= buf[j].x) min = buf[j], min_pos = j;
			if (l >= w + k - 1 && min.x != UINT64_MAX) { // write identical k-mers
				for (j = buf_pos + 1; j < w; ++j) // these two loops make sure the output is sorted
					if (min.x == buf[j].x && min.y != buf[j].y) kv_push(mm128_t, km, *p, buf[j]);
				for (j = 0; j <= buf_pos; ++j)
					if (min.x == buf[j].x && min.y != buf[j].y) kv_push(mm128_t, km, *p, buf[j]);
			}
		}
		if (++buf_pos == w) buf_pos = 0;
	}
	if (min.x != UINT64_MAX)
		kv_push(mm128_t, km, *p, min);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1148, %rsp           # imm = 0x1148
movq %r9, 0xa0(%rsp)
movl %ecx, %r13d
movq %rsi, 0x10(%rsp)
movq %r8, 0x38(%rsp)
leal (%r8,%r8), %ecx
movq $-0x1, %rax
shlq %cl, %rax
movq %rax, 0x70(%rsp)
movq %rdi, 0x18(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x90(%rsp)
movl %edx, 0xc(%rsp)
testl %edx, %edx
jle 0x1407a
leal -0x1(%r13), %eax
movl %eax, 0x50(%rsp)
cmpl $0xfe, %eax
ja 0x1407a
movq 0x38(%rsp), %rax
decl %eax
cmpl $0x1c, %eax
jae 0x1407a
movq 0x1188(%rsp), %r14
movq 0x38(%rsp), %rax
leal -0x2(,%rax,2), %ebx
movl %r13d, %edx
shll $0x4, %edx
leaq 0x140(%rsp), %rdi
movl $0xff, %esi
callq 0x21b0
leaq 0xb8(%rsp), %rdi
movl $0x88, %edx
xorl %esi, %esi
callq 0x21b0
movq 0x8(%r14), %rcx
movl 0xc(%rsp), %eax
xorl %edx, %edx
divl %r13d
addq (%r14), %rax
cmpq %rax, %rcx
jae 0x1388a
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rdx
shrq $0x10, %rdx
orq %rax, %rdx
incq %rdx
movq %rdx, 0x8(%r14)
movq 0x10(%r14), %rsi
shlq $0x4, %rdx
movq 0x18(%rsp), %rdi
callq 0x127ec
movq %rax, 0x10(%r14)
notq 0x70(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x98(%rsp), %rax
movq %rax, 0x60(%rsp)
movl 0xb8(%rsp), %eax
movq %rax, 0x58(%rsp)
movl 0xbc(%rsp), %eax
movq %rax, 0x48(%rsp)
movl %ebx, %eax
movq %rax, 0xa8(%rsp)
shlq $0x20, 0xa0(%rsp)
movq 0x38(%rsp), %rax
leal (%rax,%r13), %ecx
movl %ecx, 0x8c(%rsp)
addl %r13d, %eax
decl %eax
movl %eax, 0x34(%rsp)
movl 0xc(%rsp), %eax
movq %rax, 0xb0(%rsp)
movq $-0x1, %rbp
xorl %r10d, %r10d
movq $-0x1, %r15
xorl %r12d, %r12d
movl $0x0, 0x8(%rsp)
xorl %r11d, %r11d
movq $0x0, 0x20(%rsp)
movq 0x10(%rsp), %rbx
movq %r13, 0x28(%rsp)
movslq %r10d, %rdx
movzbl (%rbx,%rdx), %eax
leaq 0x21ed7(%rip), %rcx     # 0x35810
movzbl (%rax,%rcx), %eax
cmpq $0x3, %rax
ja 0x139cd
cmpl $0x0, 0x1180(%rsp)
je 0x13a17
leaq 0x1(%rdx), %rsi
movl $0x1, %ecx
cmpl 0xc(%rsp), %esi
jge 0x13a36
movzbl (%rbx,%rsi), %esi
leaq 0x21e9d(%rip), %rdi     # 0x35810
cmpb %al, (%rsi,%rdi)
jne 0x13a36
leal 0x2(%r10), %esi
movl $0x2, %ecx
cmpl 0xc(%rsp), %esi
jge 0x13a30
movl 0xc(%rsp), %ecx
subl %r10d, %ecx
movl %r10d, %edi
movl $0x2, %esi
leal (%rdi,%rsi), %r8d
movslq %r8d, %r8
movzbl (%rbx,%r8), %r8d
leaq 0x21e5f(%rip), %r9      # 0x35810
cmpb %al, (%r8,%r9)
jne 0x13a2e
leaq (%rdx,%rsi), %r8
incq %r8
incq %rsi
cmpq 0xb0(%rsp), %r8
jl 0x1399e
jmp 0x13a30
movq %r10, 0x80(%rsp)
movq $0x0, 0xb8(%rsp)
movq $-0x1, %rdx
movq $0x0, 0x48(%rsp)
movq $0x0, 0x58(%rsp)
movq $0x0, 0x20(%rsp)
movl $0x0, 0x54(%rsp)
movq $-0x1, %r12
jmp 0x13bc7
movq 0x20(%rsp), %rcx
leal 0x1(%rcx), %r12d
movq 0x38(%rsp), %rcx
cmpl %ecx, %r12d
cmovgel %ecx, %r12d
jmp 0x13aa8
movl %esi, %ecx
addl %ecx, %r10d
decl %r10d
movq 0x48(%rsp), %rdi
leal 0x1(%rdi), %edx
movl %edx, 0xbc(%rsp)
movq 0x58(%rsp), %rsi
addl %edi, %esi
andl $0x1f, %esi
movl %ecx, 0xc0(%rsp,%rsi,4)
addl %ecx, %r12d
cmpl 0x38(%rsp), %edi
jl 0x13aa1
testl %edx, %edx
je 0x13a99
movq 0x58(%rsp), %rdx
movslq %edx, %rcx
leal 0x1(%rdx), %esi
movl %esi, 0xb8(%rsp)
movl 0xc0(%rsp,%rcx,4), %ecx
andl $0x1f, %esi
movl %esi, 0xb8(%rsp)
movq 0x48(%rsp), %rdx
movl %edx, 0xbc(%rsp)
movq %rsi, 0x58(%rsp)
jmp 0x13a9e
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
subl %ecx, %r12d
movl %edx, %ecx
movq %rcx, 0x48(%rsp)
movq 0x68(%rsp), %rsi
leaq (%rax,%rsi,4), %rsi
andq 0x70(%rsp), %rsi
movq %rsi, 0x90(%rsp)
movq 0x60(%rsp), %rdx
shrq $0x2, %rdx
xorq $0x3, %rax
movq 0xa8(%rsp), %rcx
shlq %cl, %rax
orq %rdx, %rax
movq %rax, 0x98(%rsp)
movq $-0x1, %rdx
movq %rsi, 0x68(%rsp)
cmpq %rax, %rsi
movq %rax, 0x60(%rsp)
movq %r10, 0x80(%rsp)
movl %r12d, 0x54(%rsp)
jne 0x13b10
movq $-0x1, %r12
jmp 0x13bbc
movq 0x20(%rsp), %rcx
incl %ecx
movq %rcx, 0x20(%rsp)
cmpl 0x38(%rsp), %ecx
jl 0x13b04
cmpl $0xff, %r12d
jg 0x13b04
xorl %eax, %eax
movq 0x60(%rsp), %rcx
cmpq %rcx, 0x68(%rsp)
setae %al
movq 0x90(%rsp,%rax,8), %rcx
movq %rcx, %rdx
notq %rdx
shlq $0x15, %rcx
addq %rdx, %rcx
movq 0x70(%rsp), %rsi
andq %rsi, %rcx
movq %rcx, %rdx
shrq $0x18, %rdx
xorq %rcx, %rdx
imulq $0x109, %rdx, %rcx      # imm = 0x109
andq %rsi, %rcx
movq %rcx, %rdx
shrq $0xe, %rdx
xorq %rcx, %rdx
leaq (%rdx,%rdx,4), %rcx
leaq (%rdx,%rcx,4), %rcx
andq %rsi, %rcx
movq %rcx, %rdx
shrq $0x1c, %rdx
xorq %rcx, %rdx
movq %rdx, %rcx
shlq $0x1f, %rcx
addq %rdx, %rcx
andq %rsi, %rcx
shlq $0x8, %rcx
movslq %r12d, %r12
orq %rcx, %r12
movq 0x80(%rsp), %rcx
leal (%rcx,%rcx), %edx
orq 0xa0(%rsp), %rdx
orq %rax, %rdx
movq 0x60(%rsp), %rax
cmpq %rax, 0x68(%rsp)
je 0x13ff9
movslq %r11d, %rax
shlq $0x4, %rax
movq %r12, 0x140(%rsp,%rax)
movq %rdx, 0x78(%rsp)
movq %rdx, 0x148(%rsp,%rax)
movq 0x20(%rsp), %rax
cmpl 0x34(%rsp), %eax
movq %r11, 0x40(%rsp)
jne 0x13d14
cmpq $-0x1, %rbp
je 0x13d14
leal 0x1(%r11), %eax
cmpl 0x28(%rsp), %eax
jge 0x13c8a
cltq
shlq $0x4, %rax
leaq (%rsp,%rax), %r13
addq $0x140, %r13            # imm = 0x140
movl 0x50(%rsp), %ebx
subl %r11d, %ebx
cmpq (%r13), %rbp
jne 0x13c82
cmpq %r15, 0x8(%r13)
je 0x13c82
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0x13c67
leaq (%rax,%rax), %rdx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rdx
movq %rdx, 0x8(%r14)
movq 0x10(%r14), %rsi
shlq $0x4, %rdx
movq 0x18(%rsp), %rdi
callq 0x127ec
movq 0x40(%rsp), %r11
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r14)
shlq $0x4, %rax
movups (%r13), %xmm0
movups %xmm0, (%rcx,%rax)
addq $0x10, %r13
decl %ebx
jne 0x13c23
testl %r11d, %r11d
jle 0x13d14
movl %r11d, %r13d
shlq $0x4, %r13
xorl %ebx, %ebx
cmpq 0x140(%rsp,%rbx), %rbp
jne 0x13d0b
cmpq %r15, 0x148(%rsp,%rbx)
je 0x13d0b
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0x13ce8
leaq (%rax,%rax), %rdx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rdx
movq %rdx, 0x8(%r14)
movq 0x10(%r14), %rsi
shlq $0x4, %rdx
movq 0x18(%rsp), %rdi
callq 0x127ec
movq 0x40(%rsp), %r11
movq %rax, 0x10(%r14)
leaq (%rsp,%rbx), %rax
addq $0x140, %rax            # imm = 0x140
movq (%r14), %rcx
movq 0x10(%r14), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r14)
shlq $0x4, %rcx
movups (%rax), %xmm0
movups %xmm0, (%rdx,%rcx)
addq $0x10, %rbx
cmpq %rbx, %r13
jne 0x13c9c
cmpq %rbp, %r12
jbe 0x13dde
cmpl 0x8(%rsp), %r11d
jne 0x13e5d
movq 0x20(%rsp), %rax
cmpl 0x34(%rsp), %eax
movq 0x28(%rsp), %r13
jl 0x13d91
cmpq $-0x1, %rbp
je 0x13d91
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0x13d76
leaq (%rax,%rax), %rdx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rdx
movq %rdx, 0x8(%r14)
movq 0x10(%r14), %rsi
shlq $0x4, %rdx
movq 0x18(%rsp), %rdi
callq 0x127ec
movq 0x40(%rsp), %r11
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r14)
shlq $0x4, %rax
movq %rbp, (%rcx,%rax)
movq %r15, 0x8(%rcx,%rax)
leal 0x1(%r11), %ebx
movq $-0x1, %r12
cmpl %r13d, %ebx
jge 0x13e65
movslq %ebx, %rax
shlq $0x4, %rax
leaq 0x148(%rsp), %rcx
addq %rcx, %rax
movl %ebx, %ecx
movl 0x8(%rsp), %edi
movq -0x8(%rax), %rdx
cmpq %rdx, %r12
jb 0x13dce
movq (%rax), %r15
movl %ecx, %edi
movq %rdx, %r12
incl %ecx
addq $0x10, %rax
cmpl %ecx, %r13d
jne 0x13dbd
jmp 0x13e69
movq 0x20(%rsp), %rax
cmpl 0x8c(%rsp), %eax
jl 0x13fd3
cmpq $-0x1, %rbp
movq 0x28(%rsp), %r13
movq 0x10(%rsp), %rbx
je 0x13e53
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0x13e38
leaq (%rax,%rax), %rdx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rdx
movq %rdx, 0x8(%r14)
movq 0x10(%r14), %rsi
shlq $0x4, %rdx
movq 0x18(%rsp), %rdi
callq 0x127ec
movq 0x40(%rsp), %r11
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r14)
shlq $0x4, %rax
movq %rbp, (%rcx,%rax)
movq %r15, 0x8(%rcx,%rax)
movl %r11d, 0x8(%rsp)
jmp 0x13fe2
movq %rbp, %r12
jmp 0x13fc7
movl 0x8(%rsp), %edi
testl %r11d, %r11d
js 0x13e97
movl %ebx, %eax
leaq 0x148(%rsp), %rcx
xorl %edx, %edx
movq -0x8(%rcx), %rsi
cmpq %rsi, %r12
jb 0x13e8b
movq (%rcx), %r15
movl %edx, %edi
movq %rsi, %r12
incq %rdx
addq $0x10, %rcx
cmpq %rdx, %rax
jne 0x13e7a
movl %edi, 0x8(%rsp)
movq 0x20(%rsp), %rax
cmpl 0x34(%rsp), %eax
jl 0x13fcc
cmpq $-0x1, %r12
je 0x13fcc
cmpl %r13d, %ebx
jge 0x13f3d
movslq %ebx, %rax
shlq $0x4, %rax
leaq (%rsp,%rax), %r13
addq $0x140, %r13            # imm = 0x140
movl 0x50(%rsp), %ebp
subl %r11d, %ebp
cmpq (%r13), %r12
jne 0x13f35
cmpq 0x8(%r13), %r15
je 0x13f35
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0x13f1a
leaq (%rax,%rax), %rdx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rdx
movq %rdx, 0x8(%r14)
movq 0x10(%r14), %rsi
shlq $0x4, %rdx
movq 0x18(%rsp), %rdi
callq 0x127ec
movq 0x40(%rsp), %r11
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r14)
shlq $0x4, %rax
movups (%r13), %xmm0
movups %xmm0, (%rcx,%rax)
addq $0x10, %r13
decl %ebp
jne 0x13ed6
testl %r11d, %r11d
js 0x13fc7
movl %ebx, %ebx
shlq $0x4, %rbx
xorl %r13d, %r13d
cmpq 0x140(%rsp,%r13), %r12
jne 0x13fbe
cmpq 0x148(%rsp,%r13), %r15
je 0x13fbe
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0x13f9b
leaq (%rax,%rax), %rdx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rdx
movq %rdx, 0x8(%r14)
movq 0x10(%r14), %rsi
shlq $0x4, %rdx
movq 0x18(%rsp), %rdi
callq 0x127ec
movq 0x40(%rsp), %r11
movq %rax, 0x10(%r14)
leaq (%rsp,%r13), %rax
addq $0x140, %rax            # imm = 0x140
movq (%r14), %rcx
movq 0x10(%r14), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r14)
shlq $0x4, %rcx
movups (%rax), %xmm0
movups %xmm0, (%rdx,%rcx)
addq $0x10, %r13
cmpq %r13, %rbx
jne 0x13f4f
movq 0x28(%rsp), %r13
movq 0x10(%rsp), %rbx
jmp 0x13fe7
movl %r11d, 0x8(%rsp)
movq 0x28(%rsp), %r13
movq 0x10(%rsp), %rbx
movq 0x78(%rsp), %r15
incl %r11d
cmpl %r13d, %r11d
movl $0x0, %eax
cmovel %eax, %r11d
movq %r12, %rbp
movq 0x80(%rsp), %r10
incl %r10d
cmpl 0xc(%rsp), %r10d
movl 0x54(%rsp), %r12d
jl 0x1392b
cmpq $-0x1, %rbp
je 0x14068
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0x1404d
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %edx
cmovneq %rcx, %rdx
movq %rdx, 0x8(%r14)
movq 0x10(%r14), %rsi
shlq $0x4, %rdx
movq 0x18(%rsp), %rdi
callq 0x127ec
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r14)
shlq $0x4, %rax
movq %rbp, (%rcx,%rax)
movq %r15, 0x8(%rcx,%rax)
addq $0x1148, %rsp           # imm = 0x1148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x192ae(%rip), %rdi     # 0x2d32f
leaq 0x192db(%rip), %rsi     # 0x2d363
leaq 0x192dd(%rip), %rcx     # 0x2d36c
movl $0x54, %edx
callq 0x21a0
nopl (%rax)