// File: BenLangmead[P]bowtie/pat.cpp
// Function: FastaPatternSource::nextBatchFromFile(PerThreadReadBuf&, bool, unsigned long)
pair<bool, int> FastaPatternSource::nextBatchFromFile(
	PerThreadReadBuf& pt,
	bool batch_a,
	size_t readi)
{
	int c;
	EList<Read>& readbuf = batch_a ? pt.bufa_ : pt.bufb_;
	if(first_) {
		c = getc_wrapper();
		if(c == EOF) {
			return make_pair(true, 0);
		}
		while(c == '\r' || c == '\n') {
			c = getc_wrapper();
		}
		if(c != '>') {
			cerr << "Error: reads file does not look like a FASTA file" << endl;
			throw 1;
		}
		first_ = false;
	}
	bool done = false;
	// Read until we run out of input or until we've filled the buffer
	for(; readi < pt.max_buf_ && !done; readi++) {
		readbuf[readi].readOrigBuf.append('>');
		while(true) {
			c = getc_wrapper();
			if(c < 0 || c == '>') {
				done = c < 0;
				break;
			}
			readbuf[readi].readOrigBuf.append(c);
		}
	}
	// Immediate EOF case
	if(done && readbuf[readi-1].readOrigBuf.length() == 1) {
		readi--;
	}
	return make_pair(done, readi);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movb %dl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x60(%rbp)
testb $0x1, -0x19(%rbp)
je 0x80687
movq -0x18(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x68(%rbp)
jmp 0x80693
movq -0x18(%rbp), %rax
addq $0x28, %rax
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rax
movq -0x68(%rbp), %rcx
movq %rcx, -0x38(%rbp)
testb $0x1, 0x200a3(%rax)
je 0x80763
movq -0x60(%rbp), %rdi
callq 0x83130
movl %eax, -0x2c(%rbp)
cmpl $-0x1, -0x2c(%rbp)
jne 0x806df
movb $0x1, -0x39(%rbp)
movl $0x0, -0x40(%rbp)
leaq -0x39(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x82b20
movq %rax, -0x8(%rbp)
jmp 0x8086b
jmp 0x806e1
movb $0x1, %al
cmpl $0xd, -0x2c(%rbp)
movb %al, -0x69(%rbp)
je 0x806f6
cmpl $0xa, -0x2c(%rbp)
sete %al
movb %al, -0x69(%rbp)
movb -0x69(%rbp), %al
testb $0x1, %al
jne 0x806ff
jmp 0x8070d
movq -0x60(%rbp), %rdi
callq 0x83130
movl %eax, -0x2c(%rbp)
jmp 0x806e1
cmpl $0x3e, -0x2c(%rbp)
je 0x80758
movq 0x278d6(%rip), %rdi     # 0xa7ff0
leaq 0xdc17(%rip), %rsi      # 0x8e338
callq 0xa5d0
movq %rax, %rdi
movq 0x27838(%rip), %rsi     # 0xa7f68
callq 0xa640
movl $0x4, %edi
callq 0xa290
movq %rax, %rdi
movl $0x1, (%rdi)
movq 0x27801(%rip), %rsi     # 0xa7f50
xorl %eax, %eax
movl %eax, %edx
callq 0xab10
movq -0x60(%rbp), %rax
movb $0x0, 0x200a3(%rax)
movb $0x0, -0x41(%rbp)
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %rdx
xorl %eax, %eax
cmpq (%rdx), %rcx
movb %al, -0x6a(%rbp)
jae 0x80781
movb -0x41(%rbp), %al
xorb $-0x1, %al
movb %al, -0x6a(%rbp)
movb -0x6a(%rbp), %al
testb $0x1, %al
jne 0x8078d
jmp 0x80812
movq -0x38(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x36630
movq %rax, %rdi
addq $0x120, %rdi            # imm = 0x120
movb $0x3e, -0x42(%rbp)
leaq -0x42(%rbp), %rsi
callq 0x831e0
movq -0x60(%rbp), %rdi
callq 0x83130
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jl 0x807c9
cmpl $0x3e, -0x2c(%rbp)
jne 0x807d7
cmpl $0x0, -0x2c(%rbp)
setl %al
andb $0x1, %al
movb %al, -0x41(%rbp)
jmp 0x807ff
movq -0x38(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x36630
movq %rax, %rdi
addq $0x120, %rdi            # imm = 0x120
movl -0x2c(%rbp), %eax
movb %al, -0x43(%rbp)
leaq -0x43(%rbp), %rsi
callq 0x831e0
jmp 0x807b1
jmp 0x80801
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x80767
testb $0x1, -0x41(%rbp)
je 0x8084a
movq -0x38(%rbp), %rdi
movq -0x28(%rbp), %rsi
subq $0x1, %rsi
callq 0x36630
movq %rax, %rdi
addq $0x120, %rdi            # imm = 0x120
callq 0x82fb0
cmpq $0x1, %rax
jne 0x8084a
movq -0x28(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x28(%rbp)
leaq -0x41(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x82ba0
movb %al, -0x58(%rbp)
movq %rdx, -0x50(%rbp)
leaq -0x8(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x82bd0
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)