// File: /workspace/github_cpp_makefile_star2_O3/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, %rbx
cmpq $0x0, 0x18(%rdi)
je 0x2a94b
leaq 0x4(%rsp), %rax
movl $0x0, (%rax)
movq $0x0, 0x8(%rsp)
xorl %r14d, %r14d
xorl %ebp, %ebp
xorl %r15d, %r15d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2ac5a
movq (%rax), %rax
movq 0x20(%rax), %rcx
cmpq 0x28(%rax), %rcx
jne 0x2a57e
testb $0x1, 0x30(%rax)
jne 0x2a7bd
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2ac5a
movq (%rax), %rax
movq 0x20(%rax), %rcx
cmpq 0x28(%rax), %rcx
jne 0x2a5a0
testb $0x1, 0x30(%rax)
jne 0x2a6ac
movb $0x1, %r13b
movq %r14, 0x50(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2ac5a
movq (%rax), %rsi
movzbl %r13b, %ecx
andl $0x1, %ecx
leaq 0x18(%rsp), %rdi
movq 0x40(%rsp), %rdx
movq 0x48(%rsp), %r8
callq 0x29374
cmpb $0x1, 0x28(%rsp)
jne 0x2a5fa
cmpl $0x0, 0x8(%rsp)
je 0x2a5ee
movq 0x10(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x1f0b0
movl $0x0, 0x4(%rsp)
xorl %edx, %edx
jmp 0x2a5ff
movq 0x8(%rsp), %rdx
movq 0x20(%rsp), %r13
testq %r13, %r13
jne 0x2a60e
movb $0x0, 0x28(%rsp)
addq %r13, %r15
jb 0x2a76a
movq %rbx, %r14
movb 0x28(%rsp), %al
cmpb $0x1, %al
jne 0x2a62a
movq 0x38(%rsp), %rcx
incq (%rcx)
movl 0x4(%rsp), %ecx
addl %r13d, %ecx
movq 0x18(%rsp), %rbx
addl %ebx, %ecx
movl %ecx, 0x4(%rsp)
movq %r13, %rcx
orq %rbx, %rcx
setne %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x2a66d
movq 0x30(%rsp), %rdi
leaq 0x18(%rsp), %rsi
movq %r15, %r12
movq %rbp, %r15
movq %rdx, %rbp
callq 0x1ee04
movq %rbp, %rdx
movq %r15, %rbp
movq %r12, %r15
addl %r13d, %edx
movq %rdx, 0x8(%rsp)
addq %r13, %rbp
addq %rbx, %rbp
movq %r14, %rbx
movq %r14, %rdi
movq 0x50(%rsp), %r14
movq %r14, %rsi
callq 0x2ac5a
movq (%rax), %rax
movq 0x20(%rax), %rcx
xorl %r13d, %r13d
cmpq 0x28(%rax), %rcx
jne 0x2a5a8
testb $0x1, 0x30(%rax)
je 0x2a5a8
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2ac5a
movq (%rax), %rdi
callq 0x2ad20
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2ac5a
movq (%rax), %rax
movq 0x20(%rax), %rcx
cmpq 0x28(%rax), %rcx
jne 0x2a6e1
testb $0x1, 0x30(%rax)
jne 0x2a7dc
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2ac5a
movq (%rax), %rdi
callq 0x20ecc
cmpl $0x3e, %eax
jne 0x2a81a
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2ac5a
movq (%rax), %rdi
callq 0x2ad20
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2ac5a
movq (%rax), %rax
movq 0x20(%rax), %rcx
cmpq 0x28(%rax), %rcx
jne 0x2a732
testb $0x1, 0x30(%rax)
jne 0x2a7fb
incq %r14
cmpq 0x18(%rbx), %r14
jb 0x2a55c
cmpl $0x0, 0x8(%rsp)
je 0x2a755
leaq 0x4(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0x1f0b0
movq %r15, %rax
movq %rbp, %rdx
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xc87f(%rip), %rdi      # 0x36ff0
leaq 0x5c0e(%rip), %rsi      # 0x30386
callq 0x4310
movq %rax, %rdi
callq 0x4150
leaq 0x5c48(%rip), %rsi      # 0x303d4
movq %rax, %rdi
callq 0x4310
movq %rax, %rdi
callq 0x4150
movl $0x4, %edi
callq 0x4160
movl $0x1, (%rax)
movq 0xc7a5(%rip), %rsi      # 0x36f58
movq %rax, %rdi
xorl %edx, %edx
callq 0x45f0
leaq 0x5bb4(%rip), %rdi      # 0x30378
leaq 0x5913(%rip), %rsi      # 0x300de
leaq 0x5b04(%rip), %rcx      # 0x302d6
movl $0xdc, %edx
callq 0x41c0
leaq 0x5b95(%rip), %rdi      # 0x30378
leaq 0x58f4(%rip), %rsi      # 0x300de
leaq 0x5ae5(%rip), %rcx      # 0x302d6
movl $0x100, %edx            # imm = 0x100
callq 0x41c0
leaq 0x5b76(%rip), %rdi      # 0x30378
leaq 0x58d5(%rip), %rsi      # 0x300de
leaq 0x5ac6(%rip), %rcx      # 0x302d6
movl $0x106, %edx            # imm = 0x106
callq 0x41c0
movl %eax, %r12d
movq 0xc794(%rip), %rbx      # 0x36fb8
leaq 0x199b(%rip), %rsi      # 0x2c1c6
movq %rbx, %rdi
callq 0x4310
movq %rax, %rdi
movl $0x3e, %esi
callq 0x43d0
leaq 0x1995(%rip), %r14      # 0x2c1dc
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 0x1951(%rip), %rsi      # 0x2c1e1
movq %rax, %rdi
callq 0x4310
movq %rax, %rdi
movl %r12d, %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 %r12d, %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 0x3abb(%rip), %rsi      # 0x2e3a5
movq %rax, %rdi
callq 0x4310
movq %rax, %rdi
callq 0x4150
leaq 0x57dd(%rip), %r14      # 0x300de
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4310
leaq 0x2e95(%rip), %rsi      # 0x2d7a8
movq %rax, %rdi
callq 0x4310
movq %rax, %rdi
movl $0x104, %esi            # imm = 0x104
callq 0x4610
movq %rax, %rdi
callq 0x4150
leaq 0x2d51(%rip), %rdi      # 0x2d688
leaq 0x5998(%rip), %rcx      # 0x302d6
movq %r14, %rsi
movl $0x104, %edx            # imm = 0x104
callq 0x41c0
movq 0xc666(%rip), %r14      # 0x36fb8
leaq 0x184c(%rip), %rsi      # 0x2c1a5
movq %r14, %rdi
callq 0x4310
movq 0x18(%rbx), %rsi
movq %rax, %rdi
callq 0x40c0
leaq 0x1847(%rip), %rsi      # 0x2c1bb
movq %rax, %rdi
callq 0x4310
movq %rax, %rdi
xorl %esi, %esi
callq 0x4610
leaq 0x3a18(%rip), %rsi      # 0x2e3a5
movq %rax, %rdi
callq 0x4310
movq %rax, %rdi
callq 0x4150
leaq 0x573a(%rip), %rbx      # 0x300de
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4310
leaq 0x2df2(%rip), %rsi      # 0x2d7a8
movq %rax, %rdi
callq 0x4310
movq %rax, %rdi
movl $0xd7, %esi
callq 0x4610
movq %rax, %rdi
callq 0x4150
leaq 0x2cae(%rip), %rdi      # 0x2d688
leaq 0x58f5(%rip), %rcx      # 0x302d6
movq %rbx, %rsi
movl $0xd7, %edx
callq 0x41c0