// File: /workspace/github_cpp_makefile_star2_O2/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 $0x48, %rsp
movq %rcx, %rbx
movl %edx, %ebp
leaq 0x8(%rsi), %rax
movq %rsi, 0x40(%rsp)
leaq 0x28(%rsi), %rcx
testl %edx, %edx
movq %rcx, 0x28(%rsp)
movq %rax, 0x30(%rsp)
cmovneq %rax, %rcx
movq %rcx, 0x18(%rsp)
movq %rdi, %r15
xorl %r12d, %r12d
cmpb $0x1, 0x200a3(%rdi)
jne 0x428f3
movq %r15, %rdi
callq 0x4398e
cmpl $0xa, %eax
je 0x428a4
cmpl $0xd, %eax
je 0x428a4
cmpl $0x40, %eax
jne 0x42a28
movb $0x0, 0x200a3(%r15)
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
imulq $0x268, %rbx, %rcx      # imm = 0x268
leaq (%rax,%rcx), %rdi
addq $0x120, %rdi            # imm = 0x120
leaq 0x13(%rsp), %rsi
movb $0x40, (%rsi)
callq 0x439de
pushq $0x40
popq %r12
movl %ebp, 0x14(%rsp)
xorl %r14d, %r14d
leaq 0xb(%rsp), %r13
movl $0x0, 0xc(%rsp)
imulq $0x268, %rbx, %rax      # imm = 0x268
movq %rax, 0x38(%rsp)
movq %rbx, 0x20(%rsp)
movq 0x40(%rsp), %rax
cmpq (%rax), %rbx
jae 0x42a03
testb $0x1, %r14b
jne 0x42a03
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x38(%rsp), %rcx
leaq (%rax,%rcx), %rbp
addq $0x120, %rbp            # imm = 0x120
pushq $0x4
popq %rbx
testl %ebx, %ebx
je 0x42996
movq %r15, %rdi
callq 0x4398e
movl %eax, %r12d
testl %eax, %eax
sets %al
movl %r12d, %r14d
shrl $0x1f, %r14d
cmpl $0x1, %ebx
sete %cl
cmpl $0xa, %r12d
je 0x4297e
andb %al, %cl
jne 0x4297e
testl %r12d, %r12d
jns 0x42984
jmp 0x429a6
decl %ebx
pushq $0xa
popq %r12
movb %r12b, 0xb(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
callq 0x439de
jmp 0x4294c
testl %r12d, %r12d
movq 0x20(%rsp), %rbx
jle 0x42918
jmp 0x429c4
cmpl $0x4, %ebx
movl 0xc(%rsp), %ecx
movzbl %cl, %ecx
pushq $0x1
popq %rax
cmovnel %eax, %ecx
movl %ecx, 0xc(%rsp)
movq 0x20(%rsp), %rbx
jmp 0x42918
cmpb $0x1, 0x200a7(%r15)
je 0x429d6
incq %rbx
jmp 0x42907
movl 0x14(%rsp), %ecx
movl %ecx, %eax
xorb $0x1, %al
testb $0x1, %cl
movq 0x30(%rsp), %rcx
cmovneq 0x28(%rsp), %rcx
movq %rcx, 0x18(%rsp)
movzbl %al, %ecx
andl $0x1, %ecx
addq %rcx, %rbx
movl %eax, 0x14(%rsp)
jmp 0x42907
movl 0xc(%rsp), %eax
andb $0x1, %al
movzbl %al, %eax
subl %eax, %ebx
shlq $0x20, %rbx
movzbl %r14b, %eax
orq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1f5c1(%rip), %rdi     # 0x61ff0
leaq 0x95d4(%rip), %rsi      # 0x4c00a
callq 0x94e0
movq %rax, %rdi
callq 0x9210
pushq $0x4
popq %rdi
callq 0x9220
movl $0x1, (%rax)
movq 0x1f500(%rip), %rsi     # 0x61f58
movq %rax, %rdi
xorl %edx, %edx
callq 0x9910