// File: /workspace/github_cpp_makefile_star2_O3/BenLangmead[P]bowtie/pat.cpp
// Function: DualPatternComposer::nextBatch(PerThreadReadBuf&)
pair<bool, int> DualPatternComposer::nextBatch(PerThreadReadBuf& pt) {
	// 'cur' indexes the current pair of PatternSources
	uint32_t cur = cur_;
	while(cur < srca_.size()) {
		if(srcb_[cur] == NULL) {
			pair<bool, int> res = srca_[cur]->nextBatch(
				pt,
				true,  // batch A (or pairs)
				true); // grab lock below
			bool done = res.first;
			if(!done && res.second == 0) {
				ThreadSafe ts(&mutex_m);
				if(cur + 1 > cur_) cur_++;
				cur = cur_; // Move on to next PatternSource
				continue; // on to next pair of PatternSources
			}
			return make_pair(done, res.second);
		} else {
			pair<bool, int> resa, resb;
			// Lock to ensure that this thread gets parallel reads
			// in the two mate files
			{
				ThreadSafe ts(&mutex_m);
				resa = srca_[cur]->nextBatch(
					pt,
					true,   // batch A
					false); // don't grab lock below
				resb = srcb_[cur]->nextBatch(
					pt,
					false,  // batch B
					false); // don't grab lock below
				assert_eq(srca_[cur]->readCount(),
					  srcb_[cur]->readCount());
			}
			if(resa.second < resb.second) {
				cerr << "Error, fewer reads in file specified with -1 "
					 << "than in file specified with -2" << endl;
				throw 1;
			} else if(resa.second == 0 && resb.second == 0) {
				ThreadSafe ts(&mutex_m);
				if(cur + 1 > cur_) {
					cur_++;
				}
				cur = cur_; // Move on to next PatternSource
				continue; // on to next pair of PatternSources
			} else if(resb.second < resa.second) {
				cerr << "Error, fewer reads in file specified with -2 "
					 << "than in file specified with -1" << endl;
				throw 1;
			}
			assert_eq(resa.first, resb.first);
			assert_eq(resa.second, resb.second);
			return make_pair(resa.first, resa.second);
		}
	}
	assert_leq(cur, srca_.size());
	return make_pair(true, 0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl 0xc(%rdi), %ebp
movl $0x1, %eax
cmpq %rbp, 0x28(%rdi)
jbe 0x4b195
movq %rsi, %r15
movq %rdi, %r12
leaq 0x8(%rdi), %rbx
movl %ebp, %r14d
movq 0x38(%r12), %rax
cmpq $0x0, (%rax,%rbp,8)
je 0x4b110
movq %rbx, %rdi
callq 0x4ac58
movq 0x18(%r12), %rax
movq (%rax,%rbp,8), %rdi
movq (%rdi), %rax
movq %r15, %rsi
movl $0x1, %edx
xorl %ecx, %ecx
callq *0x10(%rax)
movq %rax, %r13
movq 0x38(%r12), %rax
movq (%rax,%rbp,8), %rdi
movq (%rdi), %rax
movq %r15, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq *0x10(%rax)
movq %rax, %rbp
movq %rbx, %rdi
callq 0x4ac94
movq %r13, %rax
shrq $0x20, %rax
shrq $0x20, %rbp
cmpl %ebp, %eax
jl 0x4b1a4
movl %ebp, %ecx
orl %eax, %ecx
jne 0x4b172
movq %rbx, %rdi
callq 0x4ac58
incl %r14d
cmpl 0xc(%r12), %r14d
jbe 0x4b101
incl 0xc(%r12)
movl 0xc(%r12), %r14d
movq %rbx, %rdi
callq 0x4ac94
jmp 0x4b15d
movq 0x18(%r12), %rax
movq (%rax,%rbp,8), %rdi
movq (%rdi), %rax
movq %r15, %rsi
movl $0x1, %edx
movl $0x1, %ecx
callq *0x10(%rax)
movq %rax, %rcx
shrq $0x20, %rcx
jne 0x4b188
testb $0x1, %al
jne 0x4b188
movq %rbx, %rdi
callq 0x4ac58
incl %r14d
cmpl 0xc(%r12), %r14d
jbe 0x4b150
incl 0xc(%r12)
movl 0xc(%r12), %r14d
movq %rbx, %rdi
callq 0x4ac94
movl %r14d, %ebp
cmpq %rbp, 0x28(%r12)
ja 0x4b078
movl $0x1, %eax
jmp 0x4b195
cmpl %eax, %ebp
jl 0x4b1ef
movabsq $-0xffffff01, %rax      # imm = 0xFFFFFFFF000000FF
andq %rax, %r13
movq %r13, %rax
jmp 0x4b195
movabsq $-0xffffff01, %rcx      # imm = 0xFFFFFFFF000000FF
andq %rcx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1ee45(%rip), %rdi     # 0x69ff0
leaq 0xbde8(%rip), %rsi      # 0x56f9a
callq 0x9490
leaq 0xbe0a(%rip), %rsi      # 0x56fc8
movq %rax, %rdi
callq 0x9490
movq %rax, %rdi
callq 0x91f0
movl $0x4, %edi
callq 0x9200
movl $0x1, (%rax)
movq 0x1ed53(%rip), %rsi     # 0x69f38
movq %rax, %rdi
xorl %edx, %edx
callq 0x98f0
movq 0x1edfa(%rip), %rdi     # 0x69ff0
leaq 0xbdea(%rip), %rsi      # 0x56fe7
callq 0x9490
leaq 0xbe0c(%rip), %rsi      # 0x57015
jmp 0x4b1be
jmp 0x4b226
jmp 0x4b226
jmp 0x4b226
jmp 0x4b213
movq %rax, %r14
movq %rbx, %rdi
callq 0x4ac94
movq %r14, %rdi
callq 0x9930
movq %rax, %rdi
callq 0x1afa3