// File: /workspace/github_cpp_makefile_star2_O1/BenLangmead[P]bowtie/ref_read.cpp
// Function: fastaRefReadSizes(EList<FileBuf*, 128>&, EList<RefRecord, 128>&, EList<unsigned int, 128>&, RefReadInParams const&, BitpairOutFileBuf*, long&)
std::pair<size_t, size_t>
fastaRefReadSizes(EList<FileBuf*>& in,
                  EList<RefRecord>& recs,
                  EList<uint32_t>& plens,
                  const RefReadInParams& rparms,
                  BitpairOutFileBuf* bpout,
                  TIndexOff& numSeqs)
{
	TIndexOffU unambigTot = 0;
	size_t bothTot = 0;
	assert_gt(in.size(), 0);
	uint32_t both = 0, unambig = 0;
	// For each input istream
	for(size_t i = 0; i < in.size(); i++) {
		bool first = true;
		assert(!in[i]->eof());
		// For each pattern in this istream
		while(!in[i]->eof()) {
			RefRecord rec = fastaRefReadSize(*in[i], rparms, first, bpout);
			// Update plens
			if(rec.first) {
				if(unambig > 0) {
					plens.push_back(both);
				}
				both = 0;
				unambig = 0;
			}
#ifndef ACCOUNT_FOR_ALL_GAP_REFS
			if(rec.len == 0) rec.first = false;
#endif
			if((unambigTot + rec.len) < unambigTot) {
#ifdef BOWTIE_64BIT_INDEX
				cerr << "Error: Reference sequence has more than 2^32-1 characters!  Please divide the" << endl
				     << "reference into smaller chunks and index each independently." << endl;
#else
				cerr << "Error: Reference sequence has more than 2^32-1 characters!  Please try to" << endl
				     << "build a large index instead using the appropiate options." << endl;
#endif
				throw 1;
			}
			// Add the length of this record.
			if(rec.first) numSeqs++;
			unambigTot += rec.len; unambig += rec.len;
			bothTot += rec.len;    both += rec.len;
			bothTot += rec.off;    both += rec.off;
			first = false;
			if(rec.len == 0 && rec.off == 0 && !rec.first) continue;
			recs.push_back(rec);
		}
		// Reset the input stream
		in[i]->reset();
		assert(!in[i]->eof());
#ifndef NDEBUG
		// Check that it's really reset
		int c = in[i]->get();
		assert_eq('>', c);
		in[i]->reset();
		assert(!in[i]->eof());
#endif
	}
	assert_geq(bothTot, 0);
	assert_geq(unambigTot, 0);
	if(unambig > 0) {
		plens.push_back(both);
	}
	return make_pair(
		unambigTot, // total number of unambiguous DNA characters read
		bothTot); // total number of DNA characters read, incl. ambiguous ones
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, 0x38(%rsp)
movq %r8, 0x48(%rsp)
movq %rcx, 0x40(%rsp)
movq %rdx, 0x10(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdi, %r15
cmpq $0x0, 0x18(%rdi)
je 0x2b4b5
movl $0x0, 0x4(%rsp)
cmpq $0x0, 0x18(%r15)
je 0x2b2a7
movq $0x0, 0x8(%rsp)
xorl %r13d, %r13d
xorl %r14d, %r14d
xorl %r12d, %r12d
movq %r15, %rdi
movq %r13, %rsi
callq 0x2b7c2
movq (%rax), %rax
movq 0x20(%rax), %rcx
cmpq 0x28(%rax), %rcx
jne 0x2b0e0
testb $0x1, 0x30(%rax)
jne 0x2b32a
movq %r15, %rdi
movq %r13, %rsi
callq 0x2b7c2
movq (%rax), %rax
movq 0x20(%rax), %rcx
cmpq 0x28(%rax), %rcx
jne 0x2b102
testb $0x1, 0x30(%rax)
jne 0x2b20a
movb $0x1, %bl
movq %r13, 0x50(%rsp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x2b7c2
movq (%rax), %rsi
movzbl %bl, %ecx
andl $0x1, %ecx
leaq 0x18(%rsp), %rdi
movq 0x40(%rsp), %rdx
movq 0x48(%rsp), %r8
callq 0x29db4
cmpb $0x1, 0x28(%rsp)
jne 0x2b15a
cmpl $0x0, 0x8(%rsp)
je 0x2b14e
movq 0x10(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x1f51c
movl $0x0, 0x4(%rsp)
xorl %edx, %edx
jmp 0x2b15f
movq 0x8(%rsp), %rdx
movq 0x20(%rsp), %rbx
testq %rbx, %rbx
jne 0x2b16e
movb $0x0, 0x28(%rsp)
addq %rbx, %r12
jb 0x2b2d7
movq %r15, %r13
movb 0x28(%rsp), %al
cmpb $0x1, %al
jne 0x2b18a
movq 0x38(%rsp), %rcx
incq (%rcx)
movl 0x4(%rsp), %ecx
addl %ebx, %ecx
movq 0x18(%rsp), %r15
addl %r15d, %ecx
movl %ecx, 0x4(%rsp)
movq %rbx, %rcx
orq %r15, %rcx
setne %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x2b1cd
movq 0x30(%rsp), %rdi
leaq 0x18(%rsp), %rsi
movq %r12, %rbp
movq %r14, %r12
movq %rdx, %r14
callq 0x1f2a0
movq %r14, %rdx
movq %r12, %r14
movq %rbp, %r12
addl %ebx, %edx
movq %rdx, 0x8(%rsp)
addq %rbx, %r14
addq %r15, %r14
movq %r13, %r15
movq %r13, %rdi
movq 0x50(%rsp), %r13
movq %r13, %rsi
callq 0x2b7c2
movq (%rax), %rax
movq 0x20(%rax), %rcx
xorl %ebx, %ebx
cmpq 0x28(%rax), %rcx
jne 0x2b109
testb $0x1, 0x30(%rax)
je 0x2b109
movq %r15, %rdi
movq %r13, %rsi
callq 0x2b7c2
movq (%rax), %rdi
callq 0x2b888
movq %r15, %rdi
movq %r13, %rsi
callq 0x2b7c2
movq (%rax), %rax
movq 0x20(%rax), %rcx
cmpq 0x28(%rax), %rcx
jne 0x2b23f
testb $0x1, 0x30(%rax)
jne 0x2b349
movq %r15, %rdi
movq %r13, %rsi
callq 0x2b7c2
movq (%rax), %rdi
callq 0x213fa
cmpl $0x3e, %eax
jne 0x2b387
movq %r15, %rdi
movq %r13, %rsi
callq 0x2b7c2
movq (%rax), %rdi
callq 0x2b888
movq %r15, %rdi
movq %r13, %rsi
callq 0x2b7c2
movq (%rax), %rax
movq 0x20(%rax), %rcx
cmpq 0x28(%rax), %rcx
jne 0x2b290
testb $0x1, 0x30(%rax)
jne 0x2b368
incq %r13
cmpq 0x18(%r15), %r13
jb 0x2b0be
cmpl $0x0, 0x8(%rsp)
sete %al
jmp 0x2b2af
movb $0x1, %al
xorl %r12d, %r12d
xorl %r14d, %r14d
testb %al, %al
jne 0x2b2c2
leaq 0x4(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0x1f51c
movq %r12, %rax
movq %r14, %rdx
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xbd12(%rip), %rdi      # 0x36ff0
leaq 0x6011(%rip), %rsi      # 0x312f6
callq 0x4310
movq %rax, %rdi
callq 0x4150
leaq 0x604b(%rip), %rsi      # 0x31344
movq %rax, %rdi
callq 0x4310
movq %rax, %rdi
callq 0x4150
movl $0x4, %edi
callq 0x4160
movl $0x1, (%rax)
movq 0xbc38(%rip), %rsi      # 0x36f58
movq %rax, %rdi
xorl %edx, %edx
callq 0x45f0
leaq 0x5fb7(%rip), %rdi      # 0x312e8
leaq 0x5d16(%rip), %rsi      # 0x3104e
leaq 0x5f07(%rip), %rcx      # 0x31246
movl $0xdc, %edx
callq 0x41c0
leaq 0x5f98(%rip), %rdi      # 0x312e8
leaq 0x5cf7(%rip), %rsi      # 0x3104e
leaq 0x5ee8(%rip), %rcx      # 0x31246
movl $0x100, %edx            # imm = 0x100
callq 0x41c0
leaq 0x5f79(%rip), %rdi      # 0x312e8
leaq 0x5cd8(%rip), %rsi      # 0x3104e
leaq 0x5ec9(%rip), %rcx      # 0x31246
movl $0x106, %edx            # imm = 0x106
callq 0x41c0
movl %eax, %ebp
movq 0xbc28(%rip), %rbx      # 0x36fb8
leaq 0x1d9f(%rip), %rsi      # 0x2d136
movq %rbx, %rdi
callq 0x4310
movq %rax, %rdi
movl $0x3e, %esi
callq 0x43d0
leaq 0x1d99(%rip), %r14      # 0x2d14c
movq %rax, %rdi
movq %r14, %rsi
callq 0x4310
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rax,%rcx)
movq %rax, %rdi
movl $0x3e, %esi
callq 0x43d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
leaq 0x1d55(%rip), %rsi      # 0x2d151
movq %rax, %rdi
callq 0x4310
movq %rax, %rdi
movl %ebp, %esi
callq 0x4610
movq %rax, %rdi
movq %r14, %rsi
callq 0x4310
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rax,%rcx)
movq %rax, %rdi
movl %ebp, %esi
callq 0x4610
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
leaq 0x3ec1(%rip), %rsi      # 0x2f315
movq %rax, %rdi
callq 0x4310
movq %rax, %rdi
callq 0x4150
leaq 0x5be3(%rip), %r14      # 0x3104e
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4310
leaq 0x329b(%rip), %rsi      # 0x2e718
movq %rax, %rdi
callq 0x4310
movq %rax, %rdi
movl $0x104, %esi            # imm = 0x104
callq 0x4610
movq %rax, %rdi
callq 0x4150
leaq 0x3157(%rip), %rdi      # 0x2e5f8
leaq 0x5d9e(%rip), %rcx      # 0x31246
movq %r14, %rsi
movl $0x104, %edx            # imm = 0x104
callq 0x41c0
movq 0xbafc(%rip), %rbx      # 0x36fb8
leaq 0x1c52(%rip), %rsi      # 0x2d115
movq %rbx, %rdi
callq 0x4310
movq 0x18(%r15), %rsi
movq %rax, %rdi
callq 0x40c0
leaq 0x1c4d(%rip), %rsi      # 0x2d12b
movq %rax, %rdi
callq 0x4310
movq %rax, %rdi
xorl %esi, %esi
callq 0x4610
leaq 0x3e1e(%rip), %rsi      # 0x2f315
movq %rax, %rdi
callq 0x4310
movq %rax, %rdi
callq 0x4150
leaq 0x5b40(%rip), %r14      # 0x3104e
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4310
leaq 0x31f8(%rip), %rsi      # 0x2e718
movq %rax, %rdi
callq 0x4310
movq %rax, %rdi
movl $0xd7, %esi
callq 0x4610
movq %rax, %rdi
callq 0x4150
leaq 0x30b4(%rip), %rdi      # 0x2e5f8
leaq 0x5cfb(%rip), %rcx      # 0x31246
movq %r14, %rsi
movl $0xd7, %edx
callq 0x41c0