// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/inter.cpp
// Function: gen_microsatellite(char const*, unsigned int, ma_utg_t*, hpc_t*, unsigned int)
void gen_microsatellite(const char *in, uint32_t in_len, ma_utg_t *idx, hpc_t *res, uint32_t mcs_len)
{
	uint32_t k, i, l, c, o; char sk[256]; 
	idx->start = idx->end = res->n; 
	if(mcs_len > 256) mcs_len = 256;
	for (k = 1; k <= mcs_len; k++) {
		memset(sk, 'N', k); ///k->length of k-mer
		o = k + (k>>1) + 1;
		for (i = l = 0; i < in_len; i++) {
			c = seq_nt4_table[(uint8_t)in[i]]; 
			if((c < 4) && (((l >= k) && (sk[l%k] == in[i])) || (l < k))) {
				if(l < k) sk[l] = in[i]; 
				l++;
			} else {
				if(l >= o) {
					kv_push(uint64_t, *res, (((uint64_t)(i-l))<<1));
					kv_push(uint64_t, *res, ((((uint64_t)i)<<1)|1));
				}
				l = 0;
			}
		}
	}

	radix_sort_gfa64(res->a+idx->start, res->a+res->n);
	int64_t dp, old_dp; uint64_t st, en;
	for (k = st = idx->start, dp = 0; k < res->n; k++) {
		old_dp = dp;
        if (res->a[k]&1) --dp;//qe
        else ++dp;
		if (old_dp < 1 && dp >= 1) {///qs
            st = res->a[k]>>1;
        } else if (old_dp >= 1 && dp < 1) {///qe
            en = res->a[k]>>1;
			res->a[idx->end++] = ((st<<32)|(en));
        }
	}
	res->n = idx->end;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq %rcx, %rbx
movq %rdx, %r14
movq 0x8(%rcx), %rax
movl %eax, 0x8(%rdx)
movl %eax, 0x4(%rdx)
movl %eax, %ecx
testl %r8d, %r8d
je 0x1e4821
movl %esi, %ebp
movq %r14, 0x20(%rsp)
movl $0x100, %eax            # imm = 0x100
cmpl %eax, %r8d
cmovbl %r8d, %eax
incl %eax
movq %rax, 0x28(%rsp)
movl %esi, %esi
movl $0x1, %r12d
movl %ebp, 0x1c(%rsp)
movq %rdi, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
leaq 0x30(%rsp), %rdi
movl $0x4e, %esi
movq %r12, %rdx
callq 0x20e0
leaq 0x5553d(%rip), %r8      # 0x239c20
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdi
testl %ebp, %ebp
je 0x1e4802
movl %r12d, %eax
shrl %eax
leal (%r12,%rax), %r9d
incl %r9d
xorl %r13d, %r13d
movl $0x1, %r15d
xorl %r14d, %r14d
movl %r9d, 0x4(%rsp)
movzbl (%rdi,%r13), %ecx
cmpb $0x3, (%r8,%rcx)
ja 0x1e4745
movl %r14d, %eax
cmpq %rax, %r12
jbe 0x1e472c
movb %cl, 0x30(%rsp,%rax)
jmp 0x1e473a
movl %r14d, %eax
xorl %edx, %edx
divl %r12d
cmpb %cl, 0x30(%rsp,%rdx)
jne 0x1e4745
incl %r14d
movl %r14d, %ebp
jmp 0x1e47ef
xorl %ebp, %ebp
cmpl %r9d, %r14d
jb 0x1e47ef
movq 0x8(%rbx), %rcx
movq 0x18(%rbx), %rax
cmpq 0x10(%rbx), %rcx
jne 0x1e4786
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x18(%rbx)
movq 0x8(%rbx), %rcx
movl %r13d, %edx
subl %r14d, %edx
addq %rdx, %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x8(%rbx)
movq %rdx, (%rax,%rcx,8)
movq 0x8(%rbx), %rcx
cmpq 0x10(%rbx), %rcx
jne 0x1e47cd
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x18(%rbx)
movq 0x8(%rbx), %rcx
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
leaq 0x55442(%rip), %r8      # 0x239c20
movl 0x4(%rsp), %r9d
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rbx)
movq %r15, (%rax,%rcx,8)
incq %r13
addq $0x2, %r15
movl %ebp, %r14d
cmpq %r13, %rsi
jne 0x1e4712
incq %r12
cmpq 0x28(%rsp), %r12
movl 0x1c(%rsp), %ebp
jne 0x1e46ca
movq 0x20(%rsp), %r14
movl 0x4(%r14), %ecx
movq 0x8(%rbx), %rax
movq 0x18(%rbx), %rdx
movl %ecx, %ecx
leaq (%rdx,%rcx,8), %rdi
leaq (%rdx,%rax,8), %rsi
callq 0x19dd99
movl 0x4(%r14), %r8d
movq 0x8(%rbx), %rdx
cmpq %r8, %rdx
jbe 0x1e48ca
movq 0x18(%rbx), %rax
leal 0x1(%r8), %ecx
xorl %esi, %esi
movq %r8, %rdi
movq %rsi, %r9
movq (%rax,%r8,8), %r8
movl %r8d, %esi
andl $0x1, %esi
negq %rsi
orq $0x1, %rsi
addq %r9, %rsi
testq %r9, %r9
setle %r10b
testq %rsi, %rsi
setg %r11b
andb %r10b, %r11b
cmpb $0x1, %r11b
jne 0x1e4888
shrq %r8
movq %r8, %rdi
jmp 0x1e48c0
testq %r9, %r9
setg %r9b
testq %rsi, %rsi
setle %r10b
andb %r9b, %r10b
cmpb $0x1, %r10b
jne 0x1e48c0
shrq %r8
movq %rdi, %rdx
shlq $0x20, %rdx
orq %r8, %rdx
movl 0x8(%r14), %r8d
leal 0x1(%r8), %r9d
movl %r9d, 0x8(%r14)
movq %rdx, (%rax,%r8,8)
movq 0x8(%rbx), %rdx
movl %ecx, %r8d
incl %ecx
cmpq %r8, %rdx
ja 0x1e4852
movl 0x8(%r14), %eax
movq %rax, 0x8(%rbx)
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq