// File: /workspace/github_c_makefile_star2_O3/ToniWestbrook[P]paladin/bntseq.c
// Function: bns_restore
bntseq_t *bns_restore(const char *prefix)
{  
	char ann_filename[1024], amb_filename[1024], pac_filename[1024], alt_filename[1024];
	FILE *fp;
	bntseq_t *bns;
	strcat(strcpy(ann_filename, prefix), ".ann");
	strcat(strcpy(amb_filename, prefix), ".amb");
	strcat(strcpy(pac_filename, prefix), ".pac");
	bns = bns_restore_core(ann_filename, amb_filename, pac_filename);
	if (bns == 0) return 0;
	if ((fp = fopen(strcat(strcpy(alt_filename, prefix), ".alt"), "r")) != 0) { // read .alt file if present
		char str[1024];
		khash_t(str) *h;
		int c, i, absent;
		khint_t k;
		h = kh_init(str);
		for (i = 0; i < bns->n_seqs; ++i) {
			k = kh_put(str, h, bns->anns[i].name, &absent);
			kh_val(h, k) = i;
		}
		i = 0;
		while ((c = fgetc(fp)) != EOF) {
			if (c == '\t' || c == '\n' || c == '\r') {
				str[i] = 0;
				if (str[0] != '@') {
					k = kh_get(str, h, str);
					if (k != kh_end(h))
						bns->anns[kh_val(h, k)].is_alt = 1;
				}
				while (c != '\n' && c != EOF) c = fgetc(fp);
				i = 0;
			} else str[i++] = c; // FIXME: potential segfault here
		}
		kh_destroy(str, h);
		fclose(fp);
	}
	return bns;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1448, %rsp           # imm = 0x1448
movq %rdi, %r14
leaq 0x1040(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x32c0
movq %rbx, %rdi
callq 0x3100
xorl %ebp, %ebp
movb %bpl, 0x1044(%rsp,%rax)
movl $0x6e6e612e, 0x1040(%rsp,%rax) # imm = 0x6E6E612E
leaq 0xc40(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x32c0
movq %r15, %rdi
callq 0x3100
movb %bpl, 0xc44(%rsp,%rax)
movl $0x626d612e, 0xc40(%rsp,%rax) # imm = 0x626D612E
leaq 0x840(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x32c0
movq %r12, %rdi
callq 0x3100
movb %bpl, 0x844(%rsp,%rax)
movl $0x6361702e, 0x840(%rsp,%rax) # imm = 0x6361702E
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x10576
movq %rax, %r13
testq %rax, %rax
je 0x10e4c
leaq 0x440(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x32c0
movq %r15, %rdi
callq 0x3100
movl $0x746c612e, 0x440(%rsp,%rax) # imm = 0x746C612E
movb $0x0, 0x444(%rsp,%rax)
leaq 0x1641d(%rip), %rsi     # 0x26e6a
movq %r15, %rdi
callq 0x3380
testq %rax, %rax
je 0x10e4c
movq %rax, %r14
leaq 0x17880(%rip), %rdx     # 0x282e8
leaq 0x17aa7(%rip), %r8      # 0x28516
movl $0x1, %edi
movl $0x28, %esi
movl $0xf, %ecx
callq 0x2319c
cmpl $0x0, 0x8(%r13)
movq %r13, 0x8(%rsp)
movq %r14, 0x18(%rsp)
movq %rax, (%rsp)
jle 0x10cab
movq %rax, %rdi
xorl %ebp, %ebp
movq 0x10(%r13), %rax
leaq (,%rbp,4), %rcx
addq %rbp, %rcx
movq 0x18(%rax,%rcx,8), %rsi
movl 0x8(%rdi), %eax
cmpl 0xc(%rdi), %eax
jb 0x10ae9
movq %rsi, %rbx
movl (%rdi), %esi
movl 0x4(%rdi), %eax
addl %eax, %eax
cmpl %eax, %esi
jbe 0x10acf
decl %esi
jmp 0x10ad1
incl %esi
movq (%rsp), %rdi
callq 0x118d0
movq (%rsp), %rdi
testl %eax, %eax
movq %rbx, %rsi
js 0x10bf4
movsbl (%rsi), %r12d
testl %r12d, %r12d
je 0x10b18
movb 0x1(%rsi), %al
testb %al, %al
je 0x10b1b
leaq 0x2(%rsi), %rcx
movl %r12d, %edx
shll $0x5, %edx
subl %r12d, %edx
movsbl %al, %r12d
addl %edx, %r12d
movb (%rcx), %al
incq %rcx
testb %al, %al
jne 0x10afd
jmp 0x10b1b
xorl %r12d, %r12d
movl (%rdi), %ebx
leal -0x1(%rbx), %r15d
movl %r12d, %r9d
andl %r15d, %r9d
movq 0x10(%rdi), %rdx
movl %r9d, %eax
shrl $0x4, %eax
movl (%rdx,%rax,4), %eax
leal (%r9,%r9), %ecx
shrl %cl, %eax
testb $0x2, %al
je 0x10b46
movl %r9d, %ebx
jmp 0x10c2b
movq %rbp, 0x30(%rsp)
movl %r12d, %eax
shrl $0x3, %eax
shll $0x3, %r12d
xorl %eax, %r12d
orl $0x1, %r12d
andl %r15d, %r12d
movl %r9d, %r13d
movq %rbx, 0x38(%rsp)
movq %rdx, 0x28(%rsp)
movq %r9, 0x20(%rsp)
movq %rsi, 0x10(%rsp)
movl %r13d, %eax
shrl $0x4, %eax
movl (%rdx,%rax,4), %r14d
leal (,%r13,2), %ebp
andl $0x1e, %ebp
movl %r14d, %eax
movl %ebp, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x10bfb
testb $0x1, %al
jne 0x10bc1
movq 0x18(%rdi), %rax
movl %r13d, %ecx
movq (%rax,%rcx,8), %rdi
callq 0x34d0
movq 0x20(%rsp), %r9
movq 0x28(%rsp), %rdx
movq 0x10(%rsp), %rsi
movq (%rsp), %rdi
testl %eax, %eax
je 0x10bfb
btl %ebp, %r14d
cmovbl %r13d, %ebx
addl %r12d, %r13d
andl %r15d, %r13d
cmpl %r9d, %r13d
jne 0x10b76
movb $0x1, %al
movq 0x38(%rsp), %r8
movl %r8d, %ecx
cmpl %r8d, %ebx
movq 0x8(%rsp), %r13
movq 0x18(%rsp), %r14
movq 0x30(%rsp), %rbp
je 0x10c1b
jmp 0x10c2b
movl (%rdi), %ebx
jmp 0x10c92
movl %ebp, %ecx
shrl %cl, %r14d
testb $0x2, %r14b
sete %al
movl %ebx, %ecx
movl %r13d, %r9d
movq 0x8(%rsp), %r13
movq 0x18(%rsp), %r14
movq 0x30(%rsp), %rbp
cmpl 0x38(%rsp), %ecx
cmovel %r9d, %ecx
testb %al, %al
cmovnel %r9d, %ecx
movl %ecx, %ebx
movl %ebx, %eax
shrl $0x4, %eax
movl (%rdx,%rax,4), %edx
leal (%rbx,%rbx), %ecx
andl $0x1e, %ecx
shrl %cl, %edx
testb $0x2, %dl
jne 0x10c65
testb $0x1, %dl
je 0x10c92
movq 0x18(%rdi), %rdx
movl %ebx, %r8d
movq %rsi, (%rdx,%r8,8)
movl $0x3, %edx
shll %cl, %edx
notl %edx
movq 0x10(%rdi), %rcx
andl %edx, (%rcx,%rax,4)
incl 0x4(%rdi)
jmp 0x10c92
movq 0x18(%rdi), %rdx
movl %ebx, %r8d
movq %rsi, (%rdx,%r8,8)
movl $0x3, %edx
shll %cl, %edx
notl %edx
movq 0x10(%rdi), %rcx
andl %edx, (%rcx,%rax,4)
movq 0x4(%rdi), %xmm0
psubd 0x164a3(%rip), %xmm0    # 0x27130
movq %xmm0, 0x4(%rdi)
movq 0x20(%rdi), %rax
movl %ebx, %ecx
movl %ebp, (%rax,%rcx,4)
incq %rbp
movslq 0x8(%r13), %rax
cmpq %rax, %rbp
jl 0x10aa1
xorl %ebx, %ebx
movq %r14, %rdi
callq 0x35c0
movl %eax, %r13d
leal -0x9(%r13), %eax
cmpl $0x2, %eax
jb 0x10cdd
cmpl $0xd, %r13d
je 0x10cdd
cmpl $-0x1, %r13d
je 0x10e13
movslq %ebx, %rax
incl %ebx
movb %r13b, 0x40(%rsp,%rax)
jmp 0x10cad
movslq %ebx, %rax
movb $0x0, 0x40(%rsp,%rax)
movsbl 0x40(%rsp), %r12d
cmpl $0x40, %r12d
movq (%rsp), %rsi
je 0x10ded
movl (%rsi), %edi
testl %edi, %edi
je 0x10d2c
testb %r12b, %r12b
je 0x10d34
movb 0x41(%rsp), %al
testb %al, %al
je 0x10d37
leaq 0x42(%rsp), %rcx
movl %r12d, %edx
shll $0x5, %edx
subl %r12d, %edx
movsbl %al, %r12d
addl %edx, %r12d
movb (%rcx), %al
incq %rcx
testb %al, %al
jne 0x10d11
jmp 0x10d37
xorl %r15d, %r15d
jmp 0x10dc8
xorl %r12d, %r12d
movq %rdi, 0x10(%rsp)
leal -0x1(%rdi), %edx
movl %r12d, %edi
andl %edx, %edi
movl %r12d, %eax
shrl $0x3, %eax
shll $0x3, %r12d
xorl %eax, %r12d
orl $0x1, %r12d
andl %edx, %r12d
movq 0x10(%rsi), %r14
movl %edi, %r15d
movl %edi, 0x28(%rsp)
movl %edx, 0x20(%rsp)
movl %r15d, %eax
shrl $0x4, %eax
movl (%r14,%rax,4), %ebx
leal (%r15,%r15), %ebp
andl $0x1e, %ebp
movl %ebx, %eax
movl %ebp, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x10db8
testb $0x1, %al
jne 0x10dab
movq 0x18(%rsi), %rax
movl %r15d, %ecx
movq (%rax,%rcx,8), %rdi
leaq 0x40(%rsp), %rsi
callq 0x34d0
movl 0x28(%rsp), %edi
movl 0x20(%rsp), %edx
movq (%rsp), %rsi
testl %eax, %eax
je 0x10db8
addl %r12d, %r15d
andl %edx, %r15d
cmpl %edi, %r15d
jne 0x10d67
jmp 0x10ded
movl %ebp, %ecx
shrl %cl, %ebx
testb $0x3, %bl
movq 0x10(%rsp), %rdi
cmovnel %edi, %r15d
cmpl %edi, %r15d
je 0x10ded
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x20(%rsi), %rcx
movl %r15d, %edx
movslq (%rcx,%rdx,4), %rcx
leaq (%rcx,%rcx,4), %rcx
movl $0x1, 0x14(%rax,%rcx,8)
movq 0x18(%rsp), %r14
cmpl $-0x1, %r13d
je 0x10cab
cmpl $0xa, %r13d
je 0x10cab
movq %r14, %rdi
callq 0x35c0
movl %eax, %r13d
jmp 0x10df2
movq (%rsp), %rbx
testq %rbx, %rbx
movq 0x8(%rsp), %r13
je 0x10e44
movq 0x18(%rbx), %rdi
callq 0x3390
movq 0x10(%rbx), %rdi
callq 0x3390
movq 0x20(%rbx), %rdi
callq 0x3390
movq %rbx, %rdi
callq 0x3390
movq %r14, %rdi
callq 0x32f0
movq %r13, %rax
addq $0x1448, %rsp           # imm = 0x1448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq