// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20a0, %rsp           # imm = 0x20A0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x1, %edi
movl $0x30, %esi
leaq 0x23e90(%rip), %rdx     # 0x3a138
movl $0x97, %ecx
leaq 0x23e8d(%rip), %r8      # 0x3a141
callq 0x31bf0
movq %rax, -0x2038(%rbp)
movq -0x8(%rbp), %rsi
movq %rsi, -0x2030(%rbp)
leaq 0x23e6f(%rip), %rdi     # 0x3a141
leaq 0x22a29(%rip), %rdx     # 0x38d02
callq 0x12740
movq %rax, -0x2028(%rbp)
movq -0x2028(%rbp), %rdi
movq -0x2038(%rbp), %rcx
addq $0x8, %rcx
movq -0x2038(%rbp), %r8
addq $0xc, %r8
leaq 0x23e49(%rip), %rsi     # 0x3a152
leaq -0x2040(%rbp), %rdx
movb $0x0, %al
callq 0x3700
movl %eax, -0x2048(%rbp)
cmpl $0x3, -0x2048(%rbp)
je 0x1632b
jmp 0x1682f
movq -0x2040(%rbp), %rcx
movq -0x2038(%rbp), %rax
movq %rcx, (%rax)
movq -0x2038(%rbp), %rax
movslq 0x8(%rax), %rdi
movl $0x28, %esi
leaq 0x23de5(%rip), %rdx     # 0x3a138
movl $0x9d, %ecx
leaq 0x23de2(%rip), %r8      # 0x3a141
callq 0x31bf0
movq %rax, %rcx
movq -0x2038(%rbp), %rax
movq %rcx, 0x10(%rax)
movl $0x0, -0x2044(%rbp)
movl -0x2044(%rbp), %eax
movq -0x2038(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x16607
movq -0x2038(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x2044(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x2050(%rbp)
leaq -0x2020(%rbp), %rax
movq %rax, -0x2058(%rbp)
movq -0x2028(%rbp), %rdi
movq -0x2050(%rbp), %rdx
addq $0x10, %rdx
leaq -0x2020(%rbp), %rcx
leaq 0x23d7b(%rip), %rsi     # 0x3a15b
movb $0x0, %al
callq 0x3700
movl %eax, -0x2048(%rbp)
cmpl $0x2, -0x2048(%rbp)
je 0x163fb
jmp 0x1682f
leaq -0x2020(%rbp), %rdi
leaq 0x23d2f(%rip), %rsi     # 0x3a138
movl $0xa5, %edx
leaq 0x23d2c(%rip), %rcx     # 0x3a141
callq 0x31df0
movq %rax, %rcx
movq -0x2050(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x2058(%rbp), %rcx
leaq -0x2020(%rbp), %rax
subq %rax, %rcx
xorl %eax, %eax
cmpq $0x1fff, %rcx           # imm = 0x1FFF
movb %al, -0x2079(%rbp)
jae 0x1647b
movq -0x2028(%rbp), %rdi
callq 0x35a0
movl %eax, %ecx
movl %ecx, -0x205c(%rbp)
xorl %eax, %eax
cmpl $0xa, %ecx
movb %al, -0x2079(%rbp)
je 0x1647b
cmpl $-0x1, -0x205c(%rbp)
setne %al
movb %al, -0x2079(%rbp)
movb -0x2079(%rbp), %al
testb $0x1, %al
jne 0x16487
jmp 0x164a8
movl -0x205c(%rbp), %eax
movb %al, %cl
movq -0x2058(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x2058(%rbp)
movb %cl, (%rax)
jmp 0x16428
jmp 0x164aa
xorl %eax, %eax
cmpl $0xa, -0x205c(%rbp)
movb %al, -0x207a(%rbp)
je 0x164cb
cmpl $-0x1, -0x205c(%rbp)
setne %al
movb %al, -0x207a(%rbp)
movb -0x207a(%rbp), %al
testb $0x1, %al
jne 0x164d7
jmp 0x164eb
movq -0x2028(%rbp), %rdi
callq 0x35a0
movl %eax, -0x205c(%rbp)
jmp 0x164aa
cmpl $-0x1, -0x205c(%rbp)
jne 0x16503
movl $0xffffffff, -0x2048(%rbp) # imm = 0xFFFFFFFF
jmp 0x1682f
movq -0x2058(%rbp), %rax
movb $0x0, (%rax)
movq -0x2058(%rbp), %rax
leaq -0x2020(%rbp), %rcx
subq %rcx, %rax
cmpq $0x1, %rax
jle 0x1656f
leaq -0x2020(%rbp), %rdi
leaq 0x23c2e(%rip), %rsi     # 0x3a160
callq 0x34b0
cmpl $0x0, %eax
je 0x1656f
leaq -0x2020(%rbp), %rdi
addq $0x1, %rdi
leaq 0x23bea(%rip), %rsi     # 0x3a138
movl $0xae, %edx
leaq 0x23be7(%rip), %rcx     # 0x3a141
callq 0x31df0
movq %rax, %rcx
movq -0x2050(%rbp), %rax
movq %rcx, 0x20(%rax)
jmp 0x1659c
leaq 0x23fa8(%rip), %rdi     # 0x3a51e
leaq 0x23bbb(%rip), %rsi     # 0x3a138
movl $0xaf, %edx
leaq 0x23bb8(%rip), %rcx     # 0x3a141
callq 0x31df0
movq %rax, %rcx
movq -0x2050(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x2028(%rbp), %rdi
movq -0x2050(%rbp), %rcx
addq $0x8, %rcx
movq -0x2050(%rbp), %r8
addq $0xc, %r8
leaq 0x23ba8(%rip), %rsi     # 0x3a168
leaq -0x2040(%rbp), %rdx
movb $0x0, %al
callq 0x3700
movl %eax, -0x2048(%rbp)
cmpl $0x3, -0x2048(%rbp)
je 0x165e2
jmp 0x1682f
movq -0x2040(%rbp), %rcx
movq -0x2050(%rbp), %rax
movq %rcx, (%rax)
movl -0x2044(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2044(%rbp)
jmp 0x1637c
movq -0x2028(%rbp), %rdi
callq 0x131b0
movq -0x10(%rbp), %rsi
movq %rsi, -0x2030(%rbp)
leaq 0x23b1c(%rip), %rdi     # 0x3a141
leaq 0x226d6(%rip), %rdx     # 0x38d02
callq 0x12740
movq %rax, -0x2028(%rbp)
movq -0x2028(%rbp), %rdi
movq -0x2038(%rbp), %r8
addq $0x18, %r8
leaq 0x23b17(%rip), %rsi     # 0x3a168
leaq -0x2040(%rbp), %rdx
leaq -0x206c(%rbp), %rcx
movb $0x0, %al
callq 0x3700
movl %eax, -0x2048(%rbp)
cmpl $0x3, -0x2048(%rbp)
je 0x1667a
jmp 0x1682f
movq -0x2040(%rbp), %rax
movq %rax, -0x2068(%rbp)
movq -0x2068(%rbp), %rcx
movq -0x2038(%rbp), %rdx
xorl %eax, %eax
cmpq (%rdx), %rcx
movb %al, -0x207b(%rbp)
jne 0x166bc
movl -0x206c(%rbp), %eax
movq -0x2038(%rbp), %rcx
cmpl 0x8(%rcx), %eax
sete %al
movb %al, -0x207b(%rbp)
movb -0x207b(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x166df
leaq 0x23a6e(%rip), %rdi     # 0x3a141
leaq 0x23a97(%rip), %rsi     # 0x3a171
callq 0x12bd0
movq -0x2038(%rbp), %rax
cmpl $0x0, 0x18(%rax)
je 0x1671d
movq -0x2038(%rbp), %rax
movslq 0x18(%rax), %rdi
movl $0x10, %esi
leaq 0x23a35(%rip), %rdx     # 0x3a138
movl $0xbf, %ecx
leaq 0x23a32(%rip), %r8      # 0x3a141
callq 0x31bf0
movq %rax, -0x2088(%rbp)
jmp 0x16728
xorl %eax, %eax
movq %rax, -0x2088(%rbp)
jmp 0x16728
movq -0x2088(%rbp), %rcx
movq -0x2038(%rbp), %rax
movq %rcx, 0x20(%rax)
movl $0x0, -0x2044(%rbp)
movl -0x2044(%rbp), %eax
movq -0x2038(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x167ee
movq -0x2038(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x2044(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x2078(%rbp)
movq -0x2028(%rbp), %rdi
movq -0x2078(%rbp), %rcx
addq $0x8, %rcx
leaq -0x2020(%rbp), %r8
leaq 0x239f9(%rip), %rsi     # 0x3a193
leaq -0x2040(%rbp), %rdx
movb $0x0, %al
callq 0x3700
movl %eax, -0x2048(%rbp)
cmpl $0x3, -0x2048(%rbp)
je 0x167b9
jmp 0x1682f
movq -0x2040(%rbp), %rcx
movq -0x2078(%rbp), %rax
movq %rcx, (%rax)
movb -0x2020(%rbp), %cl
movq -0x2078(%rbp), %rax
movb %cl, 0xc(%rax)
movl -0x2044(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2044(%rbp)
jmp 0x16744
movq -0x2028(%rbp), %rdi
callq 0x131b0
movq -0x18(%rbp), %rsi
leaq 0x2393c(%rip), %rdi     # 0x3a141
leaq 0x24084(%rip), %rdx     # 0x3a890
callq 0x12740
movq %rax, %rcx
movq -0x2038(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x2038(%rbp), %rax
addq $0x20a0, %rsp           # imm = 0x20A0
popq %rbp
retq
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl -0x2048(%rbp), %eax
jne 0x168a3
movq -0x2030(%rbp), %rax
movq %rax, -0x2090(%rbp)
movq -0x2028(%rbp), %rdi
callq 0x3730
cmpl $0x0, %eax
je 0x16870
callq 0x3050
movl (%rax), %edi
callq 0x30c0
movq %rax, -0x2098(%rbp)
jmp 0x16880
leaq 0x236e2(%rip), %rax     # 0x39f59
movq %rax, -0x2098(%rbp)
jmp 0x16880
movq -0x2090(%rbp), %rdx
movq -0x2098(%rbp), %rcx
leaq 0x238ac(%rip), %rdi     # 0x3a141
leaq 0x23900(%rip), %rsi     # 0x3a19c
movb $0x0, %al
callq 0x12840
movq -0x2030(%rbp), %rdx
leaq 0x23890(%rip), %rdi     # 0x3a141
leaq 0x238fb(%rip), %rsi     # 0x3a1b3
movb $0x0, %al
callq 0x12840
nop