// File: /workspace/github_c_makefile_star2_O3/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, -0xa0(%rbp)
movq %rdi, -0xc8(%rbp)
movq %rcx, -0x78(%rbp)
addl %ecx, %ecx
movq $-0x1, %rax
movq %rcx, -0x80(%rbp)
shlq %cl, %rax
movq %rax, -0x88(%rbp)
testl %esi, %esi
jle 0x72d2
movl %edx, %r14d
testl %edx, %edx
jle 0x72d2
cmpl $0x0, -0x78(%rbp)
jle 0x72d2
movq %r9, %rbx
movl %esi, %r12d
notq -0x88(%rbp)
movq -0x80(%rbp), %rax
addl $-0x2, %eax
movq %rax, -0x80(%rbp)
movl %r14d, %edx
shll $0x4, %edx
movq %rsp, %r15
subq %rdx, %r15
movq %r15, %rsp
movq %r15, %rdi
movl $0xff, %esi
callq 0x2130
movq %r15, %rdi
shlq $0x20, -0xa0(%rbp)
movq -0x78(%rbp), %rax
leal (%rax,%r14), %ecx
movl %ecx, -0x94(%rbp)
addl %r14d, %eax
decl %eax
movl %eax, -0x54(%rbp)
movl %r12d, %eax
movq %rax, -0xc0(%rbp)
leal -0x1(%r14), %eax
movl %eax, -0x64(%rbp)
leaq 0x8(%r15), %rax
movq %rax, -0xa8(%rbp)
movq $-0x1, %r12
movq $0x0, -0x90(%rbp)
movq $-0x1, %r8
movl $0x0, -0x2c(%rbp)
movq $0x0, -0x38(%rbp)
xorl %r15d, %r15d
movq $0x0, -0xb0(%rbp)
movq %r14, -0x48(%rbp)
xorl %r9d, %r9d
movq %rdi, -0x60(%rbp)
movq -0xc8(%rbp), %rax
movzbl (%rax,%r9), %eax
leaq 0x4441(%rip), %rcx      # 0xb1a0
movzbl (%rax,%rcx), %eax
cmpq $0x3, %rax
ja 0x6dc1
movq -0xb0(%rbp), %rsi
leaq (%rax,%rsi,4), %rsi
andq -0x88(%rbp), %rsi
movq %rsi, -0xe0(%rbp)
movq -0x90(%rbp), %rdx
shrq $0x2, %rdx
xorq $0x3, %rax
movq -0x80(%rbp), %rcx
shlq %cl, %rax
movq %rax, %rcx
orq %rdx, %rcx
movq %rcx, -0xd8(%rbp)
cmpq %rcx, %rsi
movq %rsi, -0xb0(%rbp)
jne 0x6fe0
movq %rsi, -0x90(%rbp)
jmp 0x70fa
movq %r9, -0xb8(%rbp)
xorl %r10d, %r10d
movq $-0x1, %rcx
movq $-0x1, %r13
movq %r15, -0x40(%rbp)
movslq %r15d, %rax
shlq $0x4, %rax
movq %r13, (%rdi,%rax)
movq %rcx, -0x70(%rbp)
movq %rcx, 0x8(%rdi,%rax)
movl %r10d, -0x2c(%rbp)
cmpl -0x54(%rbp), %r10d
movq %r8, -0x50(%rbp)
jne 0x6efc
movq -0x40(%rbp), %rax
incl %eax
cmpl -0x48(%rbp), %eax
jge 0x6e83
movslq %eax, %r14
shlq $0x4, %r14
addq %rdi, %r14
movl -0x64(%rbp), %r15d
subl -0x40(%rbp), %r15d
cmpq (%r14), %r12
jne 0x6e7a
cmpq %r8, 0x8(%r14)
je 0x6e7a
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rcx
jne 0x6e67
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x2200
movq -0x50(%rbp), %r8
movq -0x60(%rbp), %rdi
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbx)
shlq $0x4, %rcx
movups (%r14), %xmm0
movups %xmm0, (%rax,%rcx)
addq $0x10, %r14
decl %r15d
jne 0x6e20
cmpl $0x0, -0x40(%rbp)
jle 0x6efc
movl -0x40(%rbp), %r14d
shlq $0x4, %r14
xorl %r15d, %r15d
cmpq (%rdi,%r15), %r12
jne 0x6ef3
cmpq %r8, 0x8(%rdi,%r15)
je 0x6ef3
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rcx
jne 0x6edd
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x2200
movq -0x50(%rbp), %r8
movq -0x60(%rbp), %rdi
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
leaq (%rdi,%r15), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rbx)
shlq $0x4, %rcx
movups (%rdx), %xmm0
movups %xmm0, (%rax,%rcx)
addq $0x10, %r15
cmpq %r15, %r14
jne 0x6e94
cmpq %r12, %r13
jbe 0x6fbd
movq -0x40(%rbp), %r15
cmpl -0x38(%rbp), %r15d
jne 0x7079
movl -0x2c(%rbp), %eax
cmpl -0x54(%rbp), %eax
movq -0x48(%rbp), %r14
jl 0x6f6f
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rcx
jne 0x6f5b
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x2200
movq -0x50(%rbp), %r8
movq -0x60(%rbp), %rdi
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbx)
shlq $0x4, %rcx
movq %r12, (%rax,%rcx)
movq %r8, 0x8(%rax,%rcx)
movq -0x38(%rbp), %rdx
leal 0x1(%rdx), %r9d
movq $-0x1, %r13
cmpl %r14d, %r9d
jge 0x710f
movslq %r9d, %rax
shlq $0x4, %rax
addq -0xa8(%rbp), %rax
movl %r9d, %ecx
movl %edx, %r12d
movq -0x8(%rax), %rdx
cmpq %rdx, %r13
jb 0x6fad
movq (%rax), %r8
movl %ecx, %r12d
movq %rdx, %r13
incl %ecx
addq $0x10, %rax
cmpl %ecx, %r14d
jne 0x6f9b
jmp 0x7112
movl -0x2c(%rbp), %eax
cmpl -0x94(%rbp), %eax
movq -0x40(%rbp), %r15
jge 0x7082
movl %r15d, %eax
movq %rax, -0x38(%rbp)
movq -0x48(%rbp), %r14
jmp 0x70dd
movl -0x2c(%rbp), %r10d
incl %r10d
cmpl -0x78(%rbp), %r10d
movq %r9, -0xb8(%rbp)
movq %rcx, -0x90(%rbp)
jl 0x6dcb
xorl %eax, %eax
cmpq %rcx, %rsi
setae %al
movq -0xe0(%rbp,%rax,8), %rcx
movq %rcx, %rdx
notq %rdx
shlq $0x15, %rcx
addq %rdx, %rcx
movq -0x88(%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, %r13
shlq $0x1f, %r13
addq %rdx, %r13
andq %rsi, %r13
movq -0xa0(%rbp), %rcx
leaq (%rcx,%r9,2), %rcx
orq %rax, %rcx
jmp 0x6dd9
movq %r12, %r13
movq -0x48(%rbp), %r14
jmp 0x70e1
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rcx
movq -0x48(%rbp), %r14
jne 0x70c2
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x2200
movq -0x50(%rbp), %r8
movq -0x60(%rbp), %rdi
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbx)
shlq $0x4, %rcx
movq %r12, (%rax,%rcx)
movq %r8, 0x8(%rax,%rcx)
movl %r15d, %eax
movq %rax, -0x38(%rbp)
movq -0x70(%rbp), %r8
incl %r15d
cmpl %r14d, %r15d
movl $0x0, %eax
cmovel %eax, %r15d
movq %r13, %r12
movq -0xb8(%rbp), %r9
incq %r9
cmpq -0xc0(%rbp), %r9
jne 0x6d4c
jmp 0x726f
movl %edx, %r12d
cmpl $0x0, -0x38(%rbp)
js 0x7142
movl %r9d, %eax
movq -0xa8(%rbp), %rcx
xorl %edx, %edx
movq -0x8(%rcx), %rsi
cmpq %rsi, %r13
jb 0x7136
movq (%rcx), %r8
movl %edx, %r12d
movq %rsi, %r13
incq %rdx
addq $0x10, %rcx
cmpq %rdx, %rax
jne 0x7124
movl -0x2c(%rbp), %eax
cmpl -0x54(%rbp), %eax
jge 0x7153
movl %r12d, %eax
movq %rax, -0x38(%rbp)
jmp 0x70e1
cmpl %r14d, %r9d
movq %r8, -0x50(%rbp)
jge 0x71e3
movslq %r9d, %r14
shlq $0x4, %r14
addq %rdi, %r14
movl -0x64(%rbp), %r15d
subl -0x38(%rbp), %r15d
movl %r12d, -0x70(%rbp)
cmpq (%r14), %r13
jne 0x71da
cmpq 0x8(%r14), %r8
je 0x71da
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rcx
jne 0x71c7
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x4, %rsi
movq %rax, %rdi
movl %r9d, %r12d
callq 0x2200
movl %r12d, %r9d
movl -0x70(%rbp), %r12d
movq -0x50(%rbp), %r8
movq -0x60(%rbp), %rdi
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbx)
shlq $0x4, %rcx
movups (%r14), %xmm0
movups %xmm0, (%rax,%rcx)
addq $0x10, %r14
decl %r15d
jne 0x7176
cmpl $0x0, -0x38(%rbp)
js 0x725b
movl %r9d, %r14d
shlq $0x4, %r14
xorl %r15d, %r15d
cmpq (%rdi,%r15), %r13
jne 0x7252
cmpq 0x8(%rdi,%r15), %r8
je 0x7252
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rcx
jne 0x723c
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x2200
movq -0x50(%rbp), %r8
movq -0x60(%rbp), %rdi
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
leaq (%rdi,%r15), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rbx)
shlq $0x4, %rcx
movups (%rdx), %xmm0
movups %xmm0, (%rax,%rcx)
addq $0x10, %r15
cmpq %r15, %r14
jne 0x71f3
movl %r12d, %eax
movq %rax, -0x38(%rbp)
movq -0x48(%rbp), %r14
movq -0x40(%rbp), %r15
jmp 0x70e1
cmpq $-0x1, %r12
je 0x72c3
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rcx
jne 0x72af
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %esi
cmovneq %rdx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x4, %rsi
movq %rax, %rdi
movq %r8, %r14
callq 0x2200
movq %r14, %r8
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbx)
shlq $0x4, %rcx
movq %r12, (%rax,%rcx)
movq %r8, 0x8(%rax,%rcx)
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1652(%rip), %rdi      # 0x892b
leaq 0x1665(%rip), %rsi      # 0x8945
leaq 0x1667(%rip), %rcx      # 0x894e
movl $0x3b, %edx
callq 0x2110
nopl (%rax)