// File: 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
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
cmpl $0x100, -0x24(%rbp)     # imm = 0x100
jbe 0x2f8a66
movl $0x100, -0x24(%rbp)     # imm = 0x100
movl $0x1, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x24(%rbp), %eax
ja 0x2f8ca9
leaq -0x140(%rbp), %rdi
movl -0x28(%rbp), %eax
movl %eax, %edx
movl $0x4e, %esi
callq 0x2100
movl -0x28(%rbp), %eax
movl -0x28(%rbp), %ecx
shrl %ecx
addl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jae 0x2f8c99
movq -0x8(%rbp), %rax
movl -0x2c(%rbp), %ecx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x91d13(%rip), %rax     # 0x38a7e0
movzbl (%rax,%rcx), %eax
movl %eax, -0x34(%rbp)
cmpl $0x4, -0x34(%rbp)
jae 0x2f8b35
movl -0x30(%rbp), %eax
cmpl -0x28(%rbp), %eax
jb 0x2f8b03
movl -0x30(%rbp), %eax
xorl %edx, %edx
divl -0x28(%rbp)
movl %edx, %eax
movsbl -0x140(%rbp,%rax), %eax
movq -0x8(%rbp), %rcx
movl -0x2c(%rbp), %edx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0x2f8b0b
movl -0x30(%rbp), %eax
cmpl -0x28(%rbp), %eax
jae 0x2f8b35
movl -0x30(%rbp), %eax
cmpl -0x28(%rbp), %eax
jae 0x2f8b27
movq -0x8(%rbp), %rax
movl -0x2c(%rbp), %ecx
movb (%rax,%rcx), %cl
movl -0x30(%rbp), %eax
movb %cl, -0x140(%rbp,%rax)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x2f8c89
movl -0x30(%rbp), %eax
cmpl -0x38(%rbp), %eax
jb 0x2f8c82
jmp 0x2f8b43
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x20(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x2f8bb5
movq -0x20(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x2f8b74
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0x168(%rbp)
jmp 0x2f8b82
movl $0x2, %eax
movq %rax, -0x168(%rbp)
jmp 0x2f8b82
movq -0x168(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x18(%rax)
movl -0x2c(%rbp), %eax
subl -0x30(%rbp), %eax
movl %eax, %eax
movl %eax, %edx
shlq %rdx
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x20(%rbp), %rsi
movq 0x8(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x8(%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x2f8be3
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x20(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x2f8c55
movq -0x20(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x2f8c14
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0x170(%rbp)
jmp 0x2f8c22
movl $0x2, %eax
movq %rax, -0x170(%rbp)
jmp 0x2f8c22
movq -0x170(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x18(%rax)
movl -0x2c(%rbp), %eax
movl %eax, %edx
shlq %rdx
orq $0x1, %rdx
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x20(%rbp), %rsi
movq 0x8(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x8(%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x2f8c82
movl $0x0, -0x30(%rbp)
jmp 0x2f8c8b
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2f8aad
jmp 0x2f8c9b
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x2f8a6d
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
shlq $0x3, %rax
addq %rax, %rdi
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x27a9b0
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movq %rax, -0x158(%rbp)
movl %eax, -0x28(%rbp)
movq $0x0, -0x148(%rbp)
movl -0x28(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x2f8df2
movq -0x148(%rbp), %rax
movq %rax, -0x150(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x28(%rbp), %ecx
movq (%rax,%rcx,8), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0x2f8d43
movq -0x148(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x148(%rbp)
jmp 0x2f8d55
movq -0x148(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x148(%rbp)
cmpq $0x1, -0x150(%rbp)
jge 0x2f8d84
cmpq $0x1, -0x148(%rbp)
jl 0x2f8d84
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x28(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq %rax
movq %rax, -0x158(%rbp)
jmp 0x2f8de2
cmpq $0x1, -0x150(%rbp)
jl 0x2f8de0
cmpq $0x1, -0x148(%rbp)
jge 0x2f8de0
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x28(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq %rax
movq %rax, -0x160(%rbp)
movq -0x158(%rbp), %rdx
shlq $0x20, %rdx
orq -0x160(%rbp), %rdx
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rsi
movl 0x8(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x8(%rsi)
movl %ecx, %ecx
movq %rdx, (%rax,%rcx,8)
jmp 0x2f8de2
jmp 0x2f8de4
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x2f8cf7
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
nopl (%rax)