// File: BenLangmead[P]bowtie/pat.cpp
// Function: VectorPatternSource::parse(Read&, Read&, unsigned long) const
bool VectorPatternSource::parse(Read& ra, Read& rb, TReadId rdid) const {
	// Very similar to TabbedPatternSource

	// Light parser (nextBatchFromFile) puts unparsed data
	// into Read& r, even when the read is paired.
	assert(ra.empty());
	assert(!ra.readOrigBuf.empty()); // raw data for read/pair is here
	int c = '\t';
	size_t cur = 0;
	const size_t buflen = ra.readOrigBuf.length();

	// 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 || paired_) {
			// 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;
		}

		// 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]); // ascii to int
				}
			}
			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;
		while(c != '\t' && c != '\n' && c != '\r') {
			if(c == ' ') {
				wrongQualityFormat(r.name);
				return false;
			}
			char cadd = charToPhred33(c, false, false);
			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;
	if(!rb.parsed && rb.readOrigBuf.length() > 0) {
		return parse(rb, ra, rdid);
	}
	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)
movl $0x0, -0x44(%rbp)
xorl %eax, %eax
cmpl $0x2, -0x44(%rbp)
movb %al, -0x71(%rbp)
jge 0x7fe72
cmpl $0x9, -0x2c(%rbp)
sete %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0x7fe7e
jmp 0x801ec
cmpl $0x0, -0x44(%rbp)
jne 0x7fe8e
movq -0x18(%rbp), %rax
movq %rax, -0x80(%rbp)
jmp 0x7fe96
movq -0x20(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpl $0x1, -0x44(%rbp)
jl 0x7feb2
movq -0x70(%rbp), %rax
testb $0x1, 0x28(%rax)
je 0x7ff58
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 0x7fef6
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
setb %al
movb %al, -0x81(%rbp)
movb -0x81(%rbp), %al
testb $0x1, %al
jne 0x7ff02
jmp 0x7ff43
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 0x7fed7
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jb 0x7ff56
movb $0x0, -0x1(%rbp)
jmp 0x8023b
jmp 0x7ff7b
cmpl $0x0, -0x44(%rbp)
jle 0x7ff79
movq -0x18(%rbp), %rsi
addq $0x150, %rsi            # imm = 0x150
movq -0x20(%rbp), %rdi
addq $0x150, %rdi            # imm = 0x150
callq 0x2e7e0
jmp 0x7ff7b
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 0x7ffc6
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
setb %al
movb %al, -0x82(%rbp)
movb -0x82(%rbp), %al
testb $0x1, %al
jne 0x7ffd2
jmp 0x8003d
movl -0x2c(%rbp), %edi
callq 0xaa30
cmpl $0x0, %eax
je 0x80013
movq -0x70(%rbp), %rcx
movl -0x58(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x58(%rbp)
cmpl 0x18(%rcx), %eax
jl 0x80011
movq -0x50(%rbp), %rdi
movslq -0x2c(%rbp), %rcx
leaq 0x2a6ae(%rip), %rax     # 0xaa6b0
movb (%rax,%rcx), %al
movb %al, -0x59(%rbp)
leaq -0x59(%rbp), %rsi
callq 0x83060
jmp 0x80013
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 0x7ffa7
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jb 0x80050
movb $0x0, -0x1(%rbp)
jmp 0x8023b
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
movsbl (%rax), %eax
movl %eax, -0x2c(%rbp)
movl $0x0, -0x60(%rbp)
xorl %eax, %eax
cmpl $0x9, -0x2c(%rbp)
movb %al, -0x91(%rbp)
je 0x800ef
xorl %eax, %eax
cmpl $0xa, -0x2c(%rbp)
movb %al, -0x91(%rbp)
je 0x800ef
cmpl $0xd, -0x2c(%rbp)
setne %al
movb %al, -0x91(%rbp)
movb -0x91(%rbp), %al
testb $0x1, %al
jne 0x800fe
jmp 0x80188
cmpl $0x20, -0x2c(%rbp)
jne 0x8011d
movq -0x50(%rbp), %rdi
addq $0x150, %rdi            # imm = 0x150
callq 0x80250
movb $0x0, -0x1(%rbp)
jmp 0x8023b
movl -0x2c(%rbp), %eax
xorl %edx, %edx
movsbl %al, %edi
movl %edx, %esi
callq 0x802f0
movq -0x70(%rbp), %rcx
movb %al, -0x61(%rbp)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
cmpl 0x18(%rcx), %eax
jle 0x80152
movq -0x50(%rbp), %rdi
addq $0x60, %rdi
leaq -0x61(%rbp), %rsi
callq 0x82ff0
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jb 0x8015e
jmp 0x80188
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 0x800c6
movl -0x58(%rbp), %eax
cmpl -0x60(%rbp), %eax
jle 0x801a9
movq -0x50(%rbp), %rdi
addq $0x150, %rdi            # imm = 0x150
callq 0x80560
movb $0x0, -0x1(%rbp)
jmp 0x8023b
movl -0x60(%rbp), %eax
cmpl -0x58(%rbp), %eax
jle 0x801c7
movq -0x50(%rbp), %rdi
addq $0x150, %rdi            # imm = 0x150
callq 0x805e0
movb $0x0, -0x1(%rbp)
jmp 0x8023b
jmp 0x801c9
movq -0x70(%rbp), %rax
movq -0x50(%rbp), %rdi
addq $0x60, %rdi
movslq 0x14(%rax), %rsi
callq 0x830d0
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x7fe5d
movq -0x18(%rbp), %rax
movb $0x1, 0x190(%rax)
movq -0x20(%rbp), %rax
testb $0x1, 0x190(%rax)
jne 0x80237
movq -0x20(%rbp), %rdi
addq $0x120, %rdi            # imm = 0x120
callq 0x82fb0
cmpq $0x0, %rax
jbe 0x80237
movq -0x70(%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 0x8023b
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax)