// File: /workspace/github_c_makefile_star2_O0/c-zhou[P]yahs/telo.c
// Function: telo_finder_core
static uint64_t telo_finder_core(char *sequence, int slen, kh_64_t *mtab, int mlen, int penalty, int max_drop, int min_score)
{
	int c, hit;
	uint64_t x, mask, sum_telo;
	ssize_t i, l, max_i = -1, st = 0;
	int64_t score, max;
	
	mask = (1ULL<<2*mlen) - 1;
	sum_telo = 0;
	score = max = 0, max_i = -1;
	for (i = 0, l = 0, x = 0; i < slen; ++i) { // 5'-end
		hit = 0, c = seq_nt6_table[(uint8_t) sequence[i]];
		if (c >= 1 && c <= 4) { // not N
			x = (x<<2 | (c-1)) & mask;
			if (++l >= mlen && kh_get(64, mtab, x) != kh_end(mtab)) // x is at least mlen long and is a telomere motif
				hit = 1;
		} else l = 0, x = 0; // N, ambiguous base
		if (i >= mlen) score += hit? 1 : -penalty;
		if (score > max) max = score, max_i = i;
		else if (max - score > max_drop) break;
	}
	if (max >= min_score) {
		sum_telo += (uint64_t) (max_i + 1) << 32;
		st = max_i + 1;
	}
	score = max = 0, max_i = -1;
	for (i = slen - 1, l = 0, x = 0; i >= st; --i) { // 3'-end; similar to the for loop above
		hit = 0, c = seq_nt6_table[(uint8_t) sequence[i]];
		if (c >= 1 && c <= 4) {
			x = (x<<2 | (4-c)) & mask;
			if (++l >= mlen && kh_get(64, mtab, x) != kh_end(mtab))
				hit = 1;
		} else l = 0, x = 0;
		if (slen - i >= mlen) score += hit? 1 : -penalty;
		if (score > max) max = score, max_i = i;
		else if (max - score > max_drop) break;
	}
	if (max >= min_score)
		sum_telo += slen - max_i;
	
	return sum_telo;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
movq $-0x1, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movl -0x1c(%rbp), %eax
shll %eax
movl %eax, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
subq $0x1, %rax
movq %rax, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x70(%rbp)
movq $-0x1, -0x60(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x50(%rbp), %rax
movslq -0xc(%rbp), %rcx
cmpq %rcx, %rax
jge 0x2b6da
movl $0x0, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movq -0x50(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0xe50e(%rip), %rax      # 0x39b00
movzbl (%rax,%rcx), %eax
movl %eax, -0x28(%rbp)
cmpl $0x1, -0x28(%rbp)
jl 0x2b654
cmpl $0x4, -0x28(%rbp)
jg 0x2b654
movq -0x38(%rbp), %rax
shlq $0x2, %rax
movl -0x28(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
orq %rcx, %rax
andq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
movslq -0x1c(%rbp), %rcx
cmpq %rcx, %rax
jl 0x2b652
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x2b960
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
je 0x2b652
movl $0x1, -0x2c(%rbp)
jmp 0x2b664
movq $0x0, -0x58(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x50(%rbp), %rax
movslq -0x1c(%rbp), %rcx
cmpq %rcx, %rax
jl 0x2b696
cmpl $0x0, -0x2c(%rbp)
je 0x2b681
movl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x2b689
xorl %eax, %eax
subl -0x20(%rbp), %eax
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
cltq
addq -0x70(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
cmpq -0x78(%rbp), %rax
jle 0x2b6b2
movq -0x70(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x60(%rbp)
jmp 0x2b6c7
movq -0x78(%rbp), %rax
subq -0x70(%rbp), %rax
movslq -0x24(%rbp), %rcx
cmpq %rcx, %rax
jle 0x2b6c5
jmp 0x2b6da
jmp 0x2b6c7
jmp 0x2b6c9
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x2b5c5
movq -0x78(%rbp), %rax
movslq 0x10(%rbp), %rcx
cmpq %rcx, %rax
jl 0x2b707
movq -0x60(%rbp), %rax
addq $0x1, %rax
shlq $0x20, %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x70(%rbp)
movq $-0x1, -0x60(%rbp)
movl -0xc(%rbp), %eax
subl $0x1, %eax
cltq
movq %rax, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x68(%rbp), %rax
jl 0x2b853
movl $0x0, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movq -0x50(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0xe39b(%rip), %rax      # 0x39b00
movzbl (%rax,%rcx), %eax
movl %eax, -0x28(%rbp)
cmpl $0x1, -0x28(%rbp)
jl 0x2b7c9
cmpl $0x4, -0x28(%rbp)
jg 0x2b7c9
movq -0x38(%rbp), %rax
shlq $0x2, %rax
movl $0x4, %ecx
subl -0x28(%rbp), %ecx
movslq %ecx, %rcx
orq %rcx, %rax
andq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
movslq -0x1c(%rbp), %rcx
cmpq %rcx, %rax
jl 0x2b7c7
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x2b960
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
je 0x2b7c7
movl $0x1, -0x2c(%rbp)
jmp 0x2b7d9
movq $0x0, -0x58(%rbp)
movq $0x0, -0x38(%rbp)
movslq -0xc(%rbp), %rax
subq -0x50(%rbp), %rax
movslq -0x1c(%rbp), %rcx
cmpq %rcx, %rax
jl 0x2b80f
cmpl $0x0, -0x2c(%rbp)
je 0x2b7fa
movl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x2b802
xorl %eax, %eax
subl -0x20(%rbp), %eax
movl %eax, -0x80(%rbp)
movl -0x80(%rbp), %eax
cltq
addq -0x70(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
cmpq -0x78(%rbp), %rax
jle 0x2b82b
movq -0x70(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x60(%rbp)
jmp 0x2b840
movq -0x78(%rbp), %rax
subq -0x70(%rbp), %rax
movslq -0x24(%rbp), %rcx
cmpq %rcx, %rax
jle 0x2b83e
jmp 0x2b853
jmp 0x2b840
jmp 0x2b842
movq -0x50(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x2b73b
movq -0x78(%rbp), %rax
movslq 0x10(%rbp), %rcx
cmpq %rcx, %rax
jl 0x2b870
movslq -0xc(%rbp), %rax
subq -0x60(%rbp), %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)