// File: BenLangmead[P]bowtie/pat.cpp
// Function: FastaPatternSource::parse(Read&, Read&, unsigned long) const
bool FastaPatternSource::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 = -1;
	size_t cur = 1;
	const size_t buflen = r.readOrigBuf.length();

	// Parse read name
	assert(r.name.empty());
	while(cur < buflen) {
		c = r.readOrigBuf[cur++];
		if(c == '\n' || c == '\r') {
			do {
				c = r.readOrigBuf[cur++];
			} while((c == '\n' || c == '\r') && cur < buflen);
			break;
		}
		r.name.append(c);
	}
	if(cur >= buflen) {
		return false; // FASTA ended prematurely
	}

	// Parse sequence
	int nchar = 0;
	assert(r.patFw.empty());
	assert(c != '\n' && c != '\r');
	assert_lt(cur, buflen);
	while(c != '\n' && 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_));

	for(size_t i = 0; i < r.patFw.length(); i++) {
		r.qual.append('I');
	}

	// 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 $0xa0, %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)
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
movq $0x1, -0x38(%rbp)
movq -0x18(%rbp), %rdi
addq $0x120, %rdi            # imm = 0x120
callq 0x82fb0
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x8097c
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 0x80905
cmpl $0xd, -0x2c(%rbp)
jne 0x8095d
jmp 0x80907
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 0x80940
xorl %eax, %eax
cmpl $0xd, -0x2c(%rbp)
movb %al, -0x81(%rbp)
jne 0x80951
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
setb %al
movb %al, -0x81(%rbp)
movb -0x81(%rbp), %al
testb $0x1, %al
jne 0x80907
jmp 0x8097c
movq -0x18(%rbp), %rdi
addq $0x150, %rdi            # imm = 0x150
movl -0x2c(%rbp), %eax
movb %al, -0x41(%rbp)
leaq -0x41(%rbp), %rsi
callq 0x82ff0
jmp 0x808c6
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jb 0x8098f
movb $0x0, -0x1(%rbp)
jmp 0x80b5f
movl $0x0, -0x48(%rbp)
xorl %eax, %eax
cmpl $0xa, -0x2c(%rbp)
movb %al, -0x82(%rbp)
je 0x809b5
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
setb %al
movb %al, -0x82(%rbp)
movb -0x82(%rbp), %al
testb $0x1, %al
jne 0x809c1
jmp 0x80a39
cmpl $0x2e, -0x2c(%rbp)
jne 0x809ce
movl $0x4e, -0x2c(%rbp)
movl -0x2c(%rbp), %edi
callq 0xaa30
cmpl $0x0, %eax
je 0x80a0f
movq -0x80(%rbp), %rcx
movl -0x48(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x48(%rbp)
cmpl 0x18(%rcx), %eax
jl 0x80a0d
movq -0x18(%rbp), %rdi
movslq -0x2c(%rbp), %rcx
leaq 0x29cb2(%rip), %rax     # 0xaa6b0
movb (%rax,%rcx), %al
movb %al, -0x49(%rbp)
leaq -0x49(%rbp), %rsi
callq 0x83060
jmp 0x80a0f
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 0x80996
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 $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x18(%rbp), %rdi
callq 0x2ef90
movq %rax, %rcx
movq -0x98(%rbp), %rax
cmpq %rcx, %rax
jae 0x80ad1
movq -0x18(%rbp), %rdi
addq $0x60, %rdi
movb $0x49, -0x59(%rbp)
leaq -0x59(%rbp), %rsi
callq 0x82ff0
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x80a8b
movq -0x18(%rbp), %rdi
addq $0x150, %rdi            # imm = 0x150
callq 0x2e700
testb $0x1, %al
jne 0x80ae7
jmp 0x80b10
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 0x80b5b
movq -0x20(%rbp), %rdi
addq $0x120, %rdi            # imm = 0x120
callq 0x82fb0
cmpq $0x0, %rax
jbe 0x80b5b
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 0x80b5f
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax)