// File: /workspace/github_cpp_makefile_star2_O1/BenLangmead[P]bowtie/pat.cpp
// Function: FastaContinuousPatternSource::nextBatchFromFile(PerThreadReadBuf&, bool, unsigned long)
pair<bool, int> FastaContinuousPatternSource::nextBatchFromFile(
	PerThreadReadBuf& pt,
	bool batch_a,
	size_t readi)
{
	int c = -1;
	EList<Read>& readbuf = batch_a ? pt.bufa_ : pt.bufb_;
	while(readi < pt.max_buf_) {
		c = getc_wrapper();
		if(c < 0) {
			break;
		}
		if(c == '>') {
			resetForNextFile();
			c = getc_wrapper();
			bool sawSpace = false;
			while(c != '\n' && c != '\r') {
				if(!sawSpace) {
					sawSpace = isspace(c);
				}
				if(!sawSpace) {
					// Put it in the name prefix buffer so we
					// can re-use this prefix for all the reads
					// that are substrings of this FASTA sequence
					name_prefix_buf_.push_back(c);
				}
				c = getc_wrapper();
			}
			while(c == '\n' || c == '\r') {
				c = getc_wrapper();
			}
			if(c < 0) {
				break;
			}
			name_prefix_buf_.push_back('_');
		}
		int cat = asc2dnacat[c];
		if(cat >= 2) c = 'N';
		if(cat == 0) {
			// Non-DNA, non-IUPAC char; skip
			continue;
		} else {
			// DNA char
			buf_[bufCur_++] = c;
			if(bufCur_ == 1024) {
				bufCur_ = 0; // wrap around circular buf
			}
			if(eat_ > 0) {
				eat_--;
				// Try to keep readCnt_ aligned with the offset
				// into the reference; that lets us see where
				// the sampling gaps are by looking at the read
				// name
				if(!beginning_) {
					cur_++;
				}
				continue;
			}
			// install name
			readbuf[readi].readOrigBuf.append(name_prefix_buf_.c_str());
			itoa10<TReadId>(cur_ - last_, name_int_buf_);
			readbuf[readi].readOrigBuf.append(name_int_buf_);
			readbuf[readi].readOrigBuf.append('\t');
			// install sequence
			for(size_t i = 0; i < length_; i++) {
				if(length_ - i <= bufCur_) {
					c = buf_[bufCur_ - (length_ - i)];
				} else {
					// Rotate
					c = buf_[bufCur_ - (length_ - i) + 1024];
				}
				readbuf[readi].readOrigBuf.append(c);
			}
			eat_ = freq_-1;
			cur_++;
			beginning_ = false;
			readi++;
		}
	}
	return make_pair(c < 0, readi);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, %r12
movl $0x1, %r13d
cmpq %rcx, (%rsi)
jbe 0x4dcbc
movq %rsi, %r14
movq %rdi, %r15
xorb $0x1, %dl
movzbl %dl, %ebp
shll $0x5, %ebp
orq $0x8, %rbp
leaq 0x204c8(%rdi), %rax
movq %rax, 0x20(%rsp)
leaq 0x204e8(%rdi), %rax
movq %rax, 0x40(%rsp)
leaq 0x204e7(%rdi), %rax
movq %rax, 0x38(%rsp)
leaq 0x204e9(%rdi), %rax
movq %rax, 0x30(%rsp)
movq %rbp, 0x10(%rsp)
movq %r15, %rdi
callq 0x4f0ba
movl %eax, %r13d
testl %eax, %eax
js 0x4dcb8
cmpl $0x3e, %r13d
jne 0x4da56
movq (%r15), %rax
movq %r15, %rdi
callq *0x38(%rax)
xorl %ebx, %ebx
movq %r15, %rdi
callq 0x4f0ba
movl %eax, %r13d
cmpl $0xd, %eax
je 0x4da32
cmpl $0xa, %r13d
je 0x4da32
testb $0x1, %bl
jne 0x4da12
movl %r13d, %edi
callq 0x9080
testl %eax, %eax
setne %bl
testb $0x1, %bl
jne 0x4d9ea
movsbl %r13b, %esi
movq 0x20(%rsp), %rdi
callq 0x9400
jmp 0x4d9ea
movq %r15, %rdi
callq 0x4f0ba
movl %eax, %r13d
cmpl $0xd, %r13d
je 0x4da27
cmpl $0xa, %r13d
je 0x4da27
testl %r13d, %r13d
js 0x4dcb8
movq 0x20(%rsp), %rdi
movl $0x5f, %esi
callq 0x9400
movl %r13d, %eax
leaq 0x1fcf0(%rip), %rcx     # 0x6d750
movb (%rcx,%rax), %al
cmpb $0x2, %al
movl $0x4e, %ecx
cmovael %ecx, %r13d
testb %al, %al
je 0x4dcaf
movq 0x20500(%r15), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x20500(%r15)
movb %r13b, 0x200c1(%r15,%rax)
cmpq $0x400, 0x20500(%r15) # imm = 0x400
jne 0x4daa8
movq $0x0, 0x20500(%r15)
movq 0x200b8(%r15), %rax
testq %rax, %rax
je 0x4dad8
decq %rax
movq %rax, 0x200b8(%r15)
cmpb $0x0, 0x200c0(%r15)
jne 0x4dcaf
incq 0x20508(%r15)
jmp 0x4dcaf
movq 0x8(%r14,%rbp), %rax
imulq $0x268, %r12, %rcx      # imm = 0x268
movq %rcx, 0x28(%rsp)
leaq (%rax,%rcx), %rbp
addq $0x120, %rbp            # imm = 0x120
movq 0x204c8(%r15), %rbx
movq %rbx, %rdi
callq 0x91b0
movq %rbp, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x4f95a
movq 0x20508(%r15), %rcx
subq 0x20510(%r15), %rcx
movl $0x204e7, %edi          # imm = 0x204E7
movq 0x38(%rsp), %rsi
leaq 0xa8cc(%rip), %r9       # 0x583fc
movabsq $-0x3333333333333333, %r10 # imm = 0xCCCCCCCCCCCCCCCD
movq %rcx, %rax
mulq %r10
shrq $0x3, %rdx
leaq (%rdx,%rdx), %rax
leaq (%rax,%rax,4), %rax
movq %rcx, %r8
subq %rax, %r8
movb (%r9,%r8), %al
movb %al, 0x1(%rsi)
incq %rsi
incq %rdi
cmpq $0x9, %rcx
movq %rdx, %rcx
ja 0x4db3a
movq %r12, 0x18(%rsp)
cmpq $0x204e9, %rdi          # imm = 0x204E9
jb 0x4db99
movq 0x30(%rsp), %rax
movq %rsi, %rcx
movb -0x1(%rax), %dl
movb (%rcx), %dil
movb %dil, -0x1(%rax)
movb %dl, (%rcx)
decq %rcx
leaq 0x1(%rax), %rdx
cmpq %rcx, %rax
movq %rdx, %rax
jb 0x4db7e
movb $0x0, 0x1(%rsi)
movq %r14, %rbp
movq 0x10(%rsp), %rax
movq 0x8(%r14,%rax), %rbx
movq 0x28(%rsp), %r14
addq %r14, %rbx
movl $0x120, %eax            # imm = 0x120
addq %rax, %rbx
movq 0x40(%rsp), %r12
movq %r12, %rdi
callq 0x91b0
movq %rbx, %rdi
movq %r14, %rbx
movq %r12, %rsi
movq %rax, %rdx
callq 0x4f95a
movq 0x10(%rsp), %rax
movq 0x8(%rbp,%rax), %rdi
movq %rbp, %r14
addq %rbx, %rdi
movl $0x120, %eax            # imm = 0x120
addq %rax, %rdi
movb $0x9, 0xf(%rsp)
leaq 0xf(%rsp), %rsi
callq 0x4f10a
movq 0x200a8(%r15), %rax
testq %rax, %rax
movq 0x18(%rsp), %r12
je 0x4dc87
xorl %ebx, %ebx
xorl %r12d, %r12d
movq %r14, %rbp
movq 0x10(%rsp), %r14
movq 0x20500(%r15), %rcx
movq %rcx, %rdx
subq %rax, %rdx
addq %rbx, %rax
leaq (%r12,%rdx), %rsi
cmpq %rcx, %rax
leaq 0x400(%r12,%rdx), %rax
cmovbeq %rsi, %rax
movsbl 0x200c1(%r15,%rax), %r13d
movq 0x8(%rbp,%r14), %rax
movq 0x28(%rsp), %rcx
leaq (%rax,%rcx), %rdi
addq $0x120, %rdi            # imm = 0x120
movb %r13b, 0xe(%rsp)
leaq 0xe(%rsp), %rsi
callq 0x4f10a
incq %r12
movq 0x200a8(%r15), %rax
decq %rbx
cmpq %rax, %r12
jb 0x4dc1d
movq 0x18(%rsp), %r12
movq %rbp, %r14
movq 0x200b0(%r15), %rax
decq %rax
movq %rax, 0x200b8(%r15)
incq 0x20508(%r15)
movb $0x0, 0x200c0(%r15)
incq %r12
movq 0x10(%rsp), %rbp
cmpq (%r14), %r12
jb 0x4d9c6
shrl $0x1f, %r13d
shlq $0x20, %r12
orq %r13, %r12
movq %r12, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop