// File: /workspace/github_c_makefile_star2_O3/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, 0x68(%rsp)
callq 0x12893
movq %rax, 0x30(%rsp)
movl (%rax), %eax
movq %rax, 0x80(%rsp)
leal (%rax,%rax), %edi
movl $0x1, %eax
movq %rax, 0x60(%rsp)
movl $0x1, %esi
callq 0x2290
movq %rax, 0x28(%rsp)
movq 0xdf97(%rip), %rbx      # 0x2c618
testq %rbx, %rbx
je 0x1e69a
movl $0x8, %edi
callq 0x2330
movq %rax, 0x10(%rsp)
movq %rbx, (%rax)
jmp 0x1e6b0
leaq 0xdd6f(%rip), %rax      # 0x2c410
movq %rax, 0x10(%rsp)
movl $0x17, %eax
movq %rax, 0x60(%rsp)
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl $0x1, %esi
movl $0x28, %edx
xorl %edi, %edi
callq 0xbf84
xorl %ecx, %ecx
movq %rax, (%rsp)
movq 0x10(%rsp), %rax
movq %rcx, 0x18(%rsp)
movq (%rax,%rcx,8), %r14
movq %r14, %rdi
callq 0x2160
movq %rax, %rbp
leal (%rax,%rax), %esi
movq (%rsp), %rdi
movl %esi, 0x58(%rsp)
callq 0x1ef73
leaq 0xddd3(%rip), %r10      # 0x2c4d0
movq (%rsp), %r9
testl %ebp, %ebp
jle 0x1e8d2
xorl %r12d, %r12d
xorl %ecx, %ecx
xorl %r15d, %r15d
leal (%r12,%rcx), %eax
xorl %edx, %edx
divl %ebp
movzbl (%r14,%rdx), %eax
movzbl (%rax,%r10), %eax
leal -0x1(%rax), %edx
cmpb $0x4, %dl
jae 0x1ef54
movq %r15, %rbx
shlq $0x2, %rbx
addl %r13d, %eax
movq %rax, %r15
orq %rbx, %r15
incl %ecx
cmpl %ecx, %ebp
jne 0x1e711
movl 0x8(%r9), %eax
cmpl 0xc(%r9), %eax
jb 0x1e77d
movl (%r9), %esi
movl 0x4(%r9), %eax
addl %eax, %eax
cmpl %eax, %esi
jbe 0x1e760
decl %esi
jmp 0x1e762
incl %esi
movq %r9, %rdi
callq 0x1ef73
movq (%rsp), %r9
testl %eax, %eax
leaq 0xdd59(%rip), %r10      # 0x2c4d0
js 0x1e8c6
movl (%r9), %esi
leal -0x1(%rsi), %r8d
shrq $0x21, %rbx
xorl %r15d, %ebx
movl %r15d, %edi
shll $0xb, %edi
xorl %ebx, %edi
andl %r8d, %edi
movq 0x10(%r9), %rax
movl %edi, %ecx
shrl $0x4, %ecx
movl (%rax,%rcx,4), %edx
leal (%rdi,%rdi), %ecx
shrl %cl, %edx
testb $0x2, %dl
je 0x1e7b3
movl %edi, %edx
jmp 0x1e84c
movl $0x1, %r10d
movl %edi, %r9d
movl %esi, %edx
movl %r9d, %ecx
shrl $0x4, %ecx
movl (%rax,%rcx,4), %r11d
leal (%r9,%r9), %ecx
andl $0x1e, %ecx
movl %r11d, %ebx
shrl %cl, %ebx
testb $0x2, %bl
jne 0x1e821
testb $0x1, %bl
jne 0x1e7f5
movq (%rsp), %rbx
movq 0x18(%rbx), %rbx
movl %r9d, %r13d
cmpq %r15, (%rbx,%r13,8)
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
je 0x1e821
btl %ecx, %r11d
cmovbl %r9d, %edx
addl %r10d, %r9d
andl %r8d, %r9d
incl %r10d
cmpl %edi, %r9d
jne 0x1e7be
movb $0x1, %cl
movl %esi, %r8d
cmpl %esi, %edx
movq (%rsp), %r9
leaq 0xdcb3(%rip), %r10      # 0x2c4d0
je 0x1e83c
jmp 0x1e84c
shrl %cl, %r11d
testb $0x2, %r11b
sete %cl
movl %edx, %r8d
movl %r9d, %edi
movq (%rsp), %r9
leaq 0xdc94(%rip), %r10      # 0x2c4d0
cmpl %esi, %r8d
cmovel %edi, %r8d
testb %cl, %cl
cmovnel %edi, %r8d
movl %r8d, %edx
movl %edx, %esi
shrl $0x4, %esi
movl (%rax,%rsi,4), %edi
leal (%rdx,%rdx), %ecx
andl $0x1e, %ecx
movl %edi, %r8d
shrl %cl, %r8d
testb $0x2, %r8b
jne 0x1e892
testb $0x1, %r8b
je 0x1e8c6
movq 0x18(%r9), %r8
movl $0x3, %r9d
shll %cl, %r9d
movl %edx, %ecx
movq %r15, (%r8,%rcx,8)
notl %r9d
andl %r9d, %edi
movq (%rsp), %r9
movl %edi, (%rax,%rsi,4)
incl 0x4(%r9)
jmp 0x1e8c6
movq 0x18(%r9), %r8
movl $0x3, %r9d
shll %cl, %r9d
movl %edx, %ecx
movq %r15, (%r8,%rcx,8)
notl %r9d
andl %r9d, %edi
movq (%rsp), %r9
movl %edi, (%rax,%rsi,4)
movq 0x4(%r9), %xmm0
psubd 0x5a40(%rip), %xmm0     # 0x24300
movq %xmm0, 0x4(%r9)
incl %r12d
cmpl %ebp, %r12d
jne 0x1e70c
cmpq $0x0, 0x80(%rsp)
je 0x1ee88
movq $-0x1, %r12
movl 0x58(%rsp), %ecx
shlq %cl, %r12
notq %r12
movslq %ebp, %rbp
xorl %ebx, %ebx
movq %r12, 0x40(%rsp)
movq %rbp, 0x38(%rsp)
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rcx
movq %rbx, 0xa0(%rsp)
leaq (%rbx,%rbx,2), %rax
movq 0x8(%rcx,%rax,8), %rdx
movq %rdx, 0x58(%rsp)
movq %rax, 0x70(%rsp)
movq %rcx, 0x90(%rsp)
movslq 0x10(%rcx,%rax,8), %r14
movslq 0xdac7(%rip), %rcx      # 0x2c400
movslq 0xdac4(%rip), %rax      # 0x2c404
movq %rax, 0x88(%rsp)
testq %r14, %r14
movq %r14, 0x48(%rsp)
jle 0x1ead3
movq %rcx, 0x20(%rsp)
negq %rcx
movq %rcx, 0x8(%rsp)
movq $-0x1, %r15
xorl %edi, %edi
xorl %r8d, %r8d
xorl %r11d, %r11d
xorl %r10d, %r10d
xorl %ebx, %ebx
movq 0x58(%rsp), %rax
movzbl (%rax,%r10), %eax
leaq 0xdb48(%rip), %rcx      # 0x2c4d0
movzbl (%rax,%rcx), %ecx
leal -0x1(%rcx), %eax
cmpb $0x3, %al
ja 0x1ea44
shlq $0x2, %rbx
addl %r13d, %ecx
orq %rcx, %rbx
andq %r12, %rbx
incq %r11
cmpq %rbp, %r11
jl 0x1ea49
movq %r15, 0x50(%rsp)
movl (%r9), %eax
testl %eax, %eax
je 0x1ea74
movq %rax, 0x78(%rsp)
leal -0x1(%rax), %ebp
movq %rbx, %r14
shrq $0x21, %r14
movl %ebx, %eax
shll $0xb, %eax
xorl %eax, %r14d
xorl %ebx, %r14d
andl %ebp, %r14d
movq 0x10(%r9), %rdx
movl $0x1, %r12d
movl %r14d, %r15d
movl %r15d, %eax
shrl $0x4, %eax
movl (%rdx,%rax,4), %eax
leal (%r15,%r15), %ecx
andl $0x1e, %ecx
movl %eax, %r13d
shrl %cl, %r13d
testb $0x2, %r13b
jne 0x1ea50
testb $0x1, %r13b
jne 0x1ea1a
movq 0x18(%r9), %r13
movl %r15d, %esi
cmpq %rbx, (%r13,%rsi,8)
je 0x1ea50
addl %r12d, %r15d
andl %ebp, %r15d
incl %r12d
cmpl %r14d, %r15d
jne 0x1e9ea
movq 0x8(%rsp), %rcx
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movq 0x40(%rsp), %r12
movq 0x38(%rsp), %rbp
movq 0x48(%rsp), %r14
jmp 0x1ea85
xorl %r11d, %r11d
xorl %ebx, %ebx
movq 0x8(%rsp), %rcx
jmp 0x1ea8a
shrl %cl, %eax
testb $0x3, %al
movq 0x78(%rsp), %rax
cmovnel %eax, %r15d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movq 0x40(%rsp), %r12
movq 0x38(%rsp), %rbp
movq 0x48(%rsp), %r14
jmp 0x1ea77
xorl %r15d, %r15d
cmpl %eax, %r15d
movl $0x1, %ecx
cmoveq 0x8(%rsp), %rcx
movq 0x50(%rsp), %r15
cmpq %rbp, %r10
movl $0x0, %eax
cmovgeq %rcx, %rax
addq %rax, %r8
movq %rdi, %rsi
movq %r10, %rcx
movq %r8, %rdx
subq %r8, %rsi
jl 0x1eab7
movq %r15, %rcx
movq %rdi, %rdx
cmpq 0x88(%rsp), %rsi
jg 0x1eac9
incq %r10
movq %rdx, %rdi
movq %rcx, %r15
cmpq %r14, %r10
jne 0x1e977
incq %r15
movq 0x20(%rsp), %rcx
jmp 0x1ead8
xorl %r15d, %r15d
xorl %edi, %edi
movslq 0xd929(%rip), %rax      # 0x2c408
movq %rax, 0x98(%rsp)
cmpq %rax, %rdi
movq %r15, 0x50(%rsp)
movq %r15, %rdx
movl $0x0, %eax
cmovlq %rax, %rdx
leal -0x1(%r14), %eax
movslq %eax, %r15
movq $-0x1, %rax
movl $0x0, %r8d
movq %rdx, 0x78(%rsp)
cmpq %r15, %rdx
jg 0x1ecbd
negl %ecx
movslq %ecx, %rax
movq %rax, 0x20(%rsp)
movq %r14, %rax
subq %rbp, %rax
movq %rax, 0xb0(%rsp)
movq $-0x1, %rax
xorl %r8d, %r8d
xorl %ebx, %ebx
movq $0x0, 0x8(%rsp)
xorl %edx, %edx
movq 0x58(%rsp), %rcx
movzbl (%rcx,%r15), %ecx
leaq 0xd973(%rip), %rsi      # 0x2c4d0
movzbl (%rcx,%rsi), %ecx
leal -0x1(%rcx), %esi
cmpb $0x3, %sil
ja 0x1ec27
shlq $0x2, %rdx
movl $0x4, %esi
subq %rcx, %rsi
orq %rsi, %rdx
andq %r12, %rdx
movq 0x8(%rsp), %rcx
incq %rcx
cmpq %rbp, %rcx
movq %rcx, 0x8(%rsp)
jl 0x1ec32
movl (%r9), %ecx
testl %ecx, %ecx
je 0x1ec5d
movq %rcx, 0xa8(%rsp)
leal -0x1(%rcx), %r13d
movq %rdx, %r10
shrq $0x21, %r10
movl %edx, %ecx
shll $0xb, %ecx
xorl %ecx, %r10d
xorl %edx, %r10d
andl %r13d, %r10d
movq 0x10(%r9), %r12
movl $0x1, %r11d
movl %r10d, %r14d
movl %r14d, %ecx
shrl $0x4, %ecx
movl (%r12,%rcx,4), %esi
leal (%r14,%r14), %ecx
andl $0x1e, %ecx
movl %esi, %ebp
shrl %cl, %ebp
testb $0x2, %bpl
jne 0x1ec39
testb $0x1, %bpl
jne 0x1ec02
movq 0x18(%r9), %rbp
movl %r14d, %r9d
cmpq %rdx, (%rbp,%r9,8)
movq (%rsp), %r9
je 0x1ec39
addl %r11d, %r14d
andl %r13d, %r14d
incl %r11d
cmpl %r10d, %r14d
jne 0x1ebcf
movq 0x20(%rsp), %rcx
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movq 0x40(%rsp), %r12
movq 0x38(%rsp), %rbp
jmp 0x1ec6e
movq $0x0, 0x8(%rsp)
xorl %edx, %edx
movq 0x20(%rsp), %rcx
jmp 0x1ec73
shrl %cl, %esi
testb $0x3, %sil
movq 0xa8(%rsp), %rcx
cmovnel %ecx, %r14d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movq 0x40(%rsp), %r12
movq 0x38(%rsp), %rbp
jmp 0x1ec60
xorl %r14d, %r14d
cmpl %ecx, %r14d
movl $0x1, %ecx
cmoveq 0x20(%rsp), %rcx
movq 0x48(%rsp), %r14
cmpq 0xb0(%rsp), %r15
movl $0x0, %esi
cmovleq %rcx, %rsi
addq %rsi, %rbx
movq %r8, %r11
movq %r15, %rcx
movq %rbx, %r10
subq %rbx, %r11
jl 0x1eca5
movq %rax, %rcx
movq %r8, %r10
cmpq 0x88(%rsp), %r11
jg 0x1ecbd
leaq -0x1(%r15), %rsi
movq %r10, %r8
movq %rcx, %rax
cmpq 0x78(%rsp), %r15
movq %rsi, %r15
jg 0x1eb4c
movq 0x50(%rsp), %r10
shlq $0x20, %r10
movq 0x98(%rsp), %rdx
cmpq %rdx, %rdi
movl $0x0, %ecx
cmovlq %rcx, %r10
subq %rax, %r14
cmpq %rdx, %r8
cmovlq %rcx, %r14
addq %r14, %r10
movq 0xa0(%rsp), %rbx
je 0x1ee1c
shrq $0x20, %r10
jne 0x1ed6d
testl %r14d, %r14d
je 0x1ee1c
leal (%rbx,%rbx), %eax
cltq
movq 0x28(%rsp), %rcx
movb $0x1, 0x1(%rcx,%rax)
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
jne 0x1ede8
movq 0xd2c7(%rip), %rcx      # 0x2bff8
movq (%rcx), %rdi
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq 0x70(%rsp), %rdx
movq (%rax,%rdx,8), %r8
movl 0x10(%rax,%rdx,8), %r9d
subl %r14d, %r9d
leaq 0x5734(%rip), %rsi      # 0x2448e
leaq 0x5721(%rip), %rdx      # 0x24482
xorl %eax, %eax
callq 0x22c0
jmp 0x1ee18
movq 0x70(%rsp), %rax
movq 0x90(%rsp), %rcx
leaq (%rcx,%rax,8), %rax
movq %rbx, %rcx
shlq $0x21, %rcx
sarq $0x20, %rcx
movq 0x28(%rsp), %rdx
movb $0x1, (%rdx,%rcx)
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x1ee2f
movq (%rax), %rdx
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
movq (%rax,%rcx,8), %r8
leaq 0x5679(%rip), %rsi      # 0x24431
movl %r10d, %ecx
xorl %eax, %eax
callq 0x22c0
testl %r14d, %r14d
movq (%rsp), %r9
je 0x1ee1c
leal (%rbx,%rbx), %eax
cltq
movq 0x28(%rsp), %rcx
movb $0x1, 0x1(%rcx,%rax)
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x68(%rsp), %rdi
movq 0x70(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
movl 0x10(%rax,%rcx,8), %r8d
movl %r8d, %ecx
subl %r14d, %ecx
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rsi
movq (%rax,%rsi,8), %r9
leaq 0x4836(%rip), %rsi      # 0x23647
xorl %eax, %eax
callq 0x22c0
movq (%rsp), %r9
incq %rbx
cmpq 0x80(%rsp), %rbx
jne 0x1e901
jmp 0x1ee88
movq 0xd1c2(%rip), %rcx      # 0x2bff8
movq (%rcx), %rdi
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq (%rax), %r8
leaq 0x55ec(%rip), %rsi      # 0x2443d
leaq 0x562a(%rip), %rdx      # 0x24482
movl %r10d, %r9d
xorl %eax, %eax
callq 0x22c0
testl %r14d, %r14d
movq (%rsp), %r9
je 0x1ee1c
leal (%rbx,%rbx), %eax
cltq
movq 0x28(%rsp), %rcx
movb $0x1, 0x1(%rcx,%rax)
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rax
jmp 0x1ed2a
testq %r9, %r9
je 0x1eed7
movq 0x10(%r9), %rdi
testq %rdi, %rdi
je 0x1eec2
movl (%r9), %eax
movl %eax, %edx
shrl $0x2, %edx
andl $-0x4, %edx
cmpl $0x10, %eax
movl $0x4, %eax
cmovbl %eax, %edx
movl $0xaa, %esi
callq 0x21e0
movq (%rsp), %r9
movq $0x0, 0x4(%r9)
movq 0x18(%rsp), %rcx
incq %rcx
cmpq 0x60(%rsp), %rcx
jne 0x1e6cd
jmp 0x1eeec
movq 0x18(%rsp), %rcx
incq %rcx
cmpq 0x60(%rsp), %rcx
jne 0x1e6cd
jmp 0x1ef1f
testq %r9, %r9
je 0x1ef1f
movq 0x18(%r9), %rsi
xorl %edi, %edi
movq %r9, %rbx
callq 0xc01f
movq 0x10(%rbx), %rsi
xorl %edi, %edi
callq 0xc01f
movq 0x20(%rbx), %rsi
xorl %edi, %edi
callq 0xc01f
xorl %edi, %edi
movq %rbx, %rsi
callq 0xc01f
cmpq $0x0, 0xd6f1(%rip)      # 0x2c618
je 0x1ef33
movq 0x10(%rsp), %rdi
callq 0x2060
movq 0x30(%rsp), %rdi
callq 0x12233
movq 0x28(%rsp), %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x548a(%rip), %rdi      # 0x243e5
leaq 0x5494(%rip), %rsi      # 0x243f6
leaq 0x5494(%rip), %rcx      # 0x243fd
movl $0xc5, %edx
callq 0x21c0