// File: /workspace/github_cpp_makefile_star2_O2/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
subq $0x18, %rsp
movq %rsi, %rbp
movq %rdi, %r15
movl 0xc(%rdi), %ebx
leaq 0x8(%rdi), %r14
movq %r14, 0x10(%rsp)
movl %ebx, %r13d
cmpq %r13, 0x28(%r15)
jbe 0x41307
movq 0x38(%r15), %rax
cmpq $0x0, (%rax,%r13,8)
je 0x412b7
movq %r14, 0x8(%rsp)
movq %r14, %rdi
callq 0x40dda
movq 0x18(%r15), %rax
movq (%rax,%r13,8), %rdi
movq (%rdi), %rax
movq %rbp, %rsi
pushq $0x1
popq %rdx
xorl %ecx, %ecx
callq *0x10(%rax)
movq %rax, %r14
movq 0x38(%r15), %rax
movq (%rax,%r13,8), %rdi
movq (%rdi), %rax
movq %rbp, %r12
movq %rbp, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq *0x10(%rax)
movq %rax, %rbp
movq %r14, %rbx
shrq $0x20, %rbx
shrq $0x20, %rbp
leaq 0x8(%rsp), %rdi
callq 0x1a9ee
cmpl %ebp, %ebx
jl 0x4133e
movl %ebp, %eax
orl %ebx, %eax
jne 0x4130c
movq 0x10(%rsp), %r14
movq %r14, 0x8(%rsp)
movq %r14, %rdi
callq 0x40dda
incl %r13d
cmpl 0xc(%r15), %r13d
jbe 0x412a1
incl 0xc(%r15)
movl 0xc(%r15), %ebx
leaq 0x8(%rsp), %rdi
callq 0x1a9ee
movq %r12, %rbp
jmp 0x411fe
movq 0x18(%r15), %rax
movq (%rax,%r13,8), %rdi
movq (%rdi), %rax
movq %rbp, %rsi
pushq $0x1
popq %rcx
movl %ecx, %edx
callq *0x10(%rax)
movq %rax, %rcx
shrq $0x20, %rcx
jne 0x41322
testb $0x1, %al
jne 0x41322
movq %r14, 0x8(%rsp)
movq %r14, %rdi
callq 0x40dda
incl %r13d
cmpl 0xc(%r15), %r13d
jbe 0x412f4
incl 0xc(%r15)
movl 0xc(%r15), %ebx
leaq 0x8(%rsp), %rdi
callq 0x1a9ee
jmp 0x411fe
pushq $0x1
popq %rax
jmp 0x4132f
cmpl %ebx, %ebp
jl 0x41387
movabsq $-0xffffff01, %rax      # imm = 0xFFFFFFFF000000FF
andq %rax, %r14
movq %r14, %rax
jmp 0x4132f
movabsq $-0xffffff01, %rcx      # imm = 0xFFFFFFFF000000FF
andq %rcx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20cab(%rip), %rdi     # 0x61ff0
leaq 0xab8c(%rip), %rsi      # 0x4bed8
callq 0x94e0
leaq 0xabae(%rip), %rsi      # 0x4bf06
movq %rax, %rdi
callq 0x94e0
movq %rax, %rdi
callq 0x9210
pushq $0x4
popq %rdi
callq 0x9220
movl $0x1, (%rax)
movq 0x20bdb(%rip), %rsi     # 0x61f58
movq %rax, %rdi
xorl %edx, %edx
callq 0x9910
movq 0x20c62(%rip), %rdi     # 0x61ff0
leaq 0xab90(%rip), %rsi      # 0x4bf25
callq 0x94e0
leaq 0xabb2(%rip), %rsi      # 0x4bf53
jmp 0x41358
jmp 0x413a5
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x1a9ee
movq %rbx, %rdi
callq 0x9950