// File: /workspace/github_c_makefile_star2_O3/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 $0x1158, %rsp           # imm = 0x1158
movq %r9, 0x88(%rsp)
movl %ecx, %r15d
movq %rdi, 0x18(%rsp)
movq %r8, 0x38(%rsp)
leal (%r8,%r8), %ecx
movq $-0x1, %rax
shlq %cl, %rax
movq %rax, 0x70(%rsp)
movl %edx, 0x4(%rsp)
testl %edx, %edx
jle 0x14062
leal -0x1(%r15), %eax
movl %eax, 0x64(%rsp)
cmpl $0xfe, %eax
ja 0x14062
movq 0x38(%rsp), %rax
decl %eax
cmpl $0x1c, %eax
jae 0x14062
movq %rsi, %rbp
movq 0x1198(%rsp), %r14
movq 0x38(%rsp), %rax
leal -0x2(,%rax,2), %ebx
movl %r15d, %edx
shll $0x4, %edx
leaq 0x150(%rsp), %rdi
movl $0xff, %esi
callq 0x21b0
xorps %xmm0, %xmm0
movups %xmm0, 0xd0(%rsp)
movups %xmm0, 0xe0(%rsp)
movups %xmm0, 0xf0(%rsp)
movups %xmm0, 0x100(%rsp)
movups %xmm0, 0x110(%rsp)
movups %xmm0, 0x120(%rsp)
movups %xmm0, 0x130(%rsp)
movups %xmm0, 0x140(%rsp)
movq 0x8(%r14), %rcx
movl 0x4(%rsp), %eax
xorl %edx, %edx
divl %r15d
addq (%r14), %rax
cmpq %rax, %rcx
jae 0x13860
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 0x12755
movq %rax, 0x10(%r14)
notq 0x70(%rsp)
movl %ebx, %eax
movq %rax, 0xa0(%rsp)
shlq $0x20, 0x88(%rsp)
movq 0x38(%rsp), %rax
leal (%rax,%r15), %ecx
movl %ecx, 0x84(%rsp)
addl %r15d, %eax
decl %eax
movl %eax, 0x34(%rsp)
movl 0x4(%rsp), %eax
movq %rax, 0xa8(%rsp)
movq $-0x1, %r12
leaq 0x22f65(%rip), %r9      # 0x36810
movq $0x0, 0x78(%rsp)
movq $0x0, 0x58(%rsp)
movq $-0x1, %r13
movl $0x0, 0x14(%rsp)
movq $0x0, 0x8(%rsp)
xorl %r11d, %r11d
movq $0x0, 0x48(%rsp)
movq $0x0, 0x68(%rsp)
movq $0x0, 0x90(%rsp)
movq %r15, 0x28(%rsp)
xorl %r10d, %r10d
movq %rbp, 0x20(%rsp)
movslq %r10d, %rdx
movzbl (%rbp,%rdx), %eax
movzbl (%rax,%r9), %eax
cmpq $0x3, %rax
ja 0x139a9
cmpl $0x0, 0x1190(%rsp)
movq 0x78(%rsp), %rbx
movq 0x90(%rsp), %r15
je 0x13c7d
leaq 0x1(%rdx), %rsi
movl $0x1, %ecx
cmpl 0x4(%rsp), %esi
jge 0x13e68
movzbl (%rbp,%rsi), %esi
cmpb %al, (%rsi,%r9)
jne 0x13e68
leal 0x2(%r10), %esi
movl $0x2, %ecx
cmpl 0x4(%rsp), %esi
jge 0x13e62
movl 0x4(%rsp), %ecx
subl %r10d, %ecx
movl %r10d, %edi
movl $0x2, %esi
leal (%rdi,%rsi), %r8d
movslq %r8d, %r8
movzbl (%rbp,%r8), %r8d
cmpb %al, (%r8,%r9)
jne 0x13e60
leaq (%rdx,%rsi), %r8
incq %r8
incq %rsi
cmpq 0xa8(%rsp), %r8
jl 0x13979
jmp 0x13e62
movq %r10, 0x98(%rsp)
movq $0x0, 0xc8(%rsp)
movq $-0x1, %rdx
movq $0x0, 0x58(%rsp)
movq $0x0, 0x68(%rsp)
xorl %edi, %edi
movl $0x0, 0x14(%rsp)
movq $-0x1, %rbx
movslq %r11d, %rax
shlq $0x4, %rax
movq %rbx, 0x150(%rsp,%rax)
movq %rdx, 0x40(%rsp)
movq %rdx, 0x158(%rsp,%rax)
movq %rdi, 0x48(%rsp)
cmpl 0x34(%rsp), %edi
movq %r11, 0x50(%rsp)
jne 0x13b31
cmpq $-0x1, %r12
je 0x13b31
leal 0x1(%r11), %eax
cmpl 0x28(%rsp), %eax
jge 0x13aa7
cltq
shlq $0x4, %rax
leaq (%rsp,%rax), %r15
addq $0x150, %r15            # imm = 0x150
movl 0x64(%rsp), %ebp
subl %r11d, %ebp
cmpq (%r15), %r12
jne 0x13a9f
cmpq %r13, 0x8(%r15)
je 0x13a9f
movq (%r14), %rcx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rcx
jne 0x13a8c
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%r14)
shlq $0x4, %rdx
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x12755
movq 0x50(%rsp), %r11
movq %rax, 0x10(%r14)
movq (%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r14)
shlq $0x4, %rcx
movups (%r15), %xmm0
movups %xmm0, (%rax,%rcx)
addq $0x10, %r15
decl %ebp
jne 0x13a43
testl %r11d, %r11d
jle 0x13b31
movl %r11d, %r15d
shlq $0x4, %r15
xorl %ebp, %ebp
cmpq 0x150(%rsp,%rbp), %r12
jne 0x13b28
cmpq %r13, 0x158(%rsp,%rbp)
je 0x13b28
movq (%r14), %rcx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rcx
jne 0x13b0b
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%r14)
shlq $0x4, %rdx
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x12755
movq 0x50(%rsp), %r11
movq %rax, 0x10(%r14)
movq (%r14), %rcx
leaq (%rsp,%rbp), %rdx
addq $0x150, %rdx            # imm = 0x150
leaq 0x1(%rcx), %rsi
movq %rsi, (%r14)
shlq $0x4, %rcx
movups (%rdx), %xmm0
movups %xmm0, (%rax,%rcx)
addq $0x10, %rbp
cmpq %rbp, %r15
jne 0x13ab9
cmpq %r12, %rbx
jbe 0x13bfc
cmpl 0x8(%rsp), %r11d
jne 0x13c98
movq 0x48(%rsp), %rax
cmpl 0x34(%rsp), %eax
movq 0x28(%rsp), %r15
jl 0x13bad
cmpq $-0x1, %r12
je 0x13bad
movq (%r14), %rcx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rcx
jne 0x13b99
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%r14)
shlq $0x4, %rdx
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x12755
movq 0x50(%rsp), %r11
movq %rax, 0x10(%r14)
movq (%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r14)
shlq $0x4, %rcx
movq %r12, (%rax,%rcx)
movq %r13, 0x8(%rax,%rcx)
movq 0x8(%rsp), %rsi
leal 0x1(%rsi), %edi
movq $-0x1, %rbx
cmpl %r15d, %edi
jge 0x13ca0
movslq %edi, %rax
shlq $0x4, %rax
leaq 0x158(%rsp), %rcx
addq %rcx, %rax
movl %edi, %ecx
movl %esi, %ebp
movq -0x8(%rax), %rdx
cmpq %rdx, %rbx
jb 0x13bec
movq (%rax), %r13
movl %ecx, %ebp
movq %rdx, %rbx
incl %ecx
addq $0x10, %rax
cmpl %ecx, %r15d
jne 0x13bdb
jmp 0x13ca2
movq 0x48(%rsp), %rax
cmpl 0x84(%rsp), %eax
jl 0x13e23
cmpq $-0x1, %r12
movq 0x28(%rsp), %r15
movq 0x20(%rsp), %rbp
je 0x13c70
movq (%r14), %rcx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rcx
jne 0x13c5c
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%r14)
shlq $0x4, %rdx
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x12755
movq 0x50(%rsp), %r11
movq %rax, 0x10(%r14)
movq (%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r14)
shlq $0x4, %rcx
movq %r12, (%rax,%rcx)
movq %r13, 0x8(%rax,%rcx)
movl %r11d, %eax
movq %rax, 0x8(%rsp)
jmp 0x13e35
movq 0x48(%rsp), %rcx
leal 0x1(%rcx), %edx
movq 0x38(%rsp), %rcx
cmpl %ecx, %edx
cmovgel %ecx, %edx
movl %edx, 0x14(%rsp)
jmp 0x13ee6
movq %r12, %rbx
jmp 0x13e0e
movl %esi, %ebp
testl %esi, %esi
js 0x13ccf
movl %edi, %eax
leaq 0x158(%rsp), %rcx
xorl %edx, %edx
movq -0x8(%rcx), %rsi
cmpq %rsi, %rbx
jb 0x13cc3
movq (%rcx), %r13
movl %edx, %ebp
movq %rsi, %rbx
incq %rdx
addq $0x10, %rcx
cmpq %rdx, %rax
jne 0x13cb2
movq 0x48(%rsp), %rax
cmpl 0x34(%rsp), %eax
jl 0x13e15
cmpq $-0x1, %rbx
je 0x13e15
movl %edi, 0x40(%rsp)
cmpl %r15d, %edi
jge 0x13d78
movslq 0x40(%rsp), %rax
shlq $0x4, %rax
leaq (%rsp,%rax), %r15
addq $0x150, %r15            # imm = 0x150
movl 0x64(%rsp), %r12d
subl 0x8(%rsp), %r12d
cmpq (%r15), %rbx
jne 0x13d6f
cmpq 0x8(%r15), %r13
je 0x13d6f
movq (%r14), %rcx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rcx
jne 0x13d5c
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%r14)
shlq $0x4, %rdx
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x12755
movq 0x50(%rsp), %r11
movq %rax, 0x10(%r14)
movq (%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r14)
shlq $0x4, %rcx
movups (%r15), %xmm0
movups %xmm0, (%rax,%rcx)
addq $0x10, %r15
decl %r12d
jne 0x13d13
cmpl $0x0, 0x8(%rsp)
js 0x13e07
movl 0x40(%rsp), %r15d
shlq $0x4, %r15
xorl %r12d, %r12d
cmpq 0x150(%rsp,%r12), %rbx
jne 0x13dfe
cmpq 0x158(%rsp,%r12), %r13
je 0x13dfe
movq (%r14), %rcx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rcx
jne 0x13de1
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%r14)
shlq $0x4, %rdx
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x12755
movq 0x50(%rsp), %r11
movq %rax, 0x10(%r14)
movq (%r14), %rcx
leaq (%rsp,%r12), %rdx
addq $0x150, %rdx            # imm = 0x150
leaq 0x1(%rcx), %rsi
movq %rsi, (%r14)
shlq $0x4, %rcx
movups (%rdx), %xmm0
movups %xmm0, (%rax,%rcx)
addq $0x10, %r12
cmpq %r12, %r15
jne 0x13d8f
movl %ebp, %eax
movq %rax, 0x8(%rsp)
movq 0x28(%rsp), %r15
jmp 0x13e1c
movl %ebp, %eax
movq %rax, 0x8(%rsp)
movq 0x20(%rsp), %rbp
jmp 0x13e3a
movl %r11d, %eax
movq %rax, 0x8(%rsp)
movq 0x28(%rsp), %r15
movq 0x20(%rsp), %rbp
movq 0x40(%rsp), %r13
incl %r11d
cmpl %r15d, %r11d
movl $0x0, %eax
cmovel %eax, %r11d
movq %rbx, %r12
leaq 0x229bd(%rip), %r9      # 0x36810
movq 0x98(%rsp), %r10
jmp 0x13f2d
movl %esi, %ecx
addl %ecx, %r10d
decl %r10d
movq 0x58(%rsp), %rdi
leal 0x1(%rdi), %edx
movl %edx, 0xcc(%rsp)
movq 0x68(%rsp), %rsi
addl %edi, %esi
andl $0x1f, %esi
movl %ecx, 0xd0(%rsp,%rsi,4)
addl %ecx, 0x14(%rsp)
cmpl 0x38(%rsp), %edi
jge 0x13e9b
movl %edx, %ecx
movq %rcx, 0x58(%rsp)
jmp 0x13ee6
testl %edx, %edx
je 0x13ed4
movq 0x68(%rsp), %rdx
movslq %edx, %rcx
incl %edx
movl %edx, 0xc8(%rsp)
movl 0xd0(%rsp,%rcx,4), %ecx
andl $0x1f, %edx
movl %edx, 0xc8(%rsp)
movq 0x58(%rsp), %rsi
movl %esi, 0xcc(%rsp)
movq %rdx, 0x68(%rsp)
jmp 0x13ee2
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq $0x0, 0x58(%rsp)
subl %ecx, 0x14(%rsp)
leaq (%rax,%r15,4), %r15
andq 0x70(%rsp), %r15
movq %r15, 0xb0(%rsp)
movq %rbx, %rdx
shrq $0x2, %rdx
xorq $0x3, %rax
movq 0xa0(%rsp), %rcx
shlq %cl, %rax
movq %rax, %rcx
orq %rdx, %rcx
movq %rcx, 0xb8(%rsp)
cmpq %rcx, %r15
movq %r15, 0x90(%rsp)
jne 0x13f40
movq %r15, 0x78(%rsp)
incl %r10d
cmpl 0x4(%rsp), %r10d
jl 0x13903
jmp 0x13ffa
movq 0x48(%rsp), %rdi
incl %edi
movq $-0x1, %rdx
cmpl 0x38(%rsp), %edi
movq %r10, 0x98(%rsp)
movq %rcx, 0x78(%rsp)
jl 0x139e0
movl 0x14(%rsp), %r8d
cmpl $0xff, %r8d
jg 0x139e0
xorl %eax, %eax
cmpq %rcx, %r15
setae %al
movq 0xb0(%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 %r8d, %rbx
orq %rcx, %rbx
leal (%r10,%r10), %edx
orq 0x88(%rsp), %rdx
orq %rax, %rdx
jmp 0x139e7
cmpq $-0x1, %r12
je 0x14050
movq (%r14), %rcx
cmpq 0x8(%r14), %rcx
jne 0x14038
leaq (%rcx,%rcx), %rax
testq %rcx, %rcx
movl $0x2, %edx
cmovneq %rax, %rdx
movq %rdx, 0x8(%r14)
movq 0x10(%r14), %rsi
shlq $0x4, %rdx
movq 0x18(%rsp), %rdi
callq 0x12755
movq %rax, 0x10(%r14)
movq (%r14), %rcx
jmp 0x1403c
movq 0x10(%r14), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, (%r14)
shlq $0x4, %rcx
movq %r12, (%rax,%rcx)
movq %r13, 0x8(%rax,%rcx)
addq $0x1158, %rsp           # imm = 0x1158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1a2e2(%rip), %rdi     # 0x2e34b
leaq 0x1a30f(%rip), %rsi     # 0x2e37f
leaq 0x1a311(%rip), %rcx     # 0x2e388
movl $0x54, %edx
callq 0x21a0
nopl (%rax)