// File: /workspace/github_cpp_makefile_star2_O1/BenLangmead[P]bowtie/pat.cpp
// Function: FastqPatternSource::nextBatchFromFile(PerThreadReadBuf&, bool, unsigned long)
pair<bool, int> FastqPatternSource::nextBatchFromFile(
	PerThreadReadBuf& pt,
	bool batch_a,
	size_t readi)
{
	int c = 0;
	EList<Read>* readBuf = batch_a ? &pt.bufa_ : &pt.bufb_;
	if(first_) {
		c = getc_wrapper();
		while(c == '\r' || c == '\n') {
			c = getc_wrapper();
		}
		if(c != '@') {
			cerr << "Error: reads file does not look like a FASTQ file" << endl;
			throw 1;
		}
		first_ = false;
		(*readBuf)[readi].readOrigBuf.append('@');
	}
	bool done = false, aborted = false;
	// Read until we run out of input or until we've filled the buffer
	while (readi < pt.max_buf_ && !done) {
		Read::TBuf& buf = (*readBuf)[readi].readOrigBuf;
		assert(readi == 0 || (*readBuf)[readi].readOrigBuf.length() == 0);
		int newlines = 4;
		while(newlines) {
			c = getc_wrapper();
			done = c < 0;
			if(c == '\n' || (done && newlines == 1)) {
				// Saw newline, or EOF that we're
				// interpreting as final newline
				newlines--;
				c = '\n';
			} else if(done) {
				if (newlines == 4) {
					newlines = 0;
				} else {
					aborted = true; // Unexpected EOF
				}
				break;
			}
			buf.append(c);
		}
		if (c > 0) {
			if (interleaved_) {
				// alternate between read buffers
				batch_a = !batch_a;
				readBuf = batch_a ? &pt.bufa_ : &pt.bufb_;
				// increment read counter after each pair gets read
				readi = batch_a ? readi + 1 : readi;
			}
			else {
				readi++;
			}
		}
	}
	if(aborted) {
		readi--;
	}
	return make_pair(done, readi);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, %r14
movl %edx, %ebx
movq %rdi, %r15
leaq 0x8(%rsi), %rax
movq %rsi, 0x18(%rsp)
leaq 0x28(%rsi), %rcx
testl %edx, %edx
movq %rcx, 0x20(%rsp)
movq %rax, 0x28(%rsp)
cmovneq %rax, %rcx
movq %rcx, 0x10(%rsp)
cmpb $0x1, 0x200a3(%rdi)
jne 0x4decc
movq %r15, %rdi
callq 0x4f0ba
cmpl $0xa, %eax
je 0x4de81
cmpl $0xd, %eax
je 0x4de81
cmpl $0x40, %eax
jne 0x4dfff
movb $0x0, 0x200a3(%r15)
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rax
imulq $0x268, %r14, %rcx      # imm = 0x268
leaq (%rax,%rcx), %rdi
addq $0x120, %rdi            # imm = 0x120
leaq 0xb(%rsp), %rsi
movb $0x40, (%rsi)
callq 0x4f10a
movq 0x18(%rsp), %rax
cmpq %r14, (%rax)
jbe 0x4dfdf
movl %ebx, 0xc(%rsp)
movl $0x0, 0x4(%rsp)
leaq 0x3(%rsp), %r12
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rax
movq %r14, 0x30(%rsp)
imulq $0x268, %r14, %rcx      # imm = 0x268
leaq (%rax,%rcx), %rbp
addq $0x120, %rbp            # imm = 0x120
movl $0x4, %r14d
movq %r15, %rdi
callq 0x4f0ba
movl %eax, %ebx
testl %eax, %eax
sets %al
cmpl $0x1, %r14d
sete %cl
cmpl $0xa, %ebx
je 0x4df39
andb %al, %cl
jne 0x4df39
testl %ebx, %ebx
js 0x4df62
movl %ebx, %r13d
jmp 0x4df42
decl %r14d
movl $0xa, %r13d
movb %r13b, 0x3(%rsp)
movq %rbp, %rdi
movq %r12, %rsi
callq 0x4f10a
testl %r14d, %r14d
jne 0x4df11
shrl $0x1f, %ebx
testl %r13d, %r13d
setne %al
jmp 0x4df7d
cmpl $0x4, %r14d
movl 0x4(%rsp), %eax
movzbl %al, %eax
movl $0x1, %ecx
cmovnel %ecx, %eax
movl %eax, 0x4(%rsp)
movb $0x1, %bl
xorl %eax, %eax
testb %al, %al
movq 0x30(%rsp), %r14
je 0x4dfbf
cmpb $0x1, 0x200a7(%r15)
jne 0x4dfbc
movl 0xc(%rsp), %edx
movl %edx, %eax
xorb $0x1, %al
movzbl %al, %ecx
andb $0x1, %al
testb $0x1, %dl
movq 0x28(%rsp), %rdx
cmovneq 0x20(%rsp), %rdx
movq %rdx, 0x10(%rsp)
andl $0x1, %ecx
addq %rcx, %r14
movl %eax, 0xc(%rsp)
jmp 0x4dfbf
incq %r14
movq 0x18(%rsp), %rax
cmpq (%rax), %r14
jae 0x4dfd1
testb %bl, %bl
je 0x4deeb
movl 0x4(%rsp), %eax
andb $0x1, %al
movzbl %al, %ecx
movzbl %bl, %eax
jmp 0x4dfe3
xorl %eax, %eax
xorl %ecx, %ecx
subl %ecx, %r14d
shlq $0x20, %r14
orq %rax, %r14
movq %r14, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1cfea(%rip), %rdi     # 0x6aff0
leaq 0xa017(%rip), %rsi      # 0x58024
callq 0x9490
movq %rax, %rdi
callq 0x91f0
movl $0x4, %edi
callq 0x9200
movl $0x1, (%rax)
movq 0x1cf07(%rip), %rsi     # 0x6af38
movq %rax, %rdi
xorl %edx, %edx
callq 0x98f0
nop