// File: /workspace/github_c_makefile_star2_O1/lh3[P]minimap/sketch.c
// Function: mm_sketch
void mm_sketch(const char *str, int len, int w, int k, uint32_t rid, 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;
	mm128_t *buf, min = { UINT64_MAX, UINT64_MAX };

	assert(len > 0 && w > 0 && k > 0);
	buf = (mm128_t*)alloca(w * 16);
	memset(buf, 0xff, w * 16);

	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;
			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
			if (++l >= k)
				info.x = hash64(kmer[z], mask), info.y = (uint64_t)rid<<32 | (uint32_t)i<<1 | z;
		} else l = 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) { // 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, *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, *p, buf[j]);
		}
		if (info.x <= min.x) { // a new minimum; then write the old min
			if (l >= w + k) kv_push(mm128_t, *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) kv_push(mm128_t, *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) { // 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, *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, *p, buf[j]);
			}
		}
		if (++buf_pos == w) buf_pos = 0;
	}
	if (min.x != UINT64_MAX)
		kv_push(mm128_t, *p, min);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %r8, -0xb8(%rbp)
movq %rcx, -0x80(%rbp)
addl %ecx, %ecx
movq $-0x1, %rax
movq %rcx, -0x88(%rbp)
shlq %cl, %rax
movq %rax, -0x90(%rbp)
movq %rdi, -0xd8(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0xb0(%rbp)
testl %esi, %esi
jle 0x7286
movl %edx, %r15d
testl %edx, %edx
jle 0x7286
cmpl $0x0, -0x80(%rbp)
jle 0x7286
movq %r9, %rbx
movl %esi, %r12d
notq -0x90(%rbp)
movq -0x88(%rbp), %rax
addl $-0x2, %eax
movq %rax, -0x88(%rbp)
movl %r15d, %edx
shll $0x4, %edx
movq %rsp, %r14
subq %rdx, %r14
movq %r14, %rsp
movq %r14, %rdi
movl $0xff, %esi
callq 0x2130
movq %r14, %rdi
movq -0xb0(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x68(%rbp)
shlq $0x20, -0xb8(%rbp)
movq -0x80(%rbp), %rax
leal (%rax,%r15), %ecx
movl %ecx, -0x94(%rbp)
addl %r15d, %eax
decl %eax
movl %eax, -0x44(%rbp)
movl %r12d, %eax
movq %rax, -0xd0(%rbp)
leal -0x1(%r15), %eax
movl %eax, -0x5c(%rbp)
leaq 0x8(%r14), %rax
movq %rax, -0xc0(%rbp)
movq $-0x1, %r12
xorl %r13d, %r13d
movq $-0x1, %r8
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
xorl %r9d, %r9d
movq %r14, -0x50(%rbp)
movq %r15, -0x38(%rbp)
movq -0xd8(%rbp), %rax
movzbl (%rax,%r13), %eax
leaq 0x446b(%rip), %rcx      # 0xb1a0
movzbl (%rax,%rcx), %eax
cmpq $0x3, %rax
ja 0x6da2
movq -0x78(%rbp), %rsi
leaq (%rax,%rsi,4), %rsi
andq -0x90(%rbp), %rsi
movq %rsi, -0xb0(%rbp)
movq -0x68(%rbp), %rdx
shrq $0x2, %rdx
xorq $0x3, %rax
movq -0x88(%rbp), %rcx
shlq %cl, %rax
orq %rdx, %rax
movq %rax, -0xa8(%rbp)
movq $-0x1, %rdx
movq %rsi, -0x78(%rbp)
cmpq %rax, %rsi
movq %rax, -0x68(%rbp)
je 0x6d96
movl -0x2c(%rbp), %ecx
incl %ecx
movl %ecx, -0x2c(%rbp)
cmpl -0x80(%rbp), %ecx
jge 0x6dbc
movq $-0x1, %r14
jmp 0x6e3a
movl $0x0, -0x2c(%rbp)
movq $-0x1, %rdx
movq $-0x1, %r14
jmp 0x6e44
xorl %eax, %eax
movq -0x68(%rbp), %rcx
cmpq %rcx, -0x78(%rbp)
setae %al
movq -0xb0(%rbp,%rax,8), %rcx
movq %rcx, %rdx
notq %rdx
shlq $0x15, %rcx
addq %rdx, %rcx
movq -0x90(%rbp), %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, %r14
shlq $0x1f, %r14
addq %rdx, %r14
andq %rsi, %r14
movq -0xb8(%rbp), %rcx
leaq (%rcx,%r13,2), %rdx
orq %rax, %rdx
movq -0x68(%rbp), %rax
cmpq %rax, -0x78(%rbp)
je 0x7206
movq %r13, -0x70(%rbp)
movslq %r9d, %rax
shlq $0x4, %rax
movq %r14, (%rdi,%rax)
movq %rdx, -0xc8(%rbp)
movq %rdx, 0x8(%rdi,%rax)
movl -0x2c(%rbp), %eax
cmpl -0x44(%rbp), %eax
movq %r8, -0x40(%rbp)
movq %r9, -0x58(%rbp)
jne 0x6f73
leal 0x1(%r9), %eax
cmpl -0x38(%rbp), %eax
jge 0x6ef7
movslq %eax, %r13
shlq $0x4, %r13
addq %rdi, %r13
movl -0x5c(%rbp), %r15d
subl %r9d, %r15d
cmpq (%r13), %r12
jne 0x6eee
cmpq %r8, 0x8(%r13)
je 0x6eee
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0x6ed3
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x4, %rsi
callq 0x2200
movq -0x58(%rbp), %r9
movq -0x40(%rbp), %r8
movq -0x50(%rbp), %rdi
movq %rax, 0x10(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
shlq $0x4, %rax
movups (%r13), %xmm0
movups %xmm0, (%rcx,%rax)
addq $0x10, %r13
decl %r15d
jne 0x6e8d
testl %r9d, %r9d
jle 0x6f73
movl %r9d, %r13d
shlq $0x4, %r13
xorl %r15d, %r15d
cmpq (%rdi,%r15), %r12
jne 0x6f6a
cmpq %r8, 0x8(%rdi,%r15)
je 0x6f6a
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0x6f4d
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x4, %rsi
callq 0x2200
movq -0x58(%rbp), %r9
movq -0x40(%rbp), %r8
movq -0x50(%rbp), %rdi
movq %rax, 0x10(%rbx)
leaq (%rdi,%r15), %rax
movq (%rbx), %rcx
movq 0x10(%rbx), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rbx)
shlq $0x4, %rcx
movups (%rax), %xmm0
movups %xmm0, (%rdx,%rcx)
addq $0x10, %r15
cmpq %r15, %r13
jne 0x6f06
cmpq %r12, %r14
jbe 0x716e
cmpl -0x30(%rbp), %r9d
movq -0x70(%rbp), %r13
jne 0x7187
movl -0x2c(%rbp), %eax
cmpl -0x44(%rbp), %eax
movq -0x38(%rbp), %r15
jl 0x6feb
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0x6fd0
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x4, %rsi
callq 0x2200
movq -0x58(%rbp), %r9
movq -0x40(%rbp), %r8
movq -0x50(%rbp), %rdi
movq %rax, 0x10(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
shlq $0x4, %rax
movq %r12, (%rcx,%rax)
movq %r8, 0x8(%rcx,%rax)
leal 0x1(%r9), %r12d
movq $-0x1, %r14
cmpl %r15d, %r12d
jge 0x7029
movslq %r12d, %rax
shlq $0x4, %rax
addq -0xc0(%rbp), %rax
movl %r12d, %ecx
movq -0x8(%rax), %rdx
cmpq %rdx, %r14
jb 0x701e
movq (%rax), %r8
movl %ecx, -0x30(%rbp)
movq %rdx, %r14
incl %ecx
addq $0x10, %rax
cmpl %ecx, %r15d
jne 0x700c
testl %r9d, %r9d
js 0x7058
movl %r12d, %eax
movq -0xc0(%rbp), %rcx
xorl %edx, %edx
movq -0x8(%rcx), %rsi
cmpq %rsi, %r14
jb 0x704c
movq (%rcx), %r8
movl %edx, -0x30(%rbp)
movq %rsi, %r14
incq %rdx
addq $0x10, %rcx
cmpq %rdx, %rax
jne 0x703a
movl -0x2c(%rbp), %eax
cmpl -0x44(%rbp), %eax
jl 0x71f4
cmpl %r15d, %r12d
movq %r8, -0x40(%rbp)
jge 0x70e8
movslq %r12d, %r13
shlq $0x4, %r13
addq %rdi, %r13
movl -0x5c(%rbp), %r15d
subl %r9d, %r15d
cmpq (%r13), %r14
jne 0x70df
cmpq 0x8(%r13), %r8
je 0x70df
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0x70c4
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x4, %rsi
callq 0x2200
movq -0x58(%rbp), %r9
movq -0x40(%rbp), %r8
movq -0x50(%rbp), %rdi
movq %rax, 0x10(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
shlq $0x4, %rax
movups (%r13), %xmm0
movups %xmm0, (%rcx,%rax)
addq $0x10, %r13
decl %r15d
jne 0x707e
testl %r9d, %r9d
js 0x7218
movl %r12d, %r15d
shlq $0x4, %r15
xorl %r12d, %r12d
movq -0x70(%rbp), %r13
cmpq (%rdi,%r12), %r14
jne 0x7163
cmpq 0x8(%rdi,%r12), %r8
je 0x7163
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0x7146
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x4, %rsi
callq 0x2200
movq -0x58(%rbp), %r9
movq -0x40(%rbp), %r8
movq -0x50(%rbp), %rdi
movq %rax, 0x10(%rbx)
leaq (%rdi,%r12), %rax
movq (%rbx), %rcx
movq 0x10(%rbx), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rbx)
shlq $0x4, %rcx
movups (%rax), %xmm0
movups %xmm0, (%rdx,%rcx)
addq $0x10, %r12
cmpq %r12, %r15
jne 0x70ff
jmp 0x718a
movl -0x2c(%rbp), %eax
cmpl -0x94(%rbp), %eax
movq -0x70(%rbp), %r13
jge 0x7190
movl %r9d, -0x30(%rbp)
movq -0x38(%rbp), %r15
jmp 0x71ed
movq %r12, %r14
movq -0x38(%rbp), %r15
jmp 0x71f4
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
movq -0x38(%rbp), %r15
jne 0x71ce
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x4, %rsi
callq 0x2200
movq -0x58(%rbp), %r9
movq -0x40(%rbp), %r8
movq -0x50(%rbp), %rdi
movq %rax, 0x10(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
shlq $0x4, %rax
movq %r12, (%rcx,%rax)
movq %r8, 0x8(%rcx,%rax)
movl %r9d, -0x30(%rbp)
movq -0xc8(%rbp), %r8
incl %r9d
cmpl %r15d, %r9d
movl $0x0, %eax
cmovel %eax, %r9d
movq %r14, %r12
incq %r13
cmpq -0xd0(%rbp), %r13
jne 0x6d22
jmp 0x7222
movq -0x38(%rbp), %r15
movq -0x70(%rbp), %r13
jmp 0x71f4
cmpq $-0x1, %r12
je 0x7277
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0x725c
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x4, %rsi
movq %r8, %r14
callq 0x2200
movq %r14, %r8
movq %rax, 0x10(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
shlq $0x4, %rax
movq %r12, (%rcx,%rax)
movq %r8, 0x8(%rcx,%rax)
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x16ce(%rip), %rdi      # 0x895b
leaq 0x16e1(%rip), %rsi      # 0x8975
leaq 0x16e3(%rip), %rcx      # 0x897e
movl $0x3b, %edx
callq 0x2110
nopl (%rax)