// File: BenLangmead[P]bowtie/pat.cpp
// Function: TabbedPatternSource::parse(Read&, Read&, unsigned long) const
bool TabbedPatternSource::parse(Read& ra, Read& rb, TReadId rdid) const {
	// Light parser (nextBatchFromFile) puts unparsed data
	// into Read& r, even when the read is paired.
	assert(ra.empty());
	assert(rb.empty());
	assert(!ra.readOrigBuf.empty()); // raw data for read/pair is here
	assert(rb.readOrigBuf.empty());
	int c = '\t';
	size_t cur = 0;
	const size_t buflen = ra.readOrigBuf.length();
	bool paired = false;

	// Loop over the two ends
	for(int endi = 0; endi < 2 && c == '\t'; endi++) {
		Read& r = ((endi == 0) ? ra : rb);
		assert(r.name.empty());
		// Parse name if (a) this is the first end, or
		// (b) this is tab6
		if(endi < 1 || secondName_) {
			// Parse read name
			c = ra.readOrigBuf[cur++];
			while(c != '\t' && cur < buflen) {
				r.name.append(c);
				c = ra.readOrigBuf[cur++];
			}
			assert_eq('\t', c);
			if(cur >= buflen) {
				return false; // record ended prematurely
			}
		} else if(endi > 0) {
			// if this is the second end and we're parsing
			// tab5, copy name from first end
			rb.name = ra.name; // not a deep copy
		}

		paired = endi > 0;

		// Parse sequence
		assert(r.patFw.empty());
		c = ra.readOrigBuf[cur++];
		int nchar = 0;
		while(c != '\t' && cur < buflen) {
			if(isalpha(c)) {
				assert_in(toupper(c), "ACGTN");
				if(nchar++ >= this->trim5_) {
					assert_neq(0, asc2dnacat[c]);
					r.patFw.append(asc2dna[c]);
				}
			}
			c = ra.readOrigBuf[cur++];
		}
		assert_eq('\t', c);
		if(cur >= buflen) {
			return false; // record ended prematurely
		}
		// record amt trimmed from 5' end due to --trim5
		r.trimmed5 = (int)(nchar - r.patFw.length());
		// record amt trimmed from 3' end due to --trim3
		r.trimmed3 = (int)(r.patFw.trimEnd(this->trim3_));

		// Parse qualities
		assert(r.qual.empty());
		c = ra.readOrigBuf[cur++];
		int nqual = 0;
		if (intQuals_) {
			int cur_int = 0;
			while(c != '\t' && c != '\n' && c != '\r' && cur < buflen) {
				cur_int *= 10;
				cur_int += (int)(c - '0');
				c = ra.readOrigBuf[cur++];
				if(c == ' ' || c == '\t' || c == '\n' || c == '\r') {
					char cadd = intToPhred33(cur_int, solQuals_);
					cur_int = 0;
					assert_geq(cadd, 33);
					if(++nqual > this->trim5_) {
						r.qual.append(cadd);
					}
				}
			}
		} else {
			while(c != '\t' && c != '\n' && c != '\r') {
				if(c == ' ') {
					wrongQualityFormat(r.name);
					return false;
				}
				char cadd = charToPhred33(c, solQuals_, phred64Quals_);
				if(++nqual > this->trim5_) {
					r.qual.append(cadd);
				}
				if(cur >= buflen) break;
				c = ra.readOrigBuf[cur++];
			}
		}
		if(nchar > nqual) {
			tooFewQualities(r.name);
			return false;
		} else if(nqual > nchar) {
			tooManyQualities(r.name);
			return false;
		}
		r.qual.trimEnd(this->trim3_);
		assert(c == '\t' || c == '\n' || c == '\r' || cur >= buflen);
		assert_eq(r.patFw.length(), r.qual.length());
	}
	ra.parsed = true;
	rb.parsed = paired;
	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x70(%rbp)
movl $0x9, -0x2c(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x18(%rbp), %rdi
addq $0x120, %rdi            # imm = 0x120
callq 0x82fb0
movq %rax, -0x40(%rbp)
movb $0x0, -0x41(%rbp)
movl $0x0, -0x48(%rbp)
xorl %eax, %eax
cmpl $0x2, -0x48(%rbp)
movb %al, -0x71(%rbp)
jge 0x81da6
cmpl $0x9, -0x2c(%rbp)
sete %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0x81db2
jmp 0x8224e
cmpl $0x0, -0x48(%rbp)
jne 0x81dc2
movq -0x18(%rbp), %rax
movq %rax, -0x80(%rbp)
jmp 0x81dca
movq -0x20(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpl $0x1, -0x48(%rbp)
jl 0x81de9
movq -0x70(%rbp), %rax
testb $0x1, 0x200a6(%rax)
je 0x81e8f
movq -0x18(%rbp), %rdi
addq $0x120, %rdi            # imm = 0x120
movq -0x38(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
callq 0x82fd0
movsbl (%rax), %eax
movl %eax, -0x2c(%rbp)
xorl %eax, %eax
cmpl $0x9, -0x2c(%rbp)
movb %al, -0x81(%rbp)
je 0x81e2d
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
setb %al
movb %al, -0x81(%rbp)
movb -0x81(%rbp), %al
testb $0x1, %al
jne 0x81e39
jmp 0x81e7a
movq -0x50(%rbp), %rdi
addq $0x150, %rdi            # imm = 0x150
movl -0x2c(%rbp), %eax
movb %al, -0x51(%rbp)
leaq -0x51(%rbp), %rsi
callq 0x82ff0
movq -0x18(%rbp), %rdi
addq $0x120, %rdi            # imm = 0x120
movq -0x38(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
callq 0x82fd0
movsbl (%rax), %eax
movl %eax, -0x2c(%rbp)
jmp 0x81e0e
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jb 0x81e8d
movb $0x0, -0x1(%rbp)
jmp 0x8226d
jmp 0x81eb2
cmpl $0x0, -0x48(%rbp)
jle 0x81eb0
movq -0x18(%rbp), %rsi
addq $0x150, %rsi            # imm = 0x150
movq -0x20(%rbp), %rdi
addq $0x150, %rdi            # imm = 0x150
callq 0x2e7e0
jmp 0x81eb2
cmpl $0x0, -0x48(%rbp)
setg %al
andb $0x1, %al
movb %al, -0x41(%rbp)
movq -0x18(%rbp), %rdi
addq $0x120, %rdi            # imm = 0x120
movq -0x38(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
callq 0x82fd0
movsbl (%rax), %eax
movl %eax, -0x2c(%rbp)
movl $0x0, -0x58(%rbp)
xorl %eax, %eax
cmpl $0x9, -0x2c(%rbp)
movb %al, -0x82(%rbp)
je 0x81f09
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
setb %al
movb %al, -0x82(%rbp)
movb -0x82(%rbp), %al
testb $0x1, %al
jne 0x81f15
jmp 0x81f80
movl -0x2c(%rbp), %edi
callq 0xaa30
cmpl $0x0, %eax
je 0x81f56
movq -0x70(%rbp), %rcx
movl -0x58(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x58(%rbp)
cmpl 0x18(%rcx), %eax
jl 0x81f54
movq -0x50(%rbp), %rdi
movslq -0x2c(%rbp), %rcx
leaq 0x2876b(%rip), %rax     # 0xaa6b0
movb (%rax,%rcx), %al
movb %al, -0x59(%rbp)
leaq -0x59(%rbp), %rsi
callq 0x83060
jmp 0x81f56
movq -0x18(%rbp), %rdi
addq $0x120, %rdi            # imm = 0x120
movq -0x38(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
callq 0x82fd0
movsbl (%rax), %eax
movl %eax, -0x2c(%rbp)
jmp 0x81eea
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jb 0x81f93
movb $0x0, -0x1(%rbp)
jmp 0x8226d
movslq -0x58(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x50(%rbp), %rdi
callq 0x2ef90
movq -0x90(%rbp), %rcx
movq %rax, %rdx
movq -0x70(%rbp), %rax
subq %rdx, %rcx
movl %ecx, %edx
movq -0x50(%rbp), %rcx
movl %edx, 0x1a8(%rcx)
movq -0x50(%rbp), %rdi
movslq 0x14(%rax), %rsi
callq 0x830d0
movl %eax, %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x1ac(%rax)
movq -0x18(%rbp), %rdi
addq $0x120, %rdi            # imm = 0x120
movq -0x38(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
callq 0x82fd0
movq %rax, %rcx
movq -0x70(%rbp), %rax
movsbl (%rcx), %ecx
movl %ecx, -0x2c(%rbp)
movl $0x0, -0x60(%rbp)
testb $0x1, 0x200a5(%rax)
je 0x8210e
movl $0x0, -0x64(%rbp)
xorl %eax, %eax
cmpl $0x9, -0x2c(%rbp)
movb %al, -0x91(%rbp)
je 0x8205f
xorl %eax, %eax
cmpl $0xa, -0x2c(%rbp)
movb %al, -0x91(%rbp)
je 0x8205f
xorl %eax, %eax
cmpl $0xd, -0x2c(%rbp)
movb %al, -0x91(%rbp)
je 0x8205f
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
setb %al
movb %al, -0x91(%rbp)
movb -0x91(%rbp), %al
testb $0x1, %al
jne 0x8206e
jmp 0x82109
imull $0xa, -0x64(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x2c(%rbp), %eax
subl $0x30, %eax
addl -0x64(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x18(%rbp), %rdi
addq $0x120, %rdi            # imm = 0x120
movq -0x38(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
callq 0x82fd0
movsbl (%rax), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x20, -0x2c(%rbp)
je 0x820be
cmpl $0x9, -0x2c(%rbp)
je 0x820be
cmpl $0xa, -0x2c(%rbp)
je 0x820be
cmpl $0xd, -0x2c(%rbp)
jne 0x82104
movq -0x70(%rbp), %rax
movl -0x64(%rbp), %edi
movb 0x200a3(%rax), %al
andb $0x1, %al
movzbl %al, %esi
callq 0x81a30
movq -0x70(%rbp), %rcx
movb %al, -0x65(%rbp)
movl $0x0, -0x64(%rbp)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
cmpl 0x18(%rcx), %eax
jle 0x82102
movq -0x50(%rbp), %rdi
addq $0x60, %rdi
leaq -0x65(%rbp), %rsi
callq 0x82ff0
jmp 0x82104
jmp 0x82024
jmp 0x821ed
jmp 0x82110
xorl %eax, %eax
cmpl $0x9, -0x2c(%rbp)
movb %al, -0x92(%rbp)
je 0x82139
xorl %eax, %eax
cmpl $0xa, -0x2c(%rbp)
movb %al, -0x92(%rbp)
je 0x82139
cmpl $0xd, -0x2c(%rbp)
setne %al
movb %al, -0x92(%rbp)
movb -0x92(%rbp), %al
testb $0x1, %al
jne 0x82148
jmp 0x821eb
cmpl $0x20, -0x2c(%rbp)
jne 0x82167
movq -0x50(%rbp), %rdi
addq $0x150, %rdi            # imm = 0x150
callq 0x80250
movb $0x0, -0x1(%rbp)
jmp 0x8226d
movq -0x70(%rbp), %rax
movl -0x2c(%rbp), %ecx
movb %cl, %dl
movb 0x200a3(%rax), %cl
movb 0x200a4(%rax), %al
andb $0x1, %cl
andb $0x1, %al
movsbl %dl, %edi
movzbl %cl, %esi
movzbl %al, %edx
callq 0x802f0
movq -0x70(%rbp), %rcx
movb %al, -0x66(%rbp)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
cmpl 0x18(%rcx), %eax
jle 0x821b5
movq -0x50(%rbp), %rdi
addq $0x60, %rdi
leaq -0x66(%rbp), %rsi
callq 0x82ff0
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jb 0x821c1
jmp 0x821eb
movq -0x18(%rbp), %rdi
addq $0x120, %rdi            # imm = 0x120
movq -0x38(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
callq 0x82fd0
movsbl (%rax), %eax
movl %eax, -0x2c(%rbp)
jmp 0x82110
jmp 0x821ed
movl -0x58(%rbp), %eax
cmpl -0x60(%rbp), %eax
jle 0x8220b
movq -0x50(%rbp), %rdi
addq $0x150, %rdi            # imm = 0x150
callq 0x80560
movb $0x0, -0x1(%rbp)
jmp 0x8226d
movl -0x60(%rbp), %eax
cmpl -0x58(%rbp), %eax
jle 0x82229
movq -0x50(%rbp), %rdi
addq $0x150, %rdi            # imm = 0x150
callq 0x805e0
movb $0x0, -0x1(%rbp)
jmp 0x8226d
jmp 0x8222b
movq -0x70(%rbp), %rax
movq -0x50(%rbp), %rdi
addq $0x60, %rdi
movslq 0x14(%rax), %rsi
callq 0x830d0
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x81d91
movq -0x18(%rbp), %rax
movb $0x1, 0x190(%rax)
movb -0x41(%rbp), %cl
movq -0x20(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x190(%rax)
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax,%rax)