// File: /workspace/github_c_makefile_star2_O1/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, 0x80(%rsp)
callq 0x11ad4
movq %rax, 0x28(%rsp)
movl (%rax), %eax
movq %rax, 0x88(%rsp)
leal (%rax,%rax), %edi
movl $0x1, %eax
movq %rax, 0x78(%rsp)
movl $0x1, %esi
callq 0x2290
movq %rax, 0x50(%rsp)
movq 0xddcc(%rip), %rbx      # 0x2b618
testq %rbx, %rbx
je 0x1d865
movl $0x8, %edi
callq 0x2330
movq %rax, 0x8(%rsp)
movq %rbx, (%rax)
jmp 0x1d87b
leaq 0xdba4(%rip), %rax      # 0x2b410
movq %rax, 0x8(%rsp)
movl $0x17, %eax
movq %rax, 0x78(%rsp)
movl $0x1, %esi
movl $0x28, %edx
xorl %edi, %edi
callq 0xb260
movq %rax, %r13
xorl %ecx, %ecx
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %rax
movq %rcx, 0x18(%rsp)
movq (%rax,%rcx,8), %r14
movq %r14, %rdi
callq 0x2160
movq %rax, %rbp
leal (%rax,%rax), %esi
movq %r13, %rdi
movl %esi, (%rsp)
callq 0x1e092
leaq 0xdc0c(%rip), %r10      # 0x2b4d0
testl %ebp, %ebp
jle 0x1da6c
xorl %ebx, %ebx
xorl %ecx, %ecx
xorl %r15d, %r15d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
leal (%rbx,%rcx), %eax
xorl %edx, %edx
divl %ebp
movzbl (%r14,%rdx), %eax
movzbl (%rax,%r10), %eax
leal -0x1(%rax), %edx
cmpb $0x4, %dl
jae 0x1e073
movq %r15, %r12
shlq $0x2, %r12
addl %esi, %eax
movq %rax, %r15
orq %r12, %r15
incl %ecx
cmpl %ecx, %ebp
jne 0x1d8d8
movl 0x8(%r13), %eax
cmpl 0xc(%r13), %eax
jb 0x1d93f
movl (%r13), %esi
movl 0x4(%r13), %eax
addl %eax, %eax
cmpl %eax, %esi
jbe 0x1d926
decl %esi
jmp 0x1d928
incl %esi
movq %r13, %rdi
callq 0x1e092
testl %eax, %eax
leaq 0xdb97(%rip), %r10      # 0x2b4d0
js 0x1da62
movl (%r13), %esi
leal -0x1(%rsi), %r9d
shrq $0x21, %r12
xorl %r15d, %r12d
movl %r15d, %edx
shll $0xb, %edx
xorl %r12d, %edx
andl %r9d, %edx
movq 0x10(%r13), %rax
movl %edx, %ecx
shrl $0x4, %ecx
movl (%rax,%rcx,4), %edi
leal (%rdx,%rdx), %ecx
shrl %cl, %edi
testb $0x2, %dil
jne 0x1d9fc
movl $0x1, %r10d
movl %edx, %r8d
movl %esi, %edi
movl %r8d, %ecx
shrl $0x4, %ecx
movl (%rax,%rcx,4), %r11d
leal (%r8,%r8), %ecx
andl $0x1e, %ecx
movl %r11d, %r12d
shrl %cl, %r12d
testb $0x2, %r12b
jne 0x1d9cf
testb $0x1, %r12b
jne 0x1d9b5
movq 0x18(%r13), %r12
movl %r8d, %r13d
cmpq %r15, (%r12,%r13,8)
movq 0x10(%rsp), %r13
je 0x1d9cf
btl %ecx, %r11d
cmovbl %r8d, %edi
addl %r10d, %r8d
andl %r9d, %r8d
incl %r10d
movl %edi, %ecx
cmpl %edx, %r8d
jne 0x1d980
jmp 0x1d9d1
movl %esi, %ecx
movl %ecx, %edx
cmpl %esi, %ecx
leaq 0xdaf4(%rip), %r10      # 0x2b4d0
jne 0x1d9fc
movl %r8d, %ecx
shrl $0x4, %ecx
movl (%rax,%rcx,4), %edx
leal (%r8,%r8), %ecx
shrl %cl, %edx
cmpl %esi, %edi
cmovel %r8d, %edi
testb $0x2, %dl
cmovel %r8d, %edi
movl %edi, %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 0x1da3e
testb $0x1, %r8b
je 0x1da62
movq 0x18(%r13), %r8
movl $0x3, %r9d
shll %cl, %r9d
movl %edx, %ecx
movq %r15, (%r8,%rcx,8)
notl %r9d
andl %r9d, %edi
movl %edi, (%rax,%rsi,4)
incl 0x4(%r13)
jmp 0x1da62
movq 0x18(%r13), %r8
movl $0x3, %r9d
shll %cl, %r9d
movl %edx, %ecx
movq %r15, (%r8,%rcx,8)
notl %r9d
andl %r9d, %edi
movl %edi, (%rax,%rsi,4)
incl 0x4(%r13)
incl 0x8(%r13)
incl %ebx
cmpl %ebp, %ebx
jne 0x1d8ce
cmpq $0x0, 0x88(%rsp)
je 0x1dfc4
movq $-0x1, %r12
movl (%rsp), %ecx
shlq %cl, %r12
notq %r12
movslq %ebp, %rbp
xorl %ecx, %ecx
movq %r12, 0x38(%rsp)
movq %rbp, 0x30(%rsp)
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdx
movq %rcx, 0x20(%rsp)
leaq (%rcx,%rcx,2), %rax
movq 0x8(%rdx,%rax,8), %r14
movq %rax, 0x58(%rsp)
movq %rdx, 0xa8(%rsp)
movslq 0x10(%rdx,%rax,8), %r9
movslq 0xd936(%rip), %rcx      # 0x2b400
movslq 0xd933(%rip), %rax      # 0x2b404
movq %rax, 0xa0(%rsp)
testq %r9, %r9
movq %r9, 0x40(%rsp)
movq %r14, 0x60(%rsp)
jle 0x1dc54
movq %rcx, 0x70(%rsp)
negq %rcx
movq %rcx, (%rsp)
movq $-0x1, %r15
xorl %edi, %edi
xorl %r8d, %r8d
xorl %r10d, %r10d
xorl %esi, %esi
xorl %r11d, %r11d
movzbl (%r14,%rsi), %eax
leaq 0xd9b8(%rip), %rcx      # 0x2b4d0
movzbl (%rax,%rcx), %ecx
leal -0x1(%rcx), %eax
cmpb $0x3, %al
ja 0x1db45
shlq $0x2, %r11
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addl %eax, %ecx
orq %rcx, %r11
andq %r12, %r11
incq %r10
cmpq %rbp, %r10
jge 0x1db54
movq (%rsp), %rcx
jmp 0x1dc0b
movq (%rsp), %rcx
xorl %r11d, %r11d
xorl %r10d, %r10d
jmp 0x1dc0b
movl (%r13), %ebx
testl %ebx, %ebx
je 0x1dbf6
movq %r15, 0x48(%rsp)
leal -0x1(%rbx), %ebp
movq %r11, %r15
shrq $0x21, %r15
movl %r11d, %eax
shll $0xb, %eax
xorl %eax, %r15d
xorl %r11d, %r15d
andl %ebp, %r15d
movq 0x10(%r13), %rdx
movl $0x1, %r12d
movl %r15d, %r14d
movl %r14d, %eax
shrl $0x4, %eax
movl (%rdx,%rax,4), %eax
leal (%r14,%r14), %ecx
andl $0x1e, %ecx
movl %eax, %r13d
shrl %cl, %r13d
testb $0x2, %r13b
jne 0x1dbd3
testb $0x1, %r13b
jne 0x1dbc0
movq 0x10(%rsp), %r9
movq 0x18(%r9), %r13
movl %r14d, %r9d
cmpq %r11, (%r13,%r9,8)
je 0x1dbd3
addl %r12d, %r14d
andl %ebp, %r14d
incl %r12d
cmpl %r15d, %r14d
jne 0x1db8b
movl %ebx, %r14d
jmp 0x1dbdb
shrl %cl, %eax
testb $0x3, %al
cmovnel %ebx, %r14d
movq 0x10(%rsp), %r13
movq 0x38(%rsp), %r12
movq 0x30(%rsp), %rbp
movq 0x40(%rsp), %r9
movq 0x48(%rsp), %r15
jmp 0x1dbf9
xorl %r14d, %r14d
cmpl %ebx, %r14d
movl $0x1, %ecx
cmoveq (%rsp), %rcx
movq 0x60(%rsp), %r14
cmpq %rbp, %rsi
movl $0x0, %eax
cmovgeq %rcx, %rax
addq %rax, %r8
movq %rdi, %rbx
movq %rsi, %rcx
movq %r8, %rdx
subq %r8, %rbx
jl 0x1dc38
movq %r15, %rcx
movq %rdi, %rdx
cmpq 0xa0(%rsp), %rbx
jg 0x1dc4a
incq %rsi
movq %rdx, %rdi
movq %rcx, %r15
cmpq %r9, %rsi
jne 0x1db0c
incq %r15
movq 0x70(%rsp), %rcx
jmp 0x1dc59
xorl %r15d, %r15d
xorl %edi, %edi
movslq 0xd7a8(%rip), %rax      # 0x2b408
movq %rax, 0xb0(%rsp)
cmpq %rax, %rdi
movq %r15, 0x48(%rsp)
movq %r15, %rbx
movl $0x0, %eax
cmovlq %rax, %rbx
leal -0x1(%r9), %eax
movslq %eax, %r15
movq $-0x1, %rax
movl $0x0, %r8d
cmpq %r15, %rbx
jg 0x1de3f
movq 0x40(%rsp), %rax
subq %rbp, %rax
movq %rax, 0x70(%rsp)
negl %ecx
movslq %ecx, %rax
movq %rax, 0x68(%rsp)
movq $-0x1, %rax
xorl %r8d, %r8d
xorl %esi, %esi
movq $0x0, (%rsp)
xorl %edx, %edx
movq %rbx, 0x90(%rsp)
movzbl (%r14,%r15), %ecx
leaq 0xd7f6(%rip), %r9       # 0x2b4d0
movzbl (%rcx,%r9), %ecx
leal -0x1(%rcx), %r9d
cmpb $0x3, %r9b
ja 0x1dd16
shlq $0x2, %rdx
movl $0x4, %r9d
subl %ecx, %r9d
orq %r9, %rdx
andq %r12, %rdx
movq (%rsp), %rcx
incq %rcx
cmpq %rbp, %rcx
movq %rcx, (%rsp)
jge 0x1dd2a
movq 0x68(%rsp), %rcx
jmp 0x1ddf9
movq 0x68(%rsp), %rcx
xorl %edx, %edx
movq $0x0, (%rsp)
jmp 0x1ddf9
movl (%r13), %ecx
testl %ecx, %ecx
je 0x1dde3
movq %rcx, 0x98(%rsp)
leal -0x1(%rcx), %r10d
movq %rdx, %r14
shrq $0x21, %r14
movl %edx, %ecx
shll $0xb, %ecx
xorl %ecx, %r14d
xorl %edx, %r14d
andl %r10d, %r14d
movq 0x10(%r13), %rbx
movl $0x1, %r11d
movl %r14d, %r13d
movl %r13d, %ecx
shrl $0x4, %ecx
movl (%rbx,%rcx,4), %r12d
leal (,%r13,2), %ecx
andl $0x1e, %ecx
movl %r12d, %ebp
shrl %cl, %ebp
testb $0x2, %bpl
jne 0x1ddb7
testb $0x1, %bpl
jne 0x1dd9c
movq 0x10(%rsp), %r9
movq 0x18(%r9), %r9
movl %r13d, %ebp
cmpq %rdx, (%r9,%rbp,8)
je 0x1ddb7
addl %r11d, %r13d
andl %r10d, %r13d
incl %r11d
cmpl %r14d, %r13d
jne 0x1dd64
movq 0x98(%rsp), %rcx
movl %ecx, %r13d
jmp 0x1ddca
shrl %cl, %r12d
testb $0x3, %r12b
movq 0x98(%rsp), %rcx
cmovnel %ecx, %r13d
movq 0x38(%rsp), %r12
movq 0x30(%rsp), %rbp
movq 0x60(%rsp), %r14
movq 0x90(%rsp), %rbx
jmp 0x1dde6
xorl %r13d, %r13d
cmpl %ecx, %r13d
movl $0x1, %ecx
cmoveq 0x68(%rsp), %rcx
movq 0x10(%rsp), %r13
cmpq 0x70(%rsp), %r15
movl $0x0, %r9d
cmovleq %rcx, %r9
addq %r9, %rsi
movq %r8, %r11
movq %r15, %rcx
movq %rsi, %r10
subq %rsi, %r11
jl 0x1de29
movq %rax, %rcx
movq %r8, %r10
cmpq 0xa0(%rsp), %r11
jg 0x1de3f
leaq -0x1(%r15), %r9
movq %r10, %r8
movq %rcx, %rax
cmpq %rbx, %r15
movq %r9, %r15
jg 0x1dcce
movq 0x48(%rsp), %r9
shlq $0x20, %r9
movq 0xb0(%rsp), %rdx
cmpq %rdx, %rdi
movl $0x0, %ecx
cmovlq %rcx, %r9
movq 0x40(%rsp), %rbx
subq %rax, %rbx
cmpq %rdx, %r8
cmovlq %rcx, %rbx
addq %rbx, %r9
movq 0x20(%rsp), %rcx
je 0x1df33
shrq $0x20, %r9
je 0x1ded6
movq 0x58(%rsp), %rax
movq 0xa8(%rsp), %rdx
leaq (%rdx,%rax,8), %rax
addl %ecx, %ecx
movslq %ecx, %rcx
movq 0x50(%rsp), %rdx
movb $0x1, (%rdx,%rcx)
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x1df8f
movq (%rax), %rdx
movq 0x8(%rsp), %rax
movq 0x18(%rsp), %rcx
movq (%rax,%rcx,8), %r8
leaq 0x5419(%rip), %rsi      # 0x232e0
movl %r9d, %ecx
xorl %eax, %eax
callq 0x22c0
movq 0x20(%rsp), %rcx
testl %ebx, %ebx
je 0x1df33
leal (%rcx,%rcx), %eax
cltq
movq 0x50(%rsp), %rcx
movb $0x1, 0x1(%rcx,%rax)
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x1df46
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x58(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
movl 0x10(%rax,%rcx,8), %r8d
movl %r8d, %ecx
subl %ebx, %ecx
movq 0x8(%rsp), %rax
movq 0x18(%rsp), %rsi
movq (%rax,%rsi,8), %r9
leaq 0x46e6(%rip), %rsi      # 0x2260d
xorl %eax, %eax
callq 0x22c0
movq 0x20(%rsp), %rcx
incq %rcx
cmpq 0x88(%rsp), %rcx
jne 0x1da9a
jmp 0x1dfc4
movq 0xd0ab(%rip), %rax      # 0x2aff8
movq (%rax), %rdi
movq 0x8(%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,8), %r8
movl 0x10(%rax,%rdx,8), %r9d
subl %ebx, %r9d
leaq 0x53be(%rip), %rsi      # 0x2333d
leaq 0x53ab(%rip), %rdx      # 0x23331
xorl %eax, %eax
callq 0x22c0
jmp 0x1df2e
movq 0xd062(%rip), %rcx      # 0x2aff8
movq (%rcx), %rdi
movq 0x8(%rsp), %rcx
movq 0x18(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq (%rax), %r8
leaq 0x533b(%rip), %rsi      # 0x232ec
leaq 0x5379(%rip), %rdx      # 0x23331
xorl %eax, %eax
callq 0x22c0
jmp 0x1ded1
testq %r13, %r13
je 0x1dffb
movq 0x10(%r13), %rdi
testq %rdi, %rdi
je 0x1dffb
movl (%r13), %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 $0x0, 0x4(%r13)
movq 0x18(%rsp), %rcx
incq %rcx
cmpq 0x78(%rsp), %rcx
jne 0x1d896
testq %r13, %r13
je 0x1e03e
movq 0x18(%r13), %rsi
xorl %edi, %edi
callq 0xb302
movq 0x10(%r13), %rsi
xorl %edi, %edi
callq 0xb302
movq 0x20(%r13), %rsi
xorl %edi, %edi
callq 0xb302
xorl %edi, %edi
movq %r13, %rsi
callq 0xb302
cmpq $0x0, 0xd5d2(%rip)      # 0x2b618
je 0x1e052
movq 0x8(%rsp), %rdi
callq 0x2060
movq 0x28(%rsp), %rdi
callq 0x1148c
movq 0x50(%rsp), %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x521a(%rip), %rdi      # 0x23294
leaq 0x5224(%rip), %rsi      # 0x232a5
leaq 0x5224(%rip), %rcx      # 0x232ac
movl $0xc5, %edx
callq 0x21c0