// File: /workspace/github_c_makefile_star2_O2/ToniWestbrook[P]paladin/bntseq.c
// Function: bns_fasta2bntseq
int64_t bns_fasta2bntseq(gzFile fp_fa, const char * prefix, int for_only) {
	kseq_t *seq;
	char name[1024];
	bntseq_t *bns;
	uint8_t *pac = 0;
	int32_t m_seqs, m_holes;
	int64_t ret = -1, m_pac, l;
	bntamb1_t *q;
	FILE *fp;

	// Initialization of sequence related structures
	seq = kseq_init(fp_fa);
	bns = (bntseq_t*)calloc(1, sizeof(bntseq_t));
	bns->seed = 11;
	srand48(bns->seed);
	m_seqs = m_holes = 8; m_pac = 0x10000;
	bns->anns = (bntann1_t*)calloc(m_seqs, sizeof(bntann1_t));
	bns->ambs = (bntamb1_t*)calloc(m_holes, sizeof(bntamb1_t));
	q = bns->ambs;

	// Allocate packed buffer to size of sequence (for now - to be converted to 40-bit word)
	pac = calloc(m_pac, 1);

	// Open packed file for writing
	strcpy(name, prefix); strcat(name, ".pac");
	fp = xopen(name, "wb");

	// Read sequences into pac buffer
	while (kseq_read(seq) >= 0) pac = add1(seq, bns, pac, &m_pac, &m_seqs, &m_holes, &q);

	// Add reverse complement if not forward only
	if (!for_only) {
		m_pac = bns->l_pac * 2;
		pac = realloc(pac, m_pac);
		memset(pac + bns->l_pac, 0, m_pac - bns->l_pac);

		for (l = bns->l_pac - 1; l >= 0; --l, ++bns->l_pac) {
			pac[bns->l_pac] = VALUE_DEFINED - 1 - pac[l];
		}
	}

	ret = bns->l_pac;

	// Write pac file
	ubyte_t ct;
	err_fwrite(pac, 1, bns->l_pac, fp);

	// Pad to nearest 40-bit word
	ct = 0;
	err_fwrite(&ct, 1, 1, fp);

	ct = 0;
	err_fwrite(&ct, 1, 1, fp);

	// Close pac file
	err_fflush(fp);
	err_fclose(fp);

	bns_dump(bns, prefix);
	bns_destroy(bns);
	kseq_destroy(seq);
	free(pac);
	return ret;}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x448, %rsp            # imm = 0x448
movl %edx, 0x10(%rsp)
movq %rsi, 0x18(%rsp)
callq 0xc1ce
movq %rax, %rbx
leaq 0x13c2e(%rip), %rdx     # 0x23280
leaq 0x13cc3(%rip), %r14     # 0x2331c
pushq $0x1
popq %rdi
pushq $0x30
popq %rsi
movl $0x158, %ecx            # imm = 0x158
movq %r14, %r8
callq 0x1dfd0
movq %rax, %r15
movl $0xb, 0xc(%rax)
pushq $0xb
popq %rdi
callq 0x3620
pushq $0x8
popq %rax
leaq 0x14(%rsp), %rcx
movl %eax, (%rcx)
leaq 0x34(%rsp), %rbp
movl %eax, (%rbp)
leaq 0x28(%rsp), %r13
movq $0x10000, (%r13)        # imm = 0x10000
pushq $0x8
popq %r12
pushq $0x28
popq %rsi
movq %r12, %rdi
leaq 0x13bd2(%rip), %rdx     # 0x23280
movl $0x15c, %ecx            # imm = 0x15C
movq %r14, %r8
callq 0x1dfd0
movq %rax, 0x10(%r15)
pushq $0x10
popq %rsi
movq %r12, %rdi
leaq 0x13bb4(%rip), %rdx     # 0x23280
movl $0x15d, %ecx            # imm = 0x15D
movq %r14, %r8
movq %r14, %r12
callq 0x1dfd0
movq %rax, 0x20(%r15)
leaq 0x38(%rsp), %r14
movq %rax, (%r14)
movl $0x10000, %edi          # imm = 0x10000
pushq $0x1
popq %rsi
leaq 0x13b89(%rip), %rdx     # 0x23280
movl $0x161, %ecx            # imm = 0x161
movq %r12, %r8
callq 0x1dfd0
movq %rax, %r12
leaq 0x40(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x32c0
leaq 0x40(%rsp), %rdi
callq 0x3100
movl $0x6361702e, 0x40(%rsp,%rax) # imm = 0x6361702E
movb $0x0, 0x44(%rsp,%rax)
leaq 0x131f8(%rip), %rdx     # 0x2292c
leaq 0x13be1(%rip), %rdi     # 0x2331c
leaq 0x40(%rsp), %rsi
callq 0xc931
movq %rax, 0x20(%rsp)
movq %rbx, %rdi
callq 0xc2aa
testl %eax, %eax
js 0xf778
movq %r14, (%rsp)
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %r13, %rcx
movq %rbp, %r8
leaq 0x14(%rsp), %r9
callq 0xf3b0
movq %rax, %r12
jmp 0xf74a
movq (%r15), %r14
cmpl $0x0, 0x10(%rsp)
je 0xf817
pushq $0x1
popq %rsi
movq %r12, %rdi
movq %r14, %rdx
movq 0x20(%rsp), %r13
movq %r13, %rcx
callq 0xcc84
xorl %eax, %eax
leaq 0xf(%rsp), %rbp
movb %al, (%rbp)
movq %rbp, %rdi
pushq $0x1
popq %rdx
movq %rdx, %rsi
movq %r13, %rcx
callq 0xcc84
xorl %eax, %eax
movb %al, (%rbp)
movq %rbp, %rdi
pushq $0x1
popq %rdx
movq %rdx, %rsi
movq %r13, %rcx
callq 0xcc84
movq %r13, %rdi
callq 0xcf7e
movq %r13, %rdi
callq 0xd01b
movq %r15, %rdi
movq 0x18(%rsp), %rsi
callq 0xe92c
movq %r15, %rdi
callq 0xf345
movq %rbx, %rdi
callq 0xc251
movq %r12, %rdi
callq 0x3390
movq %r14, %rax
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq %r14, %r14
movq %r14, 0x28(%rsp)
leaq 0x13a5a(%rip), %rdx     # 0x23280
leaq 0x13aef(%rip), %r8      # 0x2331c
movq %r12, %rdi
movq %r14, %rsi
movl $0x16d, %ecx            # imm = 0x16D
callq 0x1e0b4
movq %rax, %r12
movq (%r15), %rax
leaq (%r12,%rax), %rdi
subq %rax, %r14
xorl %esi, %esi
movq %r14, %rdx
callq 0x3140
movq (%r15), %r14
movq %r14, %rax
testq %rax, %rax
jle 0xf786
movb $0x15, %cl
subb -0x1(%r12,%rax), %cl
decq %rax
movb %cl, (%r12,%r14)
movq (%r15), %r14
incq %r14
movq %r14, (%r15)
jmp 0xf85a