// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x17050
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
shll %eax
movl %eax, %eax
movl %eax, %edi
movl $0x1, %esi
callq 0x2290
movq %rax, -0x50(%rbp)
movl $0x0, -0x38(%rbp)
movq $0x0, -0x60(%rbp)
cmpq $0x0, 0xf3db(%rip)      # 0x39db8
je 0x2aa04
movl $0x8, %edi
callq 0x2340
movq %rax, -0x60(%rbp)
movq 0xf3c4(%rip), %rcx      # 0x39db8
movq -0x60(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x38(%rbp)
jmp 0x2aa16
leaq 0xf035(%rip), %rax      # 0x39a40
movq %rax, -0x60(%rbp)
movl $0x17, -0x38(%rbp)
callq 0x2ada0
movq %rax, -0x70(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x38(%rbp), %eax
jae 0x2ad6b
movq -0x60(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdi
callq 0x2160
movl %eax, -0x2c(%rbp)
movq -0x70(%rbp), %rdi
movl -0x2c(%rbp), %esi
shll %esi
callq 0x2adc0
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x2ab29
movl $0x0, -0x20(%rbp)
movq $0x0, -0x40(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x2ab0a
movq -0x68(%rbp), %rax
movq %rax, -0x78(%rbp)
movl -0x1c(%rbp), %eax
addl -0x20(%rbp), %eax
cltd
idivl -0x2c(%rbp)
movq -0x78(%rbp), %rax
movslq %edx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0xf050(%rip), %rax      # 0x39b00
movzbl (%rax,%rcx), %eax
movl %eax, -0x28(%rbp)
cmpl $0x1, -0x28(%rbp)
jl 0x2aac5
cmpl $0x4, -0x28(%rbp)
jg 0x2aac5
jmp 0x2aae4
leaq 0x81f8(%rip), %rdi      # 0x32cc4
leaq 0x8202(%rip), %rsi      # 0x32cd5
movl $0xc5, %edx
leaq 0x81fd(%rip), %rcx      # 0x32cdc
callq 0x21c0
movq -0x40(%rbp), %rax
shlq $0x2, %rax
movl -0x28(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
orq %rcx, %rax
movq %rax, -0x40(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x2aa7e
movq -0x70(%rbp), %rdi
movq -0x40(%rbp), %rsi
leaq -0x30(%rbp), %rdx
callq 0x2b1d0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x2aa63
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jae 0x2ad54
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdi
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %esi
movq -0x70(%rbp), %rdx
movl -0x2c(%rbp), %ecx
movl 0xeeb9(%rip), %r8d      # 0x39a30
movl 0xeeb6(%rip), %r9d      # 0x39a34
movl 0xeeb4(%rip), %eax      # 0x39a38
movl %eax, (%rsp)
callq 0x2b540
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x2ab9c
jmp 0x2ad46
movq -0x48(%rbp), %rax
shrq $0x20, %rax
cmpq $0x0, %rax
jbe 0x2ac53
movq -0x50(%rbp), %rax
movl -0x1c(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
movb $0x1, (%rax,%rcx)
cmpq $0x0, -0x18(%rbp)
je 0x2ac05
movq -0x18(%rbp), %rdi
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdx
movq -0x48(%rbp), %rax
shrq $0x20, %rax
movl %eax, %ecx
movq -0x60(%rbp), %rax
movslq -0x24(%rbp), %rsi
movq (%rax,%rsi,8), %r8
leaq 0x8114(%rip), %rsi      # 0x32d10
movb $0x0, %al
callq 0x22c0
jmp 0x2ac51
movq 0xe3ec(%rip), %rax      # 0x38ff8
movq (%rax), %rdi
movq -0x60(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x1c(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq (%rax), %r8
movq -0x48(%rbp), %rax
shrq $0x20, %rax
movl %eax, %r9d
leaq 0x80d9(%rip), %rsi      # 0x32d1c
leaq 0x8117(%rip), %rdx      # 0x32d61
movb $0x0, %al
callq 0x22c0
jmp 0x2ac53
movq -0x48(%rbp), %rax
cmpl $0x0, %eax
jbe 0x2ad44
movq -0x50(%rbp), %rax
movl -0x1c(%rbp), %ecx
shll %ecx
orl $0x1, %ecx
movslq %ecx, %rcx
movb $0x1, (%rax,%rcx)
cmpq $0x0, -0x18(%rbp)
je 0x2ace3
movq -0x18(%rbp), %rdi
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdx
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %ecx
movq -0x48(%rbp), %rax
subl %eax, %ecx
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x1c(%rbp), %rsi
imulq $0x18, %rsi, %rsi
addq %rsi, %rax
movl 0x10(%rax), %r8d
movq -0x60(%rbp), %rax
movslq -0x24(%rbp), %rsi
movq (%rax,%rsi,8), %r9
leaq 0x7835(%rip), %rsi      # 0x3250f
movb $0x0, %al
callq 0x22c0
jmp 0x2ad42
movq 0xe30e(%rip), %rax      # 0x38ff8
movq (%rax), %rdi
movq -0x60(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x1c(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq (%rax), %r8
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x1c(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movl 0x10(%rax), %r9d
movq -0x48(%rbp), %rax
subl %eax, %r9d
leaq 0x8039(%rip), %rsi      # 0x32d6d
leaq 0x8026(%rip), %rdx      # 0x32d61
movb $0x0, %al
callq 0x22c0
jmp 0x2ad44
jmp 0x2ad46
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x2ab30
movq -0x70(%rbp), %rdi
callq 0x2b880
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2aa26
movq -0x70(%rbp), %rdi
callq 0x2b900
cmpq $0x0, 0xf03c(%rip)      # 0x39db8
je 0x2ad87
movq -0x60(%rbp), %rdi
callq 0x2050
movq -0x58(%rbp), %rdi
callq 0x16650
movq -0x50(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)