// File: BenLangmead[P]bowtie/pat.cpp
// Function: FastqPatternSource::parse(Read&, Read&, unsigned long) const
bool FastqPatternSource::parse(Read &r, Read& rb, TReadId rdid) const {
	// We assume the light parser has put the raw data for the separate ends
	// into separate Read objects.  That doesn't have to be the case, but
	// that's how we've chosen to do it for FastqPatternSource
	assert(!r.readOrigBuf.empty());
	assert(r.empty());
	int c;
	size_t cur = 1;
	const size_t buflen = r.readOrigBuf.length();

	// Parse read name
	assert(r.name.empty());
	while(true) {
		assert_lt(cur, buflen);
		c = r.readOrigBuf[cur++];
		if(c == '\n' || c == '\r') {
			do {
				c = r.readOrigBuf[cur++];
			} while(c == '\n' || c == '\r');
			break;
		}
		r.name.append(c);
	}

	// Parse sequence
	int nchar = 0;
	assert(r.patFw.empty());
	while(c != '+' && cur < buflen) {
		if(c == '.') {
			c = 'N';
		}
		if(isalpha(c)) {
			// If it's past the 5'-end trim point
			if(nchar++ >= this->trim5_) {
				r.patFw.append(asc2dna[c]);
			}
		}
		assert_lt(cur, buflen);
		c = r.readOrigBuf[cur++];
	}
	// 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_));

	assert_eq('+', c);
	do {
		assert_lt(cur, buflen);
		c = r.readOrigBuf[cur++];
	} while(c != '\n' && c != '\r');
	while(cur < buflen && (c == '\n' || c == '\r')) {
		c = r.readOrigBuf[cur++];
	}

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

	// Set up a default name if one hasn't been set
	if(r.name.empty()) {
		char cbuf[20];
		itoa10<TReadId>(static_cast<TReadId>(rdid), cbuf);
		r.name.install(cbuf);
	}
	r.parsed = true;
	if(!rb.parsed && rb.readOrigBuf.length() > 0) {
		return parse(rb, r, rdid);
	}
	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x80(%rbp)
movq $0x1, -0x38(%rbp)
movq -0x18(%rbp), %rdi
addq $0x120, %rdi            # imm = 0x120
callq 0x82fb0
movq %rax, -0x40(%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 $0xa, -0x2c(%rbp)
je 0x81490
cmpl $0xd, -0x2c(%rbp)
jne 0x814de
jmp 0x81492
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)
movb $0x1, %al
cmpl $0xa, -0x2c(%rbp)
movb %al, -0x81(%rbp)
je 0x814d2
cmpl $0xd, -0x2c(%rbp)
sete %al
movb %al, -0x81(%rbp)
movb -0x81(%rbp), %al
testb $0x1, %al
jne 0x81492
jmp 0x814fd
movq -0x18(%rbp), %rdi
addq $0x150, %rdi            # imm = 0x150
movl -0x2c(%rbp), %eax
movb %al, -0x41(%rbp)
leaq -0x41(%rbp), %rsi
callq 0x82ff0
jmp 0x8145f
movl $0x0, -0x48(%rbp)
xorl %eax, %eax
cmpl $0x2b, -0x2c(%rbp)
movb %al, -0x82(%rbp)
je 0x81523
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
setb %al
movb %al, -0x82(%rbp)
movb -0x82(%rbp), %al
testb $0x1, %al
jne 0x8152f
jmp 0x815a7
cmpl $0x2e, -0x2c(%rbp)
jne 0x8153c
movl $0x4e, -0x2c(%rbp)
movl -0x2c(%rbp), %edi
callq 0xaa30
cmpl $0x0, %eax
je 0x8157d
movq -0x80(%rbp), %rcx
movl -0x48(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x48(%rbp)
cmpl 0x18(%rcx), %eax
jl 0x8157b
movq -0x18(%rbp), %rdi
movslq -0x2c(%rbp), %rcx
leaq 0x29144(%rip), %rax     # 0xaa6b0
movb (%rax,%rcx), %al
movb %al, -0x49(%rbp)
leaq -0x49(%rbp), %rsi
callq 0x83060
jmp 0x8157d
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 0x81504
movslq -0x48(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x18(%rbp), %rdi
callq 0x2ef90
movq -0x90(%rbp), %rcx
movq %rax, %rdx
movq -0x80(%rbp), %rax
subq %rdx, %rcx
movl %ecx, %edx
movq -0x18(%rbp), %rcx
movl %edx, 0x1a8(%rcx)
movq -0x18(%rbp), %rdi
movslq 0x14(%rax), %rsi
callq 0x830d0
movl %eax, %ecx
movq -0x18(%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
movsbl (%rax), %eax
movl %eax, -0x2c(%rbp)
xorl %eax, %eax
cmpl $0xa, -0x2c(%rbp)
movb %al, -0x91(%rbp)
je 0x81631
cmpl $0xd, -0x2c(%rbp)
setne %al
movb %al, -0x91(%rbp)
movb -0x91(%rbp), %al
testb $0x1, %al
jne 0x815f1
jmp 0x8163d
movq -0x38(%rbp), %rcx
xorl %eax, %eax
cmpq -0x40(%rbp), %rcx
movb %al, -0x92(%rbp)
jae 0x81676
movb $0x1, %al
cmpl $0xa, -0x2c(%rbp)
movb %al, -0x93(%rbp)
je 0x8166a
cmpl $0xd, -0x2c(%rbp)
sete %al
movb %al, -0x93(%rbp)
movb -0x93(%rbp), %al
movb %al, -0x92(%rbp)
movb -0x92(%rbp), %al
testb $0x1, %al
jne 0x81682
jmp 0x816a9
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 0x8163d
movq -0x80(%rbp), %rax
movl $0x0, -0x50(%rbp)
testb $0x1, 0x200a6(%rax)
je 0x817cb
movl $0x0, -0x54(%rbp)
xorl %eax, %eax
cmpl $0x9, -0x2c(%rbp)
movb %al, -0x94(%rbp)
je 0x816f1
xorl %eax, %eax
cmpl $0xa, -0x2c(%rbp)
movb %al, -0x94(%rbp)
je 0x816f1
cmpl $0xd, -0x2c(%rbp)
setne %al
movb %al, -0x94(%rbp)
movb -0x94(%rbp), %al
testb $0x1, %al
jne 0x81700
jmp 0x817c6
imull $0xa, -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x2c(%rbp), %eax
subl $0x30, %eax
addl -0x54(%rbp), %eax
movl %eax, -0x54(%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 0x81750
cmpl $0x9, -0x2c(%rbp)
je 0x81750
cmpl $0xa, -0x2c(%rbp)
je 0x81750
cmpl $0xd, -0x2c(%rbp)
jne 0x817c1
movq -0x80(%rbp), %rax
movl -0x54(%rbp), %edi
movb 0x200a4(%rax), %al
andb $0x1, %al
movzbl %al, %esi
callq 0x81a30
movb %al, -0x55(%rbp)
movl $0x0, -0x54(%rbp)
cmpl $0x20, -0x2c(%rbp)
jne 0x8179c
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)
movq -0x80(%rbp), %rcx
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
cmpl 0x18(%rcx), %eax
jle 0x817bf
movq -0x18(%rbp), %rdi
addq $0x60, %rdi
leaq -0x55(%rbp), %rsi
callq 0x82ff0
jmp 0x817c1
jmp 0x816c8
jmp 0x81990
movq -0x80(%rbp), %rax
movl -0x2c(%rbp), %ecx
movb %cl, %dl
movb 0x200a4(%rax), %cl
movb 0x200a5(%rax), %al
andb $0x1, %cl
andb $0x1, %al
movsbl %dl, %edi
movzbl %cl, %esi
movzbl %al, %edx
callq 0x802f0
movsbl %al, %eax
movl %eax, -0x2c(%rbp)
movl -0x50(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x50(%rbp)
movq -0x18(%rbp), %rcx
cmpl 0x1a8(%rcx), %eax
jl 0x81827
movq -0x18(%rbp), %rdi
addq $0x60, %rdi
movl -0x2c(%rbp), %eax
movb %al, -0x56(%rbp)
leaq -0x56(%rbp), %rsi
callq 0x82ff0
jmp 0x81829
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x818ea
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)
jne 0x8187b
movq -0x18(%rbp), %rdi
addq $0x150, %rdi            # imm = 0x150
callq 0x80250
movb $0x0, -0x1(%rbp)
jmp 0x81a1e
cmpl $0xd, -0x2c(%rbp)
je 0x81887
cmpl $0xa, -0x2c(%rbp)
jne 0x81889
jmp 0x818ea
movq -0x80(%rbp), %rax
movl -0x2c(%rbp), %ecx
movb %cl, %dl
movb 0x200a4(%rax), %cl
movb 0x200a5(%rax), %al
andb $0x1, %cl
andb $0x1, %al
movsbl %dl, %edi
movzbl %cl, %esi
movzbl %al, %edx
callq 0x802f0
movsbl %al, %eax
movl %eax, -0x2c(%rbp)
movl -0x50(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x50(%rbp)
movq -0x18(%rbp), %rcx
cmpl 0x1a8(%rcx), %eax
jl 0x818e5
movq -0x18(%rbp), %rdi
addq $0x60, %rdi
movl -0x2c(%rbp), %eax
movb %al, -0x57(%rbp)
leaq -0x57(%rbp), %rsi
callq 0x82ff0
jmp 0x81829
movq -0x18(%rbp), %rdi
addq $0x60, %rdi
movq -0x18(%rbp), %rax
movslq 0x1ac(%rax), %rsi
callq 0x830d0
movq -0x18(%rbp), %rdi
addq $0x60, %rdi
callq 0x2ef90
movq %rax, -0xa0(%rbp)
movq -0x18(%rbp), %rdi
callq 0x2ef90
movq %rax, %rcx
movq -0xa0(%rbp), %rax
cmpq %rcx, %rax
jae 0x81947
movq -0x18(%rbp), %rdi
addq $0x150, %rdi            # imm = 0x150
callq 0x80560
movb $0x0, -0x1(%rbp)
jmp 0x81a1e
movq -0x18(%rbp), %rdi
addq $0x60, %rdi
callq 0x2ef90
movq %rax, -0xa8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x2ef90
movq %rax, %rcx
movq -0xa8(%rbp), %rax
cmpq %rcx, %rax
jbe 0x8198c
movq -0x18(%rbp), %rdi
addq $0x150, %rdi            # imm = 0x150
callq 0x805e0
movb $0x0, -0x1(%rbp)
jmp 0x81a1e
jmp 0x8198e
jmp 0x81990
movq -0x18(%rbp), %rdi
addq $0x150, %rdi            # imm = 0x150
callq 0x2e700
testb $0x1, %al
jne 0x819a6
jmp 0x819cf
movq -0x28(%rbp), %rax
movq %rax, -0x78(%rbp)
leaq -0x70(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x82eb0
movq -0x18(%rbp), %rdi
addq $0x150, %rdi            # imm = 0x150
leaq -0x70(%rbp), %rsi
callq 0x83250
movq -0x18(%rbp), %rax
movb $0x1, 0x190(%rax)
movq -0x20(%rbp), %rax
testb $0x1, 0x190(%rax)
jne 0x81a1a
movq -0x20(%rbp), %rdi
addq $0x120, %rdi            # imm = 0x120
callq 0x82fb0
cmpq $0x0, %rax
jbe 0x81a1a
movq -0x80(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq (%rdi), %rax
callq *0x18(%rax)
andb $0x1, %al
movb %al, -0x1(%rbp)
jmp 0x81a1e
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax)