// File: /workspace/github_cpp_makefile_star2_O2/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, 0x50(%rsp)
movq %rcx, 0x48(%rsp)
movq %rdx, 0x10(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdi, %rbx
cmpq $0x0, 0x18(%rdi)
je 0x268c4
leaq 0xc(%rsp), %rax
andl $0x0, (%rax)
xorl %r15d, %r15d
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %r13d, %r13d
movq %rbx, 0x40(%rsp)
cmpq 0x18(%rbx), %r14
jae 0x266de
movq %rbx, %rdi
movq %r14, %rsi
callq 0x26bc8
movq (%rax), %rax
movq 0x20(%rax), %rcx
cmpq 0x28(%rax), %rcx
jne 0x2654b
testb $0x1, 0x30(%rax)
jne 0x26758
movb $0x1, %bpl
movq %rbx, %rdi
movq %r14, %rsi
callq 0x26bc8
movq (%rax), %rax
movq 0x20(%rax), %rcx
cmpq 0x28(%rax), %rcx
jne 0x26570
testb $0x1, 0x30(%rax)
jne 0x26632
movq %rbx, %rdi
movq %r14, %rsi
callq 0x26bc8
movq (%rax), %rsi
movzbl %bpl, %ecx
andl $0x1, %ecx
leaq 0x18(%rsp), %rdi
movq 0x48(%rsp), %rdx
movq 0x50(%rsp), %r8
callq 0x25630
cmpb $0x1, 0x28(%rsp)
jne 0x265c1
testl %r13d, %r13d
je 0x265b4
movq 0x10(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x1b3de
movq %r12, %rbx
andl $0x0, 0xc(%rsp)
xorl %r13d, %r13d
jmp 0x265c4
movq %r12, %rbx
movq 0x20(%rsp), %r12
testq %r12, %r12
jne 0x265d3
movb $0x0, 0x28(%rsp)
addq %r12, %r15
jb 0x26707
movb 0x28(%rsp), %al
cmpb $0x1, %al
jne 0x265ec
movq 0x38(%rsp), %rcx
incq (%rcx)
movl 0xc(%rsp), %ecx
addl %r12d, %ecx
movq 0x18(%rsp), %rbp
addl %ebp, %ecx
movl %ecx, 0xc(%rsp)
movq %r12, %rcx
orq %rbp, %rcx
setne %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x2661d
movq 0x30(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x1b1a2
addl %r12d, %r13d
addq %rbx, %r12
addq %rbp, %r12
xorl %ebp, %ebp
movq 0x40(%rsp), %rbx
jmp 0x2654e
movq %rbx, %rdi
movq %r14, %rsi
callq 0x26bc8
movq (%rax), %rdi
callq 0x26c8e
movq %rbx, %rdi
movq %r14, %rsi
callq 0x26bc8
movq (%rax), %rax
movq 0x20(%rax), %rcx
cmpq 0x28(%rax), %rcx
jne 0x26667
testb $0x1, 0x30(%rax)
jne 0x268a5
movq %rbx, %rdi
movq %r14, %rsi
callq 0x26bc8
movq (%rax), %rdi
callq 0x1d2b6
cmpl $0x3e, %eax
jne 0x26777
movq %rbx, %rdi
movq %r14, %rsi
callq 0x26bc8
movq (%rax), %rdi
callq 0x26c8e
movq %rbx, %rdi
movq %r14, %rsi
callq 0x26bc8
movq (%rax), %rax
movq 0x20(%rax), %rcx
incq %r14
cmpq 0x28(%rax), %rcx
jne 0x2651f
testb $0x1, 0x30(%rax)
je 0x2651f
leaq 0x5d22(%rip), %rdi      # 0x2c3e8
leaq 0x5a81(%rip), %rsi      # 0x2c14e
leaq 0x5c72(%rip), %rcx      # 0x2c346
movl $0x106, %edx            # imm = 0x106
callq 0x4190
testl %r13d, %r13d
je 0x266f2
leaq 0xc(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0x1b3de
movq %r15, %rax
movq %r12, %rdx
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xd8e2(%rip), %rdi      # 0x33ff0
leaq 0x5ce1(%rip), %rsi      # 0x2c3f6
callq 0x42d0
movq %rax, %rdi
callq 0x4130
leaq 0x5d1b(%rip), %rsi      # 0x2c444
movq %rax, %rdi
callq 0x42d0
movq %rax, %rdi
callq 0x4130
pushq $0x4
popq %rdi
callq 0x4140
movl $0x1, (%rax)
movq 0xd822(%rip), %rsi      # 0x33f70
movq %rax, %rdi
xorl %edx, %edx
callq 0x45b0
leaq 0x5c89(%rip), %rdi      # 0x2c3e8
leaq 0x59e8(%rip), %rsi      # 0x2c14e
leaq 0x5bd9(%rip), %rcx      # 0x2c346
movl $0xdc, %edx
callq 0x4190
movq 0xd83a(%rip), %rbx      # 0x33fb8
leaq 0x19d4(%rip), %rsi      # 0x28159
movq %rbx, %rdi
movl %eax, %r15d
callq 0x42d0
pushq $0x3e
popq %rbp
movq %rax, %rdi
movl %ebp, %esi
callq 0x4380
leaq 0x19cb(%rip), %r14      # 0x2816f
movq %rax, %rdi
movq %r14, %rsi
callq 0x42d0
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 0x4380
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
leaq 0x198a(%rip), %rsi      # 0x28174
movq %rax, %rdi
callq 0x42d0
movq %rax, %rdi
movl %r15d, %esi
callq 0x45d0
movq %rax, %rdi
movq %r14, %rsi
callq 0x42d0
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 %r15d, %esi
callq 0x45d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
leaq 0x3bd4(%rip), %rsi      # 0x2a418
movq %rax, %rdi
callq 0x42d0
movq %rax, %rdi
callq 0x4130
leaq 0x58f3(%rip), %r14      # 0x2c14e
movq %rbx, %rdi
movq %r14, %rsi
callq 0x42d0
leaq 0x2ece(%rip), %rsi      # 0x2973b
movq %rax, %rdi
callq 0x42d0
movq %rax, %rdi
movl $0x104, %esi            # imm = 0x104
callq 0x45d0
movq %rax, %rdi
callq 0x4130
leaq 0x2d8a(%rip), %rdi      # 0x2961b
leaq 0x5aae(%rip), %rcx      # 0x2c346
movq %r14, %rsi
movl $0x104, %edx            # imm = 0x104
callq 0x4190
leaq 0x5b3c(%rip), %rdi      # 0x2c3e8
leaq 0x589b(%rip), %rsi      # 0x2c14e
leaq 0x5a8c(%rip), %rcx      # 0x2c346
movl $0x100, %edx            # imm = 0x100
callq 0x4190
movq 0xd6ed(%rip), %r14      # 0x33fb8
leaq 0x1866(%rip), %rsi      # 0x28138
movq %r14, %rdi
callq 0x42d0
movq 0x18(%rbx), %rsi
movq %rax, %rdi
callq 0x40b0
leaq 0x1861(%rip), %rsi      # 0x2814e
movq %rax, %rdi
callq 0x42d0
movq %rax, %rdi
xorl %esi, %esi
callq 0x45d0
leaq 0x3b12(%rip), %rsi      # 0x2a418
movq %rax, %rdi
callq 0x42d0
movq %rax, %rdi
callq 0x4130
leaq 0x5831(%rip), %rbx      # 0x2c14e
movq %r14, %rdi
movq %rbx, %rsi
callq 0x42d0
leaq 0x2e0c(%rip), %rsi      # 0x2973b
movq %rax, %rdi
callq 0x42d0
movq %rax, %rdi
movl $0xd7, %esi
callq 0x45d0
movq %rax, %rdi
callq 0x4130
leaq 0x2cc8(%rip), %rdi      # 0x2961b
leaq 0x59ec(%rip), %rcx      # 0x2c346
movq %rbx, %rsi
movl $0xd7, %edx
callq 0x4190
nop