// File: /workspace/github_c_makefile_star2_O1/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 $0x2058, %rsp           # imm = 0x2058
movq %rdx, 0x38(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, %r14
leaq 0x17fe1(%rip), %rdx     # 0x28250
leaq 0x17fe3(%rip), %rbx     # 0x28259
movl $0x1, %edi
movl $0x30, %esi
movl $0x97, %ecx
movq %rbx, %r8
callq 0x22cb4
movq %rax, %r12
leaq 0x16b87(%rip), %rdx     # 0x26e1e
movq %rbx, %rdi
movq %r14, 0x28(%rsp)
movq %r14, %rsi
callq 0xdd8e
movq %rax, %r15
leaq 0x8(%r12), %rcx
leaq 0xc(%r12), %r8
leaq 0x17faf(%rip), %rsi     # 0x2826a
leaq 0x8(%rsp), %rdx
movq %rax, %rdi
movq %rcx, 0x30(%rsp)
xorl %eax, %eax
callq 0x3720
cmpl $0x3, %eax
jne 0x1061d
movq %r12, 0x40(%rsp)
movq 0x8(%rsp), %rax
movq %rax, (%r12)
movslq 0x8(%r12), %rdi
leaq 0x17f5e(%rip), %rdx     # 0x28250
leaq 0x17f60(%rip), %r8      # 0x28259
movl $0x28, %esi
movl $0x9d, %ecx
callq 0x22cb4
movq %rax, 0x10(%r12)
cmpl $0x0, 0x8(%r12)
movq %r12, 0x10(%rsp)
jle 0x104aa
xorl %edx, %edx
leaq 0x50(%rsp), %rcx
movq 0x10(%r12), %r14
movq %rdx, 0x48(%rsp)
leaq (%rdx,%rdx,4), %r12
leaq (%r14,%r12,8), %rdx
addq $0x10, %rdx
xorl %ebp, %ebp
movq %r15, %rbx
movq %r15, %rdi
leaq 0x17f29(%rip), %rsi     # 0x28273
movq %rcx, %r15
xorl %eax, %eax
callq 0x3720
cmpl $0x2, %eax
jne 0x103b7
leaq (%r14,%r12,8), %r14
movq %r15, %rdi
leaq 0x17ee9(%rip), %rsi     # 0x28250
movl $0xa5, %edx
leaq 0x17ee6(%rip), %rcx     # 0x28259
callq 0x22d9d
movq %rax, 0x18(%r14)
xorl %ebp, %ebp
movq %rbx, %r15
movq %r15, %rdi
callq 0x35c0
movl %eax, %r13d
cmpl $-0x1, %eax
je 0x103c7
cmpl $0xa, %r13d
je 0x103c7
movb %r13b, 0x50(%rsp,%rbp)
incq %rbp
cmpq $0x1fff, %rbp           # imm = 0x1FFF
jne 0x10381
leaq (%rsp,%rbp), %r12
addq $0x50, %r12
movl $0x1fff, %ebp           # imm = 0x1FFF
jmp 0x103cf
movl %eax, %r13d
movq 0x10(%rsp), %r12
movq %rbx, %r15
jmp 0x10483
leaq (%rsp,%rbp), %r12
addq $0x50, %r12
cmpl $-0x1, %r13d
je 0x10417
cmpl $0xa, %r13d
je 0x103e8
movq %r15, %rdi
callq 0x35c0
movl %eax, %r13d
jmp 0x103cf
movb $0x0, (%r12)
cmpq $0x2, %rbp
jb 0x10420
movabsq $0x296c6c756e2820, %rax # imm = 0x296C6C756E2820
cmpq %rax, 0x50(%rsp)
je 0x10420
leaq 0x51(%rsp), %rdi
leaq 0x17e40(%rip), %rsi     # 0x28250
movl $0xae, %edx
jmp 0x10433
xorl %ebp, %ebp
movq 0x10(%rsp), %r12
jmp 0x10483
leaq 0x18207(%rip), %rdi     # 0x2862e
leaq 0x17e22(%rip), %rsi     # 0x28250
movl $0xaf, %edx
leaq 0x17e1f(%rip), %rcx     # 0x28259
callq 0x22d9d
movq 0x10(%rsp), %r12
movq %rax, 0x20(%r14)
leaq 0x8(%r14), %rcx
leaq 0xc(%r14), %r8
xorl %ebp, %ebp
movq %r15, %rdi
leaq 0x17e1c(%rip), %rsi     # 0x28278
leaq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x3720
cmpl $0x3, %eax
jne 0x10480
movq 0x8(%rsp), %rax
movq %rax, (%r14)
movb $0x1, %bpl
movl $0x3, %r13d
jmp 0x10483
movl %eax, %r13d
testb %bpl, %bpl
je 0x10620
movq 0x48(%rsp), %rdx
incq %rdx
movq 0x30(%rsp), %rax
movslq (%rax), %rax
cmpq %rax, %rdx
leaq 0x50(%rsp), %rcx
jl 0x10325
movq %r15, %rdi
callq 0xe490
leaq 0x17da0(%rip), %rdi     # 0x28259
leaq 0x1695e(%rip), %rdx     # 0x26e1e
movq 0x18(%rsp), %rsi
callq 0xdd8e
movq %rax, %r15
movq 0x40(%rsp), %rbp
addq $0x18, %rbp
leaq 0x17d9b(%rip), %rsi     # 0x28278
leaq 0x8(%rsp), %rdx
leaq 0x24(%rsp), %rcx
movq %rax, %rdi
movq %rbp, %r8
xorl %eax, %eax
callq 0x3720
cmpl $0x3, %eax
jne 0x10541
movq 0x8(%rsp), %rax
cmpq (%r12), %rax
jne 0x10688
movl 0x24(%rsp), %eax
movq 0x30(%rsp), %rcx
cmpl (%rcx), %eax
jne 0x10688
movslq (%rbp), %rdi
testq %rdi, %rdi
je 0x1054e
leaq 0x17d27(%rip), %rdx     # 0x28250
leaq 0x17d29(%rip), %r8      # 0x28259
movl $0x10, %esi
movl $0xbf, %ecx
callq 0x22cb4
jmp 0x10550
movl %eax, %r13d
movl $0x2, %eax
jmp 0x105e0
xorl %eax, %eax
movq %rax, 0x20(%r12)
cmpl $0x0, 0x18(%r12)
jle 0x105c9
movl $0x8, %ebx
xorl %r14d, %r14d
movq 0x20(%r12), %r12
leaq (%r12,%rbx), %rcx
movq %r15, %rdi
leaq 0x17d2b(%rip), %rsi     # 0x282a3
leaq 0x8(%rsp), %rdx
leaq 0x50(%rsp), %r8
xorl %eax, %eax
callq 0x3720
movl %eax, %r13d
movl $0x2, %eax
cmpl $0x3, %r13d
jne 0x105ac
movq 0x8(%rsp), %rax
movq %rax, -0x8(%r12,%rbx)
movb 0x50(%rsp), %al
movb %al, 0x4(%r12,%rbx)
xorl %eax, %eax
cmpl $0x3, %r13d
jne 0x105db
incq %r14
movslq (%rbp), %rax
addq $0x10, %rbx
cmpq %rax, %r14
movq 0x10(%rsp), %r12
jl 0x10565
jmp 0x105cf
movl $0x3, %r13d
movq %r15, %rdi
callq 0xe490
xorl %eax, %eax
jmp 0x105e0
movq 0x10(%rsp), %r12
testl %eax, %eax
je 0x105eb
cmpl $0x2, %eax
jne 0x10608
jmp 0x1062a
leaq 0x17c67(%rip), %rdi     # 0x28259
leaq 0x183af(%rip), %rdx     # 0x289a8
movq 0x38(%rsp), %rsi
callq 0xdd8e
movq %rax, 0x28(%r12)
movq %r12, %rax
addq $0x2058, %rsp           # imm = 0x2058
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %r13d
movq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
cmpl $-0x1, %r13d
jne 0x10645
movq %r15, %rdi
callq 0x3750
testl %eax, %eax
jne 0x1065f
leaq 0x17a2e(%rip), %rcx     # 0x28071
jmp 0x1066e
leaq 0x17c0d(%rip), %rdi     # 0x28259
leaq 0x17c70(%rip), %rsi     # 0x282c3
movq 0x18(%rsp), %rdx
xorl %eax, %eax
callq 0xde26
callq 0x3050
movl (%rax), %edi
callq 0x30c0
movq %rax, %rcx
leaq 0x17be4(%rip), %rdi     # 0x28259
leaq 0x17c30(%rip), %rsi     # 0x282ac
movq 0x18(%rsp), %rdx
xorl %eax, %eax
callq 0xde26
leaq 0x17bca(%rip), %rdi     # 0x28259
leaq 0x17beb(%rip), %rsi     # 0x28281
callq 0xe0d8