// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x470, %rsp            # imm = 0x470
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq $0x0, -0x430(%rbp)
movq $-0x1, -0x440(%rbp)
movq -0x8(%rbp), %rdi
callq 0x11a10
movq %rax, -0x20(%rbp)
movl $0x1, %edi
movl $0x30, %esi
leaq 0x22bce(%rip), %rdx     # 0x3a138
movl $0x158, %ecx            # imm = 0x158
leaq 0x22c5f(%rip), %r8      # 0x3a1d5
callq 0x31bf0
movq %rax, -0x428(%rbp)
movq -0x428(%rbp), %rax
movl $0xb, 0xc(%rax)
movq -0x428(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, %edi
callq 0x3600
movl $0x8, -0x438(%rbp)
movl $0x8, -0x434(%rbp)
movq $0x10000, -0x448(%rbp) # imm = 0x10000
movslq -0x434(%rbp), %rdi
movl $0x28, %esi
leaq 0x22b65(%rip), %rdx     # 0x3a138
movl $0x15c, %ecx            # imm = 0x15C
leaq 0x22bf6(%rip), %r8      # 0x3a1d5
callq 0x31bf0
movq %rax, %rcx
movq -0x428(%rbp), %rax
movq %rcx, 0x10(%rax)
movslq -0x438(%rbp), %rdi
movl $0x10, %esi
leaq 0x22b33(%rip), %rdx     # 0x3a138
movl $0x15d, %ecx            # imm = 0x15D
leaq 0x22bc4(%rip), %r8      # 0x3a1d5
callq 0x31bf0
movq %rax, %rcx
movq -0x428(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x428(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x458(%rbp)
movq -0x448(%rbp), %rdi
movl $0x1, %esi
leaq 0x22aef(%rip), %rdx     # 0x3a138
movl $0x161, %ecx            # imm = 0x161
leaq 0x22b80(%rip), %r8      # 0x3a1d5
callq 0x31bf0
movq %rax, -0x430(%rbp)
leaq -0x420(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x32b0
leaq -0x420(%rbp), %rdi
leaq 0x1fd85(%rip), %rsi     # 0x37404
callq 0x3690
leaq -0x420(%rbp), %rsi
leaq 0x22b43(%rip), %rdi     # 0x3a1d5
leaq 0x22143(%rip), %rdx     # 0x397dc
callq 0x12740
movq %rax, -0x460(%rbp)
movq -0x20(%rbp), %rdi
callq 0x11b70
cmpl $0x0, %eax
jl 0x176f3
movq -0x20(%rbp), %rdi
movq -0x428(%rbp), %rsi
movq -0x430(%rbp), %rdx
leaq -0x448(%rbp), %rcx
leaq -0x434(%rbp), %r8
leaq -0x438(%rbp), %r9
leaq -0x458(%rbp), %rax
movq %rax, (%rsp)
callq 0x17190
movq %rax, -0x430(%rbp)
jmp 0x176a5
cmpl $0x0, -0x14(%rbp)
jne 0x177dc
movq -0x428(%rbp), %rax
movq (%rax), %rax
shlq %rax
movq %rax, -0x448(%rbp)
movq -0x430(%rbp), %rdi
movq -0x448(%rbp), %rsi
leaq 0x22a12(%rip), %rdx     # 0x3a138
movl $0x16d, %ecx            # imm = 0x16D
leaq 0x22aa3(%rip), %r8      # 0x3a1d5
callq 0x31d40
movq %rax, -0x430(%rbp)
movq -0x430(%rbp), %rdi
movq -0x428(%rbp), %rax
addq (%rax), %rdi
movq -0x448(%rbp), %rdx
movq -0x428(%rbp), %rax
subq (%rax), %rdx
xorl %esi, %esi
callq 0x3130
movq -0x428(%rbp), %rax
movq (%rax), %rax
subq $0x1, %rax
movq %rax, -0x450(%rbp)
cmpq $0x0, -0x450(%rbp)
jl 0x177da
movq -0x430(%rbp), %rax
movq -0x450(%rbp), %rcx
movzbl (%rax,%rcx), %ecx
movl $0x15, %eax
subl %ecx, %eax
movb %al, %dl
movq -0x430(%rbp), %rax
movq -0x428(%rbp), %rcx
movq (%rcx), %rcx
movb %dl, (%rax,%rcx)
movq -0x450(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x450(%rbp)
movq -0x428(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0x1777c
jmp 0x177dc
movq -0x428(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x440(%rbp)
movq -0x430(%rbp), %rdi
movq -0x428(%rbp), %rax
movq (%rax), %rdx
movq -0x460(%rbp), %rcx
movl $0x1, %esi
callq 0x12c10
movb $0x0, -0x461(%rbp)
movq -0x460(%rbp), %rcx
leaq -0x461(%rbp), %rdi
movl $0x1, %edx
movq %rdx, %rsi
callq 0x12c10
movb $0x0, -0x461(%rbp)
movq -0x460(%rbp), %rcx
leaq -0x461(%rbp), %rdi
movl $0x1, %edx
movq %rdx, %rsi
callq 0x12c10
movq -0x460(%rbp), %rdi
callq 0x130e0
movq -0x460(%rbp), %rdi
callq 0x131b0
movq -0x428(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x15fe0
movq -0x428(%rbp), %rdi
callq 0x170e0
movq -0x20(%rbp), %rdi
callq 0x11ad0
movq -0x430(%rbp), %rdi
callq 0x3380
movq -0x440(%rbp), %rax
addq $0x470, %rsp            # imm = 0x470
popq %rbp
retq
nopl (%rax)