// File: 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
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq %r9, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x18(%rbp), %rdi
callq 0x3cba0
cmpq $0x0, %rax
ja 0x3bf9c
movq 0xe0e3(%rip), %rdi      # 0x49fc0
leaq 0x3214(%rip), %rsi      # 0x3f0f8
callq 0x5360
movq %rax, -0x90(%rbp)
movq -0x18(%rbp), %rdi
callq 0x3cba0
movq -0x90(%rbp), %rdi
movq %rax, %rsi
callq 0x50c0
movq %rax, %rdi
leaq 0x31fc(%rip), %rsi      # 0x3f10e
callq 0x5360
movq %rax, %rdi
xorl %esi, %esi
callq 0x5750
movq %rax, %rdi
leaq 0x568d(%rip), %rsi      # 0x415b8
callq 0x5360
movq %rax, %rdi
movq 0xe046(%rip), %rsi      # 0x49f80
callq 0x53c0
movq 0xe07a(%rip), %rdi      # 0x49fc0
leaq 0x7471(%rip), %rsi      # 0x433be
callq 0x5360
movq %rax, %rdi
leaq 0x482e(%rip), %rsi      # 0x4078a
callq 0x5360
movq %rax, %rdi
movl $0xd7, %esi
callq 0x5750
movq %rax, %rdi
movq 0xe008(%rip), %rsi      # 0x49f80
callq 0x53c0
leaq 0x46e6(%rip), %rdi      # 0x4066a
leaq 0x7433(%rip), %rsi      # 0x433be
movl $0xd7, %edx
leaq 0x761f(%rip), %rcx      # 0x435b6
callq 0x51e0
movl $0x0, -0x54(%rbp)
movl $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x18(%rbp), %rdi
callq 0x3cba0
movq %rax, %rcx
movq -0x98(%rbp), %rax
cmpq %rcx, %rax
jae 0x3c3a9
movb $0x1, -0x61(%rbp)
movq -0x18(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x3cbc0
movq (%rax), %rdi
callq 0x2e870
xorb $-0x1, %al
testb $0x1, %al
jne 0x3bffa
jmp 0x3bffc
jmp 0x3c01b
leaq 0x7655(%rip), %rdi      # 0x43658
leaq 0x73b4(%rip), %rsi      # 0x433be
movl $0xdc, %edx
leaq 0x75a0(%rip), %rcx      # 0x435b6
callq 0x51e0
jmp 0x3c01d
movq -0x18(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x3cbc0
movq (%rax), %rdi
callq 0x2e870
xorb $-0x1, %al
testb $0x1, %al
jne 0x3c03d
jmp 0x3c197
movq -0x18(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x3cbc0
movq (%rax), %rsi
movq -0x30(%rbp), %rdx
movb -0x61(%rbp), %al
movq -0x38(%rbp), %r8
leaq -0x80(%rbp), %rdi
andb $0x1, %al
movzbl %al, %ecx
callq 0x3a590
testb $0x1, -0x70(%rbp)
je 0x3c08d
cmpl $0x0, -0x58(%rbp)
jbe 0x3c07f
movq -0x28(%rbp), %rdi
leaq -0x54(%rbp), %rsi
callq 0x2c180
movl $0x0, -0x54(%rbp)
movl $0x0, -0x58(%rbp)
cmpq $0x0, -0x78(%rbp)
jne 0x3c098
movb $0x0, -0x70(%rbp)
movq -0x48(%rbp), %rax
addq -0x78(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x3c109
movq 0xdf43(%rip), %rdi      # 0x49ff0
leaq 0x75b2(%rip), %rsi      # 0x43666
callq 0x5360
movq %rax, %rdi
movq 0xdebd(%rip), %rsi      # 0x49f80
callq 0x53c0
movq %rax, %rdi
leaq 0x75e2(%rip), %rsi      # 0x436b4
callq 0x5360
movq %rax, %rdi
movq 0xde9f(%rip), %rsi      # 0x49f80
callq 0x53c0
movl $0x4, %edi
callq 0x5180
movq %rax, %rdi
movl $0x1, (%rdi)
movq 0xde70(%rip), %rsi      # 0x49f70
xorl %eax, %eax
movl %eax, %edx
callq 0x5720
testb $0x1, -0x70(%rbp)
je 0x3c11d
movq -0x40(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq -0x78(%rbp), %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x78(%rbp), %rcx
movl -0x58(%rbp), %eax
addq %rcx, %rax
movl %eax, -0x58(%rbp)
movq -0x78(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x78(%rbp), %rcx
movl -0x54(%rbp), %eax
addq %rcx, %rax
movl %eax, -0x54(%rbp)
movq -0x80(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x80(%rbp), %rcx
movl -0x54(%rbp), %eax
addq %rcx, %rax
movl %eax, -0x54(%rbp)
movb $0x0, -0x61(%rbp)
cmpq $0x0, -0x78(%rbp)
jne 0x3c185
cmpq $0x0, -0x80(%rbp)
jne 0x3c185
testb $0x1, -0x70(%rbp)
jne 0x3c185
jmp 0x3c01d
movq -0x20(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x2be10
jmp 0x3c01d
movq -0x18(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x3cbc0
movq (%rax), %rdi
callq 0x3ccc0
movq -0x18(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x3cbc0
movq (%rax), %rdi
callq 0x2e870
xorb $-0x1, %al
testb $0x1, %al
jne 0x3c1c9
jmp 0x3c1cb
jmp 0x3c1ea
leaq 0x7486(%rip), %rdi      # 0x43658
leaq 0x71e5(%rip), %rsi      # 0x433be
movl $0x100, %edx            # imm = 0x100
leaq 0x73d1(%rip), %rcx      # 0x435b6
callq 0x51e0
movq -0x18(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x3cbc0
movq (%rax), %rdi
callq 0x2f2b0
movl %eax, -0x84(%rbp)
movl $0x3e, %eax
cmpl -0x84(%rbp), %eax
je 0x3c343
movq 0xdda3(%rip), %rdi      # 0x49fc0
leaq 0x2ef5(%rip), %rsi      # 0x3f119
callq 0x5360
movq %rax, %rdi
movl $0x3e, %esi
callq 0x54a0
movq %rax, %rdi
leaq 0x2eef(%rip), %rsi      # 0x3f12f
callq 0x5360
movq %rax, %rdi
leaq -0x23a6f(%rip), %rsi    # 0x187e0
callq 0x5120
movq %rax, %rdi
movl $0x3e, %esi
callq 0x54a0
movq %rax, %rdi
leaq -0x23a5b(%rip), %rsi    # 0x18810
callq 0x5120
movq %rax, %rdi
leaq 0x2eba(%rip), %rsi      # 0x3f134
callq 0x5360
movq %rax, %rdi
movl -0x84(%rbp), %esi
callq 0x5750
movq %rax, %rdi
leaq 0x2e98(%rip), %rsi      # 0x3f12f
callq 0x5360
movq %rax, %rdi
leaq -0x23ac6(%rip), %rsi    # 0x187e0
callq 0x5120
movq %rax, %rdi
movl -0x84(%rbp), %esi
callq 0x5750
movq %rax, %rdi
leaq -0x23ab3(%rip), %rsi    # 0x18810
callq 0x5120
movq %rax, %rdi
leaq 0x52e6(%rip), %rsi      # 0x415b8
callq 0x5360
movq %rax, %rdi
movq 0xdc9f(%rip), %rsi      # 0x49f80
callq 0x53c0
movq 0xdcd3(%rip), %rdi      # 0x49fc0
leaq 0x70ca(%rip), %rsi      # 0x433be
callq 0x5360
movq %rax, %rdi
leaq 0x4487(%rip), %rsi      # 0x4078a
callq 0x5360
movq %rax, %rdi
movl $0x104, %esi            # imm = 0x104
callq 0x5750
movq %rax, %rdi
movq 0xdc61(%rip), %rsi      # 0x49f80
callq 0x53c0
leaq 0x433f(%rip), %rdi      # 0x4066a
leaq 0x708c(%rip), %rsi      # 0x433be
movl $0x104, %edx            # imm = 0x104
leaq 0x7278(%rip), %rcx      # 0x435b6
callq 0x51e0
movq -0x18(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x3cbc0
movq (%rax), %rdi
callq 0x3ccc0
movq -0x18(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x3cbc0
movq (%rax), %rdi
callq 0x2e870
xorb $-0x1, %al
testb $0x1, %al
jne 0x3c375
jmp 0x3c377
jmp 0x3c396
leaq 0x72da(%rip), %rdi      # 0x43658
leaq 0x7039(%rip), %rsi      # 0x433be
movl $0x106, %edx            # imm = 0x106
leaq 0x7225(%rip), %rcx      # 0x435b6
callq 0x51e0
jmp 0x3c398
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x3bfb2
cmpq $0x0, -0x50(%rbp)
jae 0x3c467
movq 0xdc05(%rip), %rdi      # 0x49fc0
leaq 0x2e43(%rip), %rsi      # 0x3f205
callq 0x5360
movq %rax, %rdi
movq -0x50(%rbp), %rsi
callq 0x50c0
movq %rax, %rdi
leaq 0x2e3f(%rip), %rsi      # 0x3f21c
callq 0x5360
movq %rax, %rdi
xorl %esi, %esi
callq 0x5750
movq %rax, %rdi
leaq 0x51c2(%rip), %rsi      # 0x415b8
callq 0x5360
movq %rax, %rdi
movq 0xdb7b(%rip), %rsi      # 0x49f80
callq 0x53c0
movq 0xdbaf(%rip), %rdi      # 0x49fc0
leaq 0x6fa6(%rip), %rsi      # 0x433be
callq 0x5360
movq %rax, %rdi
leaq 0x4363(%rip), %rsi      # 0x4078a
callq 0x5360
movq %rax, %rdi
movl $0x109, %esi            # imm = 0x109
callq 0x5750
movq %rax, %rdi
movq 0xdb3d(%rip), %rsi      # 0x49f80
callq 0x53c0
leaq 0x421b(%rip), %rdi      # 0x4066a
leaq 0x6f68(%rip), %rsi      # 0x433be
movl $0x109, %edx            # imm = 0x109
leaq 0x7154(%rip), %rcx      # 0x435b6
callq 0x51e0
cmpq $0x0, -0x48(%rbp)
jae 0x3c525
movq 0xdb47(%rip), %rdi      # 0x49fc0
leaq 0x2d85(%rip), %rsi      # 0x3f205
callq 0x5360
movq %rax, %rdi
movq -0x48(%rbp), %rsi
callq 0x50c0
movq %rax, %rdi
leaq 0x2d81(%rip), %rsi      # 0x3f21c
callq 0x5360
movq %rax, %rdi
xorl %esi, %esi
callq 0x5750
movq %rax, %rdi
leaq 0x5104(%rip), %rsi      # 0x415b8
callq 0x5360
movq %rax, %rdi
movq 0xdabd(%rip), %rsi      # 0x49f80
callq 0x53c0
movq 0xdaf1(%rip), %rdi      # 0x49fc0
leaq 0x6ee8(%rip), %rsi      # 0x433be
callq 0x5360
movq %rax, %rdi
leaq 0x42a5(%rip), %rsi      # 0x4078a
callq 0x5360
movq %rax, %rdi
movl $0x10a, %esi            # imm = 0x10A
callq 0x5750
movq %rax, %rdi
movq 0xda7f(%rip), %rsi      # 0x49f80
callq 0x53c0
leaq 0x415d(%rip), %rdi      # 0x4066a
leaq 0x6eaa(%rip), %rsi      # 0x433be
movl $0x10a, %edx            # imm = 0x10A
leaq 0x7096(%rip), %rcx      # 0x435b6
callq 0x51e0
cmpl $0x0, -0x58(%rbp)
jbe 0x3c538
movq -0x28(%rbp), %rdi
leaq -0x54(%rbp), %rsi
callq 0x2c180
leaq -0x48(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3cd90
movq %rax, -0x10(%rbp)
movq %rdx, -0x8(%rbp)
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rdx
addq $0xa0, %rsp
popq %rbp
retq
nop