// File: /workspace/github_c_makefile_star2_O3/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 0x17d4d(%rip), %rdx     # 0x282e8
leaq 0x17d4f(%rip), %rbx     # 0x282f1
movl $0x1, %edi
movl $0x30, %esi
movl $0x97, %ecx
movq %rbx, %r8
callq 0x2319c
movq %rax, %r13
leaq 0x168a7(%rip), %rdx     # 0x26e6a
movq %rbx, %rdi
movq %r14, 0x8(%rsp)
movq %r14, %rsi
callq 0xe023
movq %rax, %r14
leaq 0x8(%r13), %rcx
leaq 0xc(%r13), %r8
leaq 0x17d1d(%rip), %rsi     # 0x28302
movq %rsp, %rdx
movq %rax, %rdi
movq %rcx, 0x28(%rsp)
xorl %eax, %eax
callq 0x3720
cmpl $0x3, %eax
jne 0x108da
movq %r13, 0x38(%rsp)
movq (%rsp), %rax
movq %rax, (%r13)
movslq 0x8(%r13), %rdi
leaq 0x17cd0(%rip), %rdx     # 0x282e8
leaq 0x17cd2(%rip), %r8      # 0x282f1
movl $0x28, %esi
movl $0x9d, %ecx
callq 0x2319c
movq %rax, 0x10(%r13)
movq %r13, 0x18(%rsp)
cmpl $0x0, 0x8(%r13)
jle 0x10789
leaq 0x40(%rsp), %rbp
xorl %ebx, %ebx
movq 0x18(%rsp), %rax
movq 0x10(%rax), %r15
leaq (%rbx,%rbx,4), %r12
leaq (%r15,%r12,8), %rdx
addq $0x10, %rdx
movq %r14, %rdi
leaq 0x17ca3(%rip), %rsi     # 0x2830b
movq %rbp, %rcx
xorl %eax, %eax
callq 0x3720
cmpl $0x2, %eax
jne 0x108da
leaq (%r15,%r12,8), %r15
movq %rbp, %r13
movq %rbp, %rdi
leaq 0x17c5c(%rip), %rsi     # 0x282e8
movl $0xa5, %edx
leaq 0x17c59(%rip), %rcx     # 0x282f1
callq 0x23285
movq %rax, 0x18(%r15)
xorl %ebp, %ebp
movq %r14, %rdi
callq 0x35c0
cmpl $-0x1, %eax
je 0x106d4
cmpl $0xa, %eax
je 0x106d4
movb %al, 0x40(%rsp,%rbp)
incq %rbp
cmpq $0x1fff, %rbp           # imm = 0x1FFF
jne 0x106a3
leaq (%rsp,%rbp), %r12
addq $0x40, %r12
movl $0x1fff, %ebp           # imm = 0x1FFF
jmp 0x106ef
leaq (%rsp,%rbp), %r12
addq $0x40, %r12
jmp 0x106ef
cmpl $-0x1, %eax
je 0x108f3
movq %r14, %rdi
callq 0x35c0
cmpl $0xa, %eax
jne 0x106de
movb $0x0, (%r12)
cmpq $0x2, %rbp
jb 0x10723
movabsq $0x296c6c756e2820, %rax # imm = 0x296C6C756E2820
cmpq %rax, 0x40(%rsp)
je 0x10723
leaq 0x41(%rsp), %rdi
leaq 0x17bcc(%rip), %rsi     # 0x282e8
movl $0xae, %edx
jmp 0x10736
leaq 0x17f9c(%rip), %rdi     # 0x286c6
leaq 0x17bb7(%rip), %rsi     # 0x282e8
movl $0xaf, %edx
leaq 0x17bb4(%rip), %rcx     # 0x282f1
callq 0x23285
movq %r13, %rbp
movq %rax, 0x20(%r15)
leaq 0x8(%r15), %rcx
leaq 0xc(%r15), %r8
movq %r14, %rdi
leaq 0x17bb5(%rip), %rsi     # 0x28310
movq %rsp, %rdx
xorl %eax, %eax
callq 0x3720
cmpl $0x3, %eax
jne 0x108da
movq (%rsp), %rax
movq %rax, (%r15)
incq %rbx
movq 0x28(%rsp), %rax
movslq (%rax), %rax
cmpq %rax, %rbx
jl 0x10649
movq %r14, %rdi
callq 0xe71e
leaq 0x17b59(%rip), %rdi     # 0x282f1
leaq 0x166cb(%rip), %rdx     # 0x26e6a
movq 0x10(%rsp), %rsi
callq 0xe023
movq %rax, %r14
movq 0x38(%rsp), %r12
addq $0x18, %r12
leaq 0x17b54(%rip), %rsi     # 0x28310
movq %rsp, %rdx
leaq 0x24(%rsp), %rcx
movq %rax, %rdi
movq %r12, %r8
xorl %eax, %eax
callq 0x3720
cmpl $0x3, %eax
jne 0x108e4
movq (%rsp), %rax
movq 0x18(%rsp), %rcx
cmpq (%rcx), %rax
jne 0x1094b
movl 0x24(%rsp), %eax
movq 0x28(%rsp), %rcx
cmpl (%rcx), %eax
jne 0x1094b
movslq (%r12), %rdi
testq %rdi, %rdi
je 0x1088f
leaq 0x17ad7(%rip), %rdx     # 0x282e8
leaq 0x17ad9(%rip), %r8      # 0x282f1
movl $0x10, %esi
movl $0xbf, %ecx
callq 0x2319c
movq 0x18(%rsp), %rcx
cmpl $0x0, 0x18(%rcx)
movq %rax, 0x20(%rcx)
jle 0x1089c
movl $0x8, %ebp
leaq 0x17af9(%rip), %r13     # 0x2833b
xorl %ebx, %ebx
movq 0x18(%rsp), %rax
movq 0x20(%rax), %r15
leaq (%r15,%rbp), %rcx
movq %r14, %rdi
movq %r13, %rsi
movq %rsp, %rdx
leaq 0x40(%rsp), %r8
xorl %eax, %eax
callq 0x3720
cmpl $0x3, %eax
jne 0x108e4
movq (%rsp), %rax
movq %rax, -0x8(%r15,%rbp)
movb 0x40(%rsp), %al
movb %al, 0x4(%r15,%rbp)
incq %rbx
movslq (%r12), %rax
addq $0x10, %rbp
cmpq %rax, %rbx
jl 0x10844
jmp 0x1089c
movq 0x18(%rsp), %rax
movq $0x0, 0x20(%rax)
movq %r14, %rdi
callq 0xe71e
leaq 0x17a46(%rip), %rdi     # 0x282f1
leaq 0x181e6(%rip), %rdx     # 0x28a98
movq 0x30(%rsp), %rsi
callq 0xe023
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 0x10931
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %r14, %rdi
callq 0x3750
testl %eax, %eax
jne 0x10908
leaq 0x177eb(%rip), %rcx     # 0x280f1
jmp 0x10917
callq 0x3050
movl (%rax), %edi
callq 0x30c0
movq %rax, %rcx
movq 0x8(%rsp), %rdx
leaq 0x179ce(%rip), %rdi     # 0x282f1
leaq 0x17a1a(%rip), %rsi     # 0x28344
xorl %eax, %eax
callq 0xe0b5
leaq 0x179b9(%rip), %rdi     # 0x282f1
leaq 0x17a1c(%rip), %rsi     # 0x2835b
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0xe0b5
leaq 0x1799f(%rip), %rdi     # 0x282f1
leaq 0x179c0(%rip), %rsi     # 0x28319
callq 0xe360