// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r14
movq %rdi, 0x18(%rsp)
movq 0x140(%rsi), %r13
movq %rdx, 0x38(%rsp)
leaq 0x150(%rdx), %rax
movq %rax, 0x40(%rsp)
xorl %ebx, %ebx
pushq $0x9
popq %rbp
leaq 0xc(%rsp), %r12
xorl %eax, %eax
xorl %edx, %edx
movq %rsi, 0x20(%rsp)
cmpl $0x2, %edx
setae %cl
cmpl $0x9, %ebp
setne %sil
orb %cl, %sil
movb %sil, 0x28(%rsp)
jne 0x432c5
movq 0x38(%rsp), %rax
movl %edx, 0x34(%rsp)
testl %edx, %edx
cmoveq %r14, %rax
movq %rax, 0x10(%rsp)
je 0x43022
movq 0x18(%rsp), %rax
cmpb $0x1, 0x200a6(%rax)
jne 0x4306d
movq 0x128(%r14), %r15
leaq (%r15,%rbx), %rax
movq 0x10(%rsp), %rcx
leaq 0x150(%rcx), %rbp
incq %rbx
movb (%rax), %al
cmpb $0x9, %al
je 0x43063
cmpq %r13, %rbx
jae 0x43063
movb %al, 0xc(%rsp)
movq %rbp, %rdi
movq %r12, %rsi
callq 0x43902
movq 0x128(%r14), %r15
leaq (%r15,%rbx), %rax
jmp 0x43039
cmpq %r13, %rbx
jb 0x4308d
jmp 0x432da
movq 0x158(%r14), %rsi
movq 0x170(%r14), %rdx
movq 0x40(%rsp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movq 0x128(%r14), %r15
leaq (%r15,%rbx), %rax
incq %rbx
xorl %r12d, %r12d
movsbl (%rax), %ebp
cmpl $0x9, %ebp
je 0x430fc
cmpq %r13, %rbx
jae 0x430fc
movl %ebp, %edi
callq 0x9820
testl %eax, %eax
je 0x430ed
leal 0x1(%r12), %r14d
movq 0x18(%rsp), %rax
cmpl 0x18(%rax), %r12d
jl 0x430f0
movslq %ebp, %rax
leaq 0x21497(%rip), %rcx     # 0x64560
movb (%rcx,%rax), %al
movb %al, 0xf(%rsp)
movq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rsi
callq 0x43948
movq 0x20(%rsp), %rax
movq 0x128(%rax), %r15
jmp 0x430f0
movl %r12d, %r14d
leaq (%r15,%rbx), %rax
incq %rbx
movl %r14d, %r12d
jmp 0x43097
cmpq %r13, %rbx
jae 0x432da
movq 0x10(%rsp), %r8
movq 0x20(%r8), %rax
movl %r12d, %ecx
subl %eax, %ecx
movl %ecx, 0x1a8(%r8)
movq 0x18(%rsp), %rdi
movslq 0x14(%rdi), %rcx
movq %rax, %rdx
subq %rcx, %rdx
movl $0x0, %esi
cmovaeq %rdx, %rsi
cmovbq %rax, %rcx
movq %rsi, 0x20(%r8)
movl %ecx, 0x1ac(%r8)
movq 0x20(%rsp), %rax
movq 0x128(%rax), %rax
movsbl (%rax,%rbx), %ebp
incq %rbx
leaq 0x60(%r8), %rax
movq %rax, 0x28(%rsp)
cmpb $0x0, 0x200a5(%rdi)
movabsq $0x100002600, %r15      # imm = 0x100002600
je 0x43203
xorl %r14d, %r14d
movq 0x20(%rsp), %rax
movq 0x128(%rax), %rax
xorl %edi, %edi
cmpl $0xd, %ebp
ja 0x43198
movl $0x2600, %ecx           # imm = 0x2600
btl %ebp, %ecx
jb 0x43279
cmpq %r13, %rbx
jae 0x43279
imull $0xa, %edi, %ecx
leal (%rcx,%rbp), %edi
addl $-0x30, %edi
movzbl (%rax,%rbx), %ecx
incq %rbx
movsbl %cl, %ebp
cmpq $0x20, %rcx
ja 0x43185
btq %rcx, %r15
jae 0x43185
movl %r14d, %r15d
movq 0x18(%rsp), %r14
movzbl 0x200a3(%r14), %esi
callq 0x42dd8
movb %al, 0xe(%rsp)
cmpl 0x18(%r14), %r15d
movl %r15d, %r14d
jl 0x431f1
movq 0x28(%rsp), %rdi
leaq 0xe(%rsp), %rsi
callq 0x43902
incl %r14d
movabsq $0x100002600, %r15      # imm = 0x100002600
jmp 0x43177
xorl %r14d, %r14d
leal -0x9(%rbp), %eax
cmpl $0x2, %eax
jb 0x43279
cmpl $0xd, %ebp
je 0x43279
cmpl $0x20, %ebp
je 0x432ed
movl %r14d, %r15d
movq 0x18(%rsp), %r14
movzbl 0x200a3(%r14), %esi
movzbl 0x200a4(%r14), %edx
movsbl %bpl, %edi
callq 0x41f2d
movb %al, 0xd(%rsp)
cmpl 0x18(%r14), %r15d
movl %r15d, %r14d
jl 0x43259
movq 0x28(%rsp), %rdi
leaq 0xd(%rsp), %rsi
callq 0x43902
cmpq %r13, %rbx
jae 0x43276
movq 0x20(%rsp), %rax
movq 0x128(%rax), %rax
movsbl (%rax,%rbx), %ebp
incq %rbx
incl %r14d
jmp 0x43206
incl %r14d
cmpl %r14d, %r12d
jg 0x43303
movq 0x20(%rsp), %r14
leaq 0xc(%rsp), %r12
jl 0x432fe
movq 0x18(%rsp), %rax
movslq 0x14(%rax), %rax
movq 0x10(%rsp), %rdx
movq 0x80(%rdx), %rcx
subq %rax, %rcx
movl $0x0, %eax
cmovaeq %rcx, %rax
movq %rax, 0x80(%rdx)
movl 0x34(%rsp), %ecx
movl %ecx, %eax
incl %ecx
movl %ecx, %edx
jmp 0x42fe3
movb $0x1, 0x190(%r14)
andb $0x1, %al
movq 0x38(%rsp), %rcx
movb %al, 0x190(%rcx)
movb 0x28(%rsp), %al
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %rdi
addq $0x150, %rdi            # imm = 0x150
callq 0x41eb6
callq 0x420ef
movq 0x10(%rsp), %rdi
addq $0x150, %rdi            # imm = 0x150
callq 0x4208f