// File: /workspace/github_cpp_makefile_star2_O1/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
movl %esi, 0x8(%rsp)
movl 0x8(%rcx), %eax
movl %eax, 0x8(%rdx)
movq %rdx, 0x20(%rsp)
movl %eax, 0x4(%rdx)
testl %r8d, %r8d
je 0x1da5c0
movl $0x100, %eax            # imm = 0x100
cmpl %eax, %r8d
cmovbl %r8d, %eax
incl %eax
movq %rax, 0x28(%rsp)
movl 0x8(%rsp), %r8d
movl $0x1, %r12d
movq %rdi, 0x18(%rsp)
movq %r8, 0x10(%rsp)
leaq 0x30(%rsp), %rdi
movl $0x4e, %esi
movq %r12, %rdx
callq 0x20e0
leaq 0x53598(%rip), %r9      # 0x22da10
movq 0x10(%rsp), %r8
movq 0x18(%rsp), %rdi
cmpl $0x0, 0x8(%rsp)
je 0x1da5b2
movl %r12d, %eax
shrl %eax
leal (%r12,%rax), %r10d
incl %r10d
xorl %r13d, %r13d
movl $0x1, %r15d
xorl %r14d, %r14d
movl %r10d, 0xc(%rsp)
movzbl (%rdi,%r13), %ecx
cmpb $0x3, (%r9,%rcx)
ja 0x1da4e2
movl %r14d, %esi
cmpq %rsi, %r12
jbe 0x1da4cd
movb %cl, 0x30(%rsp,%rsi)
incl %r14d
movl %r14d, %ebp
jmp 0x1da59f
movl %r14d, %eax
xorl %edx, %edx
divl %r12d
cmpb %cl, 0x30(%rsp,%rdx)
jne 0x1da4e2
cmpq %rsi, %r12
ja 0x1da4be
jmp 0x1da4c2
xorl %ebp, %ebp
cmpl %r10d, %r14d
jb 0x1da59f
movq 0x10(%rbx), %rax
cmpq %rax, 0x8(%rbx)
jne 0x1da52d
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x10(%rbx)
movq 0x18(%rbx), %rdi
shlq $0x3, %rsi
callq 0x2370
movl 0xc(%rsp), %r10d
leaq 0x534ec(%rip), %r9      # 0x22da10
movq 0x10(%rsp), %r8
movq %rax, 0x18(%rbx)
movl %r13d, %eax
subl %r14d, %eax
addq %rax, %rax
movq 0x8(%rbx), %rcx
movq 0x18(%rbx), %rdi
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rbx)
movq %rax, (%rdi,%rcx,8)
movq 0x10(%rbx), %rax
cmpq %rax, 0x8(%rbx)
jne 0x1da586
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x10(%rbx)
shlq $0x3, %rsi
callq 0x2370
movl 0xc(%rsp), %r10d
leaq 0x53493(%rip), %r9      # 0x22da10
movq 0x10(%rsp), %r8
movq %rax, 0x18(%rbx)
movq 0x8(%rbx), %rax
movq 0x18(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x8(%rbx)
movq %r15, (%rcx,%rax,8)
movq 0x18(%rsp), %rdi
incq %r13
addq $0x2, %r15
movl %ebp, %r14d
cmpq %r13, %r8
jne 0x1da4aa
incq %r12
cmpq 0x28(%rsp), %r12
jne 0x1da45f
movq 0x8(%rbx), %rax
movq 0x18(%rbx), %rcx
movq 0x20(%rsp), %r14
movl 0x4(%r14), %edx
leaq (%rcx,%rdx,8), %rdi
leaq (%rcx,%rax,8), %rsi
callq 0x194fef
movl 0x4(%r14), %eax
cmpq %rax, 0x8(%rbx)
jbe 0x1da667
movq 0x18(%rbx), %rcx
leal 0x1(%rax), %edx
xorl %esi, %esi
movq %rax, %rdi
movq %rsi, %r8
movq (%rcx,%rdi,8), %rdi
movl %edi, %esi
andl $0x1, %esi
negq %rsi
orq $0x1, %rsi
addq %r8, %rsi
testq %r8, %r8
setle %r9b
testq %rsi, %rsi
setg %r10b
andb %r9b, %r10b
cmpb $0x1, %r10b
jne 0x1da629
shrq %rdi
movq %rdi, %rax
jmp 0x1da65d
testq %r8, %r8
setg %r8b
testq %rsi, %rsi
setle %r9b
andb %r8b, %r9b
cmpb $0x1, %r9b
jne 0x1da65d
shrq %rdi
movq %rax, %r8
shlq $0x20, %r8
orq %rdi, %r8
movl 0x8(%r14), %edi
leal 0x1(%rdi), %r9d
movl %r9d, 0x8(%r14)
movq %r8, (%rcx,%rdi,8)
movl %edx, %edi
incl %edx
cmpq %rdi, 0x8(%rbx)
ja 0x1da5f4
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