// File: BenLangmead[P]bowtie/./sequence_io.h
// Function: void readSequenceFile<SString<char>>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, EList<SString<char>, 128>&, long&, int, bool)
static void readSequenceFile(const std::string& infile,
                             EList<TStr>& ss,
                             int64_t& baseCutoff, // limit for total bases
                             int seqCutoff = -1,  // limit for sequences
                             bool reverse = false)
{
	// static char buf[256 * 1024]; // fairly large input buffer
	if(baseCutoff <= 0) return;
	// Read entries using SeqAn
	EList<size_t> namelens;
	EList<size_t> seqlens;
	parseFastaLens(infile, namelens, seqlens);
	FILE *in = fopen(sstr_to_cstr(infile), "r");
	if(in == NULL) {
		cerr << "Could not open sequence file" << endl;
		throw 1;
	}
	FileBuf fb(in);
	int cnt = 0;
	// size_t cur = namelens.size();
	for (size_t i = 0; !fb.eof(); i++) {
		std::string names;
		names.reserve(namelens[i] + 1);
		ss.push_back(TStr(new char[seqlens[i]], seqlens[i])); // add a new empty string to the end
		// Fill the new empty string with the next sequence from
		// the file.  SeqAn allocates just enough mem for it (at
		// the expense of lots of file seeks, which can add up)
		// ss.back() = new char[seqlens[0] + 1];
		// ss.back().install(new char[seqlens[0] + 1], seqlens[0] + 1);
		fb.parseFastaRecord(names, ss.back());
		if (ss.back().empty()) {
			ss.pop_back();
			continue;
		}
		// Enforce the base cutoff
		if((int64_t)ss.back().length() > baseCutoff) {
			ss.back().resize(baseCutoff);
			baseCutoff = 0;
		} else {
			baseCutoff -= ss.back().length();
		}
		// Reverse the newly-read sequence in-place if desired
		if(reverse) {
			size_t len = ss.back().length();
			for(size_t i = 0; i < len/2; i++) {
				char t = ss.back()[i];
				ss.back()[i] = ss.back()[len-i-1];
				ss.back()[len-i-1] = t;
			}
		}
		#ifndef NDEBUG
		// Sanity check that all (int) values are in range
		for(size_t i = 0; i < ss.back().length(); i++) {
			// assert_lt(ss.back()[i], (int)(ValueSize<TVal>::VALUE));
			assert_geq(ss.back()[i], 0);
		}
		#endif
		cnt++;
		// Enforce the sequence cutoff
		if(seqCutoff != -1 && cnt >= seqCutoff) {
			fclose(in);
			return;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x422a0, %rsp          # imm = 0x422A0
movb %r8b, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
andb $0x1, %al
movb %al, -0x1d(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
jg 0x12931
jmp 0x130eb
leaq -0x40(%rbp), %rdi
callq 0x2bd40
leaq -0x60(%rbp), %rdi
callq 0x2bd40
jmp 0x12945
movq -0x8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0x13120
jmp 0x12958
movq -0x8(%rbp), %rdi
callq 0x132d0
movq %rax, -0x42138(%rbp)
jmp 0x1296a
movq -0x42138(%rbp), %rdi
leaq 0x2cdd8(%rip), %rsi     # 0x3f750
callq 0x5460
movq %rax, -0x42140(%rbp)
jmp 0x12986
movq -0x42140(%rbp), %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
jne 0x12a13
movq 0x37651(%rip), %rdi     # 0x49ff0
leaq 0x2e926(%rip), %rsi     # 0x412cc
callq 0x5360
movq %rax, -0x42148(%rbp)
jmp 0x129b4
movq -0x42148(%rbp), %rdi
movq 0x375be(%rip), %rsi     # 0x49f80
callq 0x53c0
jmp 0x129c9
movl $0x4, %edi
callq 0x5180
movq %rax, %rdi
movl $0x1, (%rdi)
movq 0x3758d(%rip), %rsi     # 0x49f70
xorl %eax, %eax
movl %eax, %edx
callq 0x5720
jmp 0x1311b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x13109
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x13100
movq -0x78(%rbp), %rsi
leaq -0x420b8(%rbp), %rdi
callq 0x2e810
jmp 0x12a25
movl $0x0, -0x420bc(%rbp)
movq $0x0, -0x420c8(%rbp)
leaq -0x420b8(%rbp), %rdi
callq 0x2e870
movb %al, -0x42149(%rbp)
jmp 0x12a4e
movb -0x42149(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x12a5f
jmp 0x130c3
leaq -0x420e8(%rbp), %rdi
callq 0x5580
movq -0x420c8(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x17b40
movq %rax, -0x42158(%rbp)
jmp 0x12a84
movq -0x42158(%rbp), %rax
movq (%rax), %rsi
incq %rsi
leaq -0x420e8(%rbp), %rdi
callq 0x5660
jmp 0x12a9f
movq -0x10(%rbp), %rax
movq %rax, -0x42168(%rbp)
movq -0x420c8(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x17b40
movq %rax, -0x42160(%rbp)
jmp 0x12ac3
movq -0x42160(%rbp), %rax
movq (%rax), %rdi
callq 0x5030
movq %rax, -0x42170(%rbp)
jmp 0x12adb
movq -0x420c8(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x17b40
movq %rax, -0x42178(%rbp)
jmp 0x12af4
movq -0x42170(%rbp), %rsi
movq -0x42178(%rbp), %rax
movq (%rax), %rdx
leaq -0x42108(%rbp), %rdi
callq 0x2c380
jmp 0x12b13
movq -0x42168(%rbp), %rdi
leaq -0x42108(%rbp), %rsi
callq 0x2c300
jmp 0x12b28
leaq -0x42108(%rbp), %rdi
callq 0x196d0
movq -0x10(%rbp), %rdi
callq 0x2ea40
movq %rax, -0x42180(%rbp)
jmp 0x12b46
movq -0x42180(%rbp), %rdx
leaq -0x420b8(%rbp), %rdi
leaq -0x420e8(%rbp), %rsi
xorl %ecx, %ecx
callq 0x2e8a0
jmp 0x12b64
movq -0x10(%rbp), %rdi
callq 0x2ea40
movq %rax, -0x42188(%rbp)
jmp 0x12b76
movq -0x42188(%rbp), %rdi
callq 0x2eb40
movb %al, -0x42189(%rbp)
jmp 0x12b8a
movb -0x42189(%rbp), %al
testb $0x1, %al
jne 0x12b96
jmp 0x12bef
movq -0x10(%rbp), %rdi
callq 0x2eb60
jmp 0x12ba1
movl $0x4, -0x4210c(%rbp)
jmp 0x13071
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x130f4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x130b5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x42108(%rbp), %rdi
callq 0x196d0
jmp 0x130b5
movq -0x10(%rbp), %rdi
callq 0x2ea40
movq %rax, -0x42198(%rbp)
jmp 0x12c01
movq -0x42198(%rbp), %rdi
callq 0x195b0
movq %rax, -0x421a0(%rbp)
jmp 0x12c16
movq -0x421a0(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq (%rcx), %rax
jle 0x12c5a
movq -0x10(%rbp), %rdi
callq 0x2ea40
movq %rax, -0x421a8(%rbp)
jmp 0x12c38
movq -0x421a8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
callq 0x189a0
jmp 0x12c4d
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
jmp 0x12c95
movq -0x10(%rbp), %rdi
callq 0x2ea40
movq %rax, -0x421b0(%rbp)
jmp 0x12c6c
movq -0x421b0(%rbp), %rdi
callq 0x195b0
movq %rax, -0x421b8(%rbp)
jmp 0x12c81
movq -0x421b8(%rbp), %rdx
movq -0x18(%rbp), %rax
movq (%rax), %rcx
subq %rdx, %rcx
movq %rcx, (%rax)
testb $0x1, -0x1d(%rbp)
je 0x12e2c
movq -0x10(%rbp), %rdi
callq 0x2ea40
movq %rax, -0x421c0(%rbp)
jmp 0x12cb1
movq -0x421c0(%rbp), %rdi
callq 0x195b0
movq %rax, -0x421c8(%rbp)
jmp 0x12cc6
movq -0x421c8(%rbp), %rax
movq %rax, -0x42118(%rbp)
movq $0x0, -0x42120(%rbp)
movq -0x42120(%rbp), %rax
movq -0x42118(%rbp), %rcx
shrq %rcx
cmpq %rcx, %rax
jae 0x12e2a
movq -0x10(%rbp), %rdi
callq 0x2ea40
movq %rax, -0x421d0(%rbp)
jmp 0x12d0b
movq -0x421d0(%rbp), %rdi
movq -0x42120(%rbp), %rsi
callq 0x18f90
movq %rax, -0x421d8(%rbp)
jmp 0x12d27
movq -0x421d8(%rbp), %rax
movb (%rax), %al
movb %al, -0x42121(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2ea40
movq %rax, -0x421e0(%rbp)
jmp 0x12d48
movq -0x421e0(%rbp), %rdi
movq -0x42118(%rbp), %rax
movq -0x42120(%rbp), %rsi
notq %rsi
addq %rax, %rsi
callq 0x18f90
movq %rax, -0x421e8(%rbp)
jmp 0x12d71
movq -0x421e8(%rbp), %rax
movb (%rax), %al
movb %al, -0x421f1(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2ea40
movq %rax, -0x421f0(%rbp)
jmp 0x12d92
movq -0x421f0(%rbp), %rdi
movq -0x42120(%rbp), %rsi
callq 0x18f90
movq %rax, -0x42200(%rbp)
jmp 0x12dae
movq -0x42200(%rbp), %rax
movb -0x421f1(%rbp), %cl
movb %cl, (%rax)
movb -0x42121(%rbp), %al
movb %al, -0x42209(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2ea40
movq %rax, -0x42208(%rbp)
jmp 0x12ddb
movq -0x42208(%rbp), %rdi
movq -0x42118(%rbp), %rax
movq -0x42120(%rbp), %rsi
notq %rsi
addq %rax, %rsi
callq 0x18f90
movq %rax, -0x42218(%rbp)
jmp 0x12e04
movq -0x42218(%rbp), %rax
movb -0x42209(%rbp), %cl
movb %cl, (%rax)
movq -0x42120(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x42120(%rbp)
jmp 0x12cdf
jmp 0x12e2c
movq $0x0, -0x42130(%rbp)
movq -0x42130(%rbp), %rax
movq %rax, -0x42228(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2ea40
movq %rax, -0x42220(%rbp)
jmp 0x12e57
movq -0x42220(%rbp), %rdi
callq 0x195b0
movq %rax, -0x42230(%rbp)
jmp 0x12e6c
movq -0x42228(%rbp), %rax
movq -0x42230(%rbp), %rcx
cmpq %rcx, %rax
jae 0x13030
movq -0x10(%rbp), %rdi
callq 0x2ea40
movq %rax, -0x42238(%rbp)
jmp 0x12e95
movq -0x42238(%rbp), %rdi
movq -0x42130(%rbp), %rsi
callq 0x18f90
movq %rax, -0x42240(%rbp)
jmp 0x12eb1
movq -0x42240(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jge 0x13017
movq 0x370f5(%rip), %rdi     # 0x49fc0
leaq 0x2c333(%rip), %rsi     # 0x3f205
callq 0x5360
movq %rax, -0x42248(%rbp)
jmp 0x12ee0
movq -0x10(%rbp), %rdi
callq 0x2ea40
movq %rax, -0x42250(%rbp)
jmp 0x12ef2
movq -0x42250(%rbp), %rdi
movq -0x42130(%rbp), %rsi
callq 0x18f90
movq %rax, -0x42258(%rbp)
jmp 0x12f0e
movq -0x42248(%rbp), %rdi
movq -0x42258(%rbp), %rax
movsbl (%rax), %esi
callq 0x54a0
movq %rax, -0x42260(%rbp)
jmp 0x12f2d
movq -0x42260(%rbp), %rdi
leaq 0x2c2e1(%rip), %rsi     # 0x3f21c
callq 0x5360
movq %rax, -0x42268(%rbp)
jmp 0x12f49
movq -0x42268(%rbp), %rdi
xorl %esi, %esi
callq 0x5750
movq %rax, -0x42270(%rbp)
jmp 0x12f60
movq -0x42270(%rbp), %rdi
leaq 0x2e64a(%rip), %rsi     # 0x415b8
callq 0x5360
movq %rax, -0x42278(%rbp)
jmp 0x12f7c
movq -0x42278(%rbp), %rdi
movq 0x36ff6(%rip), %rsi     # 0x49f80
callq 0x53c0
jmp 0x12f91
movq 0x37028(%rip), %rdi     # 0x49fc0
leaq 0x2e34a(%rip), %rsi     # 0x412e9
callq 0x5360
movq %rax, -0x42280(%rbp)
jmp 0x12fad
movq -0x42280(%rbp), %rdi
leaq 0x2d7cf(%rip), %rsi     # 0x4078a
callq 0x5360
movq %rax, -0x42288(%rbp)
jmp 0x12fc9
movq -0x42288(%rbp), %rdi
movl $0x69, %esi
callq 0x5750
movq %rax, -0x42290(%rbp)
jmp 0x12fe3
movq -0x42290(%rbp), %rdi
movq 0x36f8f(%rip), %rsi     # 0x49f80
callq 0x53c0
jmp 0x12ff8
leaq 0x2d66b(%rip), %rdi     # 0x4066a
leaq 0x2e2e3(%rip), %rsi     # 0x412e9
movl $0x69, %edx
leaq 0x2e2e7(%rip), %rcx     # 0x412f9
callq 0x51e0
jmp 0x13019
movq -0x42130(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x42130(%rbp)
jmp 0x12e37
movl -0x420bc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x420bc(%rbp)
cmpl $-0x1, -0x1c(%rbp)
je 0x13067
movl -0x420bc(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jl 0x13067
movq -0x78(%rbp), %rdi
callq 0x5370
jmp 0x1305b
movl $0x1, -0x4210c(%rbp)
jmp 0x13071
movl $0x0, -0x4210c(%rbp)
leaq -0x420e8(%rbp), %rdi
callq 0x5888
movl -0x4210c(%rbp), %eax
movl %eax, -0x42294(%rbp)
testl %eax, %eax
je 0x1309c
jmp 0x1308f
movl -0x42294(%rbp), %eax
subl $0x4, %eax
je 0x1309e
jmp 0x130cd
jmp 0x1309e
movq -0x420c8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x420c8(%rbp)
jmp 0x12a3a
leaq -0x420e8(%rbp), %rdi
callq 0x5888
jmp 0x130f4
movl $0x0, -0x4210c(%rbp)
leaq -0x420b8(%rbp), %rdi
callq 0x2ec50
leaq -0x60(%rbp), %rdi
callq 0x2caf0
leaq -0x40(%rbp), %rdi
callq 0x2caf0
addq $0x422a0, %rsp          # imm = 0x422A0
popq %rbp
retq
leaq -0x420b8(%rbp), %rdi
callq 0x2ec50
leaq -0x60(%rbp), %rdi
callq 0x2caf0
leaq -0x40(%rbp), %rdi
callq 0x2caf0
movq -0x68(%rbp), %rdi
callq 0x5760
nopl (%rax,%rax)