// File: /workspace/github_c_makefile_star2_O2/ToniWestbrook[P]paladin/bntseq.c
// Function: bns_restore_core
bntseq_t *bns_restore_core(const char *ann_filename, const char* amb_filename, const char* pac_filename)
{
	char str[8192];
	FILE *fp;
	const char *fname;
	bntseq_t *bns;
	long long xx;
	int i;
	int scanres;
	bns = (bntseq_t*)calloc(1, sizeof(bntseq_t));
	{ // read .ann
		fp = xopen(fname = ann_filename, "r");
		scanres = fscanf(fp, "%lld%d%u", &xx, &bns->n_seqs, &bns->seed);
		if (scanres != 3) goto badread;
		bns->l_pac = xx;
		bns->anns = (bntann1_t*)calloc(bns->n_seqs, sizeof(bntann1_t));
		for (i = 0; i < bns->n_seqs; ++i) {
			bntann1_t *p = bns->anns + i;
			char *q = str;
			int c;
			// read gi and sequence name
			scanres = fscanf(fp, "%u%s", &p->gi, str);
			if (scanres != 2) goto badread;
			p->name = strdup(str);
			// read fasta comments 
			while (q - str < sizeof(str) - 1 && (c = fgetc(fp)) != '\n' && c != EOF) *q++ = c;
			while (c != '\n' && c != EOF) c = fgetc(fp);
			if (c == EOF) {
				scanres = EOF;
				goto badread;
			}
			*q = 0;
			if (q - str > 1 && strcmp(str, " (null)") != 0) p->anno = strdup(str + 1); // skip leading space
			else p->anno = strdup("");
			// read the rest
			scanres = fscanf(fp, "%lld%d%d", &xx, &p->len, &p->n_ambs);
			if (scanres != 3) goto badread;
			p->offset = xx;
		}
		err_fclose(fp);
	}
	{ // read .amb
		int64_t l_pac;
		int32_t n_seqs;
		fp = xopen(fname = amb_filename, "r");
		scanres = fscanf(fp, "%lld%d%d", &xx, &n_seqs, &bns->n_holes);
		if (scanres != 3) goto badread;
		l_pac = xx;
		xassert(l_pac == bns->l_pac && n_seqs == bns->n_seqs, "inconsistent .ann and .amb files.");
		bns->ambs = bns->n_holes? (bntamb1_t*)calloc(bns->n_holes, sizeof(bntamb1_t)) : 0;
		for (i = 0; i < bns->n_holes; ++i) {
			bntamb1_t *p = bns->ambs + i;
			scanres = fscanf(fp, "%lld%d%s", &xx, &p->len, str);
			if (scanres != 3) goto badread;
			p->offset = xx;
			p->amb = str[0];
		}
		err_fclose(fp);
	}
	{ // open .pac
		bns->fp_pac = xopen(pac_filename, "rb");
	}
	return bns;

 badread:
	if (EOF == scanres) {
		err_fatal(__func__, "Error reading %s : %s\n", fname, ferror(fp) ? strerror(errno) : "Unexpected end of file");
	}
	err_fatal(__func__, "Parse error reading %s\n", fname);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2048, %rsp           # imm = 0x2048
movq %rdx, 0x30(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdi, %r14
leaq 0x1476d(%rip), %rdx     # 0x23280
leaq 0x1476f(%rip), %rbx     # 0x23289
pushq $0x1
popq %rdi
pushq $0x30
popq %rsi
movl $0x97, %ecx
movq %rbx, %r8
callq 0x1dfd0
leaq 0x132ea(%rip), %rdx     # 0x21e1e
movq %rbx, %rdi
movq %rax, %rbx
movq %r14, 0x8(%rsp)
movq %r14, %rsi
callq 0xc931
movq %rax, %r14
leaq 0x8(%rbx), %rcx
leaq 0xc(%rbx), %r8
leaq 0x14741(%rip), %rsi     # 0x2329a
movq %rsp, %rdx
movq %rax, %rdi
movq %rcx, 0x28(%rsp)
xorl %eax, %eax
callq 0x3720
cmpl $0x3, %eax
jne 0xee29
movq %rbx, 0x38(%rsp)
movq %rsp, %rax
movq (%rax), %rax
movq %rax, (%rbx)
movslq 0x8(%rbx), %rdi
leaq 0x146f3(%rip), %r13     # 0x23280
leaq 0x146f5(%rip), %r8      # 0x23289
pushq $0x28
popq %rsi
movq %r13, %rdx
movl $0x9d, %ecx
callq 0x1dfd0
movq %rbx, 0x18(%rsp)
movq %rax, 0x10(%rbx)
leaq 0x40(%rsp), %r12
xorl %ebx, %ebx
movq 0x28(%rsp), %rax
movslq (%rax), %rax
cmpq %rax, %rbx
jge 0xecf1
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rbp
imulq $0x28, %rbx, %r15
leaq (%r15,%rbp), %rdx
addq $0x10, %rdx
movq %r14, %rdi
leaq 0x146bf(%rip), %rsi     # 0x232a3
movq %r12, %rcx
xorl %eax, %eax
callq 0x3720
cmpl $0x2, %eax
jne 0xee29
addq %r15, %rbp
movq %r12, %rdi
movq %r13, %rsi
movl $0xa5, %edx
leaq 0x1467d(%rip), %rcx     # 0x23289
callq 0x1e123
movq %rax, 0x18(%rbp)
xorl %r15d, %r15d
pushq $0xa
popq %rax
cmpq $0x1ffe, %r15           # imm = 0x1FFE
ja 0xec45
movq %r14, %rdi
callq 0x35c0
cmpl $-0x1, %eax
je 0xec40
cmpl $0xa, %eax
je 0xec40
movb %al, 0x40(%rsp,%r15)
incq %r15
jmp 0xec1b
movq %r15, %r13
jmp 0xec5e
movl $0x1fff, %r13d          # imm = 0x1FFF
jmp 0xec5e
cmpl $-0x1, %eax
je 0xee42
movq %r14, %rdi
callq 0x35c0
cmpl $0xa, %eax
jne 0xec4d
movb $0x0, 0x40(%rsp,%r15)
cmpq $0x2, %r13
jl 0xec96
movabsq $0x296c6c756e2820, %rax # imm = 0x296C6C756E2820
cmpq %rax, 0x40(%rsp)
je 0xec96
leaq 0x41(%rsp), %rdi
leaq 0x145f4(%rip), %r13     # 0x23280
movq %r13, %rsi
movl $0xae, %edx
jmp 0xecac
leaq 0x149c1(%rip), %rdi     # 0x2365e
leaq 0x145dc(%rip), %r13     # 0x23280
movq %r13, %rsi
movl $0xaf, %edx
leaq 0x145d6(%rip), %rcx     # 0x23289
callq 0x1e123
movq %rax, 0x20(%rbp)
leaq 0x8(%rbp), %rcx
leaq 0xc(%rbp), %r8
movq %r14, %rdi
leaq 0x145da(%rip), %rsi     # 0x232a8
movq %rsp, %rdx
xorl %eax, %eax
callq 0x3720
cmpl $0x3, %eax
jne 0xee29
movq (%rsp), %rax
movq %rax, (%rbp)
incq %rbx
jmp 0xebb4
movq %r14, %rdi
callq 0xd01b
leaq 0x14589(%rip), %rdi     # 0x23289
leaq 0x13117(%rip), %rdx     # 0x21e1e
movq 0x10(%rsp), %rsi
callq 0xc931
movq %rax, %r14
movq 0x38(%rsp), %r15
addq $0x18, %r15
leaq 0x14584(%rip), %rsi     # 0x232a8
movq %rsp, %rdx
leaq 0x24(%rsp), %rcx
movq %rax, %rdi
movq %r15, %r8
xorl %eax, %eax
callq 0x3720
cmpl $0x3, %eax
jne 0xee33
movq (%rsp), %rax
movq 0x18(%rsp), %rcx
cmpq (%rcx), %rax
jne 0xee9a
movl 0x24(%rsp), %eax
movq 0x28(%rsp), %rcx
cmpl (%rcx), %eax
jne 0xee9a
movslq (%r15), %rdi
testq %rdi, %rdi
je 0xed8a
leaq 0x1450c(%rip), %rdx     # 0x23280
leaq 0x1450e(%rip), %r8      # 0x23289
pushq $0x10
popq %rsi
movl $0xbf, %ecx
callq 0x1dfd0
jmp 0xed8c
xorl %eax, %eax
movq 0x18(%rsp), %rcx
movq %rax, 0x20(%rcx)
pushq $0x8
popq %rbp
leaq 0x40(%rsp), %r12
xorl %r13d, %r13d
movslq (%r15), %rax
cmpq %rax, %r13
jge 0xedeb
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rbx
leaq (%rbx,%rbp), %rcx
movq %r14, %rdi
leaq 0x14514(%rip), %rsi     # 0x232d3
movq %rsp, %rdx
movq %r12, %r8
xorl %eax, %eax
callq 0x3720
cmpl $0x3, %eax
jne 0xee33
movq (%rsp), %rax
movq %rax, -0x8(%rbx,%rbp)
movb 0x40(%rsp), %al
movb %al, 0x4(%rbx,%rbp)
incq %r13
addq $0x10, %rbp
jmp 0xeda0
movq %r14, %rdi
callq 0xd01b
leaq 0x1448f(%rip), %rdi     # 0x23289
leaq 0x14c27(%rip), %rdx     # 0x23a28
movq 0x30(%rsp), %rsi
callq 0xc931
movq 0x18(%rsp), %rcx
movq %rax, 0x28(%rcx)
movq %rcx, %rax
addq $0x2048, %rsp           # imm = 0x2048
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rcx
movq %rcx, 0x10(%rsp)
cmpl $-0x1, %eax
jne 0xee80
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %r14, %rdi
callq 0x3750
testl %eax, %eax
jne 0xee57
leaq 0x1424c(%rip), %rcx     # 0x230a1
jmp 0xee66
callq 0x3050
movl (%rax), %edi
callq 0x30c0
movq %rax, %rcx
movq 0x8(%rsp), %rdx
leaq 0x14417(%rip), %rdi     # 0x23289
leaq 0x14463(%rip), %rsi     # 0x232dc
xorl %eax, %eax
callq 0xc9c1
leaq 0x14402(%rip), %rdi     # 0x23289
leaq 0x14465(%rip), %rsi     # 0x232f3
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0xc9c1
leaq 0x143e8(%rip), %rdi     # 0x23289
leaq 0x14409(%rip), %rsi     # 0x232b1
callq 0xcc60