// File: /workspace/github_c_makefile_star2_O1/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 %r13d, %r13d
movb %r13b, 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 %r13b, 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 %r13b, 0x844(%rsp,%rax)
movl $0x6361702e, 0x840(%rsp,%rax) # imm = 0x6361702E
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x1024a
testq %rax, %rax
je 0x10b75
movq %rax, %rbp
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 0x16693(%rip), %rsi     # 0x26e1e
movq %r15, %rdi
callq 0x3380
testq %rax, %rax
je 0x10b77
movq %rax, %r14
leaq 0x17aaa(%rip), %rdx     # 0x28250
leaq 0x17cd1(%rip), %r8      # 0x2847e
movl $0x1, %edi
movl $0x28, %esi
movl $0xf, %ecx
callq 0x22cb4
cmpl $0x0, 0x8(%rbp)
movq %rbp, 0x20(%rsp)
movq %r14, 0x18(%rsp)
movq %rax, (%rsp)
jle 0x109ca
movq %rax, %rdi
xorl %ebx, %ebx
movq 0x10(%rbp), %rax
leaq (%rbx,%rbx,4), %rcx
movq 0x18(%rax,%rcx,8), %rsi
movl 0x8(%rdi), %eax
cmpl 0xc(%rdi), %eax
jb 0x1081f
movq %rsi, %r15
movl (%rdi), %esi
movl 0x4(%rdi), %eax
addl %eax, %eax
cmpl %eax, %esi
jbe 0x10805
decl %esi
jmp 0x10807
incl %esi
movq (%rsp), %rdi
callq 0x115a8
movq (%rsp), %rdi
testl %eax, %eax
movq %r15, %rsi
js 0x10908
movsbl (%rsi), %r13d
testl %r13d, %r13d
je 0x1084e
movb 0x1(%rsi), %al
testb %al, %al
je 0x10851
leaq 0x2(%rsi), %rcx
movl %r13d, %edx
shll $0x5, %edx
subl %r13d, %edx
movsbl %al, %r13d
addl %edx, %r13d
movb (%rcx), %al
incq %rcx
testb %al, %al
jne 0x10833
jmp 0x10851
xorl %r13d, %r13d
movq %rbx, 0x38(%rsp)
movl (%rdi), %r8d
leal -0x1(%r8), %r15d
movl %r13d, %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
jne 0x10949
movl %r13d, %eax
shrl $0x3, %eax
shll $0x3, %r13d
xorl %eax, %r13d
orl $0x1, %r13d
andl %r15d, %r13d
movl %r9d, %ebx
movq %r8, 0x10(%rsp)
movl %r8d, %r12d
movq %r9, 0x30(%rsp)
movq %rdx, 0x28(%rsp)
movq %rsi, 0x8(%rsp)
movl %ebx, %eax
shrl $0x4, %eax
movl (%rdx,%rax,4), %r14d
leal (%rbx,%rbx), %ebp
andl $0x1e, %ebp
movl %r14d, %eax
movl %ebp, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x10910
testb $0x1, %al
jne 0x108f0
movq 0x18(%rdi), %rax
movl %ebx, %ecx
movq (%rax,%rcx,8), %rdi
callq 0x34d0
movq 0x28(%rsp), %rdx
movq 0x30(%rsp), %r9
movq 0x8(%rsp), %rsi
movq (%rsp), %rdi
testl %eax, %eax
je 0x10910
btl %ebp, %r14d
cmovbl %ebx, %r12d
addl %r13d, %ebx
andl %r15d, %ebx
movl %r12d, %eax
cmpl %r9d, %ebx
jne 0x108ac
jmp 0x10915
movl (%rdi), %r9d
jmp 0x109b0
movq 0x10(%rsp), %rax
movl %eax, %r9d
movq 0x10(%rsp), %r8
cmpl %r8d, %eax
movq 0x20(%rsp), %rbp
movq 0x18(%rsp), %r14
jne 0x10949
movl %ebx, %eax
shrl $0x4, %eax
movl (%rdx,%rax,4), %eax
leal (%rbx,%rbx), %ecx
shrl %cl, %eax
cmpl %r8d, %r12d
cmovel %ebx, %r12d
testb $0x2, %al
cmovel %ebx, %r12d
movl %r12d, %r9d
movl %r9d, %eax
shrl $0x4, %eax
movl (%rdx,%rax,4), %edx
leal (%r9,%r9), %ecx
andl $0x1e, %ecx
shrl %cl, %edx
testb $0x2, %dl
jne 0x1098a
testb $0x1, %dl
movq 0x38(%rsp), %rbx
je 0x109b0
movq 0x18(%rdi), %rdx
movl %r9d, %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 0x109b0
movq 0x18(%rdi), %rdx
movl %r9d, %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)
incl 0x8(%rdi)
movq 0x38(%rsp), %rbx
movq 0x20(%rdi), %rax
movl %r9d, %ecx
movl %ebx, (%rax,%rcx,4)
incq %rbx
movslq 0x8(%rbp), %rax
cmpq %rax, %rbx
jl 0x107de
xorl %ebx, %ebx
movq %r14, %rdi
callq 0x35c0
movl %eax, %r13d
leal -0x9(%r13), %eax
cmpl $0x2, %eax
jb 0x109fc
cmpl $0xd, %r13d
je 0x109fc
cmpl $-0x1, %r13d
je 0x10b3f
movslq %ebx, %rax
incl %ebx
movb %r13b, 0x40(%rsp,%rax)
jmp 0x109cc
movslq %ebx, %rax
movb $0x0, 0x40(%rsp,%rax)
movsbl 0x40(%rsp), %r12d
cmpl $0x40, %r12d
je 0x10b2a
movq (%rsp), %rsi
movl (%rsi), %edi
testl %edi, %edi
je 0x10a4b
testb %r12b, %r12b
je 0x10a53
movb 0x41(%rsp), %al
testb %al, %al
je 0x10a56
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 0x10a30
jmp 0x10a56
xorl %r15d, %r15d
jmp 0x10af9
xorl %r12d, %r12d
movq %rdi, 0x8(%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, 0x30(%rsp)
movl %edx, 0x28(%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 0x10adf
testb $0x1, %al
jne 0x10aca
movq 0x18(%rsi), %rax
movl %r15d, %ecx
movq (%rax,%rcx,8), %rdi
leaq 0x40(%rsp), %rsi
callq 0x34d0
movl 0x30(%rsp), %edi
movl 0x28(%rsp), %edx
movq (%rsp), %rsi
testl %eax, %eax
je 0x10adf
addl %r12d, %r15d
andl %edx, %r15d
cmpl %edi, %r15d
jne 0x10a86
movq 0x8(%rsp), %rdi
movl %edi, %r15d
jmp 0x10aef
movl %ebp, %ecx
shrl %cl, %ebx
testb $0x3, %bl
movq 0x8(%rsp), %rdi
cmovnel %edi, %r15d
movq 0x20(%rsp), %rbp
movq 0x18(%rsp), %r14
cmpl %edi, %r15d
je 0x10b2a
movq 0x10(%rbp), %rax
movq (%rsp), %rcx
movq 0x20(%rcx), %rcx
movl %r15d, %edx
movslq (%rcx,%rdx,4), %rcx
leaq (%rcx,%rcx,4), %rcx
movl $0x1, 0x14(%rax,%rcx,8)
jmp 0x10b2a
movq %r14, %rdi
callq 0x35c0
movl %eax, %r13d
cmpl $-0x1, %r13d
je 0x109ca
cmpl $0xa, %r13d
jne 0x10b1f
jmp 0x109ca
movq (%rsp), %rbx
testq %rbx, %rbx
je 0x10b6b
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
jmp 0x10b77
xorl %ebp, %ebp
movq %rbp, %rax
addq $0x1448, %rsp           # imm = 0x1448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq