// File: /workspace/github_c_makefile_star2_O2/c-zhou[P]yahs/telo.c
// Function: telo_finder
int8_t *telo_finder(const char *f, uint32_t ml, FILE *out)
{
	int i, j, t, c, len, absent;
	uint32_t nseq, ntelo;
	uint64_t x, telo;
	int8_t *telo_ends;
	sdict_t *sdict;
	char **telo_db, *motif;
	khash_t(64) *h;

	sdict = make_sdict_from_fa(f, ml);
	nseq  = sdict->n;
	telo_ends = (int8_t *) calloc(nseq * 2, sizeof(int8_t));

	ntelo = 0;
	telo_db = NULL;
	if (telo_motif != NULL) {
		telo_db = (char **) malloc(sizeof(char *));
		telo_db[0] = telo_motif;
		ntelo = 1;
	} else {
		telo_db = telo_motif_db;
		ntelo = sizeof(telo_motif_db) / sizeof(char *);
	}

	h = kh_init(64); // hash table for all roations of the telomere motif
	for (t = 0; t < ntelo; t++) {
		// make motif table
		motif = telo_db[t];
		len = strlen(motif);
		kh_resize(64, h, len * 2);
		for (i = 0; i < len; ++i) {
			for (j = 0, x = 0; j < len; ++j) {
				c = seq_nt6_table[(uint8_t) motif[(i + j) % len]];
				assert(c >= 1 && c <= 4);
				x = x<<2 | (c-1);
			}
			kh_put(64, h, x, &absent);
		}

		// do telo_finder for each sequence in the dictionary
		for (i = 0; i < nseq; i++) {
			telo = telo_finder_core(sdict->s[i].seq, sdict->s[i].len, h, len, 
				telo_penalty, telo_maxDrop, telo_minScore);
			if (telo == 0)
				continue;
			if ((telo>>32) > 0) {
				telo_ends[i<<1] = 1;
				if (out) 
					fprintf(out, "%s\t0\t%u\t%s\n", sdict->s[i].name, (uint32_t) (telo>>32), telo_db[t]);
				else
					fprintf(stderr, "[I::%s] found telo motif %s in sequence %s 5'-end up to position %u\n", 
						__func__, telo_db[t], sdict->s[i].name, (uint32_t) (telo>>32));
			}
			if ((uint32_t) telo > 0) {
				telo_ends[i<<1|1] = 1;
				if (out) 
					fprintf(out, "%s\t%u\t%u\t%s\n", sdict->s[i].name, sdict->s[i].len - (uint32_t) telo, 
						sdict->s[i].len, telo_db[t]);
				else
					fprintf(stderr, "[I::%s] found telo motif %s in sequence %s 3'-end from position %u\n", 
						__func__, telo_db[t], sdict->s[i].name, sdict->s[i].len - (uint32_t) telo);
			}
		}

		kh_clear(64, h);
	}

	kh_destroy(64, h);
	if (telo_motif != NULL)
		free(telo_db);
	sd_destroy(sdict);

	return telo_ends;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rdx, %r14
callq 0xe7a6
movq %rax, 0x28(%rsp)
movl (%rax), %eax
movq %rax, 0x90(%rsp)
leal (%rax,%rax), %edi
pushq $0x1
popq %r15
movq %r15, %rsi
callq 0x2290
movq %rax, 0x38(%rsp)
movq 0xeb1b(%rip), %rbx      # 0x28618
testq %rbx, %rbx
je 0x19b18
pushq $0x8
popq %rdi
callq 0x2330
movq %rax, (%rsp)
movq %rbx, (%rax)
movq %r15, 0x48(%rsp)
jmp 0x19b2b
leaq 0xe8f1(%rip), %rax      # 0x28410
movq %rax, (%rsp)
pushq $0x17
popq %rax
movq %rax, 0x48(%rsp)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
pushq $0x28
popq %rdx
xorl %edi, %edi
movq %r15, %rsi
callq 0x83c0
movq %rax, %r12
xorl %ecx, %ecx
movq %rax, 0x20(%rsp)
movq %r14, 0x88(%rsp)
cmpq 0x48(%rsp), %rcx
je 0x1a1d0
movq (%rsp), %rax
movq %rcx, 0x18(%rsp)
movq (%rax,%rcx,8), %r15
movq %r15, %rdi
callq 0x2160
movq %rax, %r14
leal (%rax,%rax), %esi
movq %r12, %rdi
movl %esi, 0x30(%rsp)
callq 0x1a256
leaq 0xe948(%rip), %r9       # 0x284d0
xorl %ebx, %ebx
testl %r14d, %r14d
movl $0x0, %eax
cmovgl %r14d, %eax
movl %eax, 0x8(%rsp)
cmpl 0x8(%rsp), %ebx
je 0x19d60
xorl %r13d, %r13d
xorl %ecx, %ecx
cmpl %ecx, %r14d
je 0x19bd8
leal (%rbx,%rcx), %eax
cltd
idivl %r14d
movzbl (%r15,%rdx), %eax
movzbl (%rax,%r9), %eax
leal -0x1(%rax), %edx
cmpb $0x4, %dl
jae 0x1a237
shlq $0x2, %r13
addl %ebp, %eax
orq %rax, %r13
incl %ecx
jmp 0x19ba9
movl 0x8(%r12), %eax
cmpl 0xc(%r12), %eax
jb 0x19c10
movl (%r12), %esi
movl 0x4(%r12), %eax
addl %eax, %eax
cmpl %eax, %esi
jbe 0x19bf7
decl %esi
jmp 0x19bf9
incl %esi
movq %r12, %rdi
callq 0x1a256
testl %eax, %eax
leaq 0xe8c6(%rip), %r9       # 0x284d0
js 0x19d59
movl (%r12), %edx
leal -0x1(%rdx), %r8d
movq %r13, %rsi
shrq $0x21, %rsi
movl %r13d, %eax
shll $0xb, %eax
xorl %eax, %esi
xorl %r13d, %esi
andl %r8d, %esi
movq 0x10(%r12), %rax
movl %esi, %ecx
shrl $0x4, %ecx
movl (%rax,%rcx,4), %edi
leal (%rsi,%rsi), %ecx
shrl %cl, %edi
testb $0x2, %dil
je 0x19c4c
movl %esi, %edi
jmp 0x19ce8
pushq $0x1
popq %r10
movl %esi, %r9d
movl %edx, %edi
movl %r9d, %ecx
shrl $0x4, %ecx
movl (%rax,%rcx,4), %r11d
leal (%r9,%r9), %ecx
andl $0x1e, %ecx
movl %r11d, %ebp
shrl %cl, %ebp
testb $0x2, %bpl
jne 0x19cbc
testb $0x1, %bpl
jne 0x19c8f
movq 0x20(%rsp), %r12
movq 0x18(%r12), %r12
movl %r9d, %ebp
cmpq %r13, (%r12,%rbp,8)
movq 0x20(%rsp), %r12
je 0x19cbc
btl %ecx, %r11d
cmovbl %r9d, %edi
addl %r10d, %r9d
andl %r8d, %r9d
incl %r10d
cmpl %esi, %r9d
jne 0x19c55
movb $0x1, %cl
movl %edx, %r8d
cmpl %edx, %edi
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
leaq 0xe818(%rip), %r9       # 0x284d0
je 0x19cd8
jmp 0x19ce8
shrl %cl, %r11d
testb $0x2, %r11b
sete %cl
movl %edi, %r8d
movl %r9d, %esi
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
leaq 0xe7f8(%rip), %r9       # 0x284d0
cmpl %edx, %r8d
cmovel %esi, %r8d
testb %cl, %cl
cmovnel %esi, %r8d
movl %r8d, %edi
movl %edi, %edx
shrl $0x4, %edx
movl (%rax,%rdx,4), %esi
leal (%rdi,%rdi), %ecx
andl $0x1e, %ecx
movl %esi, %r8d
shrl %cl, %r8d
movl %edi, %edi
testb $0x2, %r8b
jne 0x19d2a
testb $0x1, %r8b
je 0x19d59
pushq $0x3
popq %r8
shll %cl, %r8d
movq 0x18(%r12), %rcx
movq %r13, (%rcx,%rdi,8)
notl %r8d
andl %r8d, %esi
movl %esi, (%rax,%rdx,4)
incl 0x4(%r12)
jmp 0x19d59
pushq $0x3
popq %r8
shll %cl, %r8d
movq 0x18(%r12), %rcx
movq %r13, (%rcx,%rdi,8)
notl %r8d
andl %r8d, %esi
movl %esi, (%rax,%rdx,4)
movq 0x4(%r12), %xmm0
psubd 0x645e(%rip), %xmm0     # 0x201b0
movq %xmm0, 0x4(%r12)
incl %ebx
jmp 0x19b9a
pushq $-0x1
popq %rax
movl 0x30(%rsp), %ecx
shlq %cl, %rax
notq %rax
movq %rax, 0x30(%rsp)
movslq %r14d, %rsi
xorl %ebx, %ebx
movq %rsi, 0x10(%rsp)
cmpq 0x90(%rsp), %rbx
je 0x1a18f
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movq %rbx, 0xa0(%rsp)
imulq $0x18, %rbx, %rcx
leaq (%rax,%rcx), %rdx
movq %rdx, 0x50(%rsp)
movq 0x8(%rax,%rcx), %r8
movq %rcx, 0x58(%rsp)
movslq 0x10(%rax,%rcx), %rax
movslq 0xe642(%rip), %r10      # 0x28400
movslq 0xe63f(%rip), %r11      # 0x28404
movslq 0xe63c(%rip), %rcx      # 0x28408
movq %rcx, 0x60(%rsp)
negq %r10
testq %rax, %rax
movl $0x0, %r13d
movq %rax, 0x68(%rsp)
cmovgq %rax, %r13
xorl %r15d, %r15d
xorl %ebx, %ebx
xorl %r12d, %r12d
pushq $-0x1
popq %rdi
xorl %ebp, %ebp
xorl %r14d, %r14d
movq %r8, 0x80(%rsp)
movq %r10, 0x78(%rsp)
movq %r11, 0x70(%rsp)
movq %r13, 0x8(%rsp)
cmpq %rbx, %r13
je 0x19ed8
movzbl (%r8,%rbx), %eax
movzbl (%rax,%r9), %eax
leal -0x1(%rax), %ecx
cmpb $0x3, %cl
ja 0x19e48
shlq $0x2, %r15
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
addl %ecx, %eax
orq %rax, %r15
andq 0x30(%rsp), %r15
incq %r12
cmpq %rsi, %r12
jge 0x19e53
movq %r10, %rcx
jmp 0x19ea2
movq %r10, %rcx
xorl %r15d, %r15d
xorl %r12d, %r12d
jmp 0x19ea2
movq %r14, 0x40(%rsp)
movq %rdi, %r14
movq 0x20(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x1a46a
movq 0x78(%rsp), %r10
movq %r10, %rcx
cmpl (%r13), %eax
je 0x19e7c
pushq $0x1
popq %rcx
leaq 0xe64d(%rip), %r9       # 0x284d0
movq 0x10(%rsp), %rsi
movq %r14, %rdi
movq 0x80(%rsp), %r8
movq 0x70(%rsp), %r11
movq 0x40(%rsp), %r14
movq 0x8(%rsp), %r13
cmpq %rsi, %rbx
movl $0x0, %eax
cmovgeq %rcx, %rax
addq %rax, %rbp
movq %r14, %rdx
movq %rbx, %rax
movq %rbp, %rcx
subq %rbp, %rdx
jl 0x19eca
cmpq %r11, %rdx
jg 0x19ed8
movq %rdi, %rax
movq %r14, %rcx
incq %rbx
movq %rax, %rdi
movq %rcx, %r14
jmp 0x19e0d
incq %rdi
movq %r14, 0x40(%rsp)
cmpq 0x60(%rsp), %r14
movq %rdi, 0x98(%rsp)
movl $0x0, %eax
cmovlq %rax, %rdi
movq 0x68(%rsp), %rcx
leal -0x1(%rcx), %eax
movslq %eax, %rbx
movq %rcx, %r14
subq %rsi, %r14
xorl %r15d, %r15d
movq $0x0, 0x8(%rsp)
pushq $-0x1
popq %rbp
xorl %r12d, %r12d
xorl %r13d, %r13d
movq %rdi, 0xb0(%rsp)
movq %r14, 0xa8(%rsp)
cmpq %rdi, %rbx
jl 0x1a000
movzbl (%r8,%rbx), %eax
movzbl (%rax,%r9), %eax
leal -0x1(%rax), %ecx
cmpb $0x3, %cl
ja 0x19f70
shlq $0x2, %r15
pushq $0x4
popq %rcx
subq %rax, %rcx
orq %rcx, %r15
andq 0x30(%rsp), %r15
movq 0x8(%rsp), %rcx
incq %rcx
movq %rcx, 0x8(%rsp)
cmpq %rsi, %rcx
jge 0x19f81
movq %r10, %rcx
jmp 0x19fca
movq %r10, %rcx
xorl %r15d, %r15d
movq $0x0, 0x8(%rsp)
jmp 0x19fca
movq 0x20(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x1a46a
movq 0x78(%rsp), %r10
movq %r10, %rcx
cmpl (%r14), %eax
je 0x19fa1
pushq $0x1
popq %rcx
leaq 0xe528(%rip), %r9       # 0x284d0
movq 0x10(%rsp), %rsi
movq 0x80(%rsp), %r8
movq 0x70(%rsp), %r11
movq 0xb0(%rsp), %rdi
movq 0xa8(%rsp), %r14
cmpq %r14, %rbx
movl $0x0, %eax
cmovleq %rcx, %rax
addq %rax, %r12
movq %r13, %rdx
movq %rbx, %rax
movq %r12, %rcx
subq %r12, %rdx
jl 0x19ff2
cmpq %r11, %rdx
jg 0x1a000
movq %rbp, %rax
movq %r13, %rcx
decq %rbx
movq %rax, %rbp
movq %rcx, %r13
jmp 0x19f2c
movq 0x98(%rsp), %r10
shlq $0x20, %r10
movq 0x60(%rsp), %rcx
cmpq %rcx, 0x40(%rsp)
movl $0x0, %eax
cmovlq %rax, %r10
movq 0x68(%rsp), %r15
subq %rbp, %r15
cmpq %rcx, %r13
cmovlq %rax, %r15
addq %r15, %r10
movq 0x88(%rsp), %r14
movq 0x20(%rsp), %r12
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0xa0(%rsp), %rbx
je 0x1a103
shrq $0x20, %r10
je 0x1a0a3
leal (%rbx,%rbx), %eax
cltq
movq 0x38(%rsp), %rcx
movb $0x1, (%rcx,%rax)
testq %r14, %r14
je 0x1a153
movq 0x50(%rsp), %rax
movq (%rax), %rdx
movq (%rsp), %rax
movq 0x18(%rsp), %rcx
movq (%rax,%rcx,8), %r8
movq %r14, %rdi
leaq 0x6254(%rip), %rsi      # 0x202e1
movl %r10d, %ecx
xorl %eax, %eax
callq 0x22c0
leaq 0xe432(%rip), %r9       # 0x284d0
movq 0x10(%rsp), %rsi
testl %r15d, %r15d
je 0x1a103
leal (%rbx,%rbx), %eax
cltq
movq 0x38(%rsp), %rcx
movb $0x1, 0x1(%rcx,%rax)
testq %r14, %r14
je 0x1a10b
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x58(%rsp), %rcx
movq (%rax,%rcx), %rdx
movl 0x10(%rax,%rcx), %r8d
movl %r8d, %ecx
subl %r15d, %ecx
movq (%rsp), %rax
movq 0x18(%rsp), %rsi
movq (%rax,%rsi,8), %r9
movq %r14, %rdi
leaq 0x541f(%rip), %rsi      # 0x1f50f
xorl %eax, %eax
callq 0x22c0
leaq 0xe3d2(%rip), %r9       # 0x284d0
movq 0x10(%rsp), %rsi
incq %rbx
jmp 0x19d7c
movq 0xdee6(%rip), %rax      # 0x27ff8
movq (%rax), %rdi
movq (%rsp), %rax
movq 0x18(%rsp), %rcx
movq (%rax,%rcx,8), %rcx
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x58(%rsp), %rdx
movq (%rax,%rdx), %r8
movl 0x10(%rax,%rdx), %r9d
subl %r15d, %r9d
leaq 0x61fb(%rip), %rsi      # 0x2033e
leaq 0x61e8(%rip), %rdx      # 0x20332
xorl %eax, %eax
callq 0x22c0
jmp 0x1a0f7
movq 0xde9e(%rip), %rax      # 0x27ff8
movq (%rax), %rdi
movq (%rsp), %rax
movq 0x18(%rsp), %rcx
movq (%rax,%rcx,8), %rcx
movq 0x50(%rsp), %rax
movq (%rax), %r8
leaq 0x6174(%rip), %rsi      # 0x202ed
leaq 0x61b2(%rip), %rdx      # 0x20332
movl %r10d, %r9d
xorl %eax, %eax
callq 0x22c0
jmp 0x1a097
testq %r12, %r12
je 0x1a1c3
movq 0x10(%r12), %rdi
testq %rdi, %rdi
je 0x1a1c3
movl (%r12), %eax
movl %eax, %edx
shrl $0x2, %edx
andl $-0x4, %edx
cmpl $0x10, %eax
pushq $0x4
popq %rax
cmovbl %eax, %edx
movl $0xaa, %esi
callq 0x21e0
andq $0x0, 0x4(%r12)
movq 0x18(%rsp), %rcx
incq %rcx
jmp 0x19b4f
testq %r12, %r12
je 0x1a203
movq 0x18(%r12), %rsi
xorl %edi, %edi
callq 0x8447
movq 0x10(%r12), %rsi
xorl %edi, %edi
callq 0x8447
movq 0x20(%r12), %rsi
xorl %edi, %edi
callq 0x8447
xorl %edi, %edi
movq %r12, %rsi
callq 0x8447
cmpq $0x0, 0xe40d(%rip)      # 0x28618
je 0x1a216
movq (%rsp), %rdi
callq 0x2060
movq 0x28(%rsp), %rdi
callq 0xe20a
movq 0x38(%rsp), %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6057(%rip), %rdi      # 0x20295
leaq 0x6061(%rip), %rsi      # 0x202a6
leaq 0x6061(%rip), %rcx      # 0x202ad
movl $0xc5, %edx
callq 0x21c0