// File: /workspace/github_cpp_makefile_star2_O1/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, 0x8(%rsp)
movq 0x140(%rsi), %rbp
movq %rdx, 0x30(%rsp)
leaq 0x150(%rdx), %rax
movq %rax, 0x38(%rsp)
movq $0x0, 0x28(%rsp)
xorl %eax, %eax
xorl %ebx, %ebx
xorl %r15d, %r15d
movq 0x30(%rsp), %rcx
movq %rax, 0x18(%rsp)
testl %eax, %eax
cmoveq %r14, %rcx
movq %rcx, 0x10(%rsp)
je 0x4e681
movq 0x8(%rsp), %rax
cmpb $0x1, 0x200a6(%rax)
jne 0x4e6ef
movq 0x128(%r14), %rax
movb (%rax,%r15), %al
incq %r15
cmpb $0x9, %al
setne %dl
cmpq %rbp, %r15
setb %cl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x4e6db
movq 0x10(%rsp), %rcx
leaq 0x150(%rcx), %r13
movb %al, 0x7(%rsp)
movq %r13, %rdi
leaq 0x7(%rsp), %rsi
callq 0x4f02e
movq 0x128(%r14), %rax
movb (%rax,%r15), %al
incq %r15
cmpq %rbp, %r15
setb %cl
cmpb $0x9, %al
je 0x4e6db
cmpq %rbp, %r15
jb 0x4e6ad
testb %cl, %cl
jne 0x4e708
movsbl %al, %r13d
xorl %ecx, %ecx
movq 0x18(%rsp), %rax
jmp 0x4e99e
movq 0x158(%r14), %rsi
movq 0x170(%r14), %rdx
movq 0x38(%rsp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movq 0x128(%r14), %rax
movsbl (%rax,%r15), %r13d
cmpl $0x9, %r13d
setne %dl
leaq 0x1(%r15), %rax
cmpq %rbp, %rax
setb %cl
andb %cl, %dl
xorl %ebx, %ebx
cmpb $0x1, %dl
jne 0x4e797
xorl %ebx, %ebx
movl %r13d, %edi
callq 0x9800
testl %eax, %eax
je 0x4e76e
leal 0x1(%rbx), %r12d
movq 0x8(%rsp), %rax
cmpl 0x18(%rax), %ebx
jl 0x4e76b
movsbq %r13b, %rax
leaq 0x1edfb(%rip), %rcx     # 0x6d550
movb (%rcx,%rax), %al
movb %al, 0x6(%rsp)
movq 0x10(%rsp), %rdi
leaq 0x6(%rsp), %rsi
callq 0x4f074
movl %r12d, %ebx
movq 0x128(%r14), %rax
movsbl 0x1(%rax,%r15), %r13d
leaq 0x2(%r15), %rax
cmpq %rbp, %rax
setb %cl
incq %r15
cmpl $0x9, %r13d
je 0x4e793
cmpq %rbp, %rax
jb 0x4e730
leaq 0x1(%r15), %rax
testb %cl, %cl
je 0x4e8b8
movq 0x10(%rsp), %r9
movq 0x20(%r9), %rcx
movl %ebx, %edx
subl %ecx, %edx
movl %edx, 0x1a8(%r9)
movq 0x8(%rsp), %r8
movslq 0x14(%r8), %rdx
movq %rcx, %rsi
subq %rdx, %rsi
movl $0x0, %edi
cmovaeq %rsi, %rdi
cmovbq %rcx, %rdx
movq %rdi, 0x20(%r9)
movl %edx, 0x1ac(%r9)
addq $0x2, %r15
movq 0x128(%r14), %rcx
movsbl (%rcx,%rax), %r13d
leaq 0x60(%r9), %rax
movq %rax, 0x20(%rsp)
cmpb $0x0, 0x200a5(%r8)
je 0x4e8bf
xorl %r12d, %r12d
movq 0x128(%r14), %rcx
xorl %eax, %eax
cmpl $0xd, %r13d
ja 0x4e822
movl $0x2600, %edx           # imm = 0x2600
btl %r13d, %edx
jb 0x4e958
cmpq %rbp, %r15
jae 0x4e958
leal (%rax,%rax,4), %eax
leal -0x30(%r13,%rax,2), %eax
movzbl (%rcx,%r15), %edx
incq %r15
movsbl %dl, %r13d
cmpq $0x20, %rdx
ja 0x4e80d
movabsq $0x100002600, %rsi      # imm = 0x100002600
btq %rdx, %rsi
jae 0x4e80d
movq 0x8(%rsp), %rcx
cmpb $0x1, 0x200a3(%rcx)
jne 0x4e87a
xorl %ecx, %ecx
cmpl $-0xa, %eax
jl 0x4e887
addl $0xa, %eax
leaq 0x1f38c(%rip), %rcx     # 0x6dc00
movzbl (%rcx,%rax), %ecx
jmp 0x4e887
cmpl $0x5d, %eax
movl $0x5d, %ecx
cmovgel %ecx, %eax
movl %eax, %ecx
testl %ecx, %ecx
js 0x4ea15
addb $0x21, %cl
movb %cl, 0x5(%rsp)
movq 0x8(%rsp), %rax
cmpl 0x18(%rax), %r12d
jl 0x4e8b0
movq 0x20(%rsp), %rdi
leaq 0x5(%rsp), %rsi
callq 0x4f02e
incl %r12d
jmp 0x4e804
xorl %ecx, %ecx
jmp 0x4e994
xorl %r12d, %r12d
movq %rbx, 0x40(%rsp)
leal -0x9(%r13), %eax
cmpl $0x2, %eax
jb 0x4e958
cmpl $0xd, %r13d
je 0x4e958
cmpl $0x20, %r13d
je 0x4e9ee
movq %r14, %rbx
movl %r12d, %r14d
movq 0x8(%rsp), %r12
movzbl 0x200a3(%r12), %esi
movzbl 0x200a4(%r12), %edx
movsbl %r13b, %edi
callq 0x4d361
movb %al, 0x4(%rsp)
cmpl 0x18(%r12), %r14d
movl %r14d, %r12d
jl 0x4e927
movq 0x20(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x4f02e
movq %r15, %rax
cmpq %rbp, %r15
movq %rbx, %r14
jae 0x4e942
leaq 0x1(%r15), %rax
movq 0x128(%r14), %rcx
movsbl (%rcx,%r15), %r13d
incl %r12d
cmpq %rbp, %r15
movq %rax, %r15
movq 0x40(%rsp), %rbx
jb 0x4e8c7
jmp 0x4e95b
movq %r15, %rax
cmpl %r12d, %ebx
jg 0x4e9ff
jl 0x4ea10
movq 0x8(%rsp), %rcx
movslq 0x14(%rcx), %rcx
movq 0x10(%rsp), %rsi
movq 0x80(%rsi), %rdx
subq %rcx, %rdx
movl $0x0, %ecx
cmovaeq %rdx, %rcx
movq %rcx, 0x80(%rsi)
movb $0x1, %cl
movq %rax, %r15
movq 0x18(%rsp), %rax
movl %eax, %ebx
testb %cl, %cl
je 0x4e9ba
xorl $0x9, %r13d
orl %eax, %r13d
leal 0x1(%rax), %eax
setne %cl
movq %rcx, 0x28(%rsp)
je 0x4e65c
movq 0x28(%rsp), %rcx
testb $0x1, %cl
je 0x4e9da
movb $0x1, 0x190(%r14)
andb $0x1, %bl
movq 0x30(%rsp), %rax
movb %bl, 0x190(%rax)
andb $0x1, %cl
movl %ecx, %eax
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 0x4d2e8
movq 0x10(%rsp), %rdi
addq $0x150, %rdi            # imm = 0x150
callq 0x4d4c9
callq 0x4d52b
movq 0x1c5d4(%rip), %rdi     # 0x6aff0
movl %ecx, %ebx
leaq 0x99b7(%rip), %rsi      # 0x583dc
callq 0x9490
movq %rax, %rdi
movl %ebx, %esi
callq 0x9910
leaq 0x8b53(%rip), %rsi      # 0x5758e
movq %rax, %rdi
callq 0x9490
movq %rax, %rdi
callq 0x91f0
movl $0x4, %edi
callq 0x9200
movl $0x1, (%rax)
movq 0x1c4d6(%rip), %rsi     # 0x6af38
movq %rax, %rdi
xorl %edx, %edx
callq 0x98f0