// File: BenLangmead[P]bowtie/pat.cpp
// Function: RawPatternSource::nextBatchFromFile(PerThreadReadBuf&, bool, unsigned long)
pair<bool, int> RawPatternSource::nextBatchFromFile(
	PerThreadReadBuf& pt,
	bool batch_a,
	size_t readi)
{
	int c = getc_wrapper();
	while(c >= 0 && (c == '\n' || c == '\r')) {
		c = getc_wrapper();
	}
	EList<Read>& readbuf = batch_a ? pt.bufa_ : pt.bufb_;
	// Read until we run out of input or until we've filled the buffer
	for(; readi < pt.max_buf_ && c >= 0; readi++) {
		readbuf[readi].readOrigBuf.clear();
		while(c >= 0 && (c == '\n' || c == '\r')) {
			c = getc_wrapper();
		}
		while(c >= 0 && (c != '\n' && c != '\r')) {
			readbuf[readi].readOrigBuf.append(c);
			c = getc_wrapper();
		}
                if (c == '\n') {
			readbuf[readi].readOrigBuf.append(c);
			c = getc_wrapper();
			if (c == '\r')
				readbuf[readi].readOrigBuf.append(c);
			else {
				ungetc_wrapper(c);
				c = '\n'; // reset to last character seen
			}
                }
        }
	while (readi > 0 && readbuf[readi-1].readOrigBuf.length() == 0)
		readi--;
	return make_pair(c < 0, readi);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %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), %rdi
movq %rdi, -0x60(%rbp)
callq 0x83130
movl %eax, -0x2c(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x2c(%rbp)
movb %al, -0x61(%rbp)
jl 0x822d4
movb $0x1, %al
cmpl $0xa, -0x2c(%rbp)
movb %al, -0x62(%rbp)
je 0x822ce
cmpl $0xd, -0x2c(%rbp)
sete %al
movb %al, -0x62(%rbp)
movb -0x62(%rbp), %al
movb %al, -0x61(%rbp)
movb -0x61(%rbp), %al
testb $0x1, %al
jne 0x822dd
jmp 0x822eb
movq -0x60(%rbp), %rdi
callq 0x83130
movl %eax, -0x2c(%rbp)
jmp 0x822ae
testb $0x1, -0x19(%rbp)
je 0x822ff
movq -0x18(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x70(%rbp)
jmp 0x8230b
movq -0x18(%rbp), %rax
addq $0x28, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %rdx
xorl %eax, %eax
cmpq (%rdx), %rcx
movb %al, -0x71(%rbp)
jae 0x8232f
cmpl $0x0, -0x2c(%rbp)
setge %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0x8233b
jmp 0x82487
movq -0x38(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x36630
movq %rax, %rdi
addq $0x120, %rdi            # imm = 0x120
callq 0x359e0
xorl %eax, %eax
cmpl $0x0, -0x2c(%rbp)
movb %al, -0x72(%rbp)
jl 0x8237d
movb $0x1, %al
cmpl $0xa, -0x2c(%rbp)
movb %al, -0x73(%rbp)
je 0x82377
cmpl $0xd, -0x2c(%rbp)
sete %al
movb %al, -0x73(%rbp)
movb -0x73(%rbp), %al
movb %al, -0x72(%rbp)
movb -0x72(%rbp), %al
testb $0x1, %al
jne 0x82386
jmp 0x82394
movq -0x60(%rbp), %rdi
callq 0x83130
movl %eax, -0x2c(%rbp)
jmp 0x82357
jmp 0x82396
xorl %eax, %eax
cmpl $0x0, -0x2c(%rbp)
movb %al, -0x74(%rbp)
jl 0x823bc
xorl %eax, %eax
cmpl $0xa, -0x2c(%rbp)
movb %al, -0x75(%rbp)
je 0x823b6
cmpl $0xd, -0x2c(%rbp)
setne %al
movb %al, -0x75(%rbp)
movb -0x75(%rbp), %al
movb %al, -0x74(%rbp)
movb -0x74(%rbp), %al
testb $0x1, %al
jne 0x823c5
jmp 0x823f9
movq -0x38(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x36630
movq %rax, %rdi
addq $0x120, %rdi            # imm = 0x120
movl -0x2c(%rbp), %eax
movb %al, -0x39(%rbp)
leaq -0x39(%rbp), %rsi
callq 0x831e0
movq -0x60(%rbp), %rdi
callq 0x83130
movl %eax, -0x2c(%rbp)
jmp 0x82396
cmpl $0xa, -0x2c(%rbp)
jne 0x82474
movq -0x38(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x36630
movq %rax, %rdi
addq $0x120, %rdi            # imm = 0x120
movl -0x2c(%rbp), %eax
movb %al, -0x3a(%rbp)
leaq -0x3a(%rbp), %rsi
callq 0x831e0
movq -0x60(%rbp), %rdi
callq 0x83130
movl %eax, -0x2c(%rbp)
cmpl $0xd, -0x2c(%rbp)
jne 0x8245f
movq -0x38(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x36630
movq %rax, %rdi
addq $0x120, %rdi            # imm = 0x120
movl -0x2c(%rbp), %eax
movb %al, -0x3b(%rbp)
leaq -0x3b(%rbp), %rsi
callq 0x831e0
jmp 0x82472
movq -0x60(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x83290
movl $0xa, -0x2c(%rbp)
jmp 0x82474
jmp 0x82476
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x82313
jmp 0x82489
xorl %eax, %eax
cmpq $0x0, -0x28(%rbp)
movb %al, -0x76(%rbp)
jbe 0x824bf
movq -0x38(%rbp), %rdi
movq -0x28(%rbp), %rsi
subq $0x1, %rsi
callq 0x36630
movq %rax, %rdi
addq $0x120, %rdi            # imm = 0x120
callq 0x82fb0
cmpq $0x0, %rax
sete %al
movb %al, -0x76(%rbp)
movb -0x76(%rbp), %al
testb $0x1, %al
jne 0x824c8
jmp 0x824d6
movq -0x28(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x82489
cmpl $0x0, -0x2c(%rbp)
setl %al
andb $0x1, %al
movb %al, -0x51(%rbp)
leaq -0x51(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x82f80
movb %al, -0x50(%rbp)
movq %rdx, -0x48(%rbp)
leaq -0x8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x82bd0
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq